77 lines
1.4 KiB
C++
77 lines
1.4 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() < 9;
|
|
}
|
|
|
|
void Compose::IncNum()
|
|
{
|
|
++num_;
|
|
}
|
|
|
|
void Compose::TakeOnWeapon(Weapon* weapon)
|
|
{
|
|
std::set<int>* buffs = mt::MergeItem::GetBuffs(weapon->meta->id(),
|
|
num_);
|
|
Clear();
|
|
if (buffs) {
|
|
for (int buff_id : *buffs) {
|
|
hold_buffs_.push_back(owner_->TryAddBuff(owner_, buff_id, nullptr));
|
|
}
|
|
}
|
|
}
|
|
|
|
void Compose::Reset()
|
|
{
|
|
Clear();
|
|
num_ = 0;
|
|
}
|