From 0e1917a672ba0cec6c7d0a75ba3b53c90bc0ff2f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 20 Mar 2023 13:47:59 +0800 Subject: [PATCH] 1 --- server/gameserver/buff.cc | 2 +- server/gameserver/buff.h | 1 + server/gameserver/buff/batch_add.cc | 4 ++-- server/gameserver/creature.cc | 33 +++++++++++++++++------------ server/gameserver/creature.h | 18 ++++++++++------ 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/server/gameserver/buff.cc b/server/gameserver/buff.cc index 4ae3ac6f..5e88bca0 100644 --- a/server/gameserver/buff.cc +++ b/server/gameserver/buff.cc @@ -122,7 +122,7 @@ void Buff::InternalTimerAddBuff() caster.Get()->FillSkillCasterState(&old_caster_state); caster.Get()->RecoverSkillCasterState(caster_state.get()); //!!!在AddBuff的过程可能删除buff导致caster_state野指针 - receiver->AddBuff(caster.Get(), buff_meta, skill); + receiver->AddBuff(caster.Get(), buff_meta, skill, false, nullptr, buff_vars); #if 0 caster.Get()->RecoverSkillCasterState(&old_caster_state); #endif diff --git a/server/gameserver/buff.h b/server/gameserver/buff.h index 8442746c..c7e3a7dc 100644 --- a/server/gameserver/buff.h +++ b/server/gameserver/buff.h @@ -36,6 +36,7 @@ class Buff std::shared_ptr init_args; float res_scale = 1; long long res_scale_frameno = 0; + std::shared_ptr> buff_vars; Buff(); ~Buff(); diff --git a/server/gameserver/buff/batch_add.cc b/server/gameserver/buff/batch_add.cc index 821c8b08..2c15a823 100644 --- a/server/gameserver/buff/batch_add.cc +++ b/server/gameserver/buff/batch_add.cc @@ -33,7 +33,7 @@ void BatchAddBuff::Activate() buff_meta->name() }); #endif - owner->AddBuff(caster_.Get(), buff_meta, skill_meta); + owner->AddBuff(caster_.Get(), buff_meta, skill_meta, false, nullptr, buff_vars); } } } else { @@ -43,7 +43,7 @@ void BatchAddBuff::Activate() if (rnd <= std::get<1>(item)) { const mt::Buff* buff_meta = mt::Buff::GetById(std::get<0>(item)); if (buff_meta) { - owner->AddBuff(caster_.Get(), buff_meta, skill_meta); + owner->AddBuff(caster_.Get(), buff_meta, skill_meta, false, nullptr, buff_vars); } break; } diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index 50181e2e..677d7443 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -132,7 +132,8 @@ int Creature::AddBuff(Creature* caster, const mt::Buff* buff_meta, const mt::Skill* buff_skill_meta, bool no_check_immune, - std::shared_ptr init_args) + std::shared_ptr init_args, + std::shared_ptr> buff_vars) { #if 999 if (buff_meta->buff_id() == 8042) { @@ -254,6 +255,7 @@ int Creature::AddBuff(Creature* caster, buff->add_frameno = room->GetFrameNo(); buff->xtimer_attacher.SetOwner(&room->xtimer); buff->init_args = init_args; + buff->buff_vars = buff_vars; buff->Init(); buff->PreProcess(); if (on_add_buff) { @@ -361,7 +363,7 @@ int Creature::AddBuff(Creature* caster, for (int child_buff_id : buff->meta->_child_buff_list) { const mt::Buff* child_buff_meta = mt::Buff::GetById(child_buff_id); if (child_buff_meta) { - AddBuff(caster, child_buff_meta, buff_skill_meta, true); + AddBuff(caster, child_buff_meta, buff_skill_meta, true, init_args, buff_vars); } } } @@ -380,23 +382,25 @@ bool Creature::IsImmuneBuffEffect(int buff_effect) int Creature::MustBeAddBuff(Creature* caster, int buff_id, - std::shared_ptr init_args) + std::shared_ptr init_args, + std::shared_ptr> buff_vars) { const mt::Buff* buff_meta = mt::Buff::GetById(buff_id); if (!buff_meta) { A8_ABORT(); } - return AddBuff(caster, buff_meta, nullptr, false, init_args); + return AddBuff(caster, buff_meta, nullptr, false, init_args, buff_vars); } int Creature::TryAddBuff(Creature* caster, int buff_id, const mt::Skill* skill_meta, - std::shared_ptr init_args) + std::shared_ptr init_args, + std::shared_ptr> buff_vars) { const mt::Buff* buff_meta = mt::Buff::GetById(buff_id); if (buff_meta) { - return AddBuff(caster, buff_meta, skill_meta, false, init_args); + return AddBuff(caster, buff_meta, skill_meta, false, init_args, buff_vars); } return 0; } @@ -405,9 +409,10 @@ int Creature::TryAddBuffAndSetTime(Creature* caster, int buff_id, int time, const mt::Skill* skill_meta, - std::shared_ptr init_args) + std::shared_ptr init_args, + std::shared_ptr> buff_vars) { - int buff_uniid = TryAddBuff(caster, buff_id, skill_meta, init_args); + int buff_uniid = TryAddBuff(caster, buff_id, skill_meta, init_args, buff_vars); if (buff_uniid) { Buff* buff = GetBuffByUniId(buff_uniid); room->xtimer.ModifyTime @@ -421,13 +426,14 @@ a8::XTimerWp Creature::TryDelayAddBuff(Creature* caster, int buff_id, int time, DelayAddBuffHandle* handle, - std::shared_ptr init_args) + std::shared_ptr init_args, + std::shared_ptr> buff_vars) { auto caster_wp = caster->GetWeakPtrRef(); return room->xtimer.SetTimeoutWpEx ( time / FRAME_RATE_MS, - [this, caster_wp, buff_id, handle, init_args] + [this, caster_wp, buff_id, handle, init_args, buff_vars] (int event, const a8::Args* args) mutable { if (a8::TIMER_EXEC_EVENT == event) { @@ -435,7 +441,7 @@ a8::XTimerWp Creature::TryDelayAddBuff(Creature* caster, if (handle && handle->pre_add_cb) { handle->pre_add_cb(this); } - int buff_uniid = TryAddBuff(caster_wp.Get(), buff_id, nullptr, init_args); + int buff_uniid = TryAddBuff(caster_wp.Get(), buff_id, nullptr, init_args, buff_vars); if (handle && handle->post_add_cb) { handle->post_add_cb(this, buff_uniid); } @@ -451,7 +457,8 @@ a8::XTimerWp Creature::TryDelayAddBuff(Creature* caster, int Creature::TryAddBuffWithTarget(Creature* caster, int buff_id, - std::shared_ptr init_args) + std::shared_ptr init_args, + std::shared_ptr> buff_vars) { const mt::Buff* buff_meta = mt::Buff::GetById(buff_id); if (buff_meta) { @@ -477,7 +484,7 @@ int Creature::TryAddBuffWithTarget(Creature* caster, } break; } - return TryAddBuff(caster, buff_id, nullptr, init_args); + return TryAddBuff(caster, buff_id, nullptr, init_args, buff_vars); } return -1; } diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index bc1fe259..1e3fcbda 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -145,31 +145,37 @@ class Creature : public MoveableEntity const mt::Buff* buff_meta, const mt::Skill* buff_skill_meta = nullptr, bool no_check_immune = false, - std::shared_ptr init_args = nullptr); + std::shared_ptr init_args = nullptr, + std::shared_ptr> buff_vars = nullptr); bool IsImmuneBuffEffect(int buff_effect); int MustBeAddBuff(Creature* caster, int buff_id, - std::shared_ptr init_args = nullptr); + std::shared_ptr init_args = nullptr, + std::shared_ptr> buff_vars = nullptr); a8::XTimerWp TryDelayAddBuff ( Creature* caster, int buff_id, int time, DelayAddBuffHandle* handle = nullptr, - std::shared_ptr init_args = nullptr + std::shared_ptr init_args = nullptr, + std::shared_ptr> buff_vars = nullptr ); int TryAddBuff(Creature* caster, int buff_id, const mt::Skill* skill_meta = nullptr, - std::shared_ptr init_args = nullptr); + std::shared_ptr init_args = nullptr, + std::shared_ptr> buff_vars = nullptr); int TryAddBuffAndSetTime(Creature* caster, int buff_id, int time, const mt::Skill* skill_meta = nullptr, - std::shared_ptr init_args = nullptr); + std::shared_ptr init_args = nullptr, + std::shared_ptr> buff_vars = nullptr); int TryAddBuffWithTarget(Creature* caster, int buff_id, - std::shared_ptr init_args = nullptr); + std::shared_ptr init_args = nullptr, + std::shared_ptr> buff_vars = nullptr); void RemoveBuffById(int buff_id); void RemoveBuffByUniId(int buff_uniid); void ClearBuffById(int buff_id);