This commit is contained in:
aozhiwei 2023-03-24 17:10:20 +08:00
parent 38876e9ede
commit 490491df00
7 changed files with 53 additions and 1 deletions

View File

@ -55,10 +55,29 @@ void HoldShieldBuff::Activate()
}, },
&xtimer_attacher); &xtimer_attacher);
} }
handlers_.push_back(owner->GetTrigger()->AddListener
(
kDownedEvent,
[this] (const a8::Args& args)
{
if (owner->IsHuman()) {
owner->AsHuman()->ShiledBreak();
}
}));
handlers_.push_back(owner->GetTrigger()->AddListener
(
kDieEvent,
[this] (const a8::Args& args)
{
if (owner->IsHuman()) {
owner->AsHuman()->ShiledBreak();
}
}));
} }
void HoldShieldBuff::Deactivate() void HoldShieldBuff::Deactivate()
{ {
owner->GetTrigger()->RemoveEventHandlers(handlers_);
} }
void HoldShieldBuff::OnEnemyHit(Creature* enemy) void HoldShieldBuff::OnEnemyHit(Creature* enemy)

View File

@ -15,4 +15,5 @@ class HoldShieldBuff : public Buff
private: private:
float check_distance_ = 0.0f; float check_distance_ = 0.0f;
float check_interval_time_ = 0.0f; float check_interval_time_ = 0.0f;
std::vector<std::weak_ptr<EventHandlerPtr>> handlers_;
}; };

View File

@ -395,6 +395,7 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string killer_name, in
&xtimer_attacher); &xtimer_attacher);
SyncAroundPlayers(__FILE__, __LINE__, __func__); SyncAroundPlayers(__FILE__, __LINE__, __func__);
TryAddBuff(this, kDownBuffId); TryAddBuff(this, kDownBuffId);
GetTrigger()->Downed();
} else { } else {
BeKill(killer_id, killer_name, weapon_id, real_killer_id, real_killer_name); BeKill(killer_id, killer_name, weapon_id, real_killer_id, real_killer_name);
} }
@ -3336,3 +3337,15 @@ void Human::ProcLoveItem(AddItemDTO& dto)
} }
} }
} }
void Human::ShiledBreak()
{
Buff* hold_shield_buff = GetBuffByEffectId(kBET_HoldShield);
if (hold_shield_buff) {
GetTrigger()->ShieldDestory();
if (hold_shield_buff->meta->_buff_param1_int_list.size() > 0) {
TryAddBuff(this, hold_shield_buff->meta->_buff_param1_int_list[0]);
}
RemoveBuffByUniId(hold_shield_buff->buff_uniid);
}
}

View File

@ -255,6 +255,7 @@ class Human : public Creature
void CalcAssists(Human* target); void CalcAssists(Human* target);
void ProcThrowDmg(int throw_uniid); void ProcThrowDmg(int throw_uniid);
void CalcStats(); void CalcStats();
void ShiledBreak();
protected: protected:
void ProcLootWeapon(AddItemDTO& dto); void ProcLootWeapon(AddItemDTO& dto);

View File

@ -1386,6 +1386,9 @@ void Player::_CMRequestBulletDmg(f8::MsgHdr& hdr, const cs::CMRequestBulletDmg&
c->shield_hp_); c->shield_hp_);
if (c->shield_hp_ <= 0) { if (c->shield_hp_ <= 0) {
c->GetTrigger()->ShieldDestory(); c->GetTrigger()->ShieldDestory();
if (hold_shield_buff->meta->_buff_param1_int_list.size() > 0) {
TryAddBuff(this, hold_shield_buff->meta->_buff_param1_int_list[0]);
}
c->RemoveBuffByUniId(hold_shield_buff->buff_uniid); c->RemoveBuffByUniId(hold_shield_buff->buff_uniid);
} }
shield = true; shield = true;

View File

@ -438,6 +438,13 @@ void Trigger::RemoveEventHandler(std::weak_ptr<EventHandlerPtr> handler)
} }
} }
void Trigger::RemoveEventHandlers(std::vector<std::weak_ptr<EventHandlerPtr>> handlers)
{
for (auto handler : handlers) {
RemoveEventHandler(handler);
}
}
void Trigger::DispatchEvent(int event_id, const std::vector<std::any>& param) void Trigger::DispatchEvent(int event_id, const std::vector<std::any>& param)
{ {
auto itr = listeners_hash_.find(event_id); auto itr = listeners_hash_.find(event_id);
@ -539,3 +546,8 @@ void Trigger::BulletKill(IBullet* bullet, Creature* target)
{ {
DispatchEvent(kBulletKill, {bullet, target}); DispatchEvent(kBulletKill, {bullet, target});
} }
void Trigger::Downed()
{
DispatchEvent(kDownedEvent, {});
}

View File

@ -43,7 +43,8 @@ enum EventId_e
kEndJump, kEndJump,
kTakeonWeaponEvent, kTakeonWeaponEvent,
kBulletKill, kBulletKill,
kAttackTargetEvent kAttackTargetEvent,
kDownedEvent
}; };
class Weapon; class Weapon;
@ -86,9 +87,11 @@ public:
void BulletBlock(IBullet* bullet, const glm::vec3& pos); void BulletBlock(IBullet* bullet, const glm::vec3& pos);
void StartJump(Creature* sender); void StartJump(Creature* sender);
void EndJump(Creature* sender); void EndJump(Creature* sender);
void Downed();
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);
void RemoveEventHandlers(std::vector<std::weak_ptr<EventHandlerPtr>> handlers);
void DispatchEvent(int event_id, const std::vector<std::any>& params); void DispatchEvent(int event_id, const std::vector<std::any>& params);
bool HasCondBuff(int cond); bool HasCondBuff(int cond);