Partially refactor ammo extraction, work on pulse rifle

This commit is contained in:
2025-07-26 23:17:14 +01:00
parent 190068737d
commit 68a4bc7aab
16 changed files with 753 additions and 733 deletions
+24 -34
View File
@@ -153,6 +153,7 @@ invRootItemEffs cr =
invItemLocUpdate :: Creature -> LocationDT OItem -> World -> World
invItemLocUpdate cr loc w = doAnyEquipmentEffect loc cr $ case itm ^. itType of
ATTACH BULLETSYNTH -> trySynthBullet loc w
ATTACH CAPACITOR -> tryDrawToCapacitor loc w
EQUIP WRIST_ECG | haspulse -> tryUseParent loc w
COPIER _ -> copierItemUpdate itm cr w
HELD FLATSHIELD -> rootNotrootEff createShieldWall removeShieldWall itm cr w
@@ -229,6 +230,22 @@ tryUseParent loc w = fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix 0
return $ gadgetEffect InitialPress t cr w
tryDrawToCapacitor :: LocationDT OItem -> World -> World
tryDrawToCapacitor loc w = fromMaybe w $ do
itm <- loc ^? locDT . dtValue . _1
i <- itm ^? itLocation . ilInvID
x <- loc ^? locDT . dtValue . _1 . itConsumables . _Just
guard $ x < 250
bat <- loc ^? locDT . dtLeft . ix 0 . dtValue . _1
j <- bat ^? itLocation . ilInvID
y <- bat ^? itConsumables . _Just
let z = min y 10
return $ w
& invpoint . ix i . itConsumables . _Just +~ z
& invpoint . ix j . itConsumables . _Just -~ z
where
invpoint = cWorld . lWorld . creatures . ix 0 . crInv
trySynthBullet :: LocationDT OItem -> World -> World
trySynthBullet loc w = fromMaybe w $ do
i <- itm ^? itLocation . ilInvID
@@ -239,48 +256,21 @@ trySynthBullet loc w = fromMaybe w $ do
j <- bat ^? itLocation . ilInvID
y <- bat ^. itConsumables
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
. itConsumables
. _Just
-~ 1
return $ w
& invpoint . ix i . itUse . uaParams . apInt +~ 1
& invpoint . ix j . itConsumables . _Just -~ 1
else do
mag <- loc ^? locDtContext . cdtParent . _1
j <- mag ^? itLocation . ilInvID
y <- mag ^. itConsumables
ymax <- maxAmmo mag
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
. itConsumables
. _Just
+~ 1
return $ w
& invpoint . ix i . itUse . uaParams . apInt .~ 0
& invpoint . ix j . itConsumables . _Just +~ 1
where
itm = loc ^. locDT . dtValue . _1
invpoint = cWorld . lWorld . creatures . ix 0 . crInv
drawARHUD :: LocationDT OItem -> World -> World
drawARHUD (LocDT con _) w = fromMaybe w $ do