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
|
@ -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
|
||||
|
||||
|
|
|
@ -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…
Reference in a new issue