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
+19 -12
View File
@@ -53,7 +53,7 @@ selectedItemDisplay cr it = itemDisplayWithNumber (showSelectedConsumption cr (_
-- | Displays the item name, ammo if loaded, and any selected '_itCharMode'.
showSelectedConsumption :: Creature -> ItemUse -> String
showSelectedConsumption cr iu = case iu of
HeldUse{} -> showReloadProgress cr (_heldConsumption iu)
HeldUse{} -> showReloadProgress cr (iu ^?! heldConsumption . laSource)
LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu)
EquipUse{} -> ""
_ -> show $ iu ^?! useAmount . getItAmount -- partial, be careful if adding new data constructors
@@ -65,12 +65,14 @@ showAutoRechargeProgress lc = case lc of
| otherwise -> show (_arLoaded lc)
ChargeableAmmo{} -> show (_wpCharge lc)
showReloadProgress :: Creature -> HeldConsumption -> String
showReloadProgress :: Creature -> AmmoSource -> String
showReloadProgress cr ic = case cr ^? crManipulation . manObject . inInventory . iselAction of
Just (ReloadAction i la) -> show i ++ showLoadActionType la (_laLoaded ic)
_ -> case ic ^? laProgress . _Just . ix 0 of
Nothing -> show $ _laLoaded ic
Just la -> show (_actionTime la) ++ showLoadActionType la (_laLoaded ic)
Just (ReloadAction i la) -> show i ++ showLoadActionType la ic
_ -> case ic of
InternalSource ia -> case ia ^? iaProgress . _Just . ix 0 of
Nothing -> show $ ia ^. iaLoaded
Just la -> show (_actionTime la) ++ showLoadActionType la ic
_ -> "X"
showConsumption :: ItemUse -> String
showConsumption iu = case iu of
@@ -85,16 +87,21 @@ showEUseNumber ee = case _eeUse ee of
_ -> ""
showReloadProgress' :: HeldConsumption -> String
showReloadProgress' ic = case ic ^? laProgress . _Just . ix 0 of
Nothing -> show $ _laLoaded ic
Just la -> show (_actionTime la) ++ showLoadActionType la (_laLoaded ic)
showReloadProgress' ic = case ic ^? laSource . _InternalSource . iaProgress . _Just . ix 0 of
Nothing -> fromMaybe "X" $ do
x <- ic ^? laSource . _InternalSource . iaLoaded
return $ show x
Just la -> show (_actionTime la) ++ showLoadActionType la (_laSource ic)
showLoadActionType :: LoadAction -> Int -> String
showLoadActionType la x = case la of
showLoadActionType :: LoadAction -> AmmoSource -> String
showLoadActionType la as = case la of
LoadEject{} -> "E"
LoadInsert{} -> "L"
LoadAdd{} -> "A" ++ show x
LoadAdd{} -> "A" ++ x
LoadPrime{} -> "P"
where
x = maybe "" show $ as ^? _InternalSource . iaLoaded
maybeWarmupStatus :: Item -> Maybe String
maybeWarmupStatus it = case it ^? itUse . heldDelay . warmMax of
+9 -6
View File
@@ -50,6 +50,8 @@ equipItemSPic et _ = case et of
BATTERYPACK -> noPic $ colorSH blue backpackShape
FUELPACK ->
noPic $ colorSH yellow $ upperPrismPolyMT 10 $ polyCirc 3 5
BULLETBELTPACK ->
noPic $ colorSH green backpackShape
AUTODETECTOR dt -> noPic (colorSH (detectorColor dt) $ upperPrismPolySU 3 $ rectWH 2 2)
backpackShape :: Shape
@@ -249,7 +251,7 @@ baseRifleShape = colorSH red $ xCylinderST 3 25
addBullets :: Item -> Shape
addBullets itm = fromMaybe mempty $ do
x <- itm ^? itUse . heldConsumption . laLoaded
x <- itm ^? itUse . heldConsumption . laSource . _InternalSource . iaLoaded
hit <- itm ^? itType . iyBase . ibtHeld
ps <- fmap (take x) $ ammoPosition itm hit ^? amPosDirs
return $ foldMap (uncurry (drawBullet itm)) ps
@@ -315,7 +317,7 @@ makeTinClip it =
bulletEffectColor
(it ^? itUse . heldConsumption . laAmmoType . amBullet . buEffect)
y = fromIntegral y' * 0.3
y' = fromMaybe 0 $ it ^? itUse . heldConsumption . laLoaded
y' = fromMaybe 0 $ it ^? itUse . heldConsumption . laSource . _InternalSource . iaLoaded
tips = fromMaybe mempty $ do
ebt <- it ^? itUse . heldConsumption . laAmmoType . amBullet . buSpawn
return $
@@ -371,12 +373,13 @@ volleyGunShape i =
)
miniGunXPictItem :: Int -> Item -> SPic
miniGunXPictItem i it = miniGunXPict i spin (_laLoaded $ _heldConsumption (_itUse it))
miniGunXPictItem i it = miniGunXPict i spin
where
spin = (-10) * _laLoaded (_heldConsumption (_itUse it)) + _warmTime (_heldDelay $ _itUse it)
spin = (-10) -- * _iaLoaded (_laSource (_heldConsumption (_itUse it)))
+ _warmTime (_heldDelay $ _itUse it)
miniGunXPict :: Int -> Int -> Int -> SPic
miniGunXPict i spin _ =
miniGunXPict :: Int -> Int -> SPic
miniGunXPict i spin =
( colorSH red (rotateSHx a barrels)
<> baseRifleShape
, -- <> clip (-1) 0
+10
View File
@@ -12,6 +12,7 @@ module Dodge.Item.Equipment (
jetPack,
fuelPack,
batteryPack,
bulletBeltPack,
speedLegs,
jumpLegs,
flameShield,
@@ -59,6 +60,7 @@ batteryPack =
& itUse . equipEffect . eeSite .~ GoesOnBack
& itType . iyBase .~ EQUIP BATTERYPACK
& itUse . equipEffect . eeAttachPos .~ V3 (-8) 0 10
& itUse . equipEffect . eeUse .~ EBatterySource 10000 10000
fuelPack :: Item
fuelPack =
@@ -68,6 +70,14 @@ fuelPack =
& itUse . equipEffect . eeAttachPos .~ V3 (-9) 0 10
& itUse . equipEffect . eeUse .~ EFuelSource 10000 10000
bulletBeltPack :: Item
bulletBeltPack =
defaultEquipment
& itUse . equipEffect . eeSite .~ GoesOnBack
& itType . iyBase .~ EQUIP BULLETBELTPACK
& itUse . equipEffect . eeAttachPos .~ V3 (-9) 0 10
& itUse . equipEffect . eeUse .~ EAmmoSource 10000 10000 BulletSource Nothing
jetPack :: Item
jetPack =
defaultEquipment
+7 -7
View File
@@ -20,8 +20,8 @@ sparkGun =
teslaGun :: Item
teslaGun =
defaultBatteryGun
& itUse . heldConsumption . laMax .~ 200
& itUse . heldConsumption . laCycle .~ [loadEject 10, loadInsert 10, loadPrime 60]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 200
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 10, loadInsert 10, loadPrime 60]
& itDimension . dimRad .~ 9
& itDimension . dimCenter .~ V3 4 0 0
& itParams .~ teslaParams
@@ -39,8 +39,8 @@ lasGun =
defaultAutoBatteryGun
& itUse . heldConsumption
.~ ( defaultLoadable
& laMax .~ 200
& laCycle .~ [loadEject 10, loadInsert 10, loadPrime 60]
& laSource . _InternalSource . iaMax .~ 200
& laSource . _InternalSource . iaCycle .~ [loadEject 10, loadInsert 10, loadPrime 60]
)
& itParams
.~ Refracting
@@ -79,8 +79,8 @@ tractorGun =
lasGun
& itUse . heldConsumption
.~ ( defaultLoadable
& laMax .~ 10000
& laCycle .~ [loadEject 10, loadInsert 10, loadPrime 60]
& laSource . _InternalSource . iaMax .~ 10000
& laSource . _InternalSource . iaCycle .~ [loadEject 10, loadInsert 10, loadPrime 60]
)
& itParams .~ Attracting{_attractionPower = 1}
& itTweaks
@@ -136,7 +136,7 @@ lasCircle =
& itType . iyBase .~ HELD LASCIRCLE
& itParams . lasColor .~ orange
& itParams . lasDamage .~ 2
& itUse . heldConsumption . laMax .~ 10000
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 10000
& itUse . heldUse .~ HeldLaser --shootLaser
& itUse . heldDelay .~ NoDelay
& itUse . heldUse .~ HeldCircleLaser --circleLaser
+13 -12
View File
@@ -36,8 +36,8 @@ defaultBangCane =
& itUse . heldAim . aimStance .~ OneHand
& itUse . heldAim . aimHandlePos .~ 5
& itUse . heldAim . aimMuzPos .~ 15
& itUse . heldConsumption . laMax .~ 1
& itUse . heldConsumption . laCycle .~ [loadPartialInsert 10 1]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 1
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadPartialInsert 10 1]
volleyGun :: Int -> Item
volleyGun i =
@@ -50,7 +50,7 @@ volleyGun i =
& itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5}
& itUse . heldAim . aimHandlePos .~ 5
& itUse . heldAim . aimMuzPos .~ 15
& itUse . heldConsumption . laMax .~ i
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ i
& itParams
.~ BulletShooter
{ _muzVel = 0.8
@@ -78,8 +78,8 @@ rifle =
defaultBangCane
& itUse . heldAim . aimStance .~ TwoHandTwist
& itType . iyBase .~ HELD RIFLE
& itUse . heldConsumption . laMax .~ 1
& itUse . heldConsumption . laCycle .~ [loadEject 5, loadInsert 5, loadPrime 5]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 1
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 5, loadInsert 5, loadPrime 5]
& itUse . heldAim . aimWeight .~ 6
& itUse . heldAim . aimRange .~ 1
& itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5}
@@ -90,8 +90,8 @@ repeater =
rifle
& itType . iyModules . at ModRifleMag ?~ EMPTYMODULE
& itType . iyBase .~ HELD REPEATER
& itUse . heldConsumption . laCycle .~ [loadEject 20, loadInsert 20, loadPrime 20]
& itUse . heldConsumption . laMax .~ 15
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 20, loadInsert 20, loadPrime 20]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 15
autoRifle :: Item
autoRifle =
@@ -121,11 +121,12 @@ miniGunUse i =
& heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5}
& heldAim . aimHandlePos .~ 5
& heldConsumption
.~ defaultBulletLoadable
{ _laMax = 1500
, _laLoaded = 1500
}
& heldConsumption . laCycle .~ [loadEject 40, loadInsert 40, loadPrime 40]
.~ (defaultBulletLoadable & laSource .~ ExternalSource Nothing)
--(defaultBulletLoadable
-- & laSource . iaMax .~ 1500
-- & laSource . iaLoaded .~ 1500
--)
& heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 40, loadInsert 40, loadPrime 40]
miniGunX :: Int -> Item
miniGunX i =
+6 -6
View File
@@ -27,14 +27,14 @@ bangCone =
& itUse . heldAim . aimHandlePos .~ 5
& itUse . heldAim . aimMuzPos .~ 15
& itType . iyBase .~ HELD BANGCONE
& itUse . heldConsumption . laMax .~ 5
& itUse . heldConsumption . laCycle .~ [loadEject 5, loadInsert 20, loadPrime 5]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 5
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 5, loadInsert 20, loadPrime 5]
blunderbuss :: Item
blunderbuss =
bangCone
& itUse . heldConsumption . laMax .~ 25
& itUse . heldConsumption . laCycle .~ [loadEject 5, loadInsert 30, loadPrime 5]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 25
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 5, loadInsert 30, loadPrime 5]
& itUse . heldAim . aimStance .~ TwoHandTwist
& itUse . heldAim . aimWeight .~ 6
& itUse . heldAim . aimHandlePos .~ 5
@@ -45,8 +45,8 @@ grapeCannon :: Int -> Item
grapeCannon i =
blunderbuss
& itType . iyBase .~ HELD (GRAPECANNON i)
& itUse . heldConsumption . laMax .~ 25 + 25 * i
& itUse . heldConsumption . laCycle .~ [loadEject 5, loadInsert (30 + i * 10), loadPrime 5]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 25 + 25 * i
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 5, loadInsert (30 + i * 10), loadPrime 5]
& itParams . recoil .~ (150 + fromIntegral i * 50)
& itParams . torqueAfter .~ (0.1 + 0.2 * fromIntegral i)
& itParams . randomOffset .~ (12 + 4 * fromIntegral i)
+5 -5
View File
@@ -38,9 +38,9 @@ launcher =
, _amPjDraw = DrawShell
, _amPjCreation = CreateShell
}
& itUse . heldConsumption . laMax .~ 1
& itUse . heldConsumption . laLoaded .~ 1
& itUse . heldConsumption . laCycle .~ [loadEject 30, loadInsert 30, loadPrime 10]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 1
& itUse . heldConsumption . laSource . _InternalSource . iaLoaded .~ 1
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 30, loadInsert 30, loadPrime 10]
& itType . iyBase .~ HELD LAUNCHER
& itType . iyModules . at ModLauncherHoming ?~ EMPTYMODULE
@@ -48,8 +48,8 @@ launcherX :: Int -> Item
launcherX i =
launcher
& itType . iyBase .~ HELD (LAUNCHERX i)
& itUse . heldConsumption . laMax .~ i
& itUse . heldConsumption . laLoaded .~ i
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ i
& itUse . heldConsumption . laSource . _InternalSource . iaLoaded .~ i
& itUse . heldUse .~ HeldPJCreationX i
& itUse . heldMods .~ LauncherXMod i
+5 -5
View File
@@ -31,8 +31,8 @@ bangRod =
& itUse . heldMods .~ BangRodMod
& itDimension . dimRad .~ 12
& itDimension . dimCenter .~ V3 5 0 0
& itUse . heldConsumption . laMax .~ 1
& itUse . heldConsumption . laCycle .~ [loadEject 5, loadInsert 10, loadPrime 5]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 1
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 5, loadInsert 10, loadPrime 5]
& itType . iyBase .~ HELD BANGROD
& itUse . heldAim . aimWeight .~ 8
& itUse . heldAim . aimRange .~ 1
@@ -56,7 +56,7 @@ amr :: Item
amr =
elephantGun
& itType . iyBase .~ HELD AMR
& itUse . heldConsumption . laMax .~ 15
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 15
autoAmr :: Item
autoAmr =
@@ -85,7 +85,7 @@ machineGun =
& itUse . heldAim . aimStance .~ TwoHandTwist
& itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5}
& itUse . heldDelay .~ VariableRate{_rateMax = 25, _rateMaxMax = 24, _rateMinMax = 7, _rateTime = 0}
& itUse . heldConsumption . laMax .~ 100
& itUse . heldConsumption . laCycle .~ [loadEject 10, loadInsert 40, loadPrime 10]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 100
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 10, loadInsert 40, loadPrime 10]
& itInvSize .~ 3
& itParams . torqueAfter .~ 0.2 -- not sure if this is necessary?
+4 -4
View File
@@ -28,8 +28,8 @@ flameSpitter :: Item
flameSpitter =
flameThrower
& itType . iyBase .~ HELD FLAMESPITTER
& itUse . heldConsumption . laMax .~ 10
& itUse . heldConsumption . laCycle .~ [loadEject 5, loadInsert 10, loadPrime 20]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 10
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 5, loadInsert 10, loadPrime 20]
& itParams . sprayNozzles . ix 0 . nzPressure .~ 4
& itUse . heldAim . aimStance .~ OneHand
& itUse . heldDelay .~ FixedRate{_rateMax = 12, _rateTime = 0}
@@ -96,12 +96,12 @@ flameThrower =
& itUse . heldAim . aimMuzPos .~ 18
& itUse . heldConsumption
.~ ( defaultLoadable
& laMax .~ 250
& laSource . _InternalSource . iaMax .~ 250
& laAmmoType
.~ GasAmmo
{ _amString = "FLAME"
, _amCreateGas = CreateFlame --aFlame
}
& laCycle .~ [loadEject 5, loadInsert 10, loadPrime 20]
& laSource . _InternalSource . iaCycle .~ [loadEject 5, loadInsert 10, loadPrime 20]
)
& itType . iyBase .~ HELD FLAMETHROWER
+7 -7
View File
@@ -40,8 +40,8 @@ bangStick i =
& itUse . heldMods .~ BangStickMod
& itUse . heldAim . aimHandlePos .~ 5
& itUse . heldAim . aimMuzPos .~ 10
& itUse . heldConsumption . laMax .~ i
& itUse . heldConsumption . laCycle .~ [loadPartialInsert 10 1]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ i
& itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadPartialInsert 10 1]
baseStickSpread :: Float
baseStickSpread = 0.2
@@ -51,8 +51,8 @@ revolver =
pistol
& itUse . heldConsumption
.~ ( defaultBulletLoadable
& laMax .~ 6
& laCycle .~ [loadPartialInsert 10 1]
& laSource . _InternalSource . iaMax .~ 6
& laSource . _InternalSource . iaCycle .~ [loadPartialInsert 10 1]
)
& itType . iyBase .~ HELD REVOLVER
@@ -61,8 +61,8 @@ pistol =
bangStick 1
& itUse . heldConsumption
.~ ( defaultBulletLoadable
& laMax .~ 15
& laCycle .~ [loadEject 5, loadInsert 5, loadPrime 5]
& laSource . _InternalSource . iaMax .~ 15
& laSource . _InternalSource . iaCycle .~ [loadEject 5, loadInsert 5, loadPrime 5]
)
& itUse . heldDelay . rateMax .~ 6
& itUse . heldMods .~ PistolMod
@@ -106,5 +106,5 @@ revolverX i =
revolver
& itUse . heldDelay . rateMax .~ 8
& itUse . heldMods .~ RevolverXMod
& itUse . heldConsumption . laMax .~ i * 6
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ i * 6
& itType . iyBase .~ HELD (REVOLVERX i)
+1
View File
@@ -122,6 +122,7 @@ equipInfo eit = case eit of
JETPACK -> "A device enabling flight."
FUELPACK -> "A liquid container with attached hose."
BULLETBELTPACK -> "A container holding a long belt of bullets."
BATTERYPACK -> "A collection of batteries with a universal adapter."
AUTODETECTOR d -> "A device that detects "++detectorInfo d ++" in an expanding radius. Pulses automatically. "
+1 -1
View File
@@ -17,7 +17,7 @@ droneLauncher =
& itUse . heldAim . aimRange .~ 0.5
& itUse . heldAim . aimStance .~ TwoHandTwist
& itUse . heldConsumption . laAmmoType .~ DroneAmmo{_amString = "LASDRONE"}
& itUse . heldConsumption . laMax .~ 2
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 2
& itType . iyBase .~ HELD DRONELAUNCHER
lasDronesPic :: Item -> SPic
+14 -10
View File
@@ -1,22 +1,26 @@
module Dodge.Item.Weapon.FractionLoaded
( fractionLoadedAmmo
, fractionLoadedAmmo2
) where
module Dodge.Item.Weapon.FractionLoaded (
fractionLoadedAmmo,
fractionLoadedAmmo2,
) where
import Control.Lens
import Data.Maybe
import Dodge.Data.Item
---- this shouldn't really be used
loadedAmmo :: Item -> Int
loadedAmmo = _laLoaded . _heldConsumption . _itUse
loadedAmmo itm = fromMaybe 0 $ itm ^? itUse . heldConsumption . laSource . _InternalSource . iaLoaded
-- | _laTransfer (_itConsumption it) == NoTransfer = _laLoaded (_itConsumption it)
-- | otherwise = 0
fractionLoadedAmmo :: Item -> Float
fractionLoadedAmmo it = fromIntegral (loadedAmmo it) / fromIntegral (itmaxammo it)
fractionLoadedAmmo it = fromIntegral (loadedAmmo it) / fromIntegral itmaxammo
where
itmaxammo = _laMax . _heldConsumption . _itUse
itmaxammo = fromMaybe 1 $ it ^? itUse . heldConsumption . laSource . _InternalSource . iaMax
fractionLoadedAmmo2 :: Item -> Float
fractionLoadedAmmo2 it = 1 -
(1 - fromIntegral (loadedAmmo it) / fromIntegral (itMaxAmmo it))**2
fractionLoadedAmmo2 it =
1 - (1 - fromIntegral (loadedAmmo it) / fromIntegral itmaxammo) ** 2
where
itMaxAmmo = _laMax . _heldConsumption . _itUse
itmaxammo = fromMaybe 1 $ it ^? itUse . heldConsumption . laSource . _InternalSource . iaMax
+23 -42
View File
@@ -19,7 +19,6 @@ module Dodge.Item.Weapon.TriggerType (
withItem,
withItemUpdate,
withItemUpdate',
ammoUseCheck,
rateIncAB,
torqueBefore,
torqueBeforeAtLeast,
@@ -136,28 +135,33 @@ withThickSmokeI eff item cr w =
-- TODO create a trigger that does different things on first and continued
-- fire.
ammoCheckI :: ChainEffect
ammoCheckI eff itm cr w
| _laLoaded ic <= 0 || not (_laPrimed ic) = w
| otherwise = eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
where
ic = _heldConsumption $ _itUse itm
ammoCheckI eff itm cr w = case itm ^? itUse . heldConsumption . laSource of
Just (InternalSource ia) | _iaLoaded ia <= 0 || not (_iaPrimed ia)
-> w
Just (ExternalSource ea) | fromMaybe True $ do
invid <- ea ^? _Just
x <- cr ^? crInv . ix invid . itUse . equipEffect . eeUse . euseAmmoAmount
return $ x <= 0
-> w
_ -> eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
-- combined ammo and hammer check: want to be able to auto-reload even if the
-- hammer is down?
ammoHammerCheck :: ChainEffect
ammoHammerCheck eff it cr w
| _laLoaded ic <= 0 || not (_laPrimed ic) = w -- fromMaybe w (startReloadingWeapon cr w)
| otherwise = case it ^? itUse . heldHammer of
Just HammerUp -> eff it cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
ammoHammerCheck eff itm cr w
| _iaLoaded ic <= 0 || not (_iaPrimed ic) = w
-- fromMaybe w (startReloadingWeapon cr w)
| otherwise = case itm ^? itUse . heldHammer of
Just HammerUp -> eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
_ -> w
where
ic = _heldConsumption $ _itUse it
ic = itm ^?! itUse . heldConsumption . laSource . _InternalSource
itUseCharge :: Int -> Item -> Item
itUseCharge x = itUse . leftConsumption . arLoaded %~ (max 0 . subtract x)
itUseAmmo :: Int -> Item -> Item
itUseAmmo x = itUse . heldConsumption . laLoaded %~ (max 0 . subtract x)
itUseAmmo x = itUse . heldConsumption . laSource . _InternalSource . iaLoaded %~ (max 0 . subtract x)
{- | Fires at an increasing rate.
Has different effect after first fire.
@@ -341,14 +345,14 @@ withSidePushAfterI maxSide eff item cr w =
useAllAmmo :: ChainEffect
useAllAmmo eff item cr =
eff item cr
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itUse . heldConsumption . laLoaded .~ 0)
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itUse . heldConsumption . laSource . _InternalSource . iaLoaded .~ 0)
where
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
useAmmoUpTo :: Int -> ChainEffect
useAmmoUpTo amAmount eff item cr =
eff item cr
. ( cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itUse . heldConsumption . laLoaded
. ( cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itUse . heldConsumption . laSource . _InternalSource . iaLoaded
%~ (max 0 . subtract amAmount)
)
where
@@ -357,7 +361,7 @@ useAmmoUpTo amAmount eff item cr =
useAmmoAmount :: Int -> ChainEffect
useAmmoAmount amAmount eff item cr =
eff item cr
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itUse . heldConsumption . laLoaded -~ amAmount)
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itUse . heldConsumption . laSource . _InternalSource . iaLoaded -~ amAmount)
where
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
@@ -378,33 +382,10 @@ useTimeCheck f item cr w = case item ^? itUse . heldDelay . rateTime of
hammerCheckI :: ChainEffect
hammerCheckI f it cr w = case it ^? itUse . heldHammer of
Just HammerUp
| _laPrimed (_heldConsumption (_itUse it)) ->
| it ^?! itUse . heldConsumption . laSource . _InternalSource . iaPrimed ->
f it cr w
_ -> w
-- | Applies a world effect after an ammo check.
-- this should be made "safe" incase there is no _rateTime
ammoUseCheck :: ChainEffect
ammoUseCheck f item cr w
| fireCondition =
f item cr w & pointerToItem
%~ ( itUseAmmo 1
. (itUse . heldDelay . rateTime .~ _rateMax (_heldDelay (_itUse item)))
)
-- | reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| otherwise = w
where
cid = _crID cr
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
pointerToItem = cWorld . lWorld . creatures . ix cid . crInv . ix itRef
fireCondition =
crWeaponReady cr
&& _rateTime (_heldDelay (_itUse item)) == 0
&& _laLoaded (_heldConsumption (_itUse item)) > 0
-- reloadCondition = _laLoaded (_itConsumption item) == 0
{- | Applies a world effect after a hammer position check.
Arbitrary inventory position.
-}
@@ -649,7 +630,7 @@ spreadLoaded eff item cr w = foldr f w dirs
dirs = subtract cd . (spread *) . fromIntegral <$> [0 .. numBulLoaded - 1]
f dir = eff item (cr & crDir +~ dir)
spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item
numBulLoaded = _laLoaded $ _heldConsumption (_itUse item)
numBulLoaded = item ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
sideEffectOnFrame ::
Int ->
@@ -684,7 +665,7 @@ duplicateLoaded :: ChainEffect
duplicateLoaded eff it cr w = foldr f w [1 .. numBul]
where
f _ = eff it cr
numBul = _laLoaded $ _heldConsumption (_itUse it)
numBul = it ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
duplicateLoadedBarrels :: ChainEffect
duplicateLoadedBarrels eff item cr w = foldr f w poss
@@ -695,7 +676,7 @@ duplicateLoadedBarrels eff item cr w = foldr f w poss
poss = map (rotateV (_crDir cr) . V2 0 . (* 5) . (+ cp) . fromIntegral) [0 .. numBul - 1]
f pos = eff item (cr & crPos %~ (+.+ pos))
numBar = _brlNum . _gunBarrels $ _itParams item
numBul = _laLoaded $ _heldConsumption (_itUse item)
numBul = item ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
duplicateOffsetsFocus :: [Float] -> ChainEffect
duplicateOffsetsFocus xs eff item cr w = foldr f w poss