Add fields to determine an item's inventory position/whether it is held
This commit is contained in:
+28
-12
@@ -38,7 +38,12 @@ import System.Random
|
||||
|
||||
foldCr :: [Creature -> World -> World]
|
||||
-> Creature -> World -> World
|
||||
foldCr xs cr w = foldr ($ cr) w xs
|
||||
--foldCr xs cr w = foldr ($ cr) w xs
|
||||
foldCr xs cr w = foldr f w xs
|
||||
where
|
||||
f g w' = case w' ^? creatures . ix (_crID cr) of
|
||||
Just cr' -> g cr' w'
|
||||
Nothing -> w'
|
||||
|
||||
-- | this seems to work, but I am not sure about the ordering:
|
||||
-- previously, the movement was updated before the ai in order to correctly set the oldpos.
|
||||
@@ -48,12 +53,14 @@ foldCr xs cr w = foldr ($ cr) w xs
|
||||
-- may effect whether the shield moves correctly
|
||||
stateUpdate :: (Creature -> World -> World) -> Creature -> World -> World
|
||||
stateUpdate f = foldCr
|
||||
[ checkDeath
|
||||
, doDamage
|
||||
[ doDamage
|
||||
, invSideEff
|
||||
, movementSideEff
|
||||
, internalUpdate
|
||||
, f
|
||||
, internalUpdate -- note that updateMovement needs to be evaluated at the correct moment
|
||||
-- wrt any changes in position made by the creature: the
|
||||
-- oldPos needs to be correctly set
|
||||
, checkDeath
|
||||
]
|
||||
|
||||
checkDeath :: Creature -> World -> World
|
||||
@@ -121,14 +128,14 @@ movementSideEff cr w
|
||||
(randDir,g) = randomR (-0.5,0.5) $ _randGen w
|
||||
(randAng,_) = randomR (0,2*pi) $ _randGen w
|
||||
|
||||
heldItemUpdate :: Item -> Item
|
||||
heldItemUpdate = invItemUpdate
|
||||
heldItemUpdate :: Int -> Item -> Item
|
||||
heldItemUpdate invid = (itIsHeld .~ True) . invItemUpdate invid
|
||||
-- . (itUse %~ useupdate)
|
||||
-- where
|
||||
-- useupdate = id
|
||||
|
||||
invItemUpdate :: Item -> Item
|
||||
invItemUpdate = itUse %~ useupdate
|
||||
invItemUpdate :: Int -> Item -> Item
|
||||
invItemUpdate invid = (itUse %~ useupdate) . (itIsHeld .~ False) . (itInvPos ?~ invid)
|
||||
where
|
||||
useupdate = (useHammer . hammerPosition %~ moveHammerUp)
|
||||
. (useDelay . warmTime %~ decreaseToZero)
|
||||
@@ -137,7 +144,7 @@ invItemUpdate = itUse %~ useupdate
|
||||
invSideEff :: Creature -> World -> World
|
||||
invSideEff cr w = weaponReloadSounds cr
|
||||
. flip (IS.foldr useeq) (_crInvEquipped cr)
|
||||
. doHeldItemTargeting cr
|
||||
-- . doHeldItemTargeting cr
|
||||
$ IM.foldrWithKey f w (_crInv cr)
|
||||
where
|
||||
useeq i = _eqUse (_itUse $ _crInv cr IM.! i) cr i
|
||||
@@ -146,16 +153,25 @@ invSideEff cr w = weaponReloadSounds cr
|
||||
Just g -> g (_itEffect it) cr i w' & doitemupdate
|
||||
where
|
||||
doitemupdate
|
||||
| i == _crInvSel cr = itpointer %~ heldItemUpdate
|
||||
| otherwise = itpointer %~ invItemUpdate
|
||||
| i == _crInvSel cr = doHeldItemTargeting cr . (itpointer %~ heldItemUpdate i)
|
||||
| otherwise = doNotHeldItemTargeting i cr . (itpointer %~ invItemUpdate i)
|
||||
itpointer = creatures . ix (_crID cr) . crInv . ix i
|
||||
|
||||
doHeldItemTargeting :: Creature -> World -> World
|
||||
doHeldItemTargeting cr w = case cr ^? crInv . ix (_crInvSel cr) . itTargeting of
|
||||
Nothing -> w
|
||||
Just NoTargeting -> w
|
||||
Just t -> let (w',t') = _tgUpdate t (_crInv cr IM.! _crInvSel cr) cr w t
|
||||
Just t -> let (w',t') = _tgHeldUpdate t (_crInv cr IM.! _crInvSel cr) cr w t
|
||||
in w' & creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) . itTargeting .~ t'
|
||||
-- & testString .~ const ["Held"]
|
||||
|
||||
doNotHeldItemTargeting :: Int -> Creature -> World -> World
|
||||
doNotHeldItemTargeting invid cr w = case cr ^? crInv . ix invid . itTargeting of
|
||||
Nothing -> w
|
||||
Just NoTargeting -> w
|
||||
Just t -> let (w',t') = _tgNotHeldUpdate t (_crInv cr IM.! invid) cr w t
|
||||
in w' & creatures . ix (_crID cr) . crInv . ix invid . itTargeting .~ t'
|
||||
-- & testString .~ const ["Not"]
|
||||
|
||||
weaponReloadSounds :: Creature -> World -> World
|
||||
weaponReloadSounds cr w = case cr ^? crInv . ix (_crInvSel cr) . itConsumption of
|
||||
|
||||
Reference in New Issue
Block a user