Commit before implementing positional inventory

This commit is contained in:
2023-05-18 09:52:46 +01:00
parent 7df81559d9
commit 2f0bb5115b
12 changed files with 132 additions and 78 deletions
+29 -7
View File
@@ -1,6 +1,6 @@
module Dodge.Reloading (
crCancelReloading,
crToggleReloading,
crUpdateLoadSource,
stepReloading,
tryStartLoading,
) where
@@ -9,6 +9,7 @@ import Dodge.Data.Item.Use.Consumption.LoadAction
import Control.Lens
import Dodge.Data.Creature
import Data.Maybe
import qualified IntMapHelp as IM
crCancelReloading :: Creature -> Creature
crCancelReloading cr =
@@ -41,16 +42,37 @@ tryNextLoadAction cr = case cr ^? crManipulation . manObject . inInventory of
& crManipulation . manObject . inInventory . iselAction . reloadAction .~ la
_ -> cr
crToggleReloading :: Creature -> Creature
crToggleReloading cr = case cr ^? crManipulation . manObject . inInventory . iselAction of
Just ReloadAction{} -> cr & crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction
_ -> cr & tryStartLoading
crUpdateLoadSource :: Creature -> Creature
crUpdateLoadSource cr = case cr ^? crManipulation . manObject . inInventory . iselAction of
Just NoInvSelAction -> cr & tryStartLoading
_ -> cr & crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction
tryStartLoading :: Creature -> Creature
tryStartLoading cr = fromMaybe cr $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
hc <- cr ^? crInv . ix i . itUse . heldConsumption . laSource . _InternalSource
return $ startLoading hc cr
as <- cr ^? crInv . ix i . itUse . heldConsumption . laSource
case as of
InternalSource ia -> return $ startLoading ia cr
ExternalSource ea -> return $ toggleExternalLoadSource i ea cr
toggleExternalLoadSource :: Int -> Maybe Int -> Creature -> Creature
toggleExternalLoadSource invid mcureqid cr = fromMaybe cr $ do
st <- inv ^? ix invid . itUse . heldConsumption . laSourceType
(eqid,eqitm) <- ifind (\_ a -> Just st == a ^? itUse . equipEffect . eeUse . euseAmmoSourceType) msplit
return $ cr
& crInv . ix invid . itUse . heldConsumption . laSource . _ExternalSource ?~ eqid
& crInv . ix eqid . itUse . equipEffect . eeUse . euseAmmoLink ?~ invid
& detachExternalSource eqitm
where
inv = cr ^. crInv
msplit = fromMaybe inv $ do
cureqid <- mcureqid
return . snd $ IM.split cureqid inv
detachExternalSource :: Item -> Creature -> Creature
detachExternalSource itm cr = fromMaybe cr $ do
i <- itm ^? itUse . equipEffect . eeUse . euseAmmoLink . _Just
return $ cr & crInv . ix i . itUse . heldConsumption . laSource . _ExternalSource .~ Nothing
startLoading :: InternalAmmo -> Creature -> Creature
startLoading ic cr = case ic ^? iaProgress . _Just . ix 0 of