This commit is contained in:
2021-12-09 22:37:14 +00:00
parent 3c35a04531
commit e84b4a29e8
10 changed files with 154 additions and 43 deletions
+24
View File
@@ -1,5 +1,6 @@
module Dodge.Creature.State
( stateUpdate
, stateUpdate'
, stateUpdateDamage
, doDamage
, clearDamage
@@ -45,6 +46,10 @@ stateUpdate :: CRUpdate -> Creature -> World -> World
stateUpdate f cr w = let (fw,mcr) = stateUpdateDamage doDamage f cr w
in fw $ w & creatures . at (_crID cr) .~ mcr
stateUpdate' :: CRUpdate' -> Creature -> World -> World
stateUpdate' f cr w = let (fw,mcr) = stateUpdateDamage' doDamage f cr w
in fw $ w & creatures . at (_crID cr) .~ mcr
stateUpdateDamage :: (Creature -> Creature) -> CRUpdate -> CRUpdate
stateUpdateDamage damageupdate u cr w = case u (updateMovement cr) w of
(f, maybeCr) ->
@@ -64,6 +69,25 @@ stateUpdateDamage damageupdate u cr w = case u (updateMovement cr) w of
$ uncurryV translate (_crOldPos cr)
$ rotate (_crDir cr)
(_crCorpse cr)
stateUpdateDamage' :: (Creature -> Creature) -> CRUpdate' -> CRUpdate
stateUpdateDamage' damageupdate u cr w = case u (updateMovement cr) w of
(f, upcr) ->
( invSideEff upcr . movementSideEff cr . deathEff . f
, (stepReloading . damageupdate) <$> crOrCorpse upcr
)
where
crOrCorpse cr'
| cr' ^. crHP > 0 = Just cr'
| otherwise = Nothing
deathEff
| cr ^.crHP > 0 = id
| otherwise = stopSoundFrom (CrWeaponSound (_crID cr) 0)
. over decorations addCorpse
. dropByState cr
addCorpse = IM.insertNewKey
$ uncurryV translate (_crOldPos cr)
$ rotate (_crDir cr)
(_crCorpse cr)
-- | Drop items according to the creature state.
dropByState :: Creature -> World -> World
dropByState cr w = foldr (copyInvItemToFloor cr) w is