From 528318d3ce20f61d0b5ee9035db1e370365d796f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 6 Sep 2024 13:10:03 +0800 Subject: [PATCH] 1 --- server/gameserver/ability.cc | 12 ++++++------ server/gameserver/ability.h | 4 ++-- server/gameserver/buff/callfunc.cc | 4 ++-- server/gameserver/buff/modify_attr.cc | 4 ++-- server/gameserver/commands.cc | 4 ++-- server/gameserver/creature.cc | 4 ++-- server/gameserver/netdata.cc | 10 ++++------ 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/server/gameserver/ability.cc b/server/gameserver/ability.cc index 244cb246..e09c6858 100644 --- a/server/gameserver/ability.cc +++ b/server/gameserver/ability.cc @@ -241,13 +241,17 @@ bool Ability::CanImmune(const std::set& tags) return false; } -AttrHandle Ability::AddAttr(int attr_id, float val) +AttrHandle Ability::AddAttr(int attr_id, float val, int source_type) { float old_max_hp = owner_.Get()->GetMaxHP(); if (IsValidHumanAttr(attr_id) || IsValidHumanVirtualAttr(attr_id)) { + if (source_type < kAstNone || source_type >= kAstEnd) { + A8_ABORT(); + } auto p = std::make_shared(attr_id, val); p->holder = p; + p->source_type = source_type; if (p->IsAdd()) { if (IsValidHumanAttr(attr_id)) { list_add_tail(&p->entry, &std::get<1>(attr_add_[attr_id])); @@ -610,12 +614,8 @@ bool Ability::HasDecAttr(int attr_id) } -void Ability::SetSource(AttrHandle handle, int source_type, std::shared_ptr> cb) +void Ability::SetSource(AttrHandle handle, std::shared_ptr> cb) { - if (source_type < kAstNone || source_type >= kAstEnd) { - A8_ABORT(); - } auto p = handle.lock(); - p->source_type = source_type; p->get_source = cb; } diff --git a/server/gameserver/ability.h b/server/gameserver/ability.h index 7c65eb44..4b7d5d09 100644 --- a/server/gameserver/ability.h +++ b/server/gameserver/ability.h @@ -24,7 +24,7 @@ class Ability void DecSwitch(int type); int GetSwitchTimes(int type); - AttrHandle AddAttr(int attr_id, float val); + AttrHandle AddAttr(int attr_id, float val, int source_type); void RemoveAttr(AttrHandle handler); float GetAttr(int attr_id); bool HasAttr(int attr_id); @@ -37,7 +37,7 @@ class Ability void GMDelAttr(int attr_id, int idx); void GMClearAttr(); std::vector GMShowAttrs(); - void SetSource(AttrHandle handle, int source_type, std::shared_ptr> cb); + void SetSource(AttrHandle handle, std::shared_ptr> cb); private: void Clear(); diff --git a/server/gameserver/buff/callfunc.cc b/server/gameserver/buff/callfunc.cc index 32b314b1..1d58f139 100644 --- a/server/gameserver/buff/callfunc.cc +++ b/server/gameserver/buff/callfunc.cc @@ -1971,9 +1971,9 @@ void CallFuncBuff::BulletDmgCalcProc() bool match = target->GetHP() / target->GetMaxHP() < cond; if (match) { if (target_type == 0) { - context->attr_handle = owner->GetAbility()->AddAttr(attr_id, attr_val); + context->attr_handle = owner->GetAbility()->AddAttr(attr_id, attr_val, kAstOther); } else if (target_type == 1) { - context->attr_handle = target->GetAbility()->AddAttr(attr_id, attr_val); + context->attr_handle = target->GetAbility()->AddAttr(attr_id, attr_val, kAstOther); } } } diff --git a/server/gameserver/buff/modify_attr.cc b/server/gameserver/buff/modify_attr.cc index 8f3d3e91..fe2702c3 100644 --- a/server/gameserver/buff/modify_attr.cc +++ b/server/gameserver/buff/modify_attr.cc @@ -16,7 +16,7 @@ void ModifyAttrBuff::Activate() int attr_id = meta->_int_buff_param1; float value = meta->GetBuffParam2(this); if (f8::App::Instance()->GetInstanceId() != 3) { - attr_handle_ = owner->GetAbility()->AddAttr(attr_id, value); + attr_handle_ = owner->GetAbility()->AddAttr(attr_id, value, kAstOther); #ifdef MYDEBUG if (!attr_handle_.expired()) { std::string source_name = a8::Format @@ -33,7 +33,7 @@ void ModifyAttrBuff::Activate() { return source_name; }); - owner->GetAbility()->SetSource(attr_handle_, kAstOther, cb); + owner->GetAbility()->SetSource(attr_handle_, cb); } #endif } diff --git a/server/gameserver/commands.cc b/server/gameserver/commands.cc index 026aa4d6..ee3b5263 100644 --- a/server/gameserver/commands.cc +++ b/server/gameserver/commands.cc @@ -339,7 +339,7 @@ void Player::_CMExecCommand(f8::MsgHdr* hdr, const cs::CMExecCommand& msg) float value = a8::XValue(cmds[3]).GetDouble(); int source_type = cmds.size() > 4 ? a8::XValue(cmds[4]).GetInt() : kAstOther; if (target) { - auto handle = target->GetAbility()->AddAttr(attr_id, value); + auto handle = target->GetAbility()->AddAttr(attr_id, value, source_type); if (!handle.expired()) { std::string source_name = "<-gm.self." + a8::XValue(source_type).GetString(); auto cb = std::make_shared> @@ -348,7 +348,7 @@ void Player::_CMExecCommand(f8::MsgHdr* hdr, const cs::CMExecCommand& msg) { return source_name; }); - target->GetAbility()->SetSource(handle, source_type, cb); + target->GetAbility()->SetSource(handle, cb); } std::vector strings = target->GetAbility()->GMShowAttrs(); for (auto& str : strings) { diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index f20f6a2e..32d51bb0 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -4250,7 +4250,7 @@ void Creature::GenLevelAttr() } grow_attr_list_.clear(); for (auto tuple : *attrs) { - auto handle = GetAbility()->AddAttr(std::get<0>(tuple), std::get<1>(tuple)); + auto handle = GetAbility()->AddAttr(std::get<0>(tuple), std::get<1>(tuple), kAstOther); if (!handle.expired()) { grow_attr_list_.push_back(handle); } @@ -4267,7 +4267,7 @@ void Creature::GenLevelAttr() { return source_name; }); - GetAbility()->SetSource(handle, kAstOther, cb); + GetAbility()->SetSource(handle, cb); } #endif } diff --git a/server/gameserver/netdata.cc b/server/gameserver/netdata.cc index 5c8a9872..f98d3271 100644 --- a/server/gameserver/netdata.cc +++ b/server/gameserver/netdata.cc @@ -292,7 +292,7 @@ private: int attr_id = a8::XValue(attr->Get("attr_id", "0")); float val = a8::XValue(attr->Get("val", "0")).GetDouble(); if (IsValidHumanAttr(attr_id)) { - auto attr_handle = owner_.Get()->GetAbility()->AddAttr(attr_id, val); + auto attr_handle = owner_.Get()->GetAbility()->AddAttr(attr_id, val, kAstOther); if (!attr_handle.expired()) { #ifdef MYDEBUG std::string source_name = a8::Format @@ -305,7 +305,7 @@ private: { return source_name; }); - owner_.Get()->GetAbility()->SetSource(attr_handle, kAstOther, cb); + owner_.Get()->GetAbility()->SetSource(attr_handle, cb); #endif } } @@ -324,7 +324,7 @@ private: int attr_id = a8::XValue(attr->Get("attr_id", "0")); float val = a8::XValue(attr->Get("val", "0")).GetDouble(); if (IsValidHumanAttr(attr_id)) { - auto attr_handle = owner_.Get()->GetAbility()->AddAttr(attr_id, val); + auto attr_handle = owner_.Get()->GetAbility()->AddAttr(attr_id, val, kAstChip); if (!attr_handle.expired()) { #ifdef MYDEBUG std::string source_name = a8::Format @@ -337,9 +337,7 @@ private: { return source_name; }); - owner_.Get()->GetAbility()->SetSource(attr_handle, kAstChip, cb); -#else - owner_.Get()->GetAbility()->SetSource(attr_handle, kAstChip, nullptr); + owner_.Get()->GetAbility()->SetSource(attr_handle, cb); #endif } }