Work towards adding external ammo sources

This commit is contained in:
2023-05-17 11:01:52 +01:00
parent 63c71c852d
commit 7df81559d9
30 changed files with 246 additions and 196 deletions
+11 -3
View File
@@ -33,6 +33,14 @@ useE eo = case eo of
EoffWristShield -> onRemoveWristShield
EFuelSource 0 _ -> const . const id
EFuelSource{} -> trySiphonFuel
EBatterySource{} -> tryChargeBattery
EAmmoSource{} -> tryAttachBulletBelt
tryAttachBulletBelt :: Item -> Creature -> World -> World
tryAttachBulletBelt _ _ w = w
tryChargeBattery :: Item -> Creature -> World -> World
tryChargeBattery _ _ w = w
trySiphonFuel :: Item -> Creature -> World -> World
trySiphonFuel itm cr w = fromMaybe w $ do
@@ -42,12 +50,12 @@ trySiphonFuel itm cr w = fromMaybe w $ do
la <- cr ^? crInv . ix hix . itUse . heldConsumption
atype <- la ^? laAmmoType
guard (isGas atype)
amax <- la ^? laMax
acur <- la ^? laLoaded
amax <- la ^? laSource . _InternalSource . iaMax
acur <- la ^? laSource . _InternalSource . iaLoaded
guard (amax > acur)
return $
w & cWorld . lWorld . creatures . ix (_crID cr) . crInv
%~ ( (ix hix . itUse . heldConsumption . laLoaded +~ 1)
%~ ( (ix hix . itUse . heldConsumption . laSource . _InternalSource . iaLoaded +~ 1)
. (ix eix . itUse . equipEffect . eeUse . euseFuelAmount -~ 1)
)