This commit is contained in:
aozhiwei 2022-09-06 18:35:24 +08:00
parent 651ae6631a
commit 2d69a6a1ec
8 changed files with 10 additions and 255 deletions

View File

@ -16,8 +16,6 @@ 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_ = {};
float GetAtk()
{
@ -56,8 +54,6 @@ class WeaponAbility
public:
long long weapon_uniid = 0;
MetaData::Equip* weapon_meta = nullptr;
std::array<float, kHAT_End> attr_abs_ = {};
std::array<float, kHAT_End> attr_rate_ = {};
float GetAtk()
{
@ -65,22 +61,6 @@ public:
}
};
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];
}
BattleDataContext::BattleDataContext()
{
hero_ability_ = std::make_shared<HeroAbility>();
@ -89,18 +69,6 @@ BattleDataContext::BattleDataContext()
void BattleDataContext::Clear()
{
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)
@ -116,11 +84,6 @@ void BattleDataContext::ParseResult(a8::XObject& obj)
if (meta) {
hero_ability_->hero_meta = meta;
}
if (hero_dto->HasKey("attr") && hero_dto->IsArray()) {
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");
@ -129,11 +92,6 @@ void BattleDataContext::ParseResult(a8::XObject& obj)
weapon1_ability_ = std::make_shared<WeaponAbility>();
weapon1_ability_->weapon_uniid = weapon_dto1->Get("gun_uniid", 0);
weapon1_ability_->weapon_meta = meta;
if (weapon_dto1->HasKey("attr") && weapon_dto1->IsArray()) {
ApplyAttr(weapon1_ability_->attr_abs_,
weapon1_ability_->attr_rate_,
weapon_dto1->At("attr"));
}
}
}
if (obj.HasKey("weapon_dto2") && obj.At("weapon_dto2")->IsObject()) {
@ -143,88 +101,6 @@ void BattleDataContext::ParseResult(a8::XObject& obj)
weapon2_ability_ = std::make_shared<WeaponAbility>();
weapon2_ability_->weapon_uniid = weapon_dto2->Get("gun_uniid", 0);
weapon1_ability_->weapon_meta = meta;
if (weapon_dto2->HasKey("attr") && weapon_dto2->IsArray()) {
ApplyAttr(weapon2_ability_->attr_abs_,
weapon2_ability_->attr_rate_,
weapon_dto2->At("attr"));
}
}
}
}
float BattleDataContext::GetHeroAttrAbs(long long hero_uniid, int attr_id)
{
if (hero_uniid && hero_uniid == hero_ability_->hero_uniid_) {
if (IsValidHumanAttr(attr_id)) {
return hero_ability_->attr_abs_[attr_id];
}
}
return 0;
}
float BattleDataContext::GetHeroAttrRate(long long hero_uniid, int attr_id)
{
if (hero_uniid && hero_uniid == hero_ability_->hero_uniid_) {
if (IsValidHumanAttr(attr_id)) {
return hero_ability_->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 (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;
}
float BattleDataContext::GetWeaponAttrRate(long long weapon_uniid, int attr_id)
{
if (!weapon_uniid) {
return 0;
}
if (IsValidHumanAttr(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;
}
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;
}
}
}
}
}
}
@ -377,6 +253,11 @@ float BattleDataContext::CalcDmg(Obstacle* target, Bullet* bullet)
return finaly_dmg;
}
float BattleDataContext::CalcDmg(Explosion* e)
{
}
float BattleDataContext::GetTotalAtk(Bullet* bullet)
{
float total_atk = (GetHeroTotalAtk() / 100 + 1) * GetWeaponAtk(bullet);

View File

@ -23,6 +23,7 @@ namespace MetaData
class Creature;
class Bullet;
class Obstacle;
class Explosion;
struct PlayerStats;
class HeroAbility;
class WeaponAbility;
@ -40,21 +41,17 @@ struct BattleDataContext
std::shared_ptr<a8::XObject> weapon_dto2;
BattleDataContext();
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, Bullet* bullet);
float CalcDmg(Obstacle* target, Bullet* bullet);
float CalcDmg(Explosion* e);
float GetDef();
@ -68,10 +65,6 @@ struct BattleDataContext
private:
void Clear();
void ApplyAttr(std::array<float, kHAT_End>& attr_abs,
std::array<float, kHAT_End>& attr_rate,
std::shared_ptr<a8::XObject> obj);
float GetTotalAtk(Bullet* bullet);
float GetHeroTotalAtk();
float GetWeaponAtk(Bullet* bullet);

