63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
#include "precompile.h"
|
|
|
|
#include "gungrasp.h"
|
|
#include "creature.h"
|
|
#include "battledatacontext.h"
|
|
#include "trigger.h"
|
|
#include "room.h"
|
|
#include "effect.h"
|
|
#include "weapon.h"
|
|
#include "human.h"
|
|
|
|
#include "mt/GraspBuff.h"
|
|
#include "mt/Grasp.h"
|
|
#include "mt/Hero.h"
|
|
#include "mt/Equip.h"
|
|
|
|
GunGrasp::GunGrasp(Creature* owner)
|
|
{
|
|
owner_ = owner;
|
|
}
|
|
|
|
GunGrasp::~GunGrasp()
|
|
{
|
|
}
|
|
|
|
void GunGrasp::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 GunGrasp::Clear()
|
|
{
|
|
for (int buff_uniid : hold_buffs_) {
|
|
owner_->RemoveBuffByUniId(buff_uniid);
|
|
}
|
|
hold_buffs_.clear();
|
|
}
|
|
|
|
void GunGrasp::TakeOnWeapon(Weapon* weapon)
|
|
{
|
|
std::set<int>* buffs = mt::Grasp::GetBuffs(owner_->AsHuman()->meta->id(),
|
|
owner_->GetBattleContext()->GetHeroLevel(),
|
|
weapon->meta->id());
|
|
Clear();
|
|
if (buffs) {
|
|
for (int buff_id : *buffs) {
|
|
owner_->TryAddBuff(owner_, buff_id, nullptr);
|
|
}
|
|
}
|
|
}
|