141 lines
4.1 KiB
C++
141 lines
4.1 KiB
C++
#include "precompile.h"
|
|
#include "metamgr.h"
|
|
|
|
float* GetAttrAbsPtr(std::array<float, kHAT_End>& attr, int attr_id)
|
|
{
|
|
if (!IsValidHumanAttr(attr_id)) {
|
|
return nullptr;
|
|
}
|
|
return &attr[attr_id];
|
|
}
|
|
|
|
float* GetAttrRatePtr(std::array<float, kHAT_End>& 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<float, kHAT_End>& attr_abs,
|
|
std::array<float, kHAT_End>& attr_rate,
|
|
std::shared_ptr<a8::XObject> obj)
|
|
{
|
|
if (obj->IsArray()) {
|
|
for (int i = 0; i < obj->Size(); ++i) {
|
|
std::shared_ptr<a8::XObject> 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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|