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