Allow for custom reloading sounds

This commit is contained in:
2022-06-21 22:21:18 +01:00
parent 53c8be0679
commit 029b6daf8e
25 changed files with 339 additions and 219 deletions
+33 -13
View File
@@ -1,6 +1,5 @@
module Dodge.Reloading
( tryStartLoading
, crStopReloading
( crCancelReloading
, crStartReloading
, stepReloading
) where
@@ -11,35 +10,56 @@ import Dodge.Data
import Control.Lens
import Data.Maybe
crStartReloading :: Creature -> World -> World
crStartReloading cr w = fromMaybe w $ w & creatures . ix (_crID cr) %%~ tryStartLoading
crStopReloading :: Creature -> Creature
crStopReloading cr = cr & crStance . posture .~ AtEase
crCancelReloading :: Creature -> Creature
crCancelReloading cr = cr
& crInv . ix (crSel cr) . itConsumption . laProgress %~ const Nothing
& crInvSel . iselAction .~ NoInvSelAction
stepReloading :: Creature -> Creature
stepReloading cr = case cr ^?! crInvSel . iselAction of
ReloadAction x la
ReloadAction x la _
| x > 0 -> cr & crInvSel . iselAction . actionProgress -~ 1
| otherwise -> cr & completeLoadAction la
_ -> cr
crStartReloading :: Creature -> World -> World
crStartReloading cr w = fromMaybe w $ w
& creatures . ix (_crID cr) %%~ tryStartLoading
tryStartLoading :: Creature -> Maybe Creature
tryStartLoading cr = case cr ^? crInv . ix (crSel cr) . itConsumption . laProgress of
Just Nothing -> Just . continueLoading $ cr
Just Nothing -> Just . startLoadAction $ cr
& crInv . ix (crSel cr) . itConsumption %~ setLoadCycle
Just (Just _) -> Just . continueLoading $ cr
Nothing -> Nothing
Just (Just (a:_)) -> Just . startNextLoadAction a $ cr
Just (Just []) -> Nothing
_ -> Nothing
-- Just (Just _) -> Just . continueLoading $ cr
-- Nothing -> Nothing
startLoadAction :: Creature -> Creature
startLoadAction cr = continueLoading $ cr
& crInvSel . iselAction .~ ReloadAction (_actionTime la) la NoHammer
where
la = cr ^?! crInv . ix (crSel cr) . itConsumption . laProgress . _Just . ix 0
setLoadCycle :: ItemConsumption -> ItemConsumption
setLoadCycle ic = ic & laProgress ?~ _laCycle ic
startNextLoadAction :: LoadAction -> Creature -> Creature
startNextLoadAction la cr = cr
& crInvSel . iselAction .~ ReloadAction (_actionTime la) la NoHammer
continueLoading :: Creature -> Creature
continueLoading cr = case cr ^? crInv . ix (crSel cr) . itConsumption . laProgress . _Just of
Just (la:_) -> cr & crInvSel . iselAction .~ ReloadAction (_actionTime la) la
Just (la:_) -> cr & crInvSel . iselAction . reloadAction .~ la
& crInvSel . iselAction . actionProgress .~ _actionTime la
Just [] -> case cr ^?! crInv . ix (crSel cr) . itConsumption of
ic | _laLoaded ic < _laMax ic -> continueLoading $ cr
& crInv . ix (crSel cr) . itConsumption . laProgress ?~ _laCycle ic
_ -> cr & crInvSel . iselAction .~ NoInvSelAction
& crInv . ix (crSel cr) . itConsumption . laProgress .~ Nothing
_ -> cr & crInvSel . iselAction .~ NoInvSelAction
& crInv . ix (crSel cr) . itConsumption . laProgress .~ Nothing
& crStance . posture .~ AtEase
completeLoadAction :: LoadAction -> Creature -> Creature
completeLoadAction la cr = continueLoading $ cr