Work on inventory management

This commit is contained in:
2023-02-16 16:12:03 +00:00
parent ff5fa6321a
commit 934dd64704
30 changed files with 129 additions and 111 deletions
+12 -12
View File
@@ -14,17 +14,17 @@ crCancelReloading :: Creature -> Creature
crCancelReloading cr =
cr
& updateProgress
& crInvSel . isel . iselAction .~ NoInvSelAction
& crManipulation . isel . iselAction .~ NoInvSelAction
where
updateProgress = case crSel cr of
SelItem i _ -> crInv . ix i . itUse . heldConsumption . laProgress %~ const Nothing
_ -> id
stepReloading :: Creature -> Creature
stepReloading cr = case cr ^?! crInvSel . isel of
stepReloading cr = case cr ^?! crManipulation . isel of
SelItem i (ReloadAction x la)
| x > 0 ->
cr & crInvSel . isel . iselAction . actionProgress -~ 1
cr & crManipulation . isel . iselAction . actionProgress -~ 1
| otherwise ->
cr
& crInv . ix i . itUse . heldConsumption %~ doLoadAction la
@@ -33,22 +33,22 @@ stepReloading cr = case cr ^?! crInvSel . isel of
_ -> cr
tryNextLoadAction :: Creature -> Creature
tryNextLoadAction cr = case cr ^? crInvSel . isel of
tryNextLoadAction cr = case cr ^? crManipulation . isel of
Just (SelItem i _) -> case cr ^? crInv . ix i . itUse . heldConsumption . laProgress . _Just . ix 0 of
Nothing -> cr & crInvSel . isel . iselAction .~ NoInvSelAction
Nothing -> cr & crManipulation . isel . iselAction .~ NoInvSelAction
Just la ->
cr & crInvSel . isel . iselAction . actionProgress .~ _actionTime la
& crInvSel . isel . iselAction . reloadAction .~ la
cr & crManipulation . isel . iselAction . actionProgress .~ _actionTime la
& crManipulation . isel . iselAction . reloadAction .~ la
_ -> cr
crToggleReloading :: Creature -> Creature
crToggleReloading cr = case cr ^? crInvSel . isel . iselAction of
Just ReloadAction{} -> cr & crInvSel . isel . iselAction .~ NoInvSelAction
crToggleReloading cr = case cr ^? crManipulation . isel . iselAction of
Just ReloadAction{} -> cr & crManipulation . isel . iselAction .~ NoInvSelAction
_ -> cr & tryStartLoading
tryStartLoading :: Creature -> Creature
tryStartLoading cr = fromMaybe cr $ do
i <- cr ^? crInvSel . isel . ispItem
i <- cr ^? crManipulation . isel . ispItem
hc <- cr ^? crInv . ix i . itUse . heldConsumption
return $ startLoading hc cr
@@ -60,12 +60,12 @@ startLoading ic cr = case ic ^? laProgress . _Just . ix 0 of
Just [] -> error "item has empty load cycle"
Just _ | _laLoaded ic >= _laMax ic -> cr
Just (la : las) -> fromMaybe (error "item loading error") $ do
i <- cr ^? crInvSel . isel . ispItem
i <- cr ^? crManipulation . isel . ispItem
return $ cr & startLoadingStep la
& crInv . ix i . itUse . heldConsumption . laProgress ?~ (la : las)
startLoadingStep :: LoadAction -> Creature -> Creature
startLoadingStep la cr = cr & crInvSel . isel . iselAction .~ ReloadAction (_actionTime la) la
startLoadingStep la cr = cr & crManipulation . isel . iselAction .~ ReloadAction (_actionTime la) la
rotateActionProgress :: HeldConsumption -> HeldConsumption
rotateActionProgress ic = case ic ^? laProgress . _Just of