about summary refs log tree commit diff
path: root/src/Xanthous/Entities/Character.hs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-10-06T16·59-0400
committerGriffin Smith <root@gws.fyi>2019-10-06T16·59-0400
commita57e36dca81274dea015c9fbdac680b44ef5576e (patch)
tree7bdb94c622e7a582d5474178728e2c397114fde3 /src/Xanthous/Entities/Character.hs
parentbf92a370a5ad215fff3e2f692da981c95175b2f3 (diff)
Fix underflow when damaging character
Fix underflow that could happen when multiple gormlaks attack the
character in a single turn
Diffstat (limited to 'src/Xanthous/Entities/Character.hs')
-rw-r--r--src/Xanthous/Entities/Character.hs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/Xanthous/Entities/Character.hs b/src/Xanthous/Entities/Character.hs
index 0bb5867ee5e1..84e653e6a09d 100644
--- a/src/Xanthous/Entities/Character.hs
+++ b/src/Xanthous/Entities/Character.hs
@@ -8,6 +8,7 @@ module Xanthous.Entities.Character
   , mkCharacter
   , pickUpItem
   , isDead
+  , damage
   ) where
 --------------------------------------------------------------------------------
 import Xanthous.Prelude
@@ -71,3 +72,7 @@ isDead = (== 0) . view characterHitpoints
 pickUpItem :: Item -> Character -> Character
 pickUpItem item = inventory %~ (item <|)
 
+damage :: Word -> Character -> Character
+damage amount = characterHitpoints %~ \case
+  n | n <= amount -> 0
+    | otherwise  -> n - amount