This commit is contained in:
2021-12-01 18:38:10 +00:00
parent 84ccff5344
commit ce06845278
+36
View File
@@ -0,0 +1,36 @@
module Dodge.Reloading where
import Dodge.Data
import Dodge.Base
--import qualified Data.IntMap.Strict as IM
import Control.Lens
startReloadingWeapon :: Creature -> World -> Maybe World
startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) . itConsumption)
icTryStartReloading
icTryStartReloading :: ItemConsumption -> Maybe ItemConsumption
icTryStartReloading am
| _ammoLoaded am < _ammoMax am && _reloadState am == Nothing'
= Just $ am & reloadState .~ Just' (_reloadTime am)
& if _reloadType am == ActiveClear then ammoLoaded .~ 0 else id
| otherwise = Nothing
crStopReloading :: Creature -> Creature
crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . reloadState .~ Nothing'
stepReloading :: Creature -> Creature
stepReloading cr = case cr ^? crInv . ix isel . itConsumption . reloadState . _Just' of
Just 0 -> cr & crInv . ix isel . itConsumption %~ doload
Just _ -> cr & crInv . ix isel . itConsumption . reloadState . _Just' %~ decreaseToZero
Nothing -> cr
where
isel = _crInvSel cr
doload itcon = case _reloadType itcon of
ActivePartial x
| x + _ammoLoaded itcon < _ammoMax itcon -> itcon & ammoLoaded %~ (+ x)
& reloadState .~ Just' (_reloadTime itcon)
| otherwise -> itcon & ammoLoaded .~ _ammoMax itcon
& reloadState .~ Nothing'
_ -> itcon & ammoLoaded .~ _ammoMax itcon
& reloadState .~ Nothing'