View File

@ -742,51 +742,6 @@ void Bullet::OnKillTarget(Entity* target)
}
}
void Bullet::CalcDmg(Entity* entity,
float& finaly_dmg,
float& hero_atk_rate,
float& target_def_rate)
{
finaly_dmg = 0;
hero_atk_rate = 0;
target_def_rate = 0;
if (sender.Get()->IsAndroid()) {
Android* android = (Android*)sender.Get();
hero_atk_rate -= android->ai->GetAttackRate();
}
hero_atk_rate += ability_->GetAttrRate(kHAT_Atk);
if (IsCurrWeapon()) {
hero_atk_rate += ability_->GetAttrRate(kHAT_WeaponDmg);
}
{
float atk = gun_meta->i->atk();
if (sender.Get()->GetBattleContext()) {
float gun_atk_add = sender.Get()->GetBattleContext()->GetWeaponAttrAbs(weapon_uniid, kHAT_Atk);
float hero_atk_add = sender.Get()->GetBattleContext()->GetHeroAttrAbs(sender.Get()->hero_uniid, kHAT_Atk);
float base_atk = sender.Get()->GetBaseAtk() + gun_meta->i->atk();
if ((gun_atk_add + hero_atk_add) > 0.0001f &&
base_atk > 0.0001f) {
hero_atk_rate += (gun_atk_add + hero_atk_add) / base_atk;
}
atk += gun_atk_add;
}
if (entity->IsCreature(room)) {
Creature* target = (Creature*)entity;
if (target->GetBattleContext()) {
float def_abs = target->GetBattleContext()->GetHeroAttrAbs(target->hero_uniid, kHAT_Def);
if (def_abs > 0.0001f &&
target->GetBaseDef() > 0.0001f) {
target_def_rate += def_abs / target->GetBaseDef();
}
}
}
finaly_dmg = atk * (1 + hero_atk_rate) * (1 - target_def_rate);
finaly_dmg = std::max(finaly_dmg, 0.0f);
}
}
void Bullet::OnStrengthen(Obstacle* ob)
{

View File

@ -43,10 +43,6 @@ class Bullet : public MoveableEntity
float GetExplosionRange();
bool IsCurrWeapon();
bool IsPreBattleBullet();
void CalcDmg(Entity* entity,
float& finaly_dmg,
float& hero_atk_rate,
float& target_def_rate);
protected:
Bullet();

View File

@ -310,17 +310,7 @@ void Car::OnBulletHit(Bullet* bullet)
{
if (!IsDead(room)) {
//超能电磁枪已删除
#ifdef ATTR
float finaly_dmg = bullet->sender.Get()->GetBattleContext()->CalcDmg(this, bullet);
#else
float finaly_dmg = 0;
float atk_rate = 0;
float def_rate = 0;
bullet->CalcDmg(this, finaly_dmg, atk_rate, def_rate);
#if 1
finaly_dmg += bullet->gun_meta->i->atk_mech();
#endif
#endif
if (bullet->meta->buff_meta) {
MustBeAddBuff(bullet->sender.Get(), bullet->meta->i->buffid());
}
@ -351,20 +341,7 @@ void Car::OnExplosionHit(Explosion* e)
HasBuffEffect(kBET_Fly)) {
return;
}
float dmg = e->GetDmg();
float def = GetDef() * (1 + GetAbility()->GetAttrRate(kHAT_Def)) +
GetAbility()->GetAttrAbs(kHAT_Def);
float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K);
finaly_dmg = std::max(finaly_dmg, 0.0f);
#ifdef DEBUG
{
room->BroadcastDebugMsg(a8::Format("explosion dmg:%d def:%d finaly_dmg:%d",
{dmg,
def,
finaly_dmg}));
}
#endif
float finaly_dmg = GetBattleContext()->CalcDmg(e);
DecHP(finaly_dmg,
VP_Explosion,
"",

View File

@ -112,19 +112,7 @@ void Hero::OnExplosionHit(Explosion* e)
}
RemoveBuffByEffectId(kBET_PeaceMode);
float dmg = e->GetDmg();
float def = GetDef() * (1 + GetAbility()->GetAttrRate(kHAT_Def)) +
GetAbility()->GetAttrAbs(kHAT_Def);
float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K);
finaly_dmg = std::max(finaly_dmg, 0.0f);
#ifdef DEBUG
{
room->BroadcastDebugMsg(a8::Format("explosion dmg:%d def:%d finaly_dmg:%d",
{dmg,
def,
finaly_dmg}));
}
#endif
float finaly_dmg = GetBattleContext()->CalcDmg(e);
DecHP(finaly_dmg,
VP_Explosion,
"",
@ -143,14 +131,7 @@ void Hero::OnBulletHit(Bullet* bullet)
RemoveBuffByEffectId(kBET_PeaceMode);
if (!IsDead(room) && (bullet->IsBomb() || bullet->sender.Get()->team_id != team_id)) {
#ifdef ATTR
float finaly_dmg = bullet->sender.Get()->GetBattleContext()->CalcDmg(this, bullet);
#else
float finaly_dmg = 0;
float atk_rate = 0;
float def_rate = 0;
bullet->CalcDmg(this, finaly_dmg, atk_rate, def_rate);
#endif
if (bullet->sender.Get()->IsHuman()) {
bullet->sender.Get()->AsHuman()->stats.damage_amount_out += finaly_dmg;
}

View File

@ -3527,16 +3527,7 @@ void Human::OnBulletHit(Bullet* bullet)
RemoveBuffByEffectId(kBET_PeaceMode);
if (!dead && (bullet->IsBomb() || bullet->sender.Get()->team_id != team_id)) {
#ifdef ATTR
float finaly_dmg = bullet->sender.Get()->GetBattleContext()->CalcDmg(this, bullet);
#else
float old_hp = GetHP();
float old_max_hp = GetMaxHP();
float finaly_dmg = 0;
float atk_rate = 0;
float def_rate = 0;
bullet->CalcDmg(this, finaly_dmg, atk_rate, def_rate);
#endif
if (bullet->sender.Get()->IsHuman()) {
bullet->sender.Get()->AsHuman()->stats.damage_amount_out += finaly_dmg;
}
@ -3585,19 +3576,7 @@ void Human::OnExplosionHit(Explosion* e)
}
RemoveBuffByEffectId(kBET_PeaceMode);
float dmg = e->GetDmg();
float def = GetDef() * (1 + GetAbility()->GetAttrRate(kHAT_Def)) +
GetAbility()->GetAttrAbs(kHAT_Def);
float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K);
finaly_dmg = std::max(finaly_dmg, 0.0f);
#ifdef DEBUG
{
room->BroadcastDebugMsg(a8::Format("explosion dmg:%d def:%d finaly_dmg:%d",
{dmg,
def,
finaly_dmg}));
}
#endif
float finaly_dmg = GetBattleContext()->CalcDmg(e);
DecHP(finaly_dmg,
VP_Explosion,
"",

View File

@ -504,14 +504,7 @@ void Obstacle::OnBulletHit(Bullet* bullet)
}
}
}
#ifdef ATTR
float finaly_dmg = bullet->sender.Get()->GetBattleContext()->CalcDmg(this, bullet);
#else
float finaly_dmg = 0;
float atk_rate = 0;
float def_rate = 0;
bullet->CalcDmg(this, finaly_dmg, atk_rate, def_rate);
#endif
SetHealth(bullet->room, std::max(0.0f, GetHealth(bullet->room) - finaly_dmg));
if (GetHealth(bullet->room) <= 0.01f) {
Die(bullet->room);