重构 hp maxhp ability
This commit is contained in:
parent
c56483e85d
commit
545939d67e
@ -43,8 +43,8 @@ void Car::Initialize()
|
||||
SetCurrWeapon(&weapons[GUN_SLOT1]);
|
||||
}
|
||||
born_frameno_ = room->GetFrameNo();
|
||||
ability.hp = hero_meta_->i->health();
|
||||
ability.max_hp = std::max(ability.hp, ability.max_hp);
|
||||
SetHP(hero_meta_->i->health());
|
||||
SetMaxHP(std::max(GetHP(), GetMaxHP()));
|
||||
TryAddBuff(this, meta->car_deactive_buff_id);
|
||||
cur_oil_ = meta->i->max_oil();
|
||||
}
|
||||
@ -270,7 +270,7 @@ void Car::OnBulletHit(Bullet* bullet)
|
||||
{
|
||||
if (!IsDead(room)) {
|
||||
float dmg = bullet->GetAtk() + bullet->gun_meta->i->atk_mech();
|
||||
float def = ability.def * (1 + GetAbility()->GetAttrRate(kHAT_Def)) +
|
||||
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);
|
||||
@ -291,7 +291,7 @@ void Car::DecHP(float dec_hp, int killer_id, const std::string& killer_name, int
|
||||
}
|
||||
float old_health = GetHP();
|
||||
float new_health = std::max(0.0f, GetHP() - dec_hp);
|
||||
ability.hp = std::max(0.0f, new_health);
|
||||
SetHP(std::max(0.0f, new_health));
|
||||
if (GetHP() <= 0.0001f && !IsDead(room)) {
|
||||
BeKill(killer_id, killer_name, weapon_id);
|
||||
}
|
||||
|
@ -1891,6 +1891,16 @@ float Creature::GetMaxHP()
|
||||
return ability.max_hp;
|
||||
}
|
||||
|
||||
float Creature::GetDef()
|
||||
{
|
||||
return ability.def;
|
||||
}
|
||||
|
||||
void Creature::SetDef(float def)
|
||||
{
|
||||
ability.def = def;
|
||||
}
|
||||
|
||||
void Creature::GetHitEnemys(std::set<Creature*>& enemys)
|
||||
{
|
||||
room->grid_service->TraverseCreatures
|
||||
@ -1923,6 +1933,16 @@ void Creature::AddHp(float hp)
|
||||
}
|
||||
}
|
||||
|
||||
void Creature::SetHP(float hp)
|
||||
{
|
||||
ability.hp = hp;
|
||||
}
|
||||
|
||||
void Creature::SetMaxHP(float max_hp)
|
||||
{
|
||||
ability.max_hp = max_hp;
|
||||
}
|
||||
|
||||
bool Creature::TryMove(const a8::Vec2& target_pos, a8::Vec2& out_pos)
|
||||
{
|
||||
bool move_ok = false;
|
||||
|
@ -60,7 +60,6 @@ class Creature : public MoveableEntity
|
||||
a8::Vec2 shoot_offset;
|
||||
int shot_hole = 0;
|
||||
Creature* shot_passenger = nullptr;
|
||||
HumanAbility ability;
|
||||
a8::Vec2 target_pos;
|
||||
std::function<bool ()> on_move_collision;
|
||||
bool poisoning = false;
|
||||
@ -145,6 +144,8 @@ class Creature : public MoveableEntity
|
||||
Car* AsCar() { return IsCar() ? (Car*)this : nullptr; };
|
||||
virtual void DecHP(float dec_hp, int killer_id, const std::string& killer_name, int weapon_id) {};
|
||||
void AddHp(float hp);
|
||||
void SetHP(float hp);
|
||||
void SetMaxHP(float max_hp);
|
||||
|
||||
RaceType_e GetRace() { return race_; }
|
||||
|
||||
@ -190,6 +191,8 @@ class Creature : public MoveableEntity
|
||||
void ClearAimingBuffs();
|
||||
float GetHP();
|
||||
float GetMaxHP();
|
||||
float GetDef();
|
||||
void SetDef(float def);
|
||||
void GetHitEnemys(std::set<Creature*>& enemys);
|
||||
bool TryMove(const a8::Vec2& target_pos, a8::Vec2& out_pos);
|
||||
void SetInfiniteBulletMode();
|
||||
@ -241,6 +244,7 @@ private:
|
||||
Team* team_ = nullptr;
|
||||
Weapon* curr_weapon_ = nullptr;
|
||||
CreatureWeakPtrChunk weak_ptr_chunk_;
|
||||
HumanAbility ability;
|
||||
std::shared_ptr<Ability> ability_;
|
||||
std::array<list_head, kBET_End> buff_effect_ = {};
|
||||
std::array<list_head, kBET_End> depend_effect_ = {};
|
||||
|
@ -83,7 +83,7 @@ void Hero::OnBulletHit(Bullet* bullet)
|
||||
}
|
||||
if (!IsDead(room) && (bullet->IsBomb() || bullet->sender.Get()->team_id != team_id)) {
|
||||
float dmg = bullet->GetAtk();
|
||||
float def = ability.def * (1 + GetAbility()->GetAttrRate(kHAT_Def)) +
|
||||
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);
|
||||
@ -202,7 +202,7 @@ void Hero::DecHP(float dec_hp, int killer_id, const std::string& killer_name, in
|
||||
}
|
||||
float old_health = GetHP();
|
||||
float new_health = std::max(0.0f, GetHP() - dec_hp);
|
||||
ability.hp = std::max(0.0f, new_health);
|
||||
SetHP(std::max(0.0f, new_health));
|
||||
if (GetHP() <= 0.0001f && !IsDead(room)) {
|
||||
BeKill(killer_id, killer_name, weapon_id);
|
||||
}
|
||||
|
@ -66,12 +66,15 @@ void Human::Initialize()
|
||||
RecalcSelfCollider();
|
||||
volume_ = meta->volume;
|
||||
observers_.insert(this);
|
||||
ability.hp = meta->i->health();
|
||||
SetHP(meta->i->health());
|
||||
for (auto& weapon : spec_weapons) {
|
||||
if (weapon.meta) {
|
||||
ability.hp += weapon.meta ? weapon.GetAttrValue(kHAT_MaxHp) : 0;
|
||||
float hp = GetHP();
|
||||
hp += weapon.meta ? weapon.GetAttrValue(kHAT_MaxHp) : 0;
|
||||
SetHP(hp);
|
||||
}
|
||||
}
|
||||
SetMaxHP(GetHP());
|
||||
}
|
||||
|
||||
float Human::GetSpeed()
|
||||
@ -784,7 +787,7 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id)
|
||||
} else {
|
||||
dead = true;
|
||||
downed = false;
|
||||
ability.hp = 0.0f;
|
||||
SetHP(0.0f);
|
||||
dead_frameno = room->GetFrameNo();
|
||||
++dead_times;
|
||||
if (HasBuffEffect(kBET_Camouflage)) {
|
||||
@ -859,7 +862,7 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name, i
|
||||
float old_health = GetHP();
|
||||
float new_health = std::max(0.0f, GetHP() - dec_hp);
|
||||
AdjustDecHp(old_health, new_health);
|
||||
ability.hp = std::max(0.0f, new_health);
|
||||
SetHP(std::max(0.0f, new_health));
|
||||
if (GetHP() - old_health > 0.001f) {
|
||||
stats.damage_amount_in += GetHP() - old_health;
|
||||
}
|
||||
@ -874,7 +877,7 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name, i
|
||||
SyncAroundPlayers(__FILE__, __LINE__, __func__);
|
||||
} else {
|
||||
if (HasNoDownedTeammate()) {
|
||||
ability.hp = MetaMgr::Instance()->GetSysParamAsInt("downed_recover_hp");
|
||||
SetHP(MetaMgr::Instance()->GetSysParamAsInt("downed_recover_hp"));
|
||||
downed = true;
|
||||
if (HasBuffEffect(kBET_Camouflage)) {
|
||||
RemoveBuffByEffectId(kBET_Camouflage);
|
||||
@ -1326,16 +1329,17 @@ void Human::RecalcVolume()
|
||||
|
||||
void Human::RecalcBaseAttr()
|
||||
{
|
||||
ability.def = meta->i->def();
|
||||
MetaData::Equip* chest_meta = MetaMgr::Instance()->GetEquip(chest);
|
||||
float def = meta->i->def();
|
||||
if (chest_meta) {
|
||||
ability.def += chest_meta->i->def();
|
||||
def += chest_meta->i->def();
|
||||
}
|
||||
MetaData::Equip* helmet_meta = MetaMgr::Instance()->GetEquip(helmet);
|
||||
if (helmet_meta) {
|
||||
ability.def += helmet_meta->i->def();
|
||||
def += helmet_meta->i->def();
|
||||
}
|
||||
ability.max_hp = std::max(ability.hp, ability.max_hp);
|
||||
SetDef(def);
|
||||
SetMaxHP(std::max(GetHP(), GetMaxHP()));
|
||||
}
|
||||
|
||||
int Human::GetVolume(int slot_id)
|
||||
@ -1349,8 +1353,10 @@ int Human::GetVolume(int slot_id)
|
||||
void Human::RecoverHp(int inc_hp)
|
||||
{
|
||||
if (!dead) {
|
||||
ability.hp += inc_hp;
|
||||
ability.hp = std::max(GetHP(), GetMaxHP());
|
||||
float hp = GetHP();
|
||||
hp += inc_hp;
|
||||
SetHP(hp);
|
||||
SetHP(std::min(GetHP(), GetMaxHP()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2586,7 +2592,7 @@ void Human::Revive()
|
||||
dead = false;
|
||||
downed = false;
|
||||
real_dead = false;
|
||||
ability.hp = GetMaxHP();
|
||||
SetHP(GetMaxHP());
|
||||
ClearBuffList();
|
||||
{
|
||||
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(kREVIVE_BUFF_ID);
|
||||
@ -2878,12 +2884,13 @@ void Human::OnMetaChange()
|
||||
SetCurrWeapon(&weapons[0]);
|
||||
}
|
||||
}
|
||||
ability.hp = meta->i->health();
|
||||
float hp = meta->i->health();
|
||||
for (auto& weapon : spec_weapons) {
|
||||
if (weapon.meta) {
|
||||
ability.hp += weapon.meta ? weapon.GetAttrValue(kHAT_MaxHp) : 0;
|
||||
hp += weapon.meta ? weapon.GetAttrValue(kHAT_MaxHp) : 0;
|
||||
}
|
||||
}
|
||||
SetHP(hp);
|
||||
room->frame_event.AddHpChg(GetWeakPtrRef());
|
||||
RecalcBaseAttr();
|
||||
ClearSkill();
|
||||
@ -3063,7 +3070,7 @@ void Human::ProcUseItemAction()
|
||||
{
|
||||
if (!dead) {
|
||||
if (downed) {
|
||||
ability.hp = MetaMgr::Instance()->GetSysParamAsInt("downed_relive_recover_hp");
|
||||
SetHP(MetaMgr::Instance()->GetSysParamAsInt("downed_relive_recover_hp"));
|
||||
downed = false;
|
||||
if (downed_timer) {
|
||||
room->xtimer.DeleteTimer(downed_timer);
|
||||
@ -3096,7 +3103,7 @@ void Human::ProcReliveAction()
|
||||
return;
|
||||
}
|
||||
if (!hum->dead && hum->downed) {
|
||||
hum->ability.hp = MetaMgr::Instance()->GetSysParamAsInt("downed_relive_recover_hp");
|
||||
SetHP(MetaMgr::Instance()->GetSysParamAsInt("downed_relive_recover_hp"));
|
||||
hum->downed = false;
|
||||
if (hum->downed_timer) {
|
||||
room->xtimer.DeleteTimer(hum->downed_timer);
|
||||
@ -3483,7 +3490,7 @@ void Human::OnBulletHit(Bullet* bullet)
|
||||
}
|
||||
if (!dead && (bullet->IsBomb() || bullet->sender.Get()->team_id != team_id)) {
|
||||
float dmg = bullet->GetAtk();
|
||||
float def = ability.def * (1 + GetAbility()->GetAttrRate(kHAT_Def)) +
|
||||
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);
|
||||
@ -3530,7 +3537,7 @@ void Human::OnExplosionHit(Explosion* e)
|
||||
return;
|
||||
}
|
||||
float dmg = e->GetDmg();
|
||||
float def = ability.def * (1 + GetAbility()->GetAttrRate(kHAT_Def)) +
|
||||
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);
|
||||
|
@ -1389,7 +1389,7 @@ void Player::_CMRevive(f8::MsgHdr& hdr, const cs::CMRevive& msg)
|
||||
real_dead = false;
|
||||
downed = false;
|
||||
FreeDownedTimer();
|
||||
ability.hp = GetMaxHP();
|
||||
SetHP(GetMaxHP());
|
||||
SyncAroundPlayers(__FILE__, __LINE__, __func__);
|
||||
FreeReviveTimer();
|
||||
#if 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user