Allow for item use when not root

This commit is contained in:
2024-12-20 16:07:58 +00:00
parent 3a72bd366f
commit d9aaa8cc05
26 changed files with 436 additions and 493 deletions
+11 -6
View File
@@ -2,6 +2,7 @@ module Dodge.Creature.Impulse.UseItem (
useSelectedItem,
) where
import Dodge.DoubleTree
import Control.Lens
import Control.Monad
import Data.Maybe
@@ -22,9 +23,12 @@ useSelectedItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMayb
itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
invid <- cr ^? crManipulation . manObject . imSelectedItem
itmtree <- invRootTrees (_crInv cr) ^? ix itRef
itmloc <- allInvLocs (_crInv cr) ^? ix invid
let itm = itmtree ^. ldtValue . _1
case itmtree ^. ldtValue . _2 of
itmloc <- allInvLocs (_crInv cr) ^? ix invid . _2
let usedloc = case itmloc ^. locLDT . ldtValue . _1 . itUseFocus of
UseFromLocation -> itmloc ^. locLDT
UseFromRoot -> locToTop itmloc ^. locLDT
let itm = usedloc ^. ldtValue . _1
case usedloc ^. ldtValue . _2 of
HeldPlatformSF ->
return $
heldEffect (bimap _iatType fst3 itmtree) cr w
@@ -33,10 +37,11 @@ useSelectedItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMayb
return $
heldEffect (bimap _iatType fst3 itmtree) cr w
& pointerToItem itm . itUse . heldHammer .~ HammerDown
EquipmentPlatformSF -> do
--EquipmentPlatformSF -> do
_ | isJust $ itm ^? itUse . uequipEffect -> do
guard (_crHammerPosition cr == HammerUp)
invid <- itm ^? itLocation . ilInvID
return $ toggleEquipmentAt invid cr w
invid' <- itm ^? itLocation . ilInvID
return $ toggleEquipmentAt invid' cr w
_ -> Nothing
where
fst3 (x,_,_) = x