Extend trigger type to apply to full item location

This commit is contained in:
2025-07-03 23:08:28 +01:00
parent 978823c87c
commit d8e811c050
7 changed files with 131 additions and 124 deletions
+33 -32
View File
@@ -4,7 +4,6 @@
module Dodge.HeldUse (
gadgetEffect,
-- heldEffect,
mcUseHeld,
heldEffectMuzzles,
) where
@@ -48,7 +47,7 @@ gadgetEffect pt loc
| UseHeld{} <- loc ^. locLDT . ldtValue . _1 . itUse =
heldEffect
pt
(loc ^. locLDT)
loc
| DROPPER x <- loc ^. locLDT . ldtValue . _1 . itType
, Just i <- loc ^? locLDT . ldtValue . _1 . itUse . uInt
, pt == InitialPress =
@@ -58,79 +57,81 @@ gadgetEffect pt loc
useInventoryPath pt i x loc
| otherwise = const id
heldEffect :: PressType -> LDTree ItemLink OItem -> Creature -> World -> World
heldEffect :: PressType -> LocationLDT ItemLink OItem -> Creature -> World -> World
heldEffect = hammerCheck heldEffectMuzzles
hammerCheck ::
(LDTree ItemLink OItem -> Creature -> World -> World) ->
(LocationLDT ItemLink OItem -> Creature -> World -> World) ->
PressType ->
LDTree ItemLink OItem ->
LocationLDT ItemLink OItem ->
Creature ->
World ->
World
hammerCheck f pt it cr w = case itemTriggerType $ it ^. ldtValue . _1 of
hammerCheck f pt loc cr w = case itemTriggerType loc of
WarmUpNoDelay wm
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) it) < wm ->
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) tree) < wm ->
w & setwarming
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. ldtValue . _1 . itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
WarmUpNoDelay{} -> f it cr w & setwarming
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix invid . itParams . wTime +~ 1
WarmUpNoDelay{} -> f loc cr w & setwarming
WarmUpCoolDown ws _ _
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) it) < ws ->
-- UNSAFE:
| _wTime (_itParams $ it) < ws ->
w & setwarming
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. ldtValue . _1 . itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix invid . itParams . wTime +~ 1
WarmUpCoolDown _ cs _
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) it) < cs ->
f it cr w & setwarming
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
| _wTime (_itParams $ it) < cs ->
f loc cr w & setwarming
& cWorld . lWorld . creatures . ix cid . crInv . ix invid . itParams . wTime +~ 1
WarmUpCoolDown{} -> w & setwarming
BurstTrigger is t
| w ^. cWorld . lWorld . lClock - t > timelastused
, pt == InitialPress ->
w & f it cr & cWorld . lWorld . delayedEvents .++~ map g is
BurstTrigger{} -> w
w & f loc cr & cWorld . lWorld . delayedEvents .++~ map g is
VolleyGunTrigger i t
| w ^. cWorld . lWorld . lClock - t > timelastused
, pt == InitialPress ->
let (is, gen) = getVolleyBurst i (w ^. randGen)
in w & f it cr
in w & f loc cr
& cWorld . lWorld . delayedEvents .++~ map g is
& randGen .~ gen
VolleyGunTrigger{} -> w
HammerTrigger t
| w ^. cWorld . lWorld . lClock - t > timelastused
, isNothing $ lookup MakeAutoLink (it ^. ldtRight)
, isNothing $ lookup MakeAutoLink (tree ^. ldtRight)
, pt == InitialPress ->
f it cr w
f loc cr w
AutoTrigger t
| w ^. cWorld . lWorld . lClock - t > timelastused ->
f it cr w
NoTrigger -> f it cr w
f loc cr w
NoTrigger -> f loc cr w
_ -> w
where
tree = loc ^. locLDT
it = loc ^. locLDT . ldtValue . _1
cid = _crID cr
-- the following is unsafe, but if ilInvID isn't correctly set we probably
-- will have problems elsewhere also
itRef = it ^?! ldtValue . _1 . itLocation . ilInvID
invid = it ^?! itLocation . ilInvID
setwarming =
cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . isWarming
cWorld . lWorld . creatures . ix cid . crInv . ix invid . itParams . isWarming
%~ const True
timelastused = it ^. ldtValue . _1 . itTimeLastUsed
g x = (x, WdWdBurstFireRepetition (_crID cr) (it ^?! ldtValue . _1 . itLocation . ilInvID))
timelastused = it ^. itTimeLastUsed
g x = (x, WdWdBurstFireRepetition (_crID cr) invid)
getVolleyBurst :: (Random a, RandomGen b, Num a) => Int -> b -> ([a], b)
getVolleyBurst i g =
let (is, g') = runState (replicateM (i -1) (state $ randomR (0, 6))) g
in (scanl1 (+) is, g')
heldEffectMuzzles :: LDTree ItemLink OItem -> Creature -> World -> World
heldEffectMuzzles t cr w =
heldEffectMuzzles :: LocationLDT ItemLink OItem -> Creature -> World -> World
heldEffectMuzzles loc cr w =
setusetime . doHeldUseEffect t cr
. uncurry (applyCME (_ldtValue t ^. _1) cr)
. foldl' (useLoadedAmmo t cr) (False, w)
$ loadedmuzzles
where
t = loc ^. locLDT
(_, loadedmuzzles) = mapAccumR loadMuzzle t . itemMuzzles $ t ^. ldtValue . _1
setusetime =
cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itid . itTimeLastUsed
@@ -404,7 +405,7 @@ applyCME itm cr cme
-- the above is quite hacky for now
_ -> failsound
where
coolstart = fromMaybe 0 $ itemTriggerType itm ^? coolStart
coolstart = fromMaybe 0 $ baseItemTriggerType itm ^? coolStart
itid = itm ^?! itLocation . ilInvID -- unsafe
spush = maybe 0 itemSidePush $ itm ^? itType . ibtHeld
failsound w = case w ^? input . mouseButtons . ix SDL.ButtonLeft of
@@ -1218,7 +1219,7 @@ mcShootLaser _ mc =
mcShootAuto :: Item -> Machine -> World -> World
mcShootAuto itm mc w
| Just (AutoTrigger rate) <- itemTriggerType <$> mc ^? mcType . mctTurret . tuWeapon -- . itUse . heldDelay
| Just (AutoTrigger rate) <- baseItemTriggerType <$> mc ^? mcType . mctTurret . tuWeapon -- . itUse . heldDelay
, w ^. cWorld . lWorld . lClock - rate > lastused =
w
& cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon