From 1cc6e36f6039ba7532dfa6e7debe0d040e3ea090 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 24 May 2024 11:15:43 +0800 Subject: [PATCH] 1 --- server/gameserver/buff/callfunc.cc | 61 +++++++++++++++++++++++++++++- server/gameserver/trigger.cc | 4 +- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/server/gameserver/buff/callfunc.cc b/server/gameserver/buff/callfunc.cc index b40b09a6..9ebf6c41 100644 --- a/server/gameserver/buff/callfunc.cc +++ b/server/gameserver/buff/callfunc.cc @@ -279,6 +279,12 @@ void CallFuncBuff::Activate() AddArmorShield(); } break; + case BuffCallFunc_e::kBulletDmgCalcProc: + { + hold_param2_ = meta->GetBuffParam2(this); + BulletDmgCalcProc(); + } + break; default: { } @@ -1924,5 +1930,58 @@ void CallFuncBuff::AddArmorShield() void CallFuncBuff::BulletDmgCalcProc() { - + int target_type = (int)hold_param2_; + if (target_type == 0 || target_type == 1) { + if (!owner->dead && !owner->downed) { + int attr_id = meta->GetBuffParam3(this); + float attr_val = meta->GetBuffParam4(this); + float cond = meta->GetBuffParam5(this); + AttrHandle attr_handle; + auto clear_func = + [this, target_type, &attr_handle] (Creature* c) + { + if (target_type == 0) { + owner->GetAbility()->RemoveAttr(attr_handle); + } else if (target_type == 1) { + c->GetAbility()->RemoveAttr(attr_handle); + } + }; + auto start_handle = owner->GetTrigger()->AddListener + ( + kBulletDmgStartEvent, + [this, &attr_handle, target_type, attr_id, attr_val, cond, clear_func] + (const a8::Args& args) mutable + { + Creature* target = args.Get(0); + clear_func(target); + if (IsValidHumanAttr(attr_id) || + IsValidHumanVirtualAttr(attr_id)) { + if (target->GetMaxHP() > 0.0f) { + bool match = target->GetHP() / target->GetMaxHP() < cond; + if (match) { + if (target_type == 0) { + attr_handle = owner->GetAbility()->AddAttr(attr_id, attr_val); + } else if (target_type == 1) { + attr_handle = target->GetAbility()->AddAttr(attr_id, attr_val); + } + } + } + } + }); + auto end_handle = owner->GetTrigger()->AddListener + ( + kBulletDmgEndEvent, + [this, clear_func] (const a8::Args& args) mutable + { + Creature* target = args.Get(0); + clear_func(target); + }); + deactivate_cb_ = + [this, start_handle, end_handle, clear_func] () mutable + { + owner->GetTrigger()->RemoveEventHandler(start_handle); + owner->GetTrigger()->RemoveEventHandler(end_handle); + }; + } + } } diff --git a/server/gameserver/trigger.cc b/server/gameserver/trigger.cc index 3fa7833d..7f0b5e8c 100644 --- a/server/gameserver/trigger.cc +++ b/server/gameserver/trigger.cc @@ -726,10 +726,10 @@ void Trigger::BeAttack(int attacker_id) void Trigger::BulletDmgStart(Creature* target) { - + DispatchEvent(kBulletDmgStartEvent, {target}); } void Trigger::BulletDmgEnd(Creature* target) { - + DispatchEvent(kBulletDmgEndEvent, {target}); }