1
This commit is contained in:
parent
2480a9473e
commit
656e6ac288
@ -9,6 +9,26 @@
|
||||
#include "creature.h"
|
||||
#include "types.h"
|
||||
|
||||
class HeroAbility
|
||||
{
|
||||
public:
|
||||
long long hero_uniid_ = 0;
|
||||
MetaData::Player* hero_meta = nullptr;
|
||||
std::array<float, kHAT_End> attr_abs_ = {};
|
||||
std::array<float, kHAT_End> attr_rate_ = {};
|
||||
|
||||
};
|
||||
|
||||
class WeaponAbility
|
||||
{
|
||||
public:
|
||||
long long weapon_uniid = 0;
|
||||
MetaData::Equip* weapon1_meta = nullptr;
|
||||
std::array<float, kHAT_End> attr_abs_ = {};
|
||||
std::array<float, kHAT_End> attr_rate_ = {};
|
||||
|
||||
};
|
||||
|
||||
float* GetAttrAbsPtr(std::array<float, kHAT_End>& attr, int attr_id)
|
||||
{
|
||||
if (!IsValidHumanAttr(attr_id)) {
|
||||
@ -27,12 +47,18 @@ float* GetAttrRatePtr(std::array<float, kHAT_End>& attr, int attr_id)
|
||||
|
||||
void BattleDataContext::Clear()
|
||||
{
|
||||
hero_attr_abs_ = {};
|
||||
hero_attr_rate_ = {};
|
||||
weapon1_attr_abs_ = {};
|
||||
weapon1_attr_rate_ = {};
|
||||
weapon2_attr_abs_ = {};
|
||||
weapon2_attr_rate_ = {};
|
||||
if (hero_ability_) {
|
||||
hero_ability_->attr_abs_ = {};
|
||||
hero_ability_->attr_rate_ = {};
|
||||
}
|
||||
if (weapon1_ability_) {
|
||||
weapon1_ability_->attr_abs_ = {};
|
||||
weapon1_ability_->attr_rate_ = {};
|
||||
}
|
||||
if (weapon2_ability_) {
|
||||
weapon2_ability_->attr_abs_ = {};
|
||||
weapon2_ability_->attr_rate_ = {};
|
||||
}
|
||||
}
|
||||
|
||||
void BattleDataContext::ParseResult(a8::XObject& obj)
|
||||
@ -43,28 +69,31 @@ 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", "");
|
||||
hero_ability_ = std::make_shared<HeroAbility>();
|
||||
hero_ability_->hero_uniid_ = hero_dto->Get("hero_uniid", "");
|
||||
if (hero_dto->HasKey("attr") && hero_dto->IsArray()) {
|
||||
ApplyAttr(hero_attr_abs_,
|
||||
hero_attr_rate_,
|
||||
ApplyAttr(hero_ability_->attr_abs_,
|
||||
hero_ability_->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);
|
||||
weapon1_ability_ = std::make_shared<WeaponAbility>();
|
||||
weapon1_ability_->weapon_uniid = weapon_dto1->Get("gun_uniid", 0);
|
||||
if (weapon_dto1->HasKey("attr") && weapon_dto1->IsArray()) {
|
||||
ApplyAttr(weapon1_attr_abs_,
|
||||
weapon1_attr_rate_,
|
||||
ApplyAttr(weapon1_ability_->attr_abs_,
|
||||
weapon1_ability_->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);
|
||||
weapon2_ability_ = std::make_shared<WeaponAbility>();
|
||||
weapon2_ability_->weapon_uniid = weapon_dto1->Get("gun_uniid", 0);
|
||||
if (weapon_dto2->HasKey("attr") && weapon_dto2->IsArray()) {
|
||||
ApplyAttr(weapon2_attr_abs_,
|
||||
weapon2_attr_rate_,
|
||||
ApplyAttr(weapon2_ability_->attr_abs_,
|
||||
weapon2_ability_->attr_rate_,
|
||||
weapon_dto2->At("attr"));
|
||||
}
|
||||
}
|
||||
@ -72,9 +101,9 @@ void BattleDataContext::ParseResult(a8::XObject& obj)
|
||||
|
||||
float BattleDataContext::GetHeroAttrAbs(long long hero_uniid, int attr_id)
|
||||
{
|
||||
if (hero_uniid && hero_uniid == hero_uniid_) {
|
||||
if (hero_uniid && hero_uniid == hero_ability_->hero_uniid_) {
|
||||
if (IsValidHumanAttr(attr_id)) {
|
||||
return hero_attr_abs_[attr_id];
|
||||
return hero_ability_->attr_abs_[attr_id];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -82,9 +111,9 @@ float BattleDataContext::GetHeroAttrAbs(long long hero_uniid, int attr_id)
|
||||
|
||||
float BattleDataContext::GetHeroAttrRate(long long hero_uniid, int attr_id)
|
||||
{
|
||||
if (hero_uniid && hero_uniid == hero_uniid_) {
|
||||
if (hero_uniid && hero_uniid == hero_ability_->hero_uniid_) {
|
||||
if (IsValidHumanAttr(attr_id)) {
|
||||
return hero_attr_rate_[attr_id]/ 100.0f;
|
||||
return hero_ability_->attr_rate_[attr_id]/ 100.0f;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -96,10 +125,10 @@ float BattleDataContext::GetWeaponAttrAbs(long long weapon_uniid, int attr_id)
|
||||
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];
|
||||
if (weapon1_ability_ && weapon_uniid == weapon1_ability_->weapon_uniid) {
|
||||
return weapon1_ability_->attr_abs_[attr_id];
|
||||
} else if (weapon2_ability_ && weapon_uniid == weapon2_ability_->weapon_uniid) {
|
||||
return weapon2_ability_->attr_abs_[attr_id];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -111,10 +140,10 @@ float BattleDataContext::GetWeaponAttrRate(long long weapon_uniid, int attr_id)
|
||||
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];
|
||||
if (weapon1_ability_ && weapon_uniid == weapon1_ability_->weapon_uniid) {
|
||||
return weapon1_ability_->attr_rate_[attr_id];
|
||||
} else if (weapon2_ability_ && weapon_uniid == weapon2_ability_->weapon_uniid) {
|
||||
return weapon2_ability_->attr_rate_[attr_id];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -151,7 +180,7 @@ void BattleDataContext::GetHeroLvQualit(int& hero_lv, int& quality)
|
||||
{
|
||||
hero_lv = 0;
|
||||
quality = 0;
|
||||
if (hero_uniid_) {
|
||||
if (hero_ability_) {
|
||||
hero_lv = hero_dto->Get("hero_lv", 0).GetInt();
|
||||
quality = hero_dto->Get("quality", 0).GetInt();
|
||||
}
|
||||
@ -161,11 +190,11 @@ void BattleDataContext::GetWeaponLvQualit(int& weapon_lv, int& quality)
|
||||
{
|
||||
weapon_lv = 0;
|
||||
quality = 0;
|
||||
if (weapon_uniid1_) {
|
||||
if (weapon1_ability_) {
|
||||
weapon_lv += weapon_dto1->Get("gun_lv", 0).GetInt();
|
||||
quality += weapon_dto1->Get("quality", 0).GetInt();
|
||||
}
|
||||
if (weapon_uniid2_) {
|
||||
if (weapon2_ability_) {
|
||||
weapon_lv += weapon_dto2->Get("gun_lv", 0).GetInt();
|
||||
quality += weapon_dto2->Get("quality", 0).GetInt();
|
||||
}
|
||||
@ -214,14 +243,14 @@ void BattleDataContext::CalcBattleStat(struct PlayerStats* stats)
|
||||
return ceg;
|
||||
};
|
||||
|
||||
if (hero_uniid_) {
|
||||
if (hero_ability_) {
|
||||
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_uniid(a8::XValue(hero_ability_->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) {
|
||||
|
@ -22,6 +22,8 @@ namespace MetaData
|
||||
class Creature;
|
||||
class Bullet;
|
||||
struct PlayerStats;
|
||||
class HeroAbility;
|
||||
class WeaponAbility;
|
||||
struct BattleDataContext
|
||||
{
|
||||
std::shared_ptr<cs::CMJoin> join_msg;
|
||||
@ -67,21 +69,10 @@ private:
|
||||
float GetDodgeRate();
|
||||
|
||||
private:
|
||||
long long hero_uniid_ = 0;
|
||||
long long weapon_uniid1_ = 0;
|
||||
long long weapon_uniid2_ = 0;
|
||||
MetaData::Player* hero_meta = nullptr;
|
||||
MetaData::Equip* weapon1_meta = nullptr;
|
||||
MetaData::Equip* weapon2_meta = nullptr;
|
||||
|
||||
std::array<float, kHAT_End> hero_attr_abs_ = {};
|
||||
std::array<float, kHAT_End> hero_attr_rate_ = {};
|
||||
|
||||
std::array<float, kHAT_End> weapon1_attr_abs_ = {};
|
||||
std::array<float, kHAT_End> weapon1_attr_rate_ = {};
|
||||
|
||||
std::array<float, kHAT_End> weapon2_attr_abs_ = {};
|
||||
std::array<float, kHAT_End> weapon2_attr_rate_ = {};
|
||||
std::shared_ptr<HeroAbility> hero_ability_;
|
||||
std::shared_ptr<WeaponAbility> weapon1_ability_;
|
||||
std::shared_ptr<WeaponAbility> weapon2_ability_;
|
||||
|
||||
float atk_ = 0;
|
||||
float def_ = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user