Fix reloading crash

This commit is contained in:
2022-12-29 01:37:03 +00:00
parent 7fc3b788b4
commit bdd022e40b
4 changed files with 56 additions and 37 deletions
+7 -4
View File
@@ -39,7 +39,7 @@ tryNextLoadAction cr = case cr ^? crInv . ix (crSel cr) . itUse . heldConsumptio
& crInvSel . iselAction . reloadAction .~ la
crToggleReloading :: Creature -> World -> World
crToggleReloading cr w = case cr ^?! crInvSel . iselAction of
crToggleReloading cr w = case cr ^. crInvSel . iselAction of
ReloadAction{} -> w & cWorld . lWorld . creatures . ix (_crID cr) . crInvSel . iselAction .~ NoInvSelAction
_ -> w & cWorld . lWorld . creatures . ix (_crID cr) %~ tryStartLoading
@@ -49,7 +49,12 @@ crHoldReloading cr w =
& cWorld . lWorld . creatures . ix (_crID cr) . crInvSel . iselAction . actionHammer .~ HasHammer HammerDown
tryStartLoading :: Creature -> Creature
tryStartLoading cr = case ic ^? laProgress . _Just . ix 0 of
tryStartLoading cr = case cr ^? crInv . ix (crSel cr) . itUse . heldConsumption of
Just hc -> tryStartLoading' hc cr
Nothing -> cr
tryStartLoading' :: HeldConsumption -> Creature -> Creature
tryStartLoading' ic cr = case ic ^? laProgress . _Just . ix 0 of
Just la -> cr & startLoadAction la
Nothing -> case ic ^? laCycle of
Nothing -> cr
@@ -58,8 +63,6 @@ tryStartLoading cr = case ic ^? laProgress . _Just . ix 0 of
Just (la : las) ->
cr & startLoadAction la
& crInv . ix (crSel cr) . itUse . heldConsumption . laProgress ?~ (la : las)
where
ic = cr ^?! crInv . ix (crSel cr) . itUse . heldConsumption
startLoadAction :: LoadAction -> Creature -> Creature
startLoadAction la cr = cr & crInvSel . iselAction .~ ReloadAction (_actionTime la) la NoHammer