about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/Xanthous/AI/Gormlak.hs5
-rw-r--r--src/Xanthous/Entities/Character.hs5
2 files changed, 8 insertions, 2 deletions
diff --git a/src/Xanthous/AI/Gormlak.hs b/src/Xanthous/AI/Gormlak.hs
index 68feb67ac227..db504c1e7d3a 100644
--- a/src/Xanthous/AI/Gormlak.hs
+++ b/src/Xanthous/AI/Gormlak.hs
@@ -14,7 +14,8 @@ import           Xanthous.Data (Positioned(..), diffPositions, stepTowards, isUn
 import           Xanthous.Data.EntityMap
 import qualified Xanthous.Entities.Creature as Creature
 import           Xanthous.Entities.Creature (Creature)
-import           Xanthous.Entities.Character (Character, characterHitpoints)
+import           Xanthous.Entities.Character (Character)
+import qualified Xanthous.Entities.Character as Character
 import qualified Xanthous.Entities.RawTypes as Raw
 import           Xanthous.Entities (Entity(..), Brain(..), brainVia)
 import           Xanthous.Game.State (entities, GameState, entityIs)
@@ -54,7 +55,7 @@ stepGormlak pe@(Positioned pos creature) = do
     vision = Creature.visionRadius creature
     attackCharacter = do
       say ["combat", "creatureAttack"] $ object [ "creature" A..= creature ]
-      character . characterHitpoints -= 1
+      character %= Character.damage 1
 
 newtype GormlakBrain = GormlakBrain Creature
 
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