Refactor reloading to use list of required steps
This commit is contained in:
@@ -231,8 +231,8 @@ doItemTargeting invid cr w = case cr ^? crInv . ix invid . itTargeting of
|
||||
|
||||
weaponReloadSounds :: Creature -> World -> World
|
||||
weaponReloadSounds cr w = case cr ^? crInv . ix (_crInvSel cr) . itConsumption of
|
||||
Just am@LoadableAmmo{} -> case am ^? laLoadType . loadProgress of
|
||||
Just NoTransfer -> w -- stopSoundFrom (CrReloadSound cid) w
|
||||
Just am@LoadableAmmo{} -> case am ^? laProgress of
|
||||
Just FinishedLoading -> w -- stopSoundFrom (CrReloadSound cid) w
|
||||
Just _ -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w
|
||||
Nothing -> w
|
||||
-- PassiveReload stype | Just (_laReloadTime am) == am ^? laTransfer . transferTime
|
||||
|
||||
+18
-13
@@ -487,7 +487,8 @@ data ItemConsumption
|
||||
{ _laAmmoType :: AmmoType
|
||||
, _laMax :: Int
|
||||
, _laLoaded :: Int
|
||||
, _laLoadType :: LoadType
|
||||
, _laCycle :: [LoadAction]
|
||||
, _laProgress :: LoadProgress
|
||||
}
|
||||
| ChargeableAmmo
|
||||
{ _wpMaxCharge :: Int
|
||||
@@ -545,19 +546,22 @@ data ItemPortage
|
||||
| WornItem
|
||||
| NoPortage
|
||||
|
||||
data LoadProgress
|
||||
= NoTransfer
|
||||
| Eject {_ejectProgress :: Int}
|
||||
| Insert {_insertProgress :: Int, _insertAmount :: Int }
|
||||
data LoadActionProgress = LoadActionProgress
|
||||
{ _actionProgress :: Int
|
||||
, _actionType :: LoadAction
|
||||
}
|
||||
deriving (Eq,Ord,Show)
|
||||
|
||||
data LoadType
|
||||
= ActiveEject
|
||||
{_ejectTime :: Int, _insertTime :: Int,_loadProgress :: LoadProgress }
|
||||
| ActivePartial
|
||||
{_insertTime :: Int, _loadAmount :: Int, _loadProgress :: LoadProgress }
|
||||
| PassiveReload SoundID
|
||||
deriving Eq
|
||||
data LoadProgress
|
||||
= InProgress { _lastAction :: Maybe LoadAction, _futureActions :: [LoadActionProgress] }
|
||||
| FinishedLoading
|
||||
deriving (Eq,Ord,Show)
|
||||
|
||||
data LoadAction
|
||||
= Eject {_actionTime :: Int}
|
||||
| Insert {_actionTime :: Int, _insertMax :: Maybe Int }
|
||||
| Prime {_actionTime :: Int}
|
||||
deriving (Eq,Ord,Show)
|
||||
|
||||
-- I believe this is called every frame, not sure when though
|
||||
data ItEffect
|
||||
@@ -1482,7 +1486,8 @@ makeLenses ''ItEffect
|
||||
makeLenses ''FloorItem
|
||||
makeLenses ''ItemConsumption
|
||||
makeLenses ''AmmoType
|
||||
makeLenses ''LoadType
|
||||
makeLenses ''LoadAction
|
||||
makeLenses ''LoadActionProgress
|
||||
makeLenses ''LoadProgress
|
||||
makeLenses ''TweakParam
|
||||
makeLenses ''Prop
|
||||
|
||||
@@ -19,7 +19,8 @@ defaultLoadable = LoadableAmmo
|
||||
{ _laAmmoType = GenericAmmo
|
||||
, _laMax = 15
|
||||
, _laLoaded = 0
|
||||
, _laLoadType = ActiveEject 20 20 NoTransfer
|
||||
, _laCycle = [Eject 10, Insert 10 Nothing, Prime 10]
|
||||
, _laProgress = FinishedLoading
|
||||
}
|
||||
defaultBulletLoadable :: ItemConsumption
|
||||
defaultBulletLoadable = defaultLoadable & laAmmoType .~ basicBullet
|
||||
|
||||
@@ -31,16 +31,20 @@ itemDisplay it = Prelude.take (itSlotsTaken it) $
|
||||
|
||||
showConsumption :: ItemConsumption -> String
|
||||
showConsumption ic = case ic of
|
||||
am@LoadableAmmo{} -> showLoading (_laLoadType ic) ++ show (_laLoaded am)
|
||||
am@LoadableAmmo{} -> showLoading (_laProgress ic) ++ show (_laLoaded am)
|
||||
am@ChargeableAmmo{} -> show $ _wpCharge am
|
||||
x@ItemItselfConsumable{} -> show (_icAmount x)
|
||||
NoConsumption -> ""
|
||||
showLoading :: LoadType -> String
|
||||
showLoading lt = case lt ^? loadProgress of
|
||||
Just (Eject t) -> show t ++ "E"
|
||||
Just (Insert t _) -> show t ++ "R"
|
||||
Just NoTransfer -> ""
|
||||
showLoading :: LoadProgress -> String
|
||||
showLoading lt = case lt ^? futureActions . ix 0 of
|
||||
Just lap -> show (_actionTime (_actionType lap) - _actionProgress lap)
|
||||
++ showLoadActionType (_actionType lap)
|
||||
Nothing -> ""
|
||||
showLoadActionType :: LoadAction -> String
|
||||
showLoadActionType la = case la of
|
||||
Eject {} -> "E"
|
||||
Insert {} -> "L"
|
||||
Prime {} -> "P"
|
||||
|
||||
-- & itInvDisplay .~ \it -> head (basicItemDisplay it) :
|
||||
-- ["*FIRERATE:" ++ fromMaybe "" (maybeRateStatus it)
|
||||
|
||||
@@ -74,8 +74,7 @@ teslaGun :: Item
|
||||
teslaGun = defaultBatteryGun
|
||||
{ _itConsumption = defaultLoadable
|
||||
& laMax .~ 200
|
||||
& laLoadType . ejectTime .~ 40
|
||||
& laLoadType . insertTime .~ 40
|
||||
& laCycle .~ [Eject 10, Insert 10 Nothing, Prime 60]
|
||||
, _itUse = ruseInstant shootTeslaArc NoHammer
|
||||
[ ammoCheckI
|
||||
, withTempLight 1 100 (V3 0 0 1)
|
||||
@@ -254,8 +253,7 @@ lasGun :: Item
|
||||
lasGun = defaultAutoBatteryGun
|
||||
{ _itConsumption = defaultLoadable
|
||||
& laMax .~ 200
|
||||
& laLoadType . ejectTime .~ 40
|
||||
& laLoadType . insertTime .~ 40
|
||||
& laCycle .~ [Eject 10, Insert 10 Nothing, Prime 60]
|
||||
, _itUse = ruseInstant shootLaser NoHammer
|
||||
[ ammoCheckI
|
||||
, withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
|
||||
@@ -320,8 +318,7 @@ tractorGun :: Item
|
||||
tractorGun = lasGun
|
||||
{ _itConsumption = defaultLoadable
|
||||
& laMax .~ 10000
|
||||
& laLoadType . ejectTime .~ 20
|
||||
& laLoadType . insertTime .~ 20
|
||||
& laCycle .~ [Eject 10, Insert 10 Nothing, Prime 60]
|
||||
, _itUse = ruseInstant aTractorBeam NoHammer
|
||||
[ ammoCheckI
|
||||
]
|
||||
|
||||
@@ -73,7 +73,7 @@ bangCane = defaultBulletWeapon
|
||||
} & itUse . useAim . aimStance .~ OneHand
|
||||
& itType . iyBase .~ BANGCANE
|
||||
& itConsumption . laMax .~ 1
|
||||
& itConsumption . laLoadType .~ ActivePartial 10 1 NoTransfer
|
||||
& itConsumption . laCycle .~ [Insert 10 (Just 1)]
|
||||
bangCaneX :: Int -> Item
|
||||
bangCaneX i = bangCane
|
||||
{ _itUse = ruseAmmoParamsRate 6 upHammer
|
||||
@@ -139,7 +139,7 @@ rifle = bangCane
|
||||
& itUse . useAim . aimStance .~ TwoHandTwist
|
||||
& itType . iyBase .~ RIFLE
|
||||
& itConsumption . laMax .~ 1
|
||||
& itConsumption . laLoadType .~ ActiveEject 5 5 NoTransfer
|
||||
& itConsumption . laCycle .~ [Eject 5, Insert 5 Nothing,Prime 5]
|
||||
& itUse . useAim . aimWeight .~ 6
|
||||
& itUse . useAim . aimRange .~ 1
|
||||
-- & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5}
|
||||
@@ -148,8 +148,7 @@ repeater :: Item
|
||||
repeater = rifle
|
||||
& itType . iyModules . at ModRifleMag ?~ EMPTYMODULE
|
||||
& itType . iyBase .~ REPEATER
|
||||
& itConsumption . laLoadType . ejectTime .~ 40
|
||||
& itConsumption . laLoadType . insertTime .~ 40
|
||||
& itConsumption . laCycle .~ [Eject 5, Insert 15 Nothing,Prime 15]
|
||||
& itConsumption . laMax .~ 15
|
||||
& itDimension . dimSPic .~ (\it -> noPic $ baseRifleShape
|
||||
<> makeTinClipAt 0 (V3 10 (-2) 0) it
|
||||
@@ -252,8 +251,7 @@ miniGunX i = defaultAutoGun
|
||||
{ _laMax = 1500
|
||||
, _laLoaded = 1500
|
||||
}
|
||||
& laLoadType . ejectTime .~ 60
|
||||
& laLoadType . insertTime .~ 60
|
||||
& laCycle .~ [Eject 40, Insert 40 Nothing,Prime 40]
|
||||
, _itUse = miniGunUse i
|
||||
& useDelay .~ WarmUpNoDelay {_warmTime = 0,_warmMax = 100}
|
||||
& useAim . aimWeight .~ 6
|
||||
|
||||
@@ -70,8 +70,7 @@ bangRod = defaultBulletWeapon
|
||||
}
|
||||
}
|
||||
& itConsumption . laMax .~ 1
|
||||
& itConsumption . laLoadType . ejectTime .~ 10
|
||||
& itConsumption . laLoadType . insertTime .~ 10
|
||||
& itConsumption . laCycle .~ [Eject 5, Insert 10 Nothing, Prime 5]
|
||||
& itType . iyBase .~ BANGROD
|
||||
& itUse . useAim . aimWeight .~ 8
|
||||
& itUse . useAim . aimRange .~ 1
|
||||
@@ -142,7 +141,6 @@ machineGun = bangRod
|
||||
& useDelay .~ VariableRate {_rateMax = 25, _rateMaxMax = 24, _rateMinMax = 7, _rateTime = 0}
|
||||
)
|
||||
& itConsumption . laMax .~ 100
|
||||
& itConsumption . laLoadType . ejectTime .~ 25
|
||||
& itConsumption . laLoadType . insertTime .~ 25
|
||||
& itConsumption . laCycle .~ [Eject 10, Insert 40 Nothing, Prime 10]
|
||||
& itInvSize .~ 3
|
||||
& itParams. torqueAfter .~ 0.2 -- not sure if this is necessary?
|
||||
|
||||
@@ -78,7 +78,7 @@ bangStick i = defaultBulletWeapon
|
||||
}
|
||||
& itType . iyBase .~ BANGSTICK i
|
||||
& itConsumption . laMax .~ i
|
||||
& itConsumption . laLoadType .~ ActivePartial 10 1 NoTransfer
|
||||
& itConsumption . laCycle .~ [Insert 10 (Just 1)]
|
||||
baseStickShapeX :: Int -> Shape
|
||||
baseStickShapeX i = foldMap f [0..i-1]
|
||||
where
|
||||
@@ -108,7 +108,7 @@ revolver = pistol
|
||||
& itConsumption .~
|
||||
(defaultBulletLoadable
|
||||
& laMax .~ 6
|
||||
& laLoadType .~ ActivePartial 10 1 NoTransfer )
|
||||
& laCycle .~ [Insert 10 (Just 1)] )
|
||||
& itDimension . dimSPic .~ (\it -> noPic $ baseStickShape <> revolverClip it)
|
||||
& itType . iyBase .~ REVOLVER
|
||||
|
||||
@@ -157,8 +157,7 @@ pistol :: Item
|
||||
pistol = (bangStick 1)
|
||||
& itConsumption .~ ( defaultBulletLoadable
|
||||
& laMax .~ 15
|
||||
& laLoadType . ejectTime .~ 20
|
||||
& laLoadType . insertTime .~ 20 )
|
||||
& laCycle .~ [Eject 5, Insert 5 Nothing, Prime 5] )
|
||||
& itUse .~ ruseAmmoParamsRate 6 upHammer (ammoHammerCheck : pistolAfterHamMods)
|
||||
& itDimension . dimSPic .~ (\it -> noPic $ baseStickShape <> makeTinClipAt pi (V3 5 2 0) it)
|
||||
& itParams %~
|
||||
|
||||
@@ -44,8 +44,7 @@ autoGun = defaultAutoGun
|
||||
{ _laMax = 30
|
||||
, _laLoaded = 30
|
||||
}
|
||||
& laLoadType . ejectTime .~ 40
|
||||
& laLoadType . insertTime .~ 40
|
||||
& laCycle .~ [Eject 30, Insert 30 Nothing, Prime 10]
|
||||
, _itUse = ruseAmmoParamsRate 4 NoHammer
|
||||
[ ammoCheckI
|
||||
, charFiringStratI
|
||||
@@ -132,8 +131,7 @@ bangCone = defaultBulletWeapon
|
||||
}
|
||||
& itType . iyBase .~ BANGCONE
|
||||
& itConsumption . laMax .~ 5
|
||||
& itConsumption . laLoadType . ejectTime .~ 10
|
||||
& itConsumption . laLoadType . insertTime .~ 10
|
||||
& itConsumption . laCycle .~ [Eject 5, Insert 20 Nothing, Prime 5]
|
||||
coneRandItemUpdate :: State StdGen (Item -> Item)
|
||||
coneRandItemUpdate = do
|
||||
wth <- state $ randomR (1,5)
|
||||
@@ -161,8 +159,7 @@ blunderbuss = bangCone
|
||||
}
|
||||
}
|
||||
& itConsumption . laMax .~ 25
|
||||
& itConsumption . laLoadType . ejectTime .~ 15
|
||||
& itConsumption . laLoadType . insertTime .~ 15
|
||||
& itConsumption . laCycle .~ [Eject 5, Insert 30 Nothing, Prime 5]
|
||||
& itUse . useAim . aimStance .~ TwoHandTwist
|
||||
& itUse . useAim . aimWeight .~ 6
|
||||
& itType . iyBase .~ BLUNDERBUSS
|
||||
@@ -170,8 +167,7 @@ bigBlunderbuss :: Item
|
||||
bigBlunderbuss = blunderbuss
|
||||
& itType . iyBase .~ BIGBLUNDERBUSS
|
||||
& itConsumption . laMax .~ 50
|
||||
& itConsumption . laLoadType . ejectTime .~ 18
|
||||
& itConsumption . laLoadType . insertTime .~ 18
|
||||
& itConsumption . laCycle .~ [Eject 5, Insert 40 Nothing, Prime 5]
|
||||
& itParams . recoil .~ 200
|
||||
& itParams . torqueAfter .~ 0.3
|
||||
& itParams . randomOffset .~ 16
|
||||
@@ -179,8 +175,7 @@ biggerBlunderbuss :: Item
|
||||
biggerBlunderbuss = bigBlunderbuss
|
||||
& itType . iyBase .~ BIGGERBLUNDERBUSS
|
||||
& itConsumption . laMax .~ 75
|
||||
& itConsumption . laLoadType . ejectTime .~ 20
|
||||
& itConsumption . laLoadType . insertTime .~ 20
|
||||
& itConsumption . laCycle .~ [Eject 5, Insert 50 Nothing, Prime 5]
|
||||
& itParams . recoil .~ 250
|
||||
& itParams . torqueAfter .~ 0.5
|
||||
& itParams . randomOffset .~ 20
|
||||
@@ -188,8 +183,7 @@ biggestBlunderbuss :: Item
|
||||
biggestBlunderbuss = biggerBlunderbuss
|
||||
& itType . iyBase .~ BIGGESTBLUNDERBUSS
|
||||
& itConsumption . laMax .~ 100
|
||||
& itConsumption . laLoadType . ejectTime .~ 25
|
||||
& itConsumption . laLoadType . insertTime .~ 25
|
||||
& itConsumption . laCycle .~ [Eject 5, Insert 60 Nothing, Prime 5]
|
||||
& itParams . recoil .~ 300
|
||||
& itParams . torqueAfter .~ 0.7
|
||||
& itParams . randomOffset .~ 24
|
||||
|
||||
@@ -33,8 +33,6 @@ droneLauncher = defaultWeapon
|
||||
}
|
||||
& itConsumption . laAmmoType .~ DroneAmmo { _amString = "LASDRONE" }
|
||||
& itConsumption . laMax .~ 2
|
||||
& itConsumption . laLoadType . ejectTime .~ 40
|
||||
& itConsumption . laLoadType . insertTime .~ 40
|
||||
& itType . iyBase .~ DRONELAUNCHER
|
||||
|
||||
lasDronesPic :: Item -> SPic
|
||||
|
||||
@@ -44,8 +44,7 @@ launcher = defaultWeapon
|
||||
}
|
||||
& laMax .~ 1
|
||||
& laLoaded .~ 1
|
||||
& laLoadType . ejectTime .~ 40
|
||||
& laLoadType . insertTime .~ 40
|
||||
& laCycle .~ [Eject 30, Insert 30 Nothing, Prime 10]
|
||||
, _itUse = ruseRate 20 usePjCreation upHammer
|
||||
[ hammerCheckI
|
||||
, ammoCheckI
|
||||
|
||||
@@ -32,8 +32,7 @@ sonicGun :: Item
|
||||
sonicGun = defaultAutoGun
|
||||
{ _itConsumption = defaultLoadable
|
||||
& laMax .~ 10
|
||||
& laLoadType . ejectTime .~ 40
|
||||
& laLoadType . insertTime .~ 40
|
||||
& laCycle .~ [Eject 10, Insert 10 Nothing, Prime 60]
|
||||
, _itUse = ruseRate 8 aSonicWave (HasHammer HammerUp)
|
||||
[ ammoHammerCheck
|
||||
, useTimeCheck
|
||||
|
||||
@@ -17,9 +17,6 @@ Creates a creature next to the creature using the item. -}
|
||||
spawnGun :: Creature -> Item
|
||||
spawnGun cr = defaultWeapon
|
||||
{ _itConsumption = defaultLoadable
|
||||
& laMax .~ 1
|
||||
& laLoadType . ejectTime .~ 40
|
||||
& laLoadType . insertTime .~ 40
|
||||
, _itUse = ruseRate 100
|
||||
(\_ -> spawnCrNextTo cr)
|
||||
upHammer
|
||||
|
||||
@@ -68,8 +68,7 @@ flameSpitter :: Item
|
||||
flameSpitter = flameThrower
|
||||
& itType . iyBase .~ FLAMESPITTER
|
||||
& itConsumption . laMax .~ 10
|
||||
& itConsumption . laLoadType . ejectTime .~ 10
|
||||
& itConsumption . laLoadType . insertTime .~ 10
|
||||
& itConsumption . laCycle .~ [Eject 5, Insert 10 Nothing, Prime 20]
|
||||
& itParams . sprayNozzles . ix 0 . nzPressure .~ 4
|
||||
& itUse . useAim . aimStance .~ OneHand
|
||||
& itUse . useDelay .~ FixedRate {_rateMax =12,_rateTime = 0}
|
||||
@@ -123,8 +122,7 @@ flameThrower = defaultAutoGun
|
||||
{_amString = "FLAME"
|
||||
,_amCreateGas = aFlame
|
||||
}
|
||||
& laLoadType . ejectTime .~ 40
|
||||
& laLoadType . insertTime .~ 40
|
||||
& laCycle .~ [Eject 5, Insert 10 Nothing, Prime 20]
|
||||
, _itUse = ruseInstant (overNozzles useGasParams) NoHammer
|
||||
[ ammoCheckI
|
||||
, useAmmoAmount 1
|
||||
|
||||
@@ -173,15 +173,15 @@ rateIncAB exeffFirst exeffCont eff item cr w
|
||||
itRef = _crInvSel cr
|
||||
pointItem = creatures . ix cid . crInv . ix itRef
|
||||
currentRate = _rateMax (_useDelay (_itUse item))
|
||||
repeatFire = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer && _rateTime (_useDelay (_itUse item)) == 1
|
||||
firstFire = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer && _rateTime (_useDelay (_itUse item)) == 0
|
||||
repeatFire = _laProgress (_itConsumption item) == FinishedLoading && _rateTime (_useDelay (_itUse item)) == 1
|
||||
firstFire = _laProgress (_itConsumption item) == FinishedLoading && _rateTime (_useDelay (_itUse item)) == 0
|
||||
{- | Apply effect after a warm up. -}
|
||||
-- note this is quite unsafe, requires the item to have the correct delay type
|
||||
withWarmUp
|
||||
:: SoundID -- ^ warm up sound id
|
||||
-> ChainEffect
|
||||
withWarmUp soundID f item cr w
|
||||
| _loadProgress (_laLoadType $ _itConsumption item) /= NoTransfer = w
|
||||
| _laProgress (_itConsumption item) /= FinishedLoading = w
|
||||
| curWarmUp < maxWarmUp = w
|
||||
& pointerToItem . itUse . useDelay . warmTime +~ 2
|
||||
& soundContinue (CrWeaponSound cid 0) (_crPos cr) soundID (Just 2)
|
||||
@@ -323,7 +323,7 @@ ammoUseCheck f item cr w
|
||||
cid = _crID cr
|
||||
itRef = _crInvSel cr
|
||||
pointerToItem = creatures . ix cid . crInv . ix itRef
|
||||
fireCondition = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer
|
||||
fireCondition = _laProgress (_itConsumption item) == FinishedLoading
|
||||
&& _rateTime (_useDelay (_itUse item)) == 0
|
||||
&& _laLoaded (_itConsumption item) > 0
|
||||
-- reloadCondition = _laLoaded (_itConsumption item) == 0
|
||||
@@ -359,7 +359,7 @@ shootL f item cr w
|
||||
cid = _crID cr
|
||||
invid = fromJust $ _itInvPos item
|
||||
pointerToItem = creatures . ix cid . crInv . ix invid
|
||||
fireCondition = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer
|
||||
fireCondition = _laProgress (_itConsumption item) == FinishedLoading
|
||||
&& _rateTime (_useDelay (_itUse item)) == 0
|
||||
&& _laLoaded (_itConsumption item) > 0
|
||||
-- reloadCondition = _laLoaded (_itConsumption item) == 0
|
||||
|
||||
+20
-46
@@ -11,41 +11,12 @@ import Dodge.Data
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
|
||||
---- TODO clean this up, rethink datatypes
|
||||
--icTryStartReloading :: Item -> Maybe Item
|
||||
--icTryStartReloading it = do
|
||||
-- am <- it ^? itConsumption
|
||||
-- amloaded <- am ^? laLoaded
|
||||
-- ammax <- am ^? laMax
|
||||
-- rstate <- am ^? laReloadState
|
||||
-- if amloaded < ammax && rstate == Nothing'
|
||||
-- then Just $ it
|
||||
-- & itConsumption . laReloadState .~ Just' (_laReloadTime am)
|
||||
-- & if _laReloadType am == ActiveClear
|
||||
-- then itConsumption . laLoaded .~ 0
|
||||
-- else id
|
||||
-- else Nothing
|
||||
|
||||
crStartReloading :: Creature -> World -> World
|
||||
crStartReloading cr = creatures . ix (_crID cr) . crStance . posture .~ Reloading
|
||||
|
||||
crStopReloading :: Creature -> Creature
|
||||
crStopReloading cr = cr & crStance . posture .~ AtEase
|
||||
|
||||
startInsertAmmo :: ItemConsumption -> ItemConsumption
|
||||
startInsertAmmo ic = ic & laLoadType . loadProgress .~ Insert intime inamount
|
||||
where
|
||||
intime = _insertTime (_laLoadType ic)
|
||||
inamount = maybe id min (ic ^? laLoadType . loadAmount) (_laMax ic - _laLoaded ic)
|
||||
|
||||
startEjectAmmo :: ItemConsumption -> ItemConsumption
|
||||
startEjectAmmo ic = ic & laLoadType . loadProgress .~ Eject (_ejectTime $ _laLoadType ic)
|
||||
|
||||
loadAmmo :: Int -> ItemConsumption -> ItemConsumption
|
||||
loadAmmo inamount ic = ic
|
||||
& laLoaded +~ inamount
|
||||
& laLoadType . loadProgress .~ NoTransfer
|
||||
|
||||
stepReloading :: Creature -> Creature
|
||||
stepReloading cr = case _posture (_crStance cr) of
|
||||
Reloading -> fromMaybe (cr & crStance . posture .~ AtEase)
|
||||
@@ -53,23 +24,26 @@ stepReloading cr = case _posture (_crStance cr) of
|
||||
_ -> cr
|
||||
|
||||
stepReloading' :: ItemConsumption -> Maybe ItemConsumption
|
||||
stepReloading' ic = do
|
||||
ltype <- ic ^? laLoadType
|
||||
lprog <- ltype ^? loadProgress
|
||||
case lprog of
|
||||
Eject x
|
||||
| x > 0 -> Just $ ic & laLoadType . loadProgress . ejectProgress -~ 1
|
||||
| otherwise -> Just $ ic & startInsertAmmo
|
||||
Insert x inamount
|
||||
| x > 0 -> Just $ ic & laLoadType . loadProgress . insertProgress -~ 1
|
||||
| otherwise -> Just $ ic & loadAmmo inamount
|
||||
NoTransfer
|
||||
| _laLoaded ic >= _laMax ic
|
||||
-> Nothing
|
||||
| otherwise -> case ltype of
|
||||
ActiveEject {} -> Just $ ic & startEjectAmmo
|
||||
ActivePartial {} -> Just $ ic & startInsertAmmo
|
||||
_ -> Nothing
|
||||
stepReloading' ic = case _laProgress ic of
|
||||
FinishedLoading
|
||||
| _laLoaded ic >= _laMax ic -> Nothing
|
||||
| otherwise -> Just $ ic & laProgress
|
||||
.~ InProgress Nothing (map toLoadProgress (_laCycle ic))
|
||||
InProgress _ [] -> Just $ ic & laProgress .~ FinishedLoading
|
||||
InProgress _ (a:_)
|
||||
| _actionProgress a > 0 -> Just $ ic & laProgress . futureActions . ix 0 . actionProgress -~ 1
|
||||
| otherwise -> Just $ ic & doLoadAction (_actionType a)
|
||||
& laProgress . futureActions %~ tail
|
||||
& laProgress . lastAction ?~ (_actionType a)
|
||||
|
||||
toLoadProgress :: LoadAction -> LoadActionProgress
|
||||
toLoadProgress la = LoadActionProgress (_actionTime la) la
|
||||
|
||||
doLoadAction :: LoadAction -> ItemConsumption -> ItemConsumption
|
||||
doLoadAction la ic = case la of
|
||||
Eject {} -> ic & laLoaded .~ 0
|
||||
Insert {_insertMax = mx} -> ic & laLoaded +~ maybe id min mx (_laMax ic - _laLoaded ic)
|
||||
Prime {} -> ic
|
||||
|
||||
--{- | Start reloading if clip is empty. -}
|
||||
--crAutoReload :: Creature -> Creature
|
||||
|
||||
Reference in New Issue
Block a user