Continue refactoring reloading
This commit is contained in:
+45
-17
@@ -19,25 +19,53 @@ crStopReloading cr = cr & crStance . posture .~ AtEase
|
||||
|
||||
stepReloading :: Creature -> Creature
|
||||
stepReloading cr = case _posture (_crStance cr) of
|
||||
Reloading -> fromMaybe (cr & crStance . posture .~ AtEase)
|
||||
(cr & crInv . ix (_crInvSel cr) . itConsumption %%~ stepReloading')
|
||||
_ -> cr
|
||||
Reloading -> fromMaybe
|
||||
(cr & crStance . posture .~ AtEase)
|
||||
(cr & stepReloading')
|
||||
_ -> cr & crInvSelAction .~ NoInvSelAction
|
||||
|
||||
stepReloading' :: ItemConsumption -> Maybe ItemConsumption
|
||||
stepReloading' ic = case _laProgress ic of
|
||||
FinishedLoading
|
||||
| _laLoaded ic >= _laMax ic -> Nothing
|
||||
| otherwise -> Just $ ic & laProgress
|
||||
.~ InProgress Nothing (map toLoadProgress (_laCycle ic))
|
||||
InProgress _ [] -> Just $ ic & laProgress .~ FinishedLoading
|
||||
InProgress _ (a:_)
|
||||
| _actionProgress a > 0 -> Just $ ic & laProgress . futureActions . ix 0 . actionProgress -~ 1
|
||||
| otherwise -> Just $ ic & doLoadAction (_actionType a)
|
||||
& laProgress . futureActions %~ tail
|
||||
& laProgress . lastAction ?~ (_actionType a)
|
||||
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
|
||||
|
||||
toLoadProgress :: LoadAction -> LoadActionProgress
|
||||
toLoadProgress la = LoadActionProgress (_actionTime la) la
|
||||
tryStartLoading :: Creature -> Maybe Creature
|
||||
tryStartLoading cr = case cr ^? crInv . ix (_crInvSel cr) . itConsumption . laProgress of
|
||||
Just Nothing -> Just . continueLoading $ cr
|
||||
& crInv . ix (_crInvSel cr) . itConsumption %~ setLoadCycle
|
||||
Just (Just _) -> Just . continueLoading $ cr
|
||||
Nothing -> Nothing
|
||||
|
||||
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
|
||||
& 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
|
||||
|
||||
|
||||
-- Just LoadFinished
|
||||
-- | _laLoaded ic >= _laMax ic -> Nothing
|
||||
-- | otherwise -> Just $ ic & laProgress
|
||||
-- .~ LoadUnderway (_actionTime (head (_laCycle ic))) (_laCycle ic)
|
||||
-- Just (LoadUnderway _ []) -> Just $ ic & laProgress .~ LoadFinished
|
||||
-- Just (LoadUnderway t (a:_))
|
||||
-- | t > 0 -> Just $ ic & laProgress . actionProgress -~ 1
|
||||
-- | otherwise -> Just $ ic & doLoadAction a
|
||||
-- & laProgress . futureActions %~ tail
|
||||
-- & laProgress . actionProgress .~ _actionTime a
|
||||
-- Just (LoadPaused (a:as)) -> Just $ ic & laProgress .~ LoadUnderway (_actionTime a) (a:as)
|
||||
-- Just (LoadPaused []) -> Just $ ic & laProgress .~ LoadFinished
|
||||
-- Nothing -> Nothing
|
||||
|
||||
doLoadAction :: LoadAction -> ItemConsumption -> ItemConsumption
|
||||
doLoadAction la ic = case la of
|
||||
|
||||
Reference in New Issue
Block a user