Start making projectile update function rather than folded list

This commit is contained in:
2024-12-28 21:31:33 +00:00
parent e028c54948
commit 2fdc6ae557
9 changed files with 95 additions and 87 deletions
+15 -19
View File
@@ -2,14 +2,13 @@ module Dodge.Creature.Impulse.UseItem (
useSelectedItem,
) where
import Data.Foldable (foldl')
import Dodge.DoubleTree
import Control.Lens
import Control.Monad
import Data.Maybe
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Dodge.Data.World
import Dodge.DoubleTree
import Dodge.Euse
import Dodge.HeldUse
import Dodge.Hotkey
@@ -38,33 +37,30 @@ useSelectedItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMayb
& pointerToItem itm . itUse . heldHammer .~ HammerDown
RemoteDetonatorSF -> do
guard (_crHammerPosition cr == HammerUp)
return $ activateDetonator usedloc cr w
return $ activateDetonator usedloc w
_ | isJust $ itm ^? itUse . uequipEffect -> do
guard (_crHammerPosition cr == HammerUp)
invid' <- itm ^? itLocation . ilInvID
return $ toggleEquipmentAt invid' cr w
_ -> Nothing
where
fst3 (x,_,_) = x
fst3 (x, _, _) = x
activateDetonator
:: LabelDoubleTree ItemLink ComposedItem -> Creature -> World
-> World
activateDetonator det _ w = foldl' remoteDetonate w
(det ^. ldtValue . _1 . itUse . uaParams . apProjectiles)
& pointerToItemID (det ^. ldtValue . _1 . itID) . itUse . uaParams . apProjectiles .~ []
remoteDetonate :: World -> Int -> World
remoteDetonate w pjid = w
& cWorld . lWorld . projectiles . ix pjid . pjTimer .~ 0
activateDetonator ::
LabelDoubleTree ItemLink ComposedItem ->
World ->
World
activateDetonator det = fromMaybe id $ do
pjid <- det ^? ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0
return $ cWorld . lWorld . projectiles . ix pjid . pjTimer .~ 0
useLocation :: LocationLDT ItemLink ComposedItem -> UseFocus
useLocation loc
useLocation loc
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uequipEffect = UseFromLocation
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apLinkedProjectile . _Just
= UseFromLocation
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0
= UseFromLocation
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apLinkedProjectile . _Just =
UseFromLocation
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0 =
UseFromLocation
| otherwise = UseFromRoot
toggleEquipmentAt :: Int -> Creature -> World -> World