From c64c00f76b45ee71fb250ded0533d5603608a2a7 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 24 May 2022 21:39:32 +0800 Subject: [PATCH] 1 --- server/gameserver/human.h | 2 +- server/gameserver/room.cc | 2 +- server/gameserver/roommgr.cc | 2 +- server/gameserver/types.cc | 66 ++++++++++-------------------------- server/gameserver/types.h | 10 +++--- 5 files changed, 25 insertions(+), 57 deletions(-) diff --git a/server/gameserver/human.h b/server/gameserver/human.h index d0997c60..5b0fa755 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -136,7 +136,7 @@ class Human : public Creature int today_enter_times = 0; int account_registertime = 0; int channel = 0; - std::string hero_uniid; + long long hero_uniid = 0; long long battle_uuid = 0; int is_valid_battle = 0; std::string payload; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index dbba00a6..e4b24bb8 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -3985,7 +3985,7 @@ void Room::AddTeam(class MatchTeam* team) } else { Player* hum = NewPlayer(); hum->proto_version = msg.proto_version(); - hum->hero_uniid = msg.hero_uniid(); + hum->hero_uniid = a8::XValue(msg.hero_uniid()); hum->battle_uuid = member->battle_uuid; hum->is_valid_battle = member->is_valid_battle; hum->payload = member->payload; diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 32d73724..7bc6c665 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -185,7 +185,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) } Player* hum = room->NewPlayer(); hum->proto_version = msg.proto_version(); - hum->hero_uniid = msg.hero_uniid(); + hum->hero_uniid = a8::XValue(msg.hero_uniid()); hum->battle_uuid = results.at(0)->battle_uuid; hum->is_valid_battle = results.at(0)->is_valid_battle; hum->payload = results.at(0)->payload; diff --git a/server/gameserver/types.cc b/server/gameserver/types.cc index e9aff61b..d687b74c 100644 --- a/server/gameserver/types.cc +++ b/server/gameserver/types.cc @@ -35,7 +35,7 @@ void BattleDataContext::ParseResult(a8::XObject& obj) errmsg = obj.Get("errmsg").GetString(); if (obj.HasKey("hero_dto") && obj.At("hero_dto")->IsObject()) { hero_dto = obj.At("hero_dto"); - hero_uniid = hero_dto->Get("hero_uniid", "").GetString(); + hero_uniid_ = hero_dto->Get("hero_uniid", ""); if (hero_dto->HasKey("attr") && hero_dto->IsArray()) { ApplyAttr(hero_attr_abs_, hero_attr_rate_, @@ -44,7 +44,7 @@ void BattleDataContext::ParseResult(a8::XObject& obj) } if (obj.HasKey("weapon_dto1") && obj.At("weapon_dto1")->IsObject()) { weapon_dto1 = obj.At("weapon_dto1"); - weapon_uniid1 = weapon_dto1->Get("gun_uniid", 0); + weapon_uniid1_ = weapon_dto1->Get("gun_uniid", 0); if (weapon_dto1->HasKey("attr") && weapon_dto1->IsArray()) { ApplyAttr(weapon1_attr_abs_, weapon1_attr_rate_, @@ -53,7 +53,7 @@ void BattleDataContext::ParseResult(a8::XObject& obj) } if (obj.HasKey("weapon_dto2") && obj.At("weapon_dto2")->IsObject()) { weapon_dto2 = obj.At("weapon_dto2"); - weapon_uniid2 = weapon_dto2->Get("gun_uniid", 0); + weapon_uniid2_ = weapon_dto2->Get("gun_uniid", 0); if (weapon_dto2->HasKey("attr") && weapon_dto2->IsArray()) { ApplyAttr(weapon2_attr_abs_, weapon2_attr_rate_, @@ -62,18 +62,22 @@ void BattleDataContext::ParseResult(a8::XObject& obj) } } -float BattleDataContext::GetHeroAttrAbs(int attr_id) +float BattleDataContext::GetHeroAttrAbs(long long hero_uniid, int attr_id) { - if (IsValidHumanAttr(attr_id)) { - return hero_attr_abs_[attr_id]; + if (hero_uniid && hero_uniid == hero_uniid_) { + if (IsValidHumanAttr(attr_id)) { + return hero_attr_abs_[attr_id]; + } } return 0; } -float BattleDataContext::GetHeroAttrRate(int attr_id) +float BattleDataContext::GetHeroAttrRate(long long hero_uniid, int attr_id) { - if (IsValidHumanAttr(attr_id)) { - return hero_attr_rate_[attr_id]/ 100.0f; + if (hero_uniid && hero_uniid == hero_uniid_) { + if (IsValidHumanAttr(attr_id)) { + return hero_attr_rate_[attr_id]/ 100.0f; + } } return 0; } @@ -84,9 +88,9 @@ float BattleDataContext::GetWeaponAttrAbs(long long weapon_uniid, int attr_id) return 0; } if (IsValidHumanAttr(attr_id)) { - if (weapon_uniid == weapon_uniid1) { + if (weapon_uniid == weapon_uniid1_) { return weapon1_attr_abs_[attr_id]; - } else if (weapon_uniid == weapon_uniid2) { + } else if (weapon_uniid == weapon_uniid2_) { return weapon2_attr_abs_[attr_id]; } } @@ -99,51 +103,15 @@ float BattleDataContext::GetWeaponAttrRate(long long weapon_uniid, int attr_id) return 0; } if (IsValidHumanAttr(attr_id)) { - if (weapon_uniid == weapon_uniid1) { + if (weapon_uniid == weapon_uniid1_) { return weapon1_attr_rate_[attr_id]; - } else if (weapon_uniid == weapon_uniid2) { + } else if (weapon_uniid == weapon_uniid2_) { return weapon2_attr_rate_[attr_id]; } } return 0; } -#if 0 -void BattleDataContext::CalcAttr(const std::string& hero_uniid, - long long curr_weapon_uniid) -{ - Clear(); - if (!hero_uniid.empty() && - hero_dto && - hero_dto->IsObject() && - hero_dto->Get("hero_uniid", "").GetString() == hero_uniid - ) { - if (hero_dto->HasKey("attr")) { - //ApplyAttr(hero_dto->At("attr")); - } - } - if (!curr_weapon_uniid) { - std::shared_ptr curr_weapon_dto; - if (weapon_dto1 && - weapon_dto1->IsObject() && - weapon_dto1->Get("gun_uniid").GetInt64() == curr_weapon_uniid) { - curr_weapon_dto = weapon_dto1; - } - if (!curr_weapon_dto && - weapon_dto1 && - weapon_dto1->IsObject() && - weapon_dto1->Get("gun_uniid").GetInt64() == curr_weapon_uniid) { - curr_weapon_dto = weapon_dto1; - } - if (curr_weapon_dto) { - if (curr_weapon_dto->HasKey("attr")) { - ApplyAttr(curr_weapon_dto->At("attr")); - } - } - } -} -#endif - void BattleDataContext::ApplyAttr(std::array& attr_abs, std::array& attr_rate, std::shared_ptr obj) diff --git a/server/gameserver/types.h b/server/gameserver/types.h index 118382d1..656a74e1 100644 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -33,8 +33,8 @@ struct BattleDataContext std::shared_ptr weapon_dto1; std::shared_ptr weapon_dto2; - float GetHeroAttrAbs(int attr_id); - float GetHeroAttrRate(int attr_id); + float GetHeroAttrAbs(long long hero_uniid, int attr_id); + float GetHeroAttrRate(long long hero_uniid, int attr_id); float GetWeaponAttrAbs(long long weapon_uniid, int attr_id); float GetWeaponAttrRate(long long weapon_uniid, int attr_id); @@ -48,9 +48,9 @@ private: std::shared_ptr obj); private: - std::string hero_uniid; - long long weapon_uniid1 = 0; - long long weapon_uniid2 = 0; + long long hero_uniid_ = 0; + long long weapon_uniid1_ = 0; + long long weapon_uniid2_ = 0; std::array hero_attr_abs_ = {}; std::array hero_attr_rate_ = {};