Fold together useDelay and itemTriggerType
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
--{-# LANGUAGE LambdaCase #-}
|
||||
|
||||
module Dodge.Creature.Impulse.UseItem (useItem) where
|
||||
|
||||
@@ -19,8 +19,9 @@ useItem :: Int -> PressType -> World -> Maybe World
|
||||
useItem invid pt w = fmap (worldEventFlags . at InventoryChange ?~ ()) $ do
|
||||
cr <- w ^? cWorld . lWorld . creatures . ix 0
|
||||
itmloc <- allInvLocs (_crInv cr) ^? ix invid . _2
|
||||
let usedloc = chooseUseLocation itmloc
|
||||
useItemLoc cr usedloc pt w
|
||||
useItemLoc cr itmloc pt w
|
||||
-- let usedloc = chooseUseLocation itmloc
|
||||
-- useItemLoc cr usedloc pt w
|
||||
|
||||
useItemLoc :: Creature -> LocationLDT ItemLink OItem -> PressType -> World -> Maybe World
|
||||
useItemLoc cr loc pt w
|
||||
@@ -50,29 +51,30 @@ useItemLoc cr loc pt w
|
||||
, pt == InitialPress
|
||||
, Just invid' <- itm ^? itLocation . ilInvID =
|
||||
return $ toggleEquipmentAt invid' cr w
|
||||
| otherwise = Nothing
|
||||
| otherwise = (\loc' -> useItemLoc cr loc' pt w) =<< locUp loc
|
||||
-- ie try location above
|
||||
where
|
||||
sf = loc ^. locLDT . ldtValue . _2
|
||||
ldt = loc ^. locLDT
|
||||
itm = ldt ^. ldtValue . _1
|
||||
|
||||
chooseUseLocation :: LocationLDT ItemLink OItem -> LocationLDT ItemLink OItem
|
||||
chooseUseLocation loc
|
||||
| isJust $ loc ^? locLDT . ldtValue . _1 . itType . ibtEquip = loc
|
||||
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0 =
|
||||
loc
|
||||
| sf <- loc ^. locLDT . ldtValue . _2
|
||||
, structureUseAtLoc sf =
|
||||
loc
|
||||
| otherwise = maybe loc chooseUseLocation $ locUp loc
|
||||
|
||||
structureUseAtLoc :: ItemStructuralFunction -> Bool
|
||||
structureUseAtLoc = \case
|
||||
HeldPlatformSF -> True
|
||||
UnderBarrelPlatformSF -> True
|
||||
GadgetPlatformSF -> True
|
||||
MapperSF -> True
|
||||
_ -> False
|
||||
--chooseUseLocation :: LocationLDT ItemLink OItem -> LocationLDT ItemLink OItem
|
||||
--chooseUseLocation loc
|
||||
-- | isJust $ loc ^? locLDT . ldtValue . _1 . itType . ibtEquip = loc
|
||||
-- | isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0 =
|
||||
-- loc
|
||||
-- | sf <- loc ^. locLDT . ldtValue . _2
|
||||
-- , structureUseAtLoc sf =
|
||||
-- loc
|
||||
-- | otherwise = maybe loc chooseUseLocation $ locUp loc
|
||||
--
|
||||
--structureUseAtLoc :: ItemStructuralFunction -> Bool
|
||||
--structureUseAtLoc = \case
|
||||
-- HeldPlatformSF -> True
|
||||
-- UnderBarrelPlatformSF -> True
|
||||
-- GadgetPlatformSF -> True
|
||||
-- MapperSF -> True
|
||||
-- _ -> False
|
||||
|
||||
activateDetonator :: LDTree ItemLink OItem -> World -> World
|
||||
activateDetonator det = fromMaybe id $ do
|
||||
|
||||
Reference in New Issue
Block a user