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 Xanthous.Data.EntityMap
|
||||||
import qualified Xanthous.Entities.Creature as Creature
|
import qualified Xanthous.Entities.Creature as Creature
|
||||||
import Xanthous.Entities.Creature (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 qualified Xanthous.Entities.RawTypes as Raw
|
||||||
import Xanthous.Entities (Entity(..), Brain(..), brainVia)
|
import Xanthous.Entities (Entity(..), Brain(..), brainVia)
|
||||||
import Xanthous.Game.State (entities, GameState, entityIs)
|
import Xanthous.Game.State (entities, GameState, entityIs)
|
||||||
|
@ -54,7 +55,7 @@ stepGormlak pe@(Positioned pos creature) = do
|
||||||
vision = Creature.visionRadius creature
|
vision = Creature.visionRadius creature
|
||||||
attackCharacter = do
|
attackCharacter = do
|
||||||
say ["combat", "creatureAttack"] $ object [ "creature" A..= creature ]
|
say ["combat", "creatureAttack"] $ object [ "creature" A..= creature ]
|
||||||
character . characterHitpoints -= 1
|
character %= Character.damage 1
|
||||||
|
|
||||||
newtype GormlakBrain = GormlakBrain Creature
|
newtype GormlakBrain = GormlakBrain Creature
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ module Xanthous.Entities.Character
|
||||||
, mkCharacter
|
, mkCharacter
|
||||||
, pickUpItem
|
, pickUpItem
|
||||||
, isDead
|
, isDead
|
||||||
|
, damage
|
||||||
) where
|
) where
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
import Xanthous.Prelude
|
import Xanthous.Prelude
|
||||||
|
@ -71,3 +72,7 @@ isDead = (== 0) . view characterHitpoints
|
||||||
pickUpItem :: Item -> Character -> Character
|
pickUpItem :: Item -> Character -> Character
|
||||||
pickUpItem item = inventory %~ (item <|)
|
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