diff --git a/server/gameserver/attr.cc b/server/gameserver/attr.cc deleted file mode 100644 index adf4d4fe..00000000 --- a/server/gameserver/attr.cc +++ /dev/null @@ -1,55 +0,0 @@ -#include "precompile.h" - -#include "attr.h" - -#include "creature.h" - -float Attr::CalcDmg(Creature* target, int weapon_uniid) -{ - float total_atk = (GetTotalAtk() / 100 + 1) * GetWeaponAtk(); - float normal_dmg = total_atk * (1 - target->attr->GetDef() / 1000); - float crit = IsCrit() ? 1 + GetCritRate() : 1; - float dodge = IsDodge() ? 1 + GetDodgeRate() : 1; - } - -float Attr::GetTotalAtk() -{ - return 0; -} - -float Attr::GetDef() -{ - return 0; -} - -float Attr::GetHeroTotalAtk() -{ - return 0; -} - -float Attr::GetWeaponAtk() -{ - return 0; -} - -bool Attr::IsCrit() -{ - return true; -} - - -bool Attr::IsDodge() -{ - return true; -} - -float Attr::GetCritRate() -{ - return 0; -} - - -float Attr::GetDodgeRate() -{ - return 0; -} diff --git a/server/gameserver/attr.h b/server/gameserver/attr.h deleted file mode 100644 index 802f7330..00000000 --- a/server/gameserver/attr.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "weakptr.h" - -/* - 子弹命中逻辑 - 1、计算总攻击力 - 2、计算普通伤害 - 3、判断是否暴击(百分比系数),对方是否闪避(系数) - 4、得到实际伤害 - - 免伤后伤害=实际伤害*(1-免伤率) - 吸血值=吸血系数*实际伤害 - - */ - -class Attr -{ - public: - float CalcDmg(Creature* target, int weapon_uniid); - - float GetDef(); - private: - float GetTotalAtk(); - float GetHeroTotalAtk(); - float GetWeaponAtk(); - bool IsCrit(); - float GetCritRate(); - bool IsDodge(); - float GetDodgeRate(); - - private: - CreatureWeakPtr owner_; -}; diff --git a/server/gameserver/battledatacontext.cc b/server/gameserver/battledatacontext.cc new file mode 100644 index 00000000..8b6a1dc1 --- /dev/null +++ b/server/gameserver/battledatacontext.cc @@ -0,0 +1,320 @@ +#include "precompile.h" + +#include + +#include "battledatacontext.h" + +#include "human.h" +#include "metamgr.h" +#include "creature.h" +#include "types.h" + +float* GetAttrAbsPtr(std::array& attr, int attr_id) +{ + if (!IsValidHumanAttr(attr_id)) { + return nullptr; + } + return &attr[attr_id]; +} + +float* GetAttrRatePtr(std::array& attr, int attr_id) +{ + if (!IsValidHumanAttr(attr_id)) { + return nullptr; + } + return &attr[attr_id]; +} + +void BattleDataContext::Clear() +{ + hero_attr_abs_ = {}; + hero_attr_rate_ = {}; + weapon1_attr_abs_ = {}; + weapon1_attr_rate_ = {}; + weapon2_attr_abs_ = {}; + weapon2_attr_rate_ = {}; +} + +void BattleDataContext::ParseResult(a8::XObject& obj) +{ + is_valid_battle = obj.Get("is_valid_battle"); + payload = obj.Get("payload").GetString(); + errcode = obj.Get("errcode"); + 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", ""); + if (hero_dto->HasKey("attr") && hero_dto->IsArray()) { + ApplyAttr(hero_attr_abs_, + hero_attr_rate_, + hero_dto->At("attr")); + } + } + if (obj.HasKey("weapon_dto1") && obj.At("weapon_dto1")->IsObject()) { + weapon_dto1 = obj.At("weapon_dto1"); + weapon_uniid1_ = weapon_dto1->Get("gun_uniid", 0); + if (weapon_dto1->HasKey("attr") && weapon_dto1->IsArray()) { + ApplyAttr(weapon1_attr_abs_, + weapon1_attr_rate_, + weapon_dto1->At("attr")); + } + } + if (obj.HasKey("weapon_dto2") && obj.At("weapon_dto2")->IsObject()) { + weapon_dto2 = obj.At("weapon_dto2"); + weapon_uniid2_ = weapon_dto2->Get("gun_uniid", 0); + if (weapon_dto2->HasKey("attr") && weapon_dto2->IsArray()) { + ApplyAttr(weapon2_attr_abs_, + weapon2_attr_rate_, + weapon_dto2->At("attr")); + } + } +} + +float BattleDataContext::GetHeroAttrAbs(long long hero_uniid, int attr_id) +{ + if (hero_uniid && hero_uniid == hero_uniid_) { + if (IsValidHumanAttr(attr_id)) { + return hero_attr_abs_[attr_id]; + } + } + return 0; +} + +float BattleDataContext::GetHeroAttrRate(long long hero_uniid, int attr_id) +{ + if (hero_uniid && hero_uniid == hero_uniid_) { + if (IsValidHumanAttr(attr_id)) { + return hero_attr_rate_[attr_id]/ 100.0f; + } + } + return 0; +} + +float BattleDataContext::GetWeaponAttrAbs(long long weapon_uniid, int attr_id) +{ + if (!weapon_uniid) { + return 0; + } + if (IsValidHumanAttr(attr_id)) { + if (weapon_uniid == weapon_uniid1_) { + return weapon1_attr_abs_[attr_id]; + } else if (weapon_uniid == weapon_uniid2_) { + return weapon2_attr_abs_[attr_id]; + } + } + return 0; +} + +float BattleDataContext::GetWeaponAttrRate(long long weapon_uniid, int attr_id) +{ + if (!weapon_uniid) { + return 0; + } + if (IsValidHumanAttr(attr_id)) { + if (weapon_uniid == weapon_uniid1_) { + return weapon1_attr_rate_[attr_id]; + } else if (weapon_uniid == weapon_uniid2_) { + return weapon2_attr_rate_[attr_id]; + } + } + return 0; +} + +void BattleDataContext::ApplyAttr(std::array& attr_abs, + std::array& attr_rate, + std::shared_ptr obj) +{ + if (obj->IsArray()) { + for (int i = 0; i < obj->Size(); ++i) { + std::shared_ptr obj = obj->At(i); + if (obj->IsObject()) { + int attr_id = obj->Get("attr_id", 0); + int type = obj->Get("type", 0); + int val = obj->Get("val", 0); + if (type == 1) { + float* p = GetAttrAbsPtr(attr_abs, attr_id); + if (p) { + *p = val; + } + } else if (type == 2) { + float* p = GetAttrRatePtr(attr_rate, attr_id); + if (p) { + *p = val; + } + } + } + } + } +} + +void BattleDataContext::GetHeroLvQualit(int& hero_lv, int& quality) +{ + hero_lv = 0; + quality = 0; + if (hero_uniid_) { + hero_lv = hero_dto->Get("hero_lv", 0).GetInt(); + quality = hero_dto->Get("quality", 0).GetInt(); + } +} + +void BattleDataContext::GetWeaponLvQualit(int& weapon_lv, int& quality) +{ + weapon_lv = 0; + quality = 0; + if (weapon_uniid1_) { + weapon_lv += weapon_dto1->Get("gun_lv", 0).GetInt(); + quality += weapon_dto1->Get("quality", 0).GetInt(); + } + if (weapon_uniid2_) { + weapon_lv += weapon_dto2->Get("gun_lv", 0).GetInt(); + quality += weapon_dto2->Get("quality", 0).GetInt(); + } +} + +void BattleDataContext::CalcBattleStat(struct PlayerStats* stats) +{ + auto CalcHeroPvpCeg = + [] (long long ceg_uplimit, struct PlayerStats* stats) -> long long + { + MetaData::FormulaPvp* meta = MetaMgr::Instance()->GetFormulaPvp(stats->ranked_topx); + if (!meta) { + return 0; + } + long long ceg = round + ( + ceg_uplimit * + ( + (0.5 * stats->ranked_topx * meta->i->ranked_topx()) + + (0.25 * stats->kills_topx * meta->i->kills_topx()) + + (0.15 * stats->hero_topx * meta->i->hero_topx()) + + (0.5 * stats->weapon_topx * meta->i->weapon_topx()) + + (0.5 * stats->survival_topx * meta->i->survival_topx()) + ) + ); + return ceg; + }; + auto CalcWeaponPvpCeg = + [] (long long ceg_uplimit, struct PlayerStats* stats) -> long long + { + MetaData::FormulaPvp* meta = MetaMgr::Instance()->GetFormulaPvp(stats->ranked_topx); + if (!meta) { + return 0; + } + long long ceg = round + ( + ceg_uplimit * + ( + (0.5 * stats->ranked_topx * meta->i->ranked_topx()) + + (0.25 * stats->kills_topx * meta->i->kills_topx()) + + (0.15 * stats->hero_topx * meta->i->hero_topx()) + + (0.5 * stats->weapon_topx * meta->i->weapon_topx()) + + (0.5 * stats->survival_topx * meta->i->survival_topx()) + ) + ); + return ceg; + }; + + if (hero_uniid_) { + int hero_id = hero_dto->Get("hero_id", 0).GetInt(); + int quality = hero_dto->Get("quality", 0).GetInt(); + int today_get_gold = hero_dto->Get("today_get_gold", 0).GetInt(); + MetaData::Player* hero_meta = MetaMgr::Instance()->GetPlayer(hero_id); + MetaData::HeroQuality* quality_meta = MetaMgr::Instance()->GetHeroQuality(quality); + + stats->pb_hero_stats.set_hero_uniid(a8::XValue(hero_uniid_).GetString()); + stats->pb_hero_stats.set_hero_id(hero_id); + stats->pb_hero_stats.set_hero_name(hero_meta ? hero_meta->i->name() : ""); + if (quality_meta) { + int up_limit = quality_meta->GetPvpCegUpLimit(); + int ceg = CalcHeroPvpCeg(up_limit, stats); + int new_ceg = std::min(up_limit, today_get_gold + ceg); + int finaly_ceg = std::max(0, new_ceg - today_get_gold); + stats->pb_hero_stats.set_ceg_uplimit(up_limit); + stats->pb_hero_stats.set_today_get_ceg + (std::min(up_limit, today_get_gold + finaly_ceg)); + stats->pb_hero_stats.set_reward_ceg(finaly_ceg); + } + } + std::vector> weapons; + if (weapon_dto1) { + weapons.push_back(weapon_dto1); + } + if (weapon_dto2) { + weapons.push_back(weapon_dto2); + } + for (auto& weapon_dto : weapons) { + std::string gun_uniid = weapon_dto->Get("gun_uniid", 0).GetString(); + int gun_id = weapon_dto->Get("gun_id", 0).GetInt(); + int quality = weapon_dto->Get("quality", 0).GetInt(); + int today_get_gold = weapon_dto->Get("today_get_gold", 0).GetInt(); + MetaData::Item* item_meta = MetaMgr::Instance()->GetItem(gun_id); + MetaData::GunQuality* quality_meta = MetaMgr::Instance()->GetGunQuality(quality); + + + auto p = stats->pb_weapons_stats.Add(); + p->set_weapon_uniid(gun_uniid); + p->set_weapon_id(gun_id); + p->set_weapon_name(item_meta ? item_meta->i->name() : ""); + if (quality_meta) { + int up_limit = quality_meta->GetPvpCegUpLimit(); + int ceg = CalcWeaponPvpCeg(up_limit, stats); + int new_ceg = std::min(up_limit, today_get_gold + ceg); + int finaly_ceg = std::max(0, new_ceg - today_get_gold); + p->set_ceg_uplimit(up_limit); + p->set_today_get_ceg + (std::min(up_limit, today_get_gold + finaly_ceg)); + p->set_reward_ceg(finaly_ceg); + } + } +} + +float BattleDataContext::CalcDmg(Creature* target, int weapon_uniid) +{ + float total_atk = (GetTotalAtk() / 100 + 1) * GetWeaponAtk(); + float normal_dmg = total_atk * (1 - target->GetBattleContext()->GetDef() / 1000); + float crit = IsCrit() ? GetCritRate() : 0; + float dodge = IsDodge() ? GetDodgeRate() : 0; + float finaly_dmg = normal_dmg * (1.0f + crit + dodge); + return finaly_dmg; +} + +float BattleDataContext::GetTotalAtk() +{ + return 0; +} + +float BattleDataContext::GetDef() +{ + return 0; +} + +float BattleDataContext::GetHeroTotalAtk() +{ + return 0; +} + +float BattleDataContext::GetWeaponAtk() +{ + return 0; +} + +bool BattleDataContext::IsCrit() +{ + return true; +} + + +bool BattleDataContext::IsDodge() +{ + return true; +} + +float BattleDataContext::GetCritRate() +{ + return 0; +} + +float BattleDataContext::GetDodgeRate() +{ + return 0; +} diff --git a/server/gameserver/battledatacontext.h b/server/gameserver/battledatacontext.h new file mode 100644 index 00000000..b6066016 --- /dev/null +++ b/server/gameserver/battledatacontext.h @@ -0,0 +1,75 @@ +#pragma once + + +/* + 子弹命中逻辑 + 1、计算总攻击力 + 2、计算普通伤害 + 3、判断是否暴击(百分比系数),对方是否闪避(系数) + 4、得到实际伤害 + + 免伤后伤害=实际伤害*(1-免伤率) + 吸血值=吸血系数*实际伤害 + + */ + +class Creature; +struct PlayerStats; +struct BattleDataContext +{ + std::shared_ptr join_msg; + long long battle_uuid = 0; + int is_valid_battle = 0; + std::string payload; + int errcode = 0; + std::string errmsg; + + std::shared_ptr hero_dto; + std::shared_ptr weapon_dto1; + std::shared_ptr weapon_dto2; + + float GetHeroAttrAbs(long long hero_uniid, int attr_id); + float GetHeroAttrRate(long long hero_uniid, int attr_id); + + void GetHeroLvQualit(int& hero_lv, int& quality); + void GetWeaponLvQualit(int& weapon_lv, int& quality); + + float GetWeaponAttrAbs(long long weapon_uniid, int attr_id); + float GetWeaponAttrRate(long long weapon_uniid, int attr_id); + + void ParseResult(a8::XObject& obj); + + void CalcBattleStat(struct PlayerStats* stats); + + float CalcDmg(Creature* target, int weapon_uniid); + + float GetDef(); + +private: + void Clear(); + void ApplyAttr(std::array& attr_abs, + std::array& attr_rate, + std::shared_ptr obj); + + float GetTotalAtk(); + float GetHeroTotalAtk(); + float GetWeaponAtk(); + bool IsCrit(); + float GetCritRate(); + bool IsDodge(); + float GetDodgeRate(); + +private: + 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_ = {}; + + std::array weapon1_attr_abs_ = {}; + std::array weapon1_attr_rate_ = {}; + + std::array weapon2_attr_abs_ = {}; + std::array weapon2_attr_rate_ = {}; +}; diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index b3d64012..0f0547de 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -5,7 +5,7 @@ #include "trigger.h" #include "ability.h" #include "weapon.h" -#include "attr.h" +#include "battledatacontext.h" #include "cs_proto.pb.h" @@ -91,7 +91,6 @@ class Creature : public MoveableEntity bool playing_skill = false; int power_idx = -1; int hold_shield_hp = 0; - Attr* attr = nullptr; Weapon second_weapon; a8::Vec2 context_pos; diff --git a/server/gameserver/matchteam.h b/server/gameserver/matchteam.h index 4ec702d9..ad7a5cce 100644 --- a/server/gameserver/matchteam.h +++ b/server/gameserver/matchteam.h @@ -2,6 +2,8 @@ #include "cs_proto.pb.h" +#include "battledatacontext.h" + enum MatchTeamPhase_e { kMatchCombining = 1, diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index 780ef964..116f4ab1 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -2,6 +2,7 @@ #include +#include "battledatacontext.h" namespace cs { class CMJoin; diff --git a/server/gameserver/types.cc b/server/gameserver/types.cc index 9e9090cc..82274b63 100644 --- a/server/gameserver/types.cc +++ b/server/gameserver/types.cc @@ -4,262 +4,3 @@ #include "metamgr.h" #include "human.h" - -float* GetAttrAbsPtr(std::array& attr, int attr_id) -{ - if (!IsValidHumanAttr(attr_id)) { - return nullptr; - } - return &attr[attr_id]; -} - -float* GetAttrRatePtr(std::array& attr, int attr_id) -{ - if (!IsValidHumanAttr(attr_id)) { - return nullptr; - } - return &attr[attr_id]; -} - -void BattleDataContext::Clear() -{ - hero_attr_abs_ = {}; - hero_attr_rate_ = {}; - weapon1_attr_abs_ = {}; - weapon1_attr_rate_ = {}; - weapon2_attr_abs_ = {}; - weapon2_attr_rate_ = {}; -} - -void BattleDataContext::ParseResult(a8::XObject& obj) -{ - is_valid_battle = obj.Get("is_valid_battle"); - payload = obj.Get("payload").GetString(); - errcode = obj.Get("errcode"); - 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", ""); - if (hero_dto->HasKey("attr") && hero_dto->IsArray()) { - ApplyAttr(hero_attr_abs_, - hero_attr_rate_, - hero_dto->At("attr")); - } - } - if (obj.HasKey("weapon_dto1") && obj.At("weapon_dto1")->IsObject()) { - weapon_dto1 = obj.At("weapon_dto1"); - weapon_uniid1_ = weapon_dto1->Get("gun_uniid", 0); - if (weapon_dto1->HasKey("attr") && weapon_dto1->IsArray()) { - ApplyAttr(weapon1_attr_abs_, - weapon1_attr_rate_, - weapon_dto1->At("attr")); - } - } - if (obj.HasKey("weapon_dto2") && obj.At("weapon_dto2")->IsObject()) { - weapon_dto2 = obj.At("weapon_dto2"); - weapon_uniid2_ = weapon_dto2->Get("gun_uniid", 0); - if (weapon_dto2->HasKey("attr") && weapon_dto2->IsArray()) { - ApplyAttr(weapon2_attr_abs_, - weapon2_attr_rate_, - weapon_dto2->At("attr")); - } - } -} - -float BattleDataContext::GetHeroAttrAbs(long long hero_uniid, int attr_id) -{ - if (hero_uniid && hero_uniid == hero_uniid_) { - if (IsValidHumanAttr(attr_id)) { - return hero_attr_abs_[attr_id]; - } - } - return 0; -} - -float BattleDataContext::GetHeroAttrRate(long long hero_uniid, int attr_id) -{ - if (hero_uniid && hero_uniid == hero_uniid_) { - if (IsValidHumanAttr(attr_id)) { - return hero_attr_rate_[attr_id]/ 100.0f; - } - } - return 0; -} - -float BattleDataContext::GetWeaponAttrAbs(long long weapon_uniid, int attr_id) -{ - if (!weapon_uniid) { - return 0; - } - if (IsValidHumanAttr(attr_id)) { - if (weapon_uniid == weapon_uniid1_) { - return weapon1_attr_abs_[attr_id]; - } else if (weapon_uniid == weapon_uniid2_) { - return weapon2_attr_abs_[attr_id]; - } - } - return 0; -} - -float BattleDataContext::GetWeaponAttrRate(long long weapon_uniid, int attr_id) -{ - if (!weapon_uniid) { - return 0; - } - if (IsValidHumanAttr(attr_id)) { - if (weapon_uniid == weapon_uniid1_) { - return weapon1_attr_rate_[attr_id]; - } else if (weapon_uniid == weapon_uniid2_) { - return weapon2_attr_rate_[attr_id]; - } - } - return 0; -} - -void BattleDataContext::ApplyAttr(std::array& attr_abs, - std::array& attr_rate, - std::shared_ptr obj) -{ - if (obj->IsArray()) { - for (int i = 0; i < obj->Size(); ++i) { - std::shared_ptr obj = obj->At(i); - if (obj->IsObject()) { - int attr_id = obj->Get("attr_id", 0); - int type = obj->Get("type", 0); - int val = obj->Get("val", 0); - if (type == 1) { - float* p = GetAttrAbsPtr(attr_abs, attr_id); - if (p) { - *p = val; - } - } else if (type == 2) { - float* p = GetAttrRatePtr(attr_rate, attr_id); - if (p) { - *p = val; - } - } - } - } - } -} - -void BattleDataContext::GetHeroLvQualit(int& hero_lv, int& quality) -{ - hero_lv = 0; - quality = 0; - if (hero_uniid_) { - hero_lv = hero_dto->Get("hero_lv", 0).GetInt(); - quality = hero_dto->Get("quality", 0).GetInt(); - } -} - -void BattleDataContext::GetWeaponLvQualit(int& weapon_lv, int& quality) -{ - weapon_lv = 0; - quality = 0; - if (weapon_uniid1_) { - weapon_lv += weapon_dto1->Get("gun_lv", 0).GetInt(); - quality += weapon_dto1->Get("quality", 0).GetInt(); - } - if (weapon_uniid2_) { - weapon_lv += weapon_dto2->Get("gun_lv", 0).GetInt(); - quality += weapon_dto2->Get("quality", 0).GetInt(); - } -} - -void BattleDataContext::CalcBattleStat(struct PlayerStats* stats) -{ - auto CalcHeroPvpCeg = - [] (long long ceg_uplimit, struct PlayerStats* stats) -> long long - { - MetaData::FormulaPvp* meta = MetaMgr::Instance()->GetFormulaPvp(stats->ranked_topx); - if (!meta) { - return 0; - } - long long ceg = round - ( - ceg_uplimit * - ( - (0.5 * stats->ranked_topx * meta->i->ranked_topx()) + - (0.25 * stats->kills_topx * meta->i->kills_topx()) + - (0.15 * stats->hero_topx * meta->i->hero_topx()) + - (0.5 * stats->weapon_topx * meta->i->weapon_topx()) + - (0.5 * stats->survival_topx * meta->i->survival_topx()) - ) - ); - return ceg; - }; - auto CalcWeaponPvpCeg = - [] (long long ceg_uplimit, struct PlayerStats* stats) -> long long - { - MetaData::FormulaPvp* meta = MetaMgr::Instance()->GetFormulaPvp(stats->ranked_topx); - if (!meta) { - return 0; - } - long long ceg = round - ( - ceg_uplimit * - ( - (0.5 * stats->ranked_topx * meta->i->ranked_topx()) + - (0.25 * stats->kills_topx * meta->i->kills_topx()) + - (0.15 * stats->hero_topx * meta->i->hero_topx()) + - (0.5 * stats->weapon_topx * meta->i->weapon_topx()) + - (0.5 * stats->survival_topx * meta->i->survival_topx()) - ) - ); - return ceg; - }; - - if (hero_uniid_) { - int hero_id = hero_dto->Get("hero_id", 0).GetInt(); - int quality = hero_dto->Get("quality", 0).GetInt(); - int today_get_gold = hero_dto->Get("today_get_gold", 0).GetInt(); - MetaData::Player* hero_meta = MetaMgr::Instance()->GetPlayer(hero_id); - MetaData::HeroQuality* quality_meta = MetaMgr::Instance()->GetHeroQuality(quality); - - stats->pb_hero_stats.set_hero_uniid(a8::XValue(hero_uniid_).GetString()); - stats->pb_hero_stats.set_hero_id(hero_id); - stats->pb_hero_stats.set_hero_name(hero_meta ? hero_meta->i->name() : ""); - if (quality_meta) { - int up_limit = quality_meta->GetPvpCegUpLimit(); - int ceg = CalcHeroPvpCeg(up_limit, stats); - int new_ceg = std::min(up_limit, today_get_gold + ceg); - int finaly_ceg = std::max(0, new_ceg - today_get_gold); - stats->pb_hero_stats.set_ceg_uplimit(up_limit); - stats->pb_hero_stats.set_today_get_ceg - (std::min(up_limit, today_get_gold + finaly_ceg)); - stats->pb_hero_stats.set_reward_ceg(finaly_ceg); - } - } - std::vector> weapons; - if (weapon_dto1) { - weapons.push_back(weapon_dto1); - } - if (weapon_dto2) { - weapons.push_back(weapon_dto2); - } - for (auto& weapon_dto : weapons) { - std::string gun_uniid = weapon_dto->Get("gun_uniid", 0).GetString(); - int gun_id = weapon_dto->Get("gun_id", 0).GetInt(); - int quality = weapon_dto->Get("quality", 0).GetInt(); - int today_get_gold = weapon_dto->Get("today_get_gold", 0).GetInt(); - MetaData::Item* item_meta = MetaMgr::Instance()->GetItem(gun_id); - MetaData::GunQuality* quality_meta = MetaMgr::Instance()->GetGunQuality(quality); - - - auto p = stats->pb_weapons_stats.Add(); - p->set_weapon_uniid(gun_uniid); - p->set_weapon_id(gun_id); - p->set_weapon_name(item_meta ? item_meta->i->name() : ""); - if (quality_meta) { - int up_limit = quality_meta->GetPvpCegUpLimit(); - int ceg = CalcWeaponPvpCeg(up_limit, stats); - int new_ceg = std::min(up_limit, today_get_gold + ceg); - int finaly_ceg = std::max(0, new_ceg - today_get_gold); - p->set_ceg_uplimit(up_limit); - p->set_today_get_ceg - (std::min(up_limit, today_get_gold + finaly_ceg)); - p->set_reward_ceg(finaly_ceg); - } - } -} diff --git a/server/gameserver/types.h b/server/gameserver/types.h index eac165ca..387680a5 100644 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -19,50 +19,3 @@ struct AddItemDTO MetaData::Equip* item_meta = nullptr; bool handled = false; }; - -struct BattleDataContext -{ - std::shared_ptr join_msg; - long long battle_uuid = 0; - int is_valid_battle = 0; - std::string payload; - int errcode = 0; - std::string errmsg; - - std::shared_ptr hero_dto; - std::shared_ptr weapon_dto1; - std::shared_ptr weapon_dto2; - - float GetHeroAttrAbs(long long hero_uniid, int attr_id); - float GetHeroAttrRate(long long hero_uniid, int attr_id); - - void GetHeroLvQualit(int& hero_lv, int& quality); - void GetWeaponLvQualit(int& weapon_lv, int& quality); - - float GetWeaponAttrAbs(long long weapon_uniid, int attr_id); - float GetWeaponAttrRate(long long weapon_uniid, int attr_id); - - void ParseResult(a8::XObject& obj); - - void CalcBattleStat(struct PlayerStats* stats); - -private: - void Clear(); - void ApplyAttr(std::array& attr_abs, - std::array& attr_rate, - std::shared_ptr obj); - -private: - 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_ = {}; - - std::array weapon1_attr_abs_ = {}; - std::array weapon1_attr_rate_ = {}; - - std::array weapon2_attr_abs_ = {}; - std::array weapon2_attr_rate_ = {}; -};