Move towards introducing pipes, generalise blocks
This commit is contained in:
+14
-13
@@ -7,11 +7,10 @@ import Dodge.Data
|
||||
import Dodge.Base
|
||||
--import qualified Data.IntMap.Strict as IM
|
||||
|
||||
--import Data.Maybe
|
||||
import Control.Lens
|
||||
|
||||
startReloadingWeapon :: Creature -> World -> Maybe World
|
||||
startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr))
|
||||
startReloadingWeapon cr = creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) %%~
|
||||
icTryStartReloading
|
||||
|
||||
-- TODO clean this up, rethink datatypes
|
||||
@@ -35,22 +34,24 @@ crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . laReloadSt
|
||||
-- ugly TODO cleanup
|
||||
stepReloading :: Creature -> Creature
|
||||
stepReloading cr = case cr ^? crInv . ix isel . itConsumption . laReloadState . _Just' of
|
||||
Just 0 -> cr & crInv . ix isel %~ doload
|
||||
Just 0 -> cr & crInv . ix isel %~ loadItem
|
||||
Just _ -> cr & crInv . ix isel . itConsumption . laReloadState . _Just' %~ decreaseToZero
|
||||
Nothing -> cr
|
||||
where
|
||||
isel = _crInvSel cr
|
||||
doload 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
|
||||
|
||||
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'
|
||||
where
|
||||
itcon = _itConsumption it
|
||||
itMaxAmmo = _laMax itcon
|
||||
_ -> it & itConsumption . laLoaded .~ itMaxAmmo
|
||||
& itConsumption . laReloadState .~ Nothing'
|
||||
where
|
||||
itcon = _itConsumption it
|
||||
itMaxAmmo = _laMax itcon
|
||||
|
||||
--{- | Start reloading if clip is empty. -}
|
||||
--crAutoReload :: Creature -> Creature
|
||||
|
||||
Reference in New Issue
Block a user