Continue reload refactor
This commit is contained in:
+16
-22
@@ -1,8 +1,8 @@
|
||||
module Dodge.Reloading
|
||||
( stepReloading
|
||||
-- , tryStartReloading
|
||||
( tryStartLoading
|
||||
, crStopReloading
|
||||
, crStartReloading
|
||||
, stepReloading
|
||||
) where
|
||||
import Dodge.Data
|
||||
--import Dodge.Base.Arithmetic
|
||||
@@ -12,28 +12,22 @@ import Control.Lens
|
||||
import Data.Maybe
|
||||
|
||||
crStartReloading :: Creature -> World -> World
|
||||
crStartReloading cr = creatures . ix (_crID cr) . crStance . posture .~ Reloading
|
||||
crStartReloading cr w = fromMaybe w $ w & creatures . ix (_crID cr) %%~ tryStartLoading
|
||||
|
||||
crStopReloading :: Creature -> Creature
|
||||
crStopReloading cr = cr & crStance . posture .~ AtEase
|
||||
|
||||
stepReloading :: Creature -> Creature
|
||||
stepReloading cr = case _posture (_crStance cr) of
|
||||
Reloading -> fromMaybe
|
||||
(cr & crStance . posture .~ AtEase)
|
||||
(cr & stepReloading')
|
||||
_ -> cr & crInvSelAction .~ NoInvSelAction
|
||||
|
||||
stepReloading' :: Creature -> Maybe Creature
|
||||
stepReloading' cr = case cr ^?! crInvSelAction of
|
||||
ReloadAction x la | x > 0 -> Just $ cr & crInvSelAction . actionProgress -~ 1
|
||||
| otherwise -> Just $ cr & completeLoadAction la
|
||||
_ -> tryStartLoading cr
|
||||
stepReloading cr = case cr ^?! crInvSel . iselAction of
|
||||
ReloadAction x la
|
||||
| x > 0 -> cr & crInvSel . iselAction . actionProgress -~ 1
|
||||
| otherwise -> cr & completeLoadAction la
|
||||
_ -> cr
|
||||
|
||||
tryStartLoading :: Creature -> Maybe Creature
|
||||
tryStartLoading cr = case cr ^? crInv . ix (_crInvSel cr) . itConsumption . laProgress of
|
||||
tryStartLoading cr = case cr ^? crInv . ix (crSel cr) . itConsumption . laProgress of
|
||||
Just Nothing -> Just . continueLoading $ cr
|
||||
& crInv . ix (_crInvSel cr) . itConsumption %~ setLoadCycle
|
||||
& crInv . ix (crSel cr) . itConsumption %~ setLoadCycle
|
||||
Just (Just _) -> Just . continueLoading $ cr
|
||||
Nothing -> Nothing
|
||||
|
||||
@@ -41,16 +35,16 @@ setLoadCycle :: ItemConsumption -> ItemConsumption
|
||||
setLoadCycle ic = ic & laProgress ?~ _laCycle ic
|
||||
|
||||
continueLoading :: Creature -> Creature
|
||||
continueLoading cr = case cr ^? crInv . ix (_crInvSel cr) . itConsumption . laProgress . _Just of
|
||||
Just (la:_) -> cr & crInvSelAction .~ ReloadAction (_actionTime la) la
|
||||
_ -> cr & crInvSelAction .~ NoInvSelAction
|
||||
& crInv . ix (_crInvSel cr) . itConsumption . laProgress .~ Nothing
|
||||
continueLoading cr = case cr ^? crInv . ix (crSel cr) . itConsumption . laProgress . _Just of
|
||||
Just (la:_) -> cr & crInvSel . iselAction .~ ReloadAction (_actionTime la) la
|
||||
_ -> cr & crInvSel . iselAction .~ NoInvSelAction
|
||||
& crInv . ix (crSel cr) . itConsumption . laProgress .~ Nothing
|
||||
& crStance . posture .~ AtEase
|
||||
|
||||
completeLoadAction :: LoadAction -> Creature -> Creature
|
||||
completeLoadAction la cr = continueLoading $ cr
|
||||
& crInv . ix (_crInvSel cr) . itConsumption . laProgress . _Just %~ tail
|
||||
& crInv . ix (_crInvSel cr) . itConsumption %~ doLoadAction la
|
||||
& crInv . ix (crSel cr) . itConsumption . laProgress . _Just %~ tail
|
||||
& crInv . ix (crSel cr) . itConsumption %~ doLoadAction la
|
||||
|
||||
|
||||
-- Just LoadFinished
|
||||
|
||||
Reference in New Issue
Block a user