Take the amount of damage given, returning true if the unit has died. Returns false if the unit is still alive.
(&mut self, mut damage: i32)
| 540 | /// Take the amount of damage given, returning true if the unit has died. |
| 541 | /// Returns false if the unit is still alive. |
| 542 | pub(crate) fn take_damage(&mut self, mut damage: i32) -> bool { |
| 543 | if damage < 0 { |
| 544 | self.be_healed((-damage) as u32); |
| 545 | return false; |
| 546 | } |
| 547 | if self.unit_type() == UnitType::Knight { |
| 548 | damage = cmp::max(damage - self.defense as i32, 0); |
| 549 | } |
| 550 | self.health -= cmp::min(damage, self.health as i32) as u32; |
| 551 | self.health == 0 |
| 552 | } |
| 553 | |
| 554 | /// Increases the unit's current health by the given amount, without healing |
| 555 | /// beyond the unit's maximum health. Returns true if unit is healed to max. |