Implement bullet synth

This commit is contained in:
2024-11-27 20:37:40 +00:00
parent b21513c4dd
commit 0d5e578f07
12 changed files with 365 additions and 298 deletions
+35
View File
@@ -67,6 +67,7 @@ crUpdate f =
, f
, footstepSideEffect
, updateInv -- upInv must be called before invSideEff 22.05.23
, invRootItemEffs
, invSideEff
, equipmentEffects
]
@@ -163,6 +164,40 @@ invSideEff cr = alaf Endo foldMap f (_crInv cr) . updateHeldRootItem cr
where
f it = maybe id (\g -> doInvEffect g it cr) (it ^? itEffect . ieInv)
-- a loop going over all root inventory items
invRootItemEffs :: Creature -> World -> World
invRootItemEffs cr = appEndo $ foldMap (reduceLocLDT (Endo . invItemLocUpdate) . LocLDT TopLDT)
(invLDT (_crInv cr))
invItemLocUpdate :: LocationLDT ItemLink PartiallyComposedItem -> World -> World
invItemLocUpdate loc w = case itm ^. itType of
ATTACH BULLETSYNTH -> fromMaybe w $ do
i <- itm ^? itLocation . ilInvID
x <- itm ^? itUse . uaParams . apInt
if x < 100
then do
bat <- loc ^? locLDT . ldtLeft . ix 0 . _2 . ldtValue . _1
j <- bat ^? itLocation . ilInvID
y <- bat ^? itUse . amagLoadStatus . iaLoaded
guard $ y > 0
return $ w & cWorld . lWorld . creatures
. ix 0 . crInv . ix i . itUse . uaParams . apInt +~ 1
& cWorld . lWorld . creatures
. ix 0 . crInv . ix j . itUse . amagLoadStatus . iaLoaded -~ 1
else do
mag <- loc ^? locLdtContext . cldtParent . _1
j <- mag ^? itLocation . ilInvID
y <- mag ^? itUse . amagLoadStatus . iaLoaded
ymax <- mag ^? itUse . amagLoadStatus . iaMax
guard $ y < ymax
return $ w & cWorld . lWorld . creatures
. ix 0 . crInv . ix i . itUse . uaParams . apInt .~ 0
& cWorld . lWorld . creatures
. ix 0 . crInv . ix j . itUse . amagLoadStatus . iaLoaded +~ 1
_ -> w
where
itm = loc ^. locLDT . ldtValue . _1
updateHeldRootItem :: Creature -> World -> World
updateHeldRootItem cr = fromMaybe id $ do
invid <- cr ^? crManipulation . manObject . imRootSelectedItem