Move towards removing item hammers, unifying item use

This commit is contained in:
2024-12-31 11:15:03 +00:00
parent 2fc960321e
commit 6aa3c701bc
2 changed files with 196 additions and 153 deletions
+39
View File
@@ -17,6 +17,45 @@ import Dodge.Item.Grammar
import Dodge.Item.Location
import qualified IntMapHelp as IM
useItem :: Int -> PressType -> World -> World
useItem invid pt w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix 0
itmloc <- allInvLocs (_crInv cr) ^? ix invid . _2
usedloc <- useLocation' itmloc
useItemLoc cr usedloc pt w
useItemLoc :: Creature -> LocationLDT ItemLink ComposedItem -> PressType
-> World -> Maybe World
useItemLoc cr loc pt w = case loc ^. locLDT . ldtValue . _2 of
HeldPlatformSF ->
return $
heldEffect (bimap _iatType (^. _1) ldt) cr w
& pointerToItem itm . itUse . heldHammer .~ HammerDown
GadgetPlatformSF ->
return $
heldEffect (bimap _iatType (^. _1) ldt) cr w
& pointerToItem itm . itUse . heldHammer .~ HammerDown
RemoteDetonatorSF -> do
return $ activateDetonator ldt w
& pointerToItem itm . itUse . heldHammer .~ HammerDown
_ | isJust $ itm ^? itUse . uequipEffect -> do
invid' <- itm ^? itLocation . ilInvID
return $ toggleEquipmentAt invid' cr w
_ -> Nothing
where
ldt = loc ^. locLDT
itm = ldt ^. ldtValue . _1
useLocation' :: LocationLDT ItemLink ComposedItem
-> Maybe (LocationLDT ItemLink ComposedItem)
useLocation' loc
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uequipEffect = return loc
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apLinkedProjectile . _Just
= return loc
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0
= return loc
| otherwise = return $ locToTop loc
useSelectedItem :: Int -> World -> World
useSelectedItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix crid