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:
parent
bf92a370a5
commit
a57e36dca8
2 changed files with 8 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue