Make reloading based upon creature stance
This commit is contained in:
+43
-35
@@ -1,6 +1,6 @@
|
||||
module Dodge.Reloading
|
||||
( stepReloading
|
||||
, startReloadingWeapon
|
||||
, tryStartReloading
|
||||
, crStopReloading
|
||||
) where
|
||||
import Dodge.Data
|
||||
@@ -9,49 +9,57 @@ import Dodge.Base.Arithmetic
|
||||
|
||||
import Control.Lens
|
||||
|
||||
startReloadingWeapon :: Creature -> World -> Maybe World
|
||||
startReloadingWeapon cr = creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) %%~
|
||||
icTryStartReloading
|
||||
tryStartReloading :: Creature -> World -> Maybe World
|
||||
tryStartReloading cr w = case cr ^? crInv . ix (_crInvSel cr) . itConsumption of
|
||||
Just LoadableAmmo {_laMax = ma, _laLoaded = la, _laReloadTime = rtime, _laReloadType = rtype, _laTransfer = NoTransfer}
|
||||
| ma > la && rtype == ActiveClear -> Just $ w & creatures . ix (_crID cr) %~ clearload
|
||||
| ma > la && isActivePartial rtype -> Just $ w & creatures . ix (_crID cr) %~ partialload
|
||||
where
|
||||
isActivePartial ActivePartial {} = True
|
||||
isActivePartial _ = False
|
||||
clearload cr' = cr'
|
||||
& crInv . ix (_crInvSel cr) . itConsumption . laLoaded .~ 0
|
||||
& crInv . ix (_crInvSel cr) . itConsumption . laTransfer .~ Transfer ma rtime
|
||||
& crStance . posture .~ Reloading
|
||||
partialload cr' = cr'
|
||||
& crInv . ix (_crInvSel cr) . itConsumption . laTransfer
|
||||
.~ Transfer (min (ma - la) (_partialReloadAmount rtype)) rtime
|
||||
& crStance . posture .~ Reloading
|
||||
_ -> Nothing
|
||||
|
||||
-- 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
|
||||
|
||||
---- 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
|
||||
|
||||
crStopReloading :: Creature -> Creature
|
||||
crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . laReloadState .~ Nothing'
|
||||
crStopReloading cr = cr & crStance . posture .~ AtEase
|
||||
|
||||
-- ugly TODO cleanup
|
||||
stepReloading :: Creature -> Creature
|
||||
stepReloading cr = case cr ^? crInv . ix isel . itConsumption . laReloadState . _Just' of
|
||||
Just 0 -> cr & crInv . ix isel %~ loadItem
|
||||
Just _ -> cr & crInv . ix isel . itConsumption . laReloadState . _Just' %~ decreaseToZero
|
||||
Nothing -> cr
|
||||
stepReloading cr = case cr ^? crInv . ix isel . itConsumption . laTransfer of
|
||||
Just (Transfer x 0) -> cr
|
||||
& crInv . ix isel %~ loadItem x
|
||||
& crStance . posture .~ AtEase
|
||||
Just Transfer {} -> cr
|
||||
& crInv . ix isel . itConsumption . laTransfer . transferTime %~ decreaseToZero
|
||||
_ -> cr
|
||||
where
|
||||
isel = _crInvSel cr
|
||||
|
||||
loadItem :: Item -> Item
|
||||
loadItem it = case _laReloadType itcon of
|
||||
ActivePartial x
|
||||
| x + _laLoaded itcon < itMaxAmmo -> it & itConsumption . laLoaded %~ (+ x)
|
||||
& itConsumption . laReloadState .~ Just' (_laReloadTime itcon)
|
||||
| otherwise -> it & itConsumption . laLoaded .~ itMaxAmmo
|
||||
& itConsumption . laReloadState .~ Nothing'
|
||||
_ -> it & itConsumption . laLoaded .~ itMaxAmmo
|
||||
& itConsumption . laReloadState .~ Nothing'
|
||||
where
|
||||
itcon = _itConsumption it
|
||||
itMaxAmmo = _laMax itcon
|
||||
loadItem :: Int -> Item -> Item
|
||||
loadItem x = itConsumption %~ (set laTransfer NoTransfer . (laLoaded +~ x))
|
||||
|
||||
--{- | Start reloading if clip is empty. -}
|
||||
--crAutoReload :: Creature -> Creature
|
||||
|
||||
Reference in New Issue
Block a user