Commit before removing reloading
Reloading as a concept should be handled by positioning magazines/tanks/ammo-stores next to items that consume ammo. Magazines themselves could have various methods for refilling or recreating: crafting, auto-refill over time (synthesis explanation), refill based on external world objects, and perhaps other ideas.
This commit is contained in:
@@ -106,10 +106,11 @@ useItemLeftClick cr w = fromMaybe w $ do
|
||||
invid <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
ituse <- cr ^? crInv . ix invid . itUse
|
||||
case ituse of
|
||||
HeldUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crReload)
|
||||
HeldUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crReloadToggle)
|
||||
ConsumeUse{} -> return $ useItemRightClick cr w
|
||||
EquipUse{} -> return $ useItemRightClick cr w
|
||||
LeftUse{} -> return $ useItemRightClick cr w
|
||||
AmmoMagUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crReloadToggle)
|
||||
_ -> Nothing
|
||||
where
|
||||
hammerTest f = case _crHammerPosition cr of
|
||||
|
||||
@@ -42,7 +42,7 @@ data InventoryManipulation
|
||||
|
||||
data InvSelAction
|
||||
= NoInvSelAction
|
||||
| ReloadAction {_actionProgress :: Int, _reloadAction :: LoadAction}
|
||||
| ReloadAction {_actionProgress :: Int, _reloadAction :: LoadAction, _reloadInvID :: Int}
|
||||
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
||||
|
||||
makeLenses ''LoadAction
|
||||
|
||||
+33
-15
@@ -1,12 +1,14 @@
|
||||
module Dodge.Reloading (
|
||||
crCancelReloading,
|
||||
crReload,
|
||||
crReloadToggle,
|
||||
stepReloading,
|
||||
) where
|
||||
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
import Dodge.Data.Creature
|
||||
import Control.Monad
|
||||
--import Data.Monoid
|
||||
|
||||
crCancelReloading :: Creature -> Creature
|
||||
crCancelReloading cr =
|
||||
@@ -22,13 +24,13 @@ crCancelReloading cr =
|
||||
|
||||
stepReloading :: Creature -> Creature
|
||||
stepReloading cr = case cr ^? crManipulation . manObject . inInventory of
|
||||
Just (SelItem i (ReloadAction x la))
|
||||
Just (SelItem _ (ReloadAction x la j))
|
||||
| x > 0 ->
|
||||
cr & crManipulation . manObject . inInventory . iselAction . actionProgress -~ 1
|
||||
| otherwise ->
|
||||
cr
|
||||
& crInv . ix (i + 1) . itUse . amagLoadStatus %~ doLoadAction la
|
||||
& crInv . ix (i + 1) . itUse . amagLoadStatus %~ rotateActionProgress
|
||||
& crInv . ix j . itUse . amagLoadStatus %~ doLoadAction la
|
||||
& crInv . ix j . itUse . amagLoadStatus %~ rotateActionProgress
|
||||
& tryNextLoadAction
|
||||
_ -> cr
|
||||
|
||||
@@ -41,35 +43,51 @@ tryNextLoadAction cr = case cr ^? crManipulation . manObject . inInventory of
|
||||
& crManipulation . manObject . inInventory . iselAction . reloadAction .~ la
|
||||
_ -> cr
|
||||
|
||||
crReload :: Creature -> Creature
|
||||
crReload cr = case cr ^? crManipulation . manObject . inInventory . iselAction of
|
||||
crReloadToggle :: Creature -> Creature
|
||||
crReloadToggle 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
|
||||
ia <- cr ^? crInv . ix (i + 1) . itUse . amagLoadStatus
|
||||
return $ startLoading ia cr
|
||||
magtypes <- cr ^? crInv . ix i . itUse . heldConsumption
|
||||
--let mags = cr ^.. crInv . dropping (i + 1) traverse -- note this gets all items below the manipulated
|
||||
let mags = cr ^.. crInv . dropping i traverse
|
||||
iaj <- listToMaybe . catMaybes $ zipWith tryStartLoadMagazine mags magtypes
|
||||
return $ startLoading iaj cr
|
||||
|
||||
tryStartLoadMagazine :: Item -> AmmoType -> Maybe (ReloadStatus, Int)
|
||||
tryStartLoadMagazine mag atype = do
|
||||
magat <- mag ^? itUse . amagType
|
||||
guard $ magat == atype
|
||||
ia <- mag ^? itUse . amagLoadStatus
|
||||
maxammo <- ia ^? iaMax
|
||||
loadedammo <- ia ^? iaLoaded
|
||||
guard $ loadedammo < maxammo
|
||||
j <- mag ^? itLocation . ipInvID
|
||||
return (ia, j)
|
||||
|
||||
-- case as of
|
||||
-- InternalSource ia -> return $ startLoading ia cr
|
||||
-- AboveSource -> return cr
|
||||
|
||||
startLoading :: ReloadStatus -> Creature -> Creature
|
||||
startLoading ic cr = case ic ^? iaProgress . _Just . ix 0 of
|
||||
Just la -> cr & startLoadingStep la
|
||||
startLoading :: (ReloadStatus,Int) -> Creature -> Creature
|
||||
startLoading (ic,j) cr = case ic ^? iaProgress . _Just . ix 0 of
|
||||
Just la -> cr & startLoadingStep la j
|
||||
Nothing -> case ic ^. iaCycle of
|
||||
[] -> error "item has empty load cycle"
|
||||
_ | _iaLoaded ic >= _iaMax ic -> cr
|
||||
_ | _iaLoaded ic >= _iaMax ic -> cr -- THIS SHOULD TRY PUSHING TO THE NEXT MAGAZINE
|
||||
(la : las) -> fromMaybe (error "item loading error") $ do
|
||||
i <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
return $
|
||||
cr & startLoadingStep la
|
||||
cr & startLoadingStep la i
|
||||
& crInv . ix i . itUse . amagLoadStatus . iaProgress ?~ (la : las)
|
||||
|
||||
startLoadingStep :: LoadAction -> Creature -> Creature
|
||||
startLoadingStep la cr = cr & crManipulation . manObject . inInventory . iselAction .~ ReloadAction (_actionTime la) la
|
||||
startLoadingStep :: LoadAction
|
||||
-> Int -- i think this is the inventory position?
|
||||
-> Creature -> Creature
|
||||
startLoadingStep la j cr = cr & crManipulation . manObject . inInventory . iselAction .~ ReloadAction (_actionTime la) la j
|
||||
|
||||
rotateActionProgress :: ReloadStatus -> ReloadStatus
|
||||
rotateActionProgress ic = case ic ^. iaProgress of
|
||||
|
||||
@@ -116,7 +116,7 @@ updateInitialPressInGame uv sc = case sc of
|
||||
ScancodeP -> pauseGame uv
|
||||
ScancodeF -> over uvWorld youDropItem uv
|
||||
ScancodeM -> toggleMap uv
|
||||
ScancodeR -> over (uvWorld . cWorld . lWorld . creatures . ix 0) crReload uv
|
||||
ScancodeR -> over (uvWorld . cWorld . lWorld . creatures . ix 0) crReloadToggle uv
|
||||
ScancodeT -> over uvWorld testEvent uv
|
||||
ScancodeX -> uv & uvWorld %~ toggleTweakInv
|
||||
ScancodeC -> toggleCombineInv uv
|
||||
|
||||
Reference in New Issue
Block a user