Move towards introducing pipes, generalise blocks

This commit is contained in:
2022-06-16 02:18:22 +01:00
parent f404f32241
commit a7201b8fb6
13 changed files with 154 additions and 65 deletions
+14 -13
View File
@@ -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