Fold together useDelay and itemTriggerType

This commit is contained in:
2025-07-03 22:25:32 +01:00
parent 8a00450e3f
commit a207073846
12 changed files with 404 additions and 365 deletions
+23 -21
View File
@@ -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
+8 -7
View File
@@ -3,9 +3,10 @@ module Dodge.Creature.State (
doDamage,
) where
import Dodge.HeldUse
import Dodge.BaseTriggerType
import Dodge.Data.DoubleTree
import Dodge.Item.Orientation
import Dodge.Item.UseDelay
import Control.Applicative
import Control.Monad
import qualified Data.Map.Strict as M
@@ -166,26 +167,26 @@ invItemLocUpdate cr loc w = doAnyEquipmentEffect loc cr $ case itm ^. itType of
w & pointerToItem itm . itParams . wTime
%~ (max 0 . subtract 1)
HELD MACHINEPISTOL{}
| fromMaybe 0 (itm ^? itParams . wTime) >= _coolEnd (useDelay itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) >= _coolEnd (itemTriggerType itm) ->
w & pointerToItem itm . itParams . wTime
.~ 0
& pointerToItem itm . itParams . coolSound .~ Nothing
| fromMaybe 0 (itm ^? itParams . wTime) == _coolStart (useDelay itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) == _coolStart (itemTriggerType itm) ->
w
& randGen .~ g
& pointerToItem itm . itParams . wTime +~ 1
& pointerToItem itm . itParams . coolSound ?~ sid
& soundContinue (CrWeaponSound (_crID cr) (fromIntegral $ _itID itm)) (_crPos cr) sid (Just 1)
| fromMaybe 0 (itm ^? itParams . wTime) > _coolStart (useDelay itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) > _coolStart (itemTriggerType itm) ->
w
& pointerToItem itm . itParams . wTime +~ 1
& soundContinue (CrWeaponSound (_crID cr) (fromIntegral $ _itID itm)) (_crPos cr) (fromMaybe undefined (itm ^? itParams . coolSound . _Just)) (Just 1)
| itm ^? itParams . isWarming == Just True ->
w
& pointerToItem itm . itParams . isWarming .~ False
| fromMaybe 0 (itm ^? itParams . wTime) >= _warmStart (useDelay itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) >= _warmStart (itemTriggerType itm) ->
w & pointerToItem itm . itParams . wTime
.~ _coolStart (useDelay itm)
.~ _coolStart (itemTriggerType itm)
| otherwise ->
w & pointerToItem itm . itParams . wTime
.~ 0
@@ -219,7 +220,7 @@ tryUseParent loc w = fromMaybe w $ do
t <- locUp loc
let t' = t ^. locLDT
cr <- w ^? cWorld . lWorld . creatures . ix 0
return $ heldEffectNoHammerCheck t' cr w
return $ heldEffect InitialPress t' cr w
trySynthBullet :: LocationLDT ItemLink OItem -> World -> World
trySynthBullet loc w = fromMaybe w $ do