Commit before changing module system to Map
This commit is contained in:
+33
-27
@@ -1,21 +1,25 @@
|
||||
module Dodge.Reloading where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Item.MaxAmmo
|
||||
--import qualified Data.IntMap.Strict as IM
|
||||
|
||||
import Data.Maybe
|
||||
--import Data.Maybe
|
||||
import Control.Lens
|
||||
|
||||
|
||||
startReloadingWeapon :: Creature -> World -> Maybe World
|
||||
startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) . itConsumption)
|
||||
startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr))
|
||||
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
|
||||
icTryStartReloading :: Item -> Maybe Item
|
||||
icTryStartReloading it
|
||||
| _ammoLoaded am < itMaxAmmo it && _reloadState am == Nothing'
|
||||
= Just $ it & itConsumption . reloadState .~ Just' (_reloadTime am)
|
||||
& if _reloadType am == ActiveClear then itConsumption . ammoLoaded .~ 0 else id
|
||||
| otherwise = Nothing
|
||||
where
|
||||
am = _itConsumption it
|
||||
|
||||
crStopReloading :: Creature -> Creature
|
||||
crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . reloadState .~ Nothing'
|
||||
@@ -25,29 +29,31 @@ crUpCrUp f cr = creatures . ix (_crID cr) %~ f
|
||||
|
||||
stepReloading :: Creature -> Creature
|
||||
stepReloading cr = case cr ^? crInv . ix isel . itConsumption . reloadState . _Just' of
|
||||
Just 0 -> cr & crInv . ix isel . itConsumption %~ doload
|
||||
Just 0 -> cr & crInv . ix isel %~ doload
|
||||
Just _ -> cr & crInv . ix isel . itConsumption . reloadState . _Just' %~ decreaseToZero
|
||||
Nothing -> cr
|
||||
where
|
||||
isel = _crInvSel cr
|
||||
doload itcon = case _reloadType itcon of
|
||||
doload it = 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'
|
||||
| x + _ammoLoaded itcon < itMaxAmmo it -> it & itConsumption . ammoLoaded %~ (+ x)
|
||||
& itConsumption . reloadState .~ Just' (_reloadTime itcon)
|
||||
| otherwise -> it & itConsumption . ammoLoaded .~ itMaxAmmo it
|
||||
& itConsumption . reloadState .~ Nothing'
|
||||
_ -> it & itConsumption . ammoLoaded .~ itMaxAmmo it
|
||||
& itConsumption . reloadState .~ Nothing'
|
||||
where
|
||||
itcon = _itConsumption it
|
||||
|
||||
{- | Start reloading if clip is empty. -}
|
||||
crAutoReload :: Creature -> Creature
|
||||
crAutoReload cr = case cr ^? ptrItConsumption' . ammoLoaded of
|
||||
Just 0 | _posture (_crStance cr) /= Aiming
|
||||
-> cr & ptrItConsumption . reloadState .~ strictify reloadT
|
||||
& ptrItConsumption . ammoLoaded %~ (`fromMaybe` maxA)
|
||||
_ -> cr
|
||||
where
|
||||
ptrItConsumption = crInv . ix (_crInvSel cr) . itConsumption
|
||||
ptrItConsumption' = crInv . ix (_crInvSel cr) . itConsumption
|
||||
reloadT = cr ^? ptrItConsumption' . reloadTime
|
||||
maxA = cr ^? ptrItConsumption' . ammoMax
|
||||
--{- | Start reloading if clip is empty. -}
|
||||
--crAutoReload :: Creature -> Creature
|
||||
--crAutoReload cr = case cr ^? ptrItConsumption' . ammoLoaded of
|
||||
-- Just 0 | _posture (_crStance cr) /= Aiming
|
||||
-- -> cr & ptrItConsumption . reloadState .~ strictify reloadT
|
||||
-- & ptrItConsumption . ammoLoaded %~ (`fromMaybe` maxA)
|
||||
-- _ -> cr
|
||||
-- where
|
||||
-- ptrItConsumption = crInv . ix (_crInvSel cr) . itConsumption
|
||||
-- ptrItConsumption' = crInv . ix (_crInvSel cr) . itConsumption
|
||||
-- reloadT = cr ^? ptrItConsumption' . reloadTime
|
||||
-- maxA = fmap itMaxAmmo $ cr ^? crInv . ix (_crInvSel cr)
|
||||
|
||||
Reference in New Issue
Block a user