Cleanup
This commit is contained in:
+17
-21
@@ -55,7 +55,9 @@ foldCr xs cr w = foldr f w xs
|
||||
stateUpdate :: (Creature -> World -> World) -> Creature -> World -> World
|
||||
stateUpdate f = foldCr
|
||||
[ doDamage
|
||||
, equipmentEffects
|
||||
, invSideEff
|
||||
, upInv -- upInv must be called before invSideEff 22.05.23
|
||||
, movementSideEff
|
||||
, f
|
||||
, internalUpdate
|
||||
@@ -137,39 +139,34 @@ movementSideEff cr w
|
||||
(randDir,g) = randomR (-0.5,0.5) $ _randGen w
|
||||
(randAng,_) = randomR (0,2*pi) $ _randGen w
|
||||
|
||||
heldItemUpdate :: Int -> Item -> Item
|
||||
heldItemUpdate invid = (itUse %~ useUpdate) . (itInvPos ?~ invid) . (itIsHeld .~ True)
|
||||
|
||||
invItemUpdate :: Int -> Item -> Item
|
||||
invItemUpdate invid = (itUse %~ useUpdate) . (itInvPos ?~ invid) . (itIsHeld .~ False)
|
||||
|
||||
useUpdate :: ItemUse -> ItemUse
|
||||
useUpdate = (useHammer . hammerPosition %~ moveHammerUp)
|
||||
. (useDelay . warmTime %~ decreaseToZero)
|
||||
. (useDelay . rateTime %~ decreaseToZero)
|
||||
. (useDelay . warmTime %~ decreaseToZero)
|
||||
. (useDelay . rateTime %~ decreaseToZero)
|
||||
|
||||
useEquipment :: Creature -> Int -> World -> World
|
||||
useEquipment cr i = _eqUse (_itUse $ _crInv cr IM.! i) cr i
|
||||
|
||||
-- a map updating all inventory items
|
||||
upInv :: Creature -> World -> World
|
||||
upInv cr = creatures . ix (_crID cr) . crInv %~ IM.mapWithKey (itemUpdate cr)
|
||||
-- a loop going over equipped items
|
||||
equipmentEffects :: Creature -> World -> World
|
||||
equipmentEffects cr = flip (foldr $ useEquipment cr) (IM.keys $ _crInvEquipped cr)
|
||||
-- a loop going over all inventory items
|
||||
invSideEff :: Creature -> World -> World
|
||||
invSideEff cr w = weaponReloadSounds cr
|
||||
. flip (foldr $ useEquipment cr) (IM.keys $ _crInvEquipped cr)
|
||||
$ IM.foldrWithKey f w (_crInv cr)
|
||||
where
|
||||
--upitemsw = w & creatures . ix (_crID cr) . crInv %~ IM.mapWithKey (itemUpdate cr)
|
||||
f i it w' = (doItemTargeting i cr . doitemupdate) w' & case it ^? itEffect . itInvEffect of
|
||||
f i it w' = doItemTargeting i cr w' & case it ^? itEffect . itInvEffect of
|
||||
Nothing -> id
|
||||
Just g -> g (heldItemUpdate i it) cr -- this is done twice!
|
||||
where
|
||||
doitemupdate
|
||||
| i == _crInvSel cr = (itpointer %~ heldItemUpdate i)
|
||||
| otherwise = (itpointer %~ invItemUpdate i)
|
||||
itpointer = creatures . ix (_crID cr) . crInv . ix i
|
||||
Just g -> g it cr
|
||||
|
||||
itemUpdate :: Creature -> Int -> Item -> Item
|
||||
itemUpdate cr i
|
||||
| i == _crInvSel cr = heldItemUpdate i
|
||||
| otherwise = invItemUpdate i
|
||||
| i == _crInvSel cr = baseupdate True
|
||||
| otherwise = baseupdate False
|
||||
where
|
||||
baseupdate bool = (itUse %~ useUpdate) . (itInvPos ?~ i) . (itIsHeld .~ bool)
|
||||
|
||||
doItemTargeting :: Int -> Creature -> World -> World
|
||||
doItemTargeting invid cr w = case cr ^? crInv . ix invid . itTargeting of
|
||||
@@ -177,7 +174,6 @@ doItemTargeting invid cr w = case cr ^? crInv . ix invid . itTargeting of
|
||||
Just NoTargeting -> w
|
||||
Just t -> let (w',t') = _tgUpdate t (_crInv cr IM.! invid) cr w t
|
||||
in w' & creatures . ix (_crID cr) . crInv . ix invid . itTargeting .~ t'
|
||||
-- & testString .~ const ["Held"]
|
||||
|
||||
weaponReloadSounds :: Creature -> World -> World
|
||||
weaponReloadSounds cr w = case cr ^? crInv . ix (_crInvSel cr) . itConsumption of
|
||||
|
||||
Reference in New Issue
Block a user