Work towards adding external ammo sources
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user