aboutsummaryrefslogtreecommitdiff
path: root/backend/Player.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-02 23:11:42 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-02 23:11:42 +0100
commited78baff64fe45479ca6c480d985ce0f9c0c9515 (patch)
treeb3224d0d01dc0c563c8e49751c628994b66f58b6 /backend/Player.cpp
parent07b8a5b0baed8c7b23681c99f25f297045945bfc (diff)
more bug fixes
Diffstat (limited to 'backend/Player.cpp')
-rw-r--r--backend/Player.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/backend/Player.cpp b/backend/Player.cpp
index 6c2cf6b..66197fa 100644
--- a/backend/Player.cpp
+++ b/backend/Player.cpp
@@ -29,9 +29,13 @@ void Player::take_damage(unsigned int dmg) {
if (this->cheating) return;
if (this->is_dead()) return;
- dmg = min(dmg, this->health_points);
+ // reduce damage by armor's protection value (if player is wearing any)
if (this->armor != nullptr)
- dmg = max(0u, dmg - this->armor->get_protection());
+ dmg -= min(dmg, this->armor->get_protection());
+
+ // make sure health_points doesn't go below 0
+ dmg = min(dmg, this->health_points);
+
this->health_points -= dmg;
auto & hp = this->health_points;