You now receive damage to multiple body parts and can heal them all too.
This commit is contained in:
parent
1777a6bbf2
commit
360402cb3c
6 changed files with 61 additions and 23 deletions
|
|
@ -8,30 +8,39 @@ namespace components {
|
|||
|
||||
if(attack) {
|
||||
my_dmg = Random::uniform<int>(1, damage);
|
||||
target.hit_limb(my_dmg);
|
||||
target.take_damage(my_dmg);
|
||||
}
|
||||
|
||||
return my_dmg;
|
||||
}
|
||||
|
||||
void Combat::hit_limb(int my_dmg) {
|
||||
body_parts["head"] -= my_dmg;
|
||||
void Combat::take_damage(int my_dmg) {
|
||||
for(auto& [key, hp] : body_parts) {
|
||||
if(Random::uniform(0, 1) == 0) {
|
||||
body_parts[key] = hp - my_dmg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Combat::less_than(int level) {
|
||||
return body_parts["head"] < level || body_parts["stomach"] < level || body_parts["chest"] < level;
|
||||
}
|
||||
|
||||
bool Combat::is_dead() {
|
||||
return body_parts["head"] < 0;
|
||||
return less_than(0);
|
||||
}
|
||||
|
||||
bool Combat::almost_dead() {
|
||||
return body_parts["head"] < 20;
|
||||
return less_than(max_hp / 4);
|
||||
}
|
||||
|
||||
bool Combat::can_heal() {
|
||||
return body_parts["head"] < 50;
|
||||
return less_than(max_hp / 2);
|
||||
}
|
||||
|
||||
void Combat::apply_healing(Curative& cure) {
|
||||
int new_hp = body_parts["head"] + cure.hp;
|
||||
body_parts["head"] = std::min(new_hp, 50);
|
||||
for(auto& [key, hp] : body_parts) {
|
||||
body_parts[key] = std::min(hp + cure.hp, max_hp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue