Cleanup
This commit is contained in:
+20
-61
@@ -1,9 +1,6 @@
|
||||
module Dodge.Creature.State
|
||||
( stateUpdate'
|
||||
, stateUpdateDamage
|
||||
( stateUpdate
|
||||
, doDamage
|
||||
, clearDamage
|
||||
, invSideEff
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Hammer
|
||||
@@ -49,54 +46,39 @@ foldCr xs cr w = foldr ($ cr) w xs
|
||||
-- the creature before or after it has moved?
|
||||
-- at what point invSideEffects is applied wrt to when the creature moves
|
||||
-- may effect whether the shield moves correctly
|
||||
stateUpdate' :: (Creature -> World -> World) -> Creature -> World -> World
|
||||
stateUpdate' f = foldCr
|
||||
stateUpdate :: (Creature -> World -> World) -> Creature -> World -> World
|
||||
stateUpdate f = foldCr
|
||||
[ checkDeath
|
||||
, doDamage
|
||||
, invSideEff
|
||||
, movementSideEff
|
||||
, moveCrHammerUp
|
||||
, stepReloading'
|
||||
, updateMovement'
|
||||
, internalUpdate
|
||||
, f
|
||||
]
|
||||
|
||||
checkDeath :: Creature -> World -> World
|
||||
checkDeath cr
|
||||
| _crHP cr < 1 = creatures . at (_crID cr) .~ Nothing -- TODO add corpse
|
||||
| otherwise = id
|
||||
moveCrHammerUp :: Creature -> World -> World
|
||||
moveCrHammerUp cr = creatures . ix (_crID cr) . crHammerPosition %~ moveHammerUp
|
||||
|
||||
stepReloading' :: Creature -> World -> World
|
||||
stepReloading' cr = creatures . ix (_crID cr) %~ stepReloading
|
||||
|
||||
updateMovement' :: Creature -> World -> World
|
||||
updateMovement' cr = creatures . ix (_crID cr) %~ updateMovement
|
||||
|
||||
stateUpdateDamage :: (Creature -> World -> World)
|
||||
-> (Creature -> World -> (World -> World, Creature))
|
||||
-> Creature -> World -> World
|
||||
stateUpdateDamage damageupdate u cr w = damageupdate cr
|
||||
$ invSideEff upcr . movementSideEff cr . deathEff . f
|
||||
$ w
|
||||
& creatures . at (_crID cr) .~ (mvcrhammerup . stepReloading <$> crOrCorpse upcr)
|
||||
checkDeath cr w
|
||||
| _crHP cr > 0 = w
|
||||
| otherwise = w
|
||||
& creatures . at (_crID cr) .~ Nothing
|
||||
& stopSoundFrom (CrWeaponSound (_crID cr) 0)
|
||||
& over decorations addCorpse
|
||||
& dropByState cr
|
||||
where
|
||||
(f,upcr) = u (updateMovement cr) w
|
||||
mvcrhammerup = crHammerPosition %~ moveHammerUp
|
||||
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)
|
||||
|
||||
internalUpdate :: Creature -> World -> World
|
||||
internalUpdate cr = creatures . ix (_crID cr) %~
|
||||
( (crHammerPosition %~ moveHammerUp)
|
||||
. stepReloading
|
||||
. updateMovement
|
||||
)
|
||||
|
||||
-- | Drop items according to the creature state.
|
||||
-- TODO make sure this doesn't mess up any ItemPosition
|
||||
dropByState :: Creature -> World -> World
|
||||
dropByState cr w = foldr (copyInvItemToFloor cr) w $ case cr ^. crState . crDropsOnDeath of
|
||||
DropAll -> IM.keys $ _crInv cr
|
||||
@@ -108,25 +90,13 @@ setOldPos cr = cr
|
||||
& crOldPos .~ _crPos cr
|
||||
& crOldDir .~ _crDir cr
|
||||
|
||||
clearDamage :: Creature -> World -> World
|
||||
clearDamage cr = creatures . ix (_crID cr) . crState . crDamage .~ []
|
||||
|
||||
doDamage :: Creature -> World -> World
|
||||
doDamage cr w = w
|
||||
& creatures . ix (_crID cr) . crState . crDamage .~ []
|
||||
-- & creatures . ix (_crID cr) . crState . crPastDamage %~ advancePastDamages dams
|
||||
& _crApplyDamage cr dams cr
|
||||
where
|
||||
dams = _crDamage $ _crState cr
|
||||
|
||||
--advancePastDamages :: [Damage] -> V.Vector [Damage] -> V.Vector [Damage]
|
||||
--advancePastDamages newDs v = f $ V.backpermute v bpVector
|
||||
-- where
|
||||
-- f = V.modify $ \v' -> MV.write v' 0 newDs
|
||||
|
||||
--bpVector :: V.Vector Int
|
||||
--bpVector = V.fromList $ 0 : [0 .. 18]
|
||||
|
||||
movementSideEff :: Creature -> World -> World
|
||||
movementSideEff cr w
|
||||
| hasJetPack = case cr ^? crStance . carriage of
|
||||
@@ -206,17 +176,6 @@ weaponReloadSounds cr w = case cr ^? crInv . ix (_crInvSel cr) . itConsumption o
|
||||
where
|
||||
cid = _crID cr
|
||||
|
||||
--weaponReloadSounds cr w = case _crInv cr IM.!? _crInvSel cr of
|
||||
-- Just Weapon{_wpAmmo=LoadableAmmo{_wpReloadType = PassiveReload stype,_wpReloadTime=rt,_wpReloadState=rs} }
|
||||
-- | rt == rs -> soundContinue (CrReloadSound 0) (_crPos cr) stype Nothing w
|
||||
-- | otherwise -> w
|
||||
-- Just Weapon{_wpAmmo=LoadableAmmo{_wpReloadState = 0}} -> w
|
||||
-- Just Weapon{_wpAmmo=LoadableAmmo{_wpReloadState = 1}} -> stopSoundFrom (CrReloadSound cid) w
|
||||
-- Just Weapon{} -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w
|
||||
-- _ -> w
|
||||
-- where
|
||||
-- cid = _crID cr
|
||||
|
||||
updateMovement :: Creature -> Creature
|
||||
updateMovement cr
|
||||
| isFrictionless cr = over crPos (+.+ momentum) $ setOldPos cr
|
||||
|
||||
Reference in New Issue
Block a user