This commit is contained in:
aozhiwei 2023-03-17 11:42:29 +08:00
parent aeaaef4d4b
commit 395a2a1a88
3 changed files with 38 additions and 8 deletions

View File

@ -6,10 +6,13 @@
#include "trigger.h" #include "trigger.h"
#include "room.h" #include "room.h"
#include "effect.h" #include "effect.h"
#include "weapon.h"
#include "human.h"
#include "mt/GraspBuff.h" #include "mt/GraspBuff.h"
#include "mt/Grasp.h" #include "mt/Grasp.h"
#include "mt/Hero.h" #include "mt/Hero.h"
#include "mt/Equip.h"
GunGrasp::GunGrasp(Creature* owner) GunGrasp::GunGrasp(Creature* owner)
{ {
@ -22,11 +25,32 @@ GunGrasp::~GunGrasp()
void GunGrasp::Init() void GunGrasp::Init()
{ {
owner_->GetTrigger()->AddListener if (owner_->IsHuman()) {
( owner_->GetTrigger()->AddListener
kTakeonWeaponEvent, (
[this] (const a8::Args& args) mutable kTakeonWeaponEvent,
{ [this] (const a8::Args& args) mutable
} {
); Weapon* old_weapon = args.Get<Weapon*>(0);
Weapon* new_weapon = args.Get<Weapon*>(1);
std::set<int>* buffs = mt::Grasp::GetBuffs(owner_->AsHuman()->meta->id(),
owner_->GetBattleContext()->GetLevel(),
new_weapon->meta->id());
Clear();
if (buffs) {
for (int buff_id : *buffs) {
owner_->TryAddBuff(owner_, buff_id, nullptr);
}
}
}
);
}
}
void GunGrasp::Clear()
{
for (int buff_uniid : hold_buffs_) {
owner_->RemoveBuffByUniId(buff_uniid);
}
hold_buffs_.clear();
} }

View File

@ -4,6 +4,7 @@
struct GraspBuff; struct GraspBuff;
class Creature; class Creature;
class Weapon;
class GunGrasp class GunGrasp
{ {
public: public:
@ -12,6 +13,11 @@ class GunGrasp
void Init(); void Init();
private:
void Clear();
private: private:
Creature* owner_ = nullptr; Creature* owner_ = nullptr;
std::vector<int> hold_buffs_;
}; };

View File

@ -17,7 +17,7 @@ namespace mt
static void StaticPostInit(); static void StaticPostInit();
std::set<int>* GetBuffs(int hero_id, int hero_lv, int gun_id); static std::set<int>* GetBuffs(int hero_id, int hero_lv, int gun_id);
protected: protected:
static std::map<long long, std::tuple<int, std::set<int>>> hero_id_lv_gun_hash_; static std::map<long long, std::tuple<int, std::set<int>>> hero_id_lv_gun_hash_;