aozhiwei 1cfa2fd7b5 1
2023-05-26 17:21:28 +08:00

90 lines
1.8 KiB
C++

#include "precompile.h"
#include "compose.h"
#include "creature.h"
#include "netdata.h"
#include "trigger.h"
#include "room.h"
#include "effect.h"
#include "weapon.h"
#include "human.h"
#include "mt/MergeItem.h"
#include "mt/Hero.h"
#include "mt/Equip.h"
Compose::Compose(Creature* owner)
{
owner_ = owner;
}
Compose::~Compose()
{
}
void Compose::Init()
{
if (owner_->IsPlayer()) {
TakeOnWeapon(owner_->GetCurrWeapon());
owner_->GetTrigger()->AddListener
(
kTakeonWeaponEvent,
[this] (const a8::Args& args) mutable
{
Weapon* old_weapon = args.Get<Weapon*>(0);
Weapon* new_weapon = args.Get<Weapon*>(1);
TakeOnWeapon(new_weapon);
}
);
}
}
void Compose::Clear()
{
for (int buff_uniid : hold_buffs_) {
owner_->RemoveBuffByUniId(buff_uniid);
}
hold_buffs_.clear();
}
bool Compose::CanAdd()
{
return GetNum() < 8;
}
void Compose::IncNum()
{
++num_;
if ((num_ + 1) % 3 == 0 && num_ < 9) {
TakeOnWeapon(owner_->GetCurrWeapon());
}
if (num_ >= 8) {
owner_->room->NotifyNewsTicker
(1,
{
owner_->GetName(),
a8::XValue(owner_->GetCurrWeapon()->meta->id()).GetString()
});
}
}
void Compose::TakeOnWeapon(Weapon* weapon)
{
Clear();
auto merge_item_meta = mt::MergeItem::GetById(weapon->meta->id());
if (merge_item_meta) {
std::set<int>* buffs = merge_item_meta->GetBuffs((num_ + 1) / 3);
if (buffs) {
for (int buff_id : *buffs) {
hold_buffs_.push_back(owner_->TryAddBuff(owner_, buff_id, nullptr));
}
}
}
}
void Compose::Reset()
{
Clear();
num_ = 0;
}