feat: set enemy health to ignore short-term values

This commit is contained in:
Sara 2024-09-09 21:21:30 +02:00
parent 8fe3bf10a8
commit 667814906e
3 changed files with 10 additions and 9 deletions

View file

@ -36,8 +36,7 @@ actions_inspector = [3, 2, 4, 5, 1]
unique_name_in_owner = true
[node name="EntityHealth" type="EntityHealth" parent="."]
injury_max = 20
wounds_max = 20
injury_max = 100
unique_name_in_owner = true
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]

View file

@ -29,8 +29,8 @@ void EntityHealth::_bind_methods() {
}
void EntityHealth::_enter_tree() {
this->injury_current = this->injury_max;
this->wounds_current = this->wounds_max;
this->injury_current = gd::Math::max(1, this->injury_max);
this->wounds_current = gd::Math::max(0, this->wounds_max);
}
void EntityHealth::damaged_by(int amount, Unit *source) {
@ -53,7 +53,7 @@ void EntityHealth::healed_by(int amount, Unit *source) {
}
void EntityHealth::receive_wounds(int incoming_amount, Unit *source) {
if(this->is_conscious()) {
if(this->wounds_max > 0 && this->is_conscious()) {
this->wounds_current -= incoming_amount;
if(this->wounds_current <= 0) {
this->emit_signal("unconscious", source);
@ -70,12 +70,14 @@ void EntityHealth::receive_injury(int incoming_amount, Unit *source) {
}
float EntityHealth::get_wounds_damage_factor() const {
return float(this->injury_current) / float(this->injury_max);
return this->injury_max == 0
? 1.f
: float(this->injury_current) / float(this->injury_max);
}
bool EntityHealth::is_conscious() const {
return !this->is_dead()
&& this->wounds_current > 0;
&& (this->wounds_current > 0 || this->wounds_max <= 0);
}
bool EntityHealth::can_be_revived() const {

View file

@ -37,10 +37,10 @@ public:
private:
Stats const *stats;
// long term health
int injury_max{10};
int injury_max{10}; //!< the "health" value, has to be more than 1
int injury_current{0};
// short term health
int wounds_max{10};
int wounds_max{0}; //!< the "healthy" value, if set to zero, short-term health is removed
int wounds_current{0};
};