This commit is contained in:
aozhiwei 2021-05-14 17:47:19 +08:00
parent bb0cbc1c0b
commit a2fe0ca1e0
3 changed files with 24 additions and 0 deletions

View File

@ -235,6 +235,9 @@ void Car::DecHP(float dec_hp, int killer_id, const std::string& killer_name, int
#ifdef DEBUG
dec_hp *= 5;
#endif
if (dec_hp < 0.001f) {
return;
}
float old_health = GetHP();
float new_health = std::max(0.0f, GetHP() - dec_hp);
ability.hp = std::max(0.0f, new_health);
@ -242,6 +245,24 @@ void Car::DecHP(float dec_hp, int killer_id, const std::string& killer_name, int
BeKill(killer_id, killer_name, weapon_id);
}
room->frame_event.AddHpChg(GetWeakPtrRef());
float hp_rate = GetHP() / GetMaxHP();
int new_buff_idx = cur_buff_idx_;
while (new_buff_idx < meta->car_buff_list.size()) {
if (hp_rate > std::get<0>(meta->car_buff_list[new_buff_idx])) {
break;
}
++new_buff_idx;
}
if (new_buff_idx != cur_buff_id_) {
if (cur_buff_id_ != 0) {
RemoveBuffById(cur_buff_id_);
}
cur_buff_idx_ = new_buff_idx;
cur_buff_id_ = std::get<1>(meta->car_buff_list[cur_buff_idx_]);
if (cur_buff_id_ != 0) {
MustBeAddBuff(this, cur_buff_id_);
}
}
}
void Car::BeKill(int killer_id, const std::string& killer_name, int weapon_id)

View File

@ -44,4 +44,6 @@ class Car : public Creature
bool later_removed_ = false;
Human* driver_ = nullptr;
std::set<Human*> passengers_;
int cur_buff_id_ = 0;
int cur_buff_idx_ = -1;
};

View File

@ -72,6 +72,7 @@ namespace MetaData
float float_param2 = 0;
std::vector<std::tuple<int, int, int>> power_charge;
MetaData::Buff* buff_meta = nullptr;
std::vector<std::tuple<float, int>> car_buff_list;
void Init();
int GetWeaponIdx();