Allow triggering items using an ECG

This commit is contained in:
2024-12-18 15:39:04 +00:00
parent c4e8046332
commit 694bc2b060
3 changed files with 161 additions and 129 deletions
+20 -2
View File
@@ -3,6 +3,7 @@ module Dodge.Creature.State (
doDamage,
) where
import Dodge.HeldUse
import Control.Monad
import qualified Data.Map.Strict as M
import Data.Maybe
@@ -176,7 +177,24 @@ invRootItemEffs cr =
invItemLocUpdate :: LocationLDT ItemLink ComposedItem -> World -> World
invItemLocUpdate loc w = case itm ^. itType of
ATTACH BULLETSYNTH -> fromMaybe w $ do
ATTACH BULLETSYNTH -> trySynthBullet loc w
EQUIP WRIST_ECG | haspulse -> tryUseParent loc w
_ -> w
where
haspulse =
w ^? cWorld . lWorld . creatures . ix 0 . crType . avatarPulse . pulseProgress
== Just 0
itm = loc ^. locLDT . ldtValue . _1
tryUseParent :: LocationLDT ItemLink ComposedItem -> World -> World
tryUseParent loc w = fromMaybe w $ do
t <- locUp loc
let t' = bimap (_iatType) (^. _1) $ t ^. locLDT
cr <- w ^? cWorld . lWorld . creatures . ix 0
return $ heldEffectNoHammerCheck t' cr w
trySynthBullet :: LocationLDT ItemLink ComposedItem -> World -> World
trySynthBullet loc w = fromMaybe w $ do
i <- itm ^? itLocation . ilInvID
x <- itm ^? itUse . uaParams . apInt
if x < 100
@@ -227,9 +245,9 @@ invItemLocUpdate loc w = case itm ^. itType of
. amagLoadStatus
. iaLoaded
+~ 1
_ -> w
where
itm = loc ^. locLDT . ldtValue . _1
updateHeldRootItem :: Creature -> World -> World
updateHeldRootItem cr = fromMaybe id $ do
+5 -1
View File
@@ -3,6 +3,7 @@
module Dodge.HeldUse (
heldEffect,
heldEffectNoHammerCheck,
mcUseHeld,
) where
@@ -32,7 +33,10 @@ import RandomHelp
import qualified SDL
heldEffect :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
heldEffect = hammerCheck $ useTimeCheck heldEffectMuzzles
heldEffect = hammerCheck $ heldEffectNoHammerCheck
heldEffectNoHammerCheck :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
heldEffectNoHammerCheck = useTimeCheck heldEffectMuzzles
hammerCheck :: ChainEffect
hammerCheck f it cr w = case it ^? ldtValue . itUse . heldTriggerType of