This commit is contained in:
aozhiwei 2022-05-24 21:39:32 +08:00
parent 731417119f
commit c64c00f76b
5 changed files with 25 additions and 57 deletions

View File

@ -136,7 +136,7 @@ class Human : public Creature
int today_enter_times = 0; int today_enter_times = 0;
int account_registertime = 0; int account_registertime = 0;
int channel = 0; int channel = 0;
std::string hero_uniid; long long hero_uniid = 0;
long long battle_uuid = 0; long long battle_uuid = 0;
int is_valid_battle = 0; int is_valid_battle = 0;
std::string payload; std::string payload;

View File

@ -3985,7 +3985,7 @@ void Room::AddTeam(class MatchTeam* team)
} else { } else {
Player* hum = NewPlayer(); Player* hum = NewPlayer();
hum->proto_version = msg.proto_version(); 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->battle_uuid = member->battle_uuid;
hum->is_valid_battle = member->is_valid_battle; hum->is_valid_battle = member->is_valid_battle;
hum->payload = member->payload; hum->payload = member->payload;

View File

@ -185,7 +185,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
} }
Player* hum = room->NewPlayer(); Player* hum = room->NewPlayer();
hum->proto_version = msg.proto_version(); 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->battle_uuid = results.at(0)->battle_uuid;
hum->is_valid_battle = results.at(0)->is_valid_battle; hum->is_valid_battle = results.at(0)->is_valid_battle;
hum->payload = results.at(0)->payload; hum->payload = results.at(0)->payload;

View File

@ -35,7 +35,7 @@ void BattleDataContext::ParseResult(a8::XObject& obj)
errmsg = obj.Get("errmsg").GetString(); errmsg = obj.Get("errmsg").GetString();
if (obj.HasKey("hero_dto") && obj.At("hero_dto")->IsObject()) { if (obj.HasKey("hero_dto") && obj.At("hero_dto")->IsObject()) {
hero_dto = obj.At("hero_dto"); 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()) { if (hero_dto->HasKey("attr") && hero_dto->IsArray()) {
ApplyAttr(hero_attr_abs_, ApplyAttr(hero_attr_abs_,
hero_attr_rate_, hero_attr_rate_,
@ -44,7 +44,7 @@ void BattleDataContext::ParseResult(a8::XObject& obj)
} }
if (obj.HasKey("weapon_dto1") && obj.At("weapon_dto1")->IsObject()) { if (obj.HasKey("weapon_dto1") && obj.At("weapon_dto1")->IsObject()) {
weapon_dto1 = obj.At("weapon_dto1"); 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()) { if (weapon_dto1->HasKey("attr") && weapon_dto1->IsArray()) {
ApplyAttr(weapon1_attr_abs_, ApplyAttr(weapon1_attr_abs_,
weapon1_attr_rate_, weapon1_attr_rate_,
@ -53,7 +53,7 @@ void BattleDataContext::ParseResult(a8::XObject& obj)
} }
if (obj.HasKey("weapon_dto2") && obj.At("weapon_dto2")->IsObject()) { if (obj.HasKey("weapon_dto2") && obj.At("weapon_dto2")->IsObject()) {
weapon_dto2 = obj.At("weapon_dto2"); 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()) { if (weapon_dto2->HasKey("attr") && weapon_dto2->IsArray()) {
ApplyAttr(weapon2_attr_abs_, ApplyAttr(weapon2_attr_abs_,
weapon2_attr_rate_, 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)) { if (hero_uniid && hero_uniid == hero_uniid_) {
return hero_attr_abs_[attr_id]; if (IsValidHumanAttr(attr_id)) {
return hero_attr_abs_[attr_id];
}
} }
return 0; return 0;
} }
float BattleDataContext::GetHeroAttrRate(int attr_id) float BattleDataContext::GetHeroAttrRate(long long hero_uniid, int attr_id)
{ {
if (IsValidHumanAttr(attr_id)) { if (hero_uniid && hero_uniid == hero_uniid_) {
return hero_attr_rate_[attr_id]/ 100.0f; if (IsValidHumanAttr(attr_id)) {
return hero_attr_rate_[attr_id]/ 100.0f;
}
} }
return 0; return 0;
} }
@ -84,9 +88,9 @@ float BattleDataContext::GetWeaponAttrAbs(long long weapon_uniid, int attr_id)
return 0; return 0;
} }
if (IsValidHumanAttr(attr_id)) { if (IsValidHumanAttr(attr_id)) {
if (weapon_uniid == weapon_uniid1) { if (weapon_uniid == weapon_uniid1_) {
return weapon1_attr_abs_[attr_id]; return weapon1_attr_abs_[attr_id];
} else if (weapon_uniid == weapon_uniid2) { } else if (weapon_uniid == weapon_uniid2_) {
return weapon2_attr_abs_[attr_id]; return weapon2_attr_abs_[attr_id];
} }
} }
@ -99,51 +103,15 @@ float BattleDataContext::GetWeaponAttrRate(long long weapon_uniid, int attr_id)
return 0; return 0;
} }
if (IsValidHumanAttr(attr_id)) { if (IsValidHumanAttr(attr_id)) {
if (weapon_uniid == weapon_uniid1) { if (weapon_uniid == weapon_uniid1_) {
return weapon1_attr_rate_[attr_id]; 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 weapon2_attr_rate_[attr_id];
} }
} }
return 0; 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<a8::XObject> 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<float, kHAT_End>& attr_abs, void BattleDataContext::ApplyAttr(std::array<float, kHAT_End>& attr_abs,
std::array<float, kHAT_End>& attr_rate, std::array<float, kHAT_End>& attr_rate,
std::shared_ptr<a8::XObject> obj) std::shared_ptr<a8::XObject> obj)

View File

@ -33,8 +33,8 @@ struct BattleDataContext
std::shared_ptr<a8::XObject> weapon_dto1; std::shared_ptr<a8::XObject> weapon_dto1;
std::shared_ptr<a8::XObject> weapon_dto2; std::shared_ptr<a8::XObject> weapon_dto2;
float GetHeroAttrAbs(int attr_id); float GetHeroAttrAbs(long long hero_uniid, int attr_id);
float GetHeroAttrRate(int attr_id); float GetHeroAttrRate(long long hero_uniid, int attr_id);
float GetWeaponAttrAbs(long long weapon_uniid, int attr_id); float GetWeaponAttrAbs(long long weapon_uniid, int attr_id);
float GetWeaponAttrRate(long long weapon_uniid, int attr_id); float GetWeaponAttrRate(long long weapon_uniid, int attr_id);
@ -48,9 +48,9 @@ private:
std::shared_ptr<a8::XObject> obj); std::shared_ptr<a8::XObject> obj);
private: private:
std::string hero_uniid; long long hero_uniid_ = 0;
long long weapon_uniid1 = 0; long long weapon_uniid1_ = 0;
long long weapon_uniid2 = 0; long long weapon_uniid2_ = 0;
std::array<float, kHAT_End> hero_attr_abs_ = {}; std::array<float, kHAT_End> hero_attr_abs_ = {};
std::array<float, kHAT_End> hero_attr_rate_ = {}; std::array<float, kHAT_End> hero_attr_rate_ = {};