This commit is contained in:
aozhiwei 2023-02-23 12:03:41 +08:00
parent bc6c1bdf3c
commit a82513cd61
6 changed files with 75 additions and 7 deletions

View File

@ -14,6 +14,16 @@ struct GraspBuff
list_head entry; list_head entry;
std::tuple<const mt::GraspBuff*, const mt::GraspBuff*> buffs; std::tuple<const mt::GraspBuff*, const mt::GraspBuff*> buffs;
std::function<void()> on_remove; std::function<void()> on_remove;
void ProcSignet(GunGrasp* gun_grasp, int count)
{
const mt::GraspBuff* buff1_meta = std::get<0>(buffs);
const mt::GraspBuff* buff2_meta = std::get<1>(buffs);
if (buff1_meta && buff2_meta) {
gun_grasp->AddSignet(buff1_meta->graspbuff_id(), count);
}
}
}; };
GunGrasp::GunGrasp(Creature* owner) GunGrasp::GunGrasp(Creature* owner)
@ -92,9 +102,9 @@ void GunGrasp::ProcHit(GraspBuff* buff)
owner_->GetTrigger()->AddListener owner_->GetTrigger()->AddListener
( (
kBulletHitEvent, kBulletHitEvent,
[] (const a8::Args& args) [this, buff] (const a8::Args& args)
{ {
buff->ProcSignet(this, 1);
}); });
} }
@ -103,15 +113,15 @@ void GunGrasp::ProcKill(GraspBuff* buff)
owner_->GetTrigger()->AddListener owner_->GetTrigger()->AddListener
( (
kKillEvent, kKillEvent,
[] (const a8::Args& args) [this, buff] (const a8::Args& args)
{ {
buff->ProcSignet(this, 1);
}); });
} }
void GunGrasp::ProcTakeOn(GraspBuff* buff) void GunGrasp::ProcTakeOn(GraspBuff* buff)
{ {
buff->ProcSignet(this, 1);
} }
void GunGrasp::ProcCond(GraspBuff* buff) void GunGrasp::ProcCond(GraspBuff* buff)
@ -124,8 +134,29 @@ void GunGrasp::ProcHitAndEnd(GraspBuff* buff)
owner_->GetTrigger()->AddListener owner_->GetTrigger()->AddListener
( (
kBulletHitEvent, kBulletHitEvent,
[] (const a8::Args& args) [this, buff] (const a8::Args& args)
{ {
buff->ProcSignet(this, 1);
}); });
} }
void GunGrasp::AddSignet(int id, int count)
{
auto itr = signet_hash_.find(id);
if (itr != signet_hash_.end()) {
itr->second += count;
} else {
signet_hash_[id] = count;
}
}
int GunGrasp::GetSignetCount(int id)
{
auto itr = signet_hash_.find(id);
return itr != signet_hash_.end() ? itr->second : 0;
}
bool GunGrasp::HasBulletBlockBuff()
{
return !list_empty(&grasp_triggers_[(int)GraspBuffTrigger_e::kHitAndEnd]);
}

View File

@ -10,6 +10,8 @@ class GunGrasp
void Clear(); void Clear();
void InstallTriggers(); void InstallTriggers();
void AddSignet(int id, int count);
bool HasBulletBlockBuff();
private: private:
void ProcHit(GraspBuff* buff); void ProcHit(GraspBuff* buff);
@ -18,7 +20,10 @@ class GunGrasp
void ProcCond(GraspBuff* buff); void ProcCond(GraspBuff* buff);
void ProcHitAndEnd(GraspBuff* buff); void ProcHitAndEnd(GraspBuff* buff);
int GetSignetCount(int id);
private: private:
Creature* owner_ = nullptr; Creature* owner_ = nullptr;
std::map<int, int> signet_hash_;
std::array<list_head, (int)GraspBuffTrigger_e::kEnd> grasp_triggers_ = {}; std::array<list_head, (int)GraspBuffTrigger_e::kEnd> grasp_triggers_ = {};
}; };

View File

@ -67,4 +67,24 @@ namespace mt
} }
int GraspBuff::GetBuffTime(int hero_lv)
{
switch (hero_lv) {
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
{
return _buff_times.size() > 1 ? _buff_times.at(1) :_buff_times.at(0);
}
default:
{
return _buff_times.at(0);
}
break;
}
}
} }

View File

@ -17,6 +17,11 @@ namespace mt
int _trigger_type = 0; int _trigger_type = 0;
int _trigger_subtype = 0; int _trigger_subtype = 0;
std::vector<int> _trigger_cond; std::vector<int> _trigger_cond;
int GetBuffTime(int hero_lv);
private:
std::vector<int> _buff_times;
}; };
} }

View File

@ -491,3 +491,8 @@ void Trigger::DmgOut(Creature* target, float dmg)
{ {
DispatchEvent(kDmgOutEvent, {target, dmg}); DispatchEvent(kDmgOutEvent, {target, dmg});
} }
void Trigger::BulletBlock(IBullet* bullet, const glm::vec3& pos)
{
DispatchEvent(kBulletBlockEvent, {bullet, pos});
}

View File

@ -24,6 +24,7 @@ enum EventId_e
kShieldDestoryEvent, kShieldDestoryEvent,
kFlyHookPullEvent, kFlyHookPullEvent,
kBulletHitEvent, kBulletHitEvent,
kBulletBlockEvent,
kYsRemoveEvent, kYsRemoveEvent,
kStartRescueEvent, kStartRescueEvent,
kEndRescueEvent, kEndRescueEvent,
@ -75,6 +76,7 @@ public:
void BulletHitBuff(Bullet* bullet); void BulletHitBuff(Bullet* bullet);
void Attacked(Creature* sender); void Attacked(Creature* sender);
void DmgOut(Creature* target, float dmg); void DmgOut(Creature* target, float dmg);
void BulletBlock(IBullet* bullet, const glm::vec3& pos);
std::weak_ptr<EventHandlerPtr> AddListener(int event_id, a8::CommonCbProc cb); std::weak_ptr<EventHandlerPtr> AddListener(int event_id, a8::CommonCbProc cb);
void RemoveEventHandler(std::weak_ptr<EventHandlerPtr> handler_ptr); void RemoveEventHandler(std::weak_ptr<EventHandlerPtr> handler_ptr);