From 034a42ed3ec6fd7fdc2e85d42006da1d19c12b2b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 28 Mar 2023 18:49:27 +0800 Subject: [PATCH] 1 --- server/gameserver/ability.cc | 109 +++++++++++++++++++++++++++++++++- server/gameserver/commands.cc | 103 +++++++++++++++++++------------- server/gameserver/room.cc | 6 ++ server/gameserver/room.h | 1 + 4 files changed, 177 insertions(+), 42 deletions(-) diff --git a/server/gameserver/ability.cc b/server/gameserver/ability.cc index afcd5a02..501c499b 100644 --- a/server/gameserver/ability.cc +++ b/server/gameserver/ability.cc @@ -501,12 +501,73 @@ float Ability::GetAttrRuduce(int attr_id) void Ability::GMDelBaseAttr(int type, int attr_id, int idx) { - + if (IsValidHumanAttr(attr_id)) { + if (type == 1) { + list_head* head = &std::get<1>(attr_abs_[attr_id]); + list_head* pos = nullptr; + list_head* next = nullptr; + int i = 0; + list_for_each_safe(pos, next, head) { + if (idx == -1 || idx == i) { + AttrAbs* e = list_entry(pos, + AttrAbs, + entry); + list_del_init(&e->entry); + delete e; + if (idx > -1) { + break; + } + } + ++i; + } + RecalcAttrAbs(attr_id); + } else if (type == 2) { + list_head* head = &std::get<1>(attr_rate_[attr_id]); + list_head* pos = nullptr; + list_head* next = nullptr; + int i = 0; + list_for_each_safe(pos, next, head) { + if (idx == -1 || idx == i) { + AttrRate* e = list_entry(pos, + AttrRate, + entry); + list_del_init(&e->entry); + delete e; + if (idx > -1) { + break; + } + } + ++i; + } + RecalcAttrRate(attr_id); + } + } } void Ability::GMClearBaseAttr(int type) { - + for (auto& tuple : attr_abs_) { + std::get<0>(tuple) = 0.0f; + while (!list_empty(&std::get<1>(tuple))) { + AttrAbs* e = list_first_entry(&std::get<1>(tuple), + AttrAbs, + entry); + e->ptr->data = nullptr; + list_del_init(&e->entry); + delete e; + } + } + for (auto& tuple : attr_rate_) { + std::get<0>(tuple) = 0.0f; + while (!list_empty(&std::get<1>(tuple))) { + AttrRate* e = list_first_entry(&std::get<1>(tuple), + AttrRate, + entry); + e->ptr->data = nullptr; + list_del_init(&e->entry); + delete e; + } + } } void Ability::GMDelGrowAttr(int type, int attr_id, int idx) @@ -516,7 +577,51 @@ void Ability::GMDelGrowAttr(int type, int attr_id, int idx) void Ability::GMClearGrowAttr(int type) { + for (auto& tuple : attr_add_) { + std::get<0>(tuple) = 0.0f; + while (!list_empty(&std::get<1>(tuple))) { + AttrAddition* e = list_first_entry(&std::get<1>(tuple), + AttrAddition, + entry); + e->ptr->data = nullptr; + list_del_init(&e->entry); + delete e; + } + } + for (auto& tuple : attr_dec_) { + std::get<0>(tuple) = 0.0f; + while (!list_empty(&std::get<1>(tuple))) { + AttrRuduce* e = list_first_entry(&std::get<1>(tuple), + AttrRuduce, + entry); + e->ptr->data = nullptr; + list_del_init(&e->entry); + delete e; + } + } + for (auto& tuple : vattr_add_) { + std::get<0>(tuple) = 0.0f; + while (!list_empty(&std::get<1>(tuple))) { + AttrAddition* e = list_first_entry(&std::get<1>(tuple), + AttrAddition, + entry); + e->ptr->data = nullptr; + list_del_init(&e->entry); + delete e; + } + } + for (auto& tuple : vattr_dec_) { + std::get<0>(tuple) = 0.0f; + while (!list_empty(&std::get<1>(tuple))) { + AttrRuduce* e = list_first_entry(&std::get<1>(tuple), + AttrRuduce, + entry); + e->ptr->data = nullptr; + list_del_init(&e->entry); + delete e; + } + } } std::vector Ability::GMShowAttrs() diff --git a/server/gameserver/commands.cc b/server/gameserver/commands.cc index 49296f45..d19d520c 100644 --- a/server/gameserver/commands.cc +++ b/server/gameserver/commands.cc @@ -167,60 +167,83 @@ void Player::_CMExecCommand(f8::MsgHdr& hdr, const cs::CMExecCommand& msg) } } } else if (cmd == "add_base_attr") { - Creature* target = nullptr; - int type = 0; - int attr_id = 0; - float value = 0; - if (target) { - if (type == 1) { - target->GetAbility()->AddAttrAbs(attr_id, value); - } else { - target->GetAbility()->AddAttrRate(attr_id, value); + if (cmds.size() > 4) { + Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : + room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); + int type = a8::XValue(cmds[2]); + int attr_id = a8::XValue(cmds[3]); + float value = a8::XValue(cmds[4]).GetDouble(); + if (target) { + if (type == 1) { + target->GetAbility()->AddAttrAbs(attr_id, value); + } else { + target->GetAbility()->AddAttrRate(attr_id, value); + } } } } else if (cmd == "del_base_attr") { - Creature* target = nullptr; - int type = 0; - int attr_id = 0; - int idx = 0; - if (target) { - target->GetAbility()->GMDelBaseAttr(type, attr_id, idx); + if (cmds.size() > 4) { + Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : + room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); + int type = a8::XValue(cmds[2]); + int attr_id = a8::XValue(cmds[3]); + int idx = a8::XValue(cmds[4]); + if (target) { + target->GetAbility()->GMDelBaseAttr(type, attr_id, idx); + } } } else if (cmd == "clear_base_attr") { - Creature* target = nullptr; - int type = 0; - if (target) { - target->GetAbility()->GMClearBaseAttr(type); + if (cmds.size() > 1) { + Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : + room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); + int type = 0; + if (target) { + target->GetAbility()->GMClearBaseAttr(type); + } } } else if (cmd == "add_grow_attr") { - Creature* target = nullptr; - int type = 0; - int attr_id = 0; - float value = 0; - if (target) { - if (type == 1) { - target->GetAbility()->AddAttrAddition(attr_id, value); - } else { - target->GetAbility()->AddAttrRuduce(attr_id, value); + if (cmds.size() > 4) { + Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : + room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); + int type = a8::XValue(cmds[2]); + int attr_id = a8::XValue(cmds[3]); + float value = a8::XValue(cmds[4]).GetDouble(); + if (target) { + if (type == 1) { + target->GetAbility()->AddAttrAddition(attr_id, value); + } else { + target->GetAbility()->AddAttrRuduce(attr_id, value); + } } } } else if (cmd == "del_grow_attr") { - Creature* target = nullptr; - int type = 0; - int attr_id = 0; - int idx = 0; - if (target) { - target->GetAbility()->GMDelGrowAttr(type, attr_id, idx); + if (cmds.size() > 4) { + Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : + room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); + int type = a8::XValue(cmds[2]); + int attr_id = a8::XValue(cmds[3]); + int idx = a8::XValue(cmds[4]); + if (target) { + target->GetAbility()->GMDelGrowAttr(type, attr_id, idx); + } } } else if (cmd == "clear_grow_attr") { - Creature* target = nullptr; - int type = 0; - if (target) { - target->GetAbility()->GMClearGrowAttr(type); + if (cmds.size() > 1) { + Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : + room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); + int type = 0; + if (target) { + target->GetAbility()->GMClearGrowAttr(type); + } } } else if (cmd == "show_attrs") { - Creature* target = nullptr; - if (target) { + if (cmds.size() > 1) { + Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : + room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); + int type = 0; + if (target) { + target->GetAbility()->GMShowAttrs(); + } } } else if (cmd == "reset_skill" && cmds.size() >= 2) { int skill_id = a8::XValue(cmds[1]); diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 9c9e25fe..65628ba2 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -3532,3 +3532,9 @@ Team* Room::GetTeam(int team_id) auto itr = team_hash_.find(team_id); return itr != team_hash_.end() ? itr->second : nullptr; } + +Creature* Room::GetCreatureByUniId(int uniid) +{ + Entity* e = GetEntityByUniId(uniid); + return e && e->IsCreature(this) ? (Creature*)e : nullptr; +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 874df54f..390a0672 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -109,6 +109,7 @@ public: Player* GetPlayerByAccountId(const std::string& accountid); Player* GetPlayerByUniId(int uniid); Entity* GetEntityByUniId(int uniid); + Creature* GetCreatureByUniId(int uniid); Human* GetHumanByUniId(int uniid); int GetRealPlayerNum() { return accountid_hash_.size();} void OnEnterNewWave(int wave);