Fix underflow when damaging character

Fix underflow that could happen when multiple gormlaks attack the
character in a single turn
This commit is contained in:
Griffin Smith 2019-10-06 12:59:53 -04:00
parent bf92a370a5
commit a57e36dca8
2 changed files with 8 additions and 2 deletions

View file

@ -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