Commit before implementing positional inventory
This commit is contained in:
@@ -262,4 +262,6 @@ stackedInventory =
|
||||
, flameThrower
|
||||
, poisonSprayer
|
||||
, launcher
|
||||
, bulletBeltPack
|
||||
, bulletBeltBracer
|
||||
]
|
||||
|
||||
@@ -10,18 +10,15 @@ import Dodge.Hotkey
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
import Data.Foldable
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Dodge.Cuse
|
||||
import Dodge.Data.World
|
||||
import Dodge.Euse
|
||||
import Dodge.HeldUse
|
||||
import Dodge.Inventory
|
||||
import Dodge.Item.Location
|
||||
import Dodge.Luse
|
||||
import Dodge.Reloading
|
||||
import qualified IntMapHelp as IM
|
||||
import qualified SDL
|
||||
|
||||
useItemRightClick :: Creature -> World -> World
|
||||
useItemRightClick cr' w = fromMaybe (f w) $ do
|
||||
@@ -37,7 +34,6 @@ useItemRightClick cr' w = fromMaybe (f w) $ do
|
||||
itemEffect :: Creature -> Item -> World -> World
|
||||
itemEffect cr it w = case it ^. itUse of
|
||||
HeldUse{_heldUse = eff, _heldMods = usemods} ->
|
||||
--hammerTest $ tryReload cr it (_input w) $ foldl' (&) (useHeld eff) (useMod usemods) it cr
|
||||
hammerTest $ foldl' (&) (useHeld eff) (useMod usemods) it cr
|
||||
LeftUse{} -> doequipmentchange
|
||||
EquipUse{} -> doequipmentchange
|
||||
@@ -56,21 +52,6 @@ itemEffect cr it w = case it ^. itUse of
|
||||
( toggleEquipmentAt itRef cr
|
||||
)
|
||||
|
||||
tryReload :: Creature -> Item -> Input -> (World -> World) -> World -> World
|
||||
tryReload cr it theinput f
|
||||
| cid == 0 && itNeedsLoading it && _mouseButtons theinput M.!? SDL.ButtonLeft == Just 0 =
|
||||
cWorld . lWorld . creatures . ix cid %~ crToggleReloading
|
||||
| otherwise =
|
||||
(runIdentity . pointerToItemLocation (_itLocation it) (return . (itUse . heldHammer .~ HammerDown)))
|
||||
. f
|
||||
where
|
||||
cid = _crID cr
|
||||
|
||||
itNeedsLoading :: Item -> Bool
|
||||
itNeedsLoading it = fromMaybe False $ do
|
||||
internalammo <- it ^? itUse . heldConsumption . laSource . _InternalSource
|
||||
return $ _iaLoaded internalammo == 0 || not (_iaPrimed internalammo)
|
||||
|
||||
toggleEquipmentAt :: Int -> Creature -> World -> World
|
||||
toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
|
||||
DoNotMoveEquipment -> w
|
||||
@@ -120,14 +101,14 @@ 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) %~ crToggleReloading)
|
||||
HeldUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crUpdateLoadSource)
|
||||
ConsumeUse{} -> return $ useItemRightClick cr w
|
||||
EquipUse{} -> return $ useItemRightClick cr w
|
||||
LeftUse{} -> return $ useItemRightClick cr w
|
||||
_ -> Nothing
|
||||
where
|
||||
hammerTest f = case _crHammerPosition cr of
|
||||
HammerUp -> f w
|
||||
HammerUp -> f w & setuhamdown
|
||||
_ -> w & setuhamdown
|
||||
setuhamdown = cWorld . lWorld . creatures . ix (_crID cr) . crHammerPosition .~ HammerDown
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@ data EquipItemType
|
||||
| JETPACK
|
||||
| FUELPACK
|
||||
| BULLETBELTPACK
|
||||
| BULLETBELTBRACER
|
||||
| BATTERYPACK
|
||||
|
||||
| AUTODETECTOR Detector
|
||||
|
||||
@@ -42,6 +42,7 @@ data InventoryManipulation
|
||||
|
||||
data InvSelAction
|
||||
= NoInvSelAction
|
||||
| AttachLoadSourceAction {_actionProgress :: Int}
|
||||
| ReloadAction {_actionProgress :: Int, _reloadAction :: LoadAction}
|
||||
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ itemFromEquipType et = case et of
|
||||
BATTERYPACK -> batteryPack
|
||||
FUELPACK -> fuelPack
|
||||
BULLETBELTPACK -> bulletBeltPack
|
||||
BULLETBELTBRACER -> bulletBeltBracer
|
||||
AUTODETECTOR d -> autoDetector d
|
||||
|
||||
itemFromLeftType :: LeftItemType -> Item
|
||||
|
||||
@@ -5,6 +5,7 @@ module Dodge.Item.Display (
|
||||
itemBaseName,
|
||||
) where
|
||||
|
||||
import Dodge.Item.Info
|
||||
import Data.Maybe
|
||||
import Data.Sequence
|
||||
import Dodge.Data.Creature
|
||||
@@ -55,7 +56,7 @@ showSelectedConsumption :: Creature -> ItemUse -> String
|
||||
showSelectedConsumption cr iu = case iu of
|
||||
HeldUse{} -> showReloadProgress cr (iu ^?! heldConsumption . laSource)
|
||||
LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu)
|
||||
EquipUse{} -> ""
|
||||
EquipUse{_equipEffect = ee} -> showEquipmentNumber ee
|
||||
_ -> show $ iu ^?! useAmount . getItAmount -- partial, be careful if adding new data constructors
|
||||
|
||||
showAutoRechargeProgress :: LeftConsumption -> String
|
||||
@@ -72,26 +73,36 @@ showReloadProgress cr ic = case cr ^? crManipulation . manObject . inInventory .
|
||||
InternalSource ia -> case ia ^? iaProgress . _Just . ix 0 of
|
||||
Nothing -> show $ ia ^. iaLoaded
|
||||
Just la -> show (_actionTime la) ++ showLoadActionType la ic
|
||||
_ -> "X"
|
||||
ExternalSource ea -> fromMaybe "X" $ do
|
||||
i <- ea ^? _Just
|
||||
itm <- cr ^? crInv . ix i
|
||||
return $ show $ itemBaseName itm
|
||||
|
||||
showConsumption :: ItemUse -> String
|
||||
showConsumption iu = case iu of
|
||||
HeldUse{} -> showReloadProgress' (_heldConsumption iu)
|
||||
LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu)
|
||||
EquipUse {_equipEffect = ee} -> showEUseNumber ee
|
||||
EquipUse{_equipEffect = ee} -> showEquipmentNumber ee
|
||||
_ -> show $ iu ^?! useAmount . getItAmount
|
||||
|
||||
showEUseNumber :: EquipEffect -> String
|
||||
showEUseNumber ee = case _eeUse ee of
|
||||
showEquipmentNumber :: EquipEffect -> String
|
||||
showEquipmentNumber ee = case _eeUse ee of
|
||||
EFuelSource x _ -> show x
|
||||
EAmmoSource {_euseAmmoAmount = x} -> showIntKMG' x
|
||||
EBatterySource {_euseBatteryAmount = x} -> show x
|
||||
_ -> ""
|
||||
|
||||
showReloadProgress' :: HeldConsumption -> String
|
||||
showReloadProgress' ic = case ic ^? laSource . _InternalSource . iaProgress . _Just . ix 0 of
|
||||
Nothing -> fromMaybe "X" $ do
|
||||
showReloadProgress' ic = case ic ^? laSource of
|
||||
Just (InternalSource ia) -> case ia ^? iaProgress . _Just . ix 0 of
|
||||
Nothing -> fromMaybe "" $ do
|
||||
x <- ic ^? laSource . _InternalSource . iaLoaded
|
||||
return $ show x
|
||||
Just la -> show (_actionTime la) ++ showLoadActionType la (_laSource ic)
|
||||
Just (ExternalSource ea) -> fromMaybe "X" $ do
|
||||
i <- ea ^? _Just
|
||||
return $ show i
|
||||
_ -> ""
|
||||
|
||||
showLoadActionType :: LoadAction -> AmmoSource -> String
|
||||
showLoadActionType la as = case la of
|
||||
@@ -102,7 +113,6 @@ showLoadActionType la as = case la of
|
||||
where
|
||||
x = maybe "" show $ as ^? _InternalSource . iaLoaded
|
||||
|
||||
|
||||
maybeWarmupStatus :: Item -> Maybe String
|
||||
maybeWarmupStatus it = case it ^? itUse . heldDelay . warmMax of
|
||||
Nothing -> Nothing
|
||||
|
||||
@@ -52,6 +52,8 @@ equipItemSPic et _ = case et of
|
||||
noPic $ colorSH yellow $ upperPrismPolyMT 10 $ polyCirc 3 5
|
||||
BULLETBELTPACK ->
|
||||
noPic $ colorSH green backpackShape
|
||||
BULLETBELTBRACER
|
||||
-> noPic (colorSH green $ upperPrismPolySU 3 $ rectWH 2 2)
|
||||
AUTODETECTOR dt -> noPic (colorSH (detectorColor dt) $ upperPrismPolySU 3 $ rectWH 2 2)
|
||||
|
||||
backpackShape :: Shape
|
||||
|
||||
@@ -13,6 +13,7 @@ module Dodge.Item.Equipment (
|
||||
fuelPack,
|
||||
batteryPack,
|
||||
bulletBeltPack,
|
||||
bulletBeltBracer,
|
||||
speedLegs,
|
||||
jumpLegs,
|
||||
flameShield,
|
||||
@@ -76,7 +77,15 @@ bulletBeltPack =
|
||||
& itUse . equipEffect . eeSite .~ GoesOnBack
|
||||
& itType . iyBase .~ EQUIP BULLETBELTPACK
|
||||
& itUse . equipEffect . eeAttachPos .~ V3 (-9) 0 10
|
||||
& itUse . equipEffect . eeUse .~ EAmmoSource 10000 10000 BulletSource Nothing
|
||||
& itUse . equipEffect . eeUse .~ EAmmoSource 2000 2000 BulletSource Nothing
|
||||
|
||||
bulletBeltBracer :: Item
|
||||
bulletBeltBracer =
|
||||
defaultEquipment
|
||||
& itUse . equipEffect . eeSite .~ GoesOnWrist
|
||||
& itType . iyBase .~ EQUIP BULLETBELTBRACER
|
||||
& itUse . equipEffect . eeAttachPos .~ V3 (-9) 0 10
|
||||
& itUse . equipEffect . eeUse .~ EAmmoSource 100 100 BulletSource Nothing
|
||||
|
||||
jetPack :: Item
|
||||
jetPack =
|
||||
|
||||
+31
-16
@@ -1,14 +1,15 @@
|
||||
module Dodge.Item.Info where
|
||||
|
||||
import StringHelp
|
||||
import Dodge.Module.Info
|
||||
import Data.Char
|
||||
import Dodge.Data.Item
|
||||
import qualified Data.Map.Strict as M
|
||||
import Dodge.Data.Item
|
||||
import Dodge.Module.Info
|
||||
import LensHelp
|
||||
import StringHelp
|
||||
|
||||
itemInfo :: Item -> String
|
||||
itemInfo itm = itmBaseInfo itm ++ " " ++ itmUsageInfo itm
|
||||
itemInfo itm =
|
||||
itmBaseInfo itm ++ " " ++ itmUsageInfo itm
|
||||
++ itmSpaceInfo itm
|
||||
++ itmModuleInfo (itm ^. itType . iyModules)
|
||||
|
||||
@@ -43,6 +44,20 @@ showInt i = case i of
|
||||
12 -> "a dozen"
|
||||
_ -> "more than a dozen"
|
||||
|
||||
showIntKMG :: Int -> String
|
||||
showIntKMG x
|
||||
| x < 1000 = show x
|
||||
| x < 1000000 = show (x `div` 1000) ++ "K"
|
||||
| x < 1000000000 = show (x `div` 1000000) ++ "M"
|
||||
| otherwise = show (x `div` 1000000000) ++ "G"
|
||||
|
||||
showIntKMG' :: Int -> String
|
||||
showIntKMG' x
|
||||
| x < 1000 = show x
|
||||
| x < 1000000 = take 3 (show ((fromIntegral x :: Float) / 1000)) ++ "K"
|
||||
| x < 1000000000 = take 3 (show ((fromIntegral x :: Float) / 1000000)) ++ "M"
|
||||
| otherwise = take 3 (show ((fromIntegral x :: Float) / 1000000000)) ++ "G"
|
||||
|
||||
heldInfo :: HeldItemType -> String
|
||||
heldInfo hit = case hit of
|
||||
BANGSTICK 1 -> "A firearm with a short barrel that requires reloading after each shot."
|
||||
@@ -119,12 +134,11 @@ equipInfo eit = case eit of
|
||||
POWERLEGS -> "Strength enhancing legs."
|
||||
SPEEDLEGS -> "Speed enhancing legs."
|
||||
JUMPLEGS -> "Jump enhancing legs."
|
||||
|
||||
JETPACK -> "A device enabling flight."
|
||||
FUELPACK -> "A liquid container with attached hose."
|
||||
BULLETBELTPACK -> "A container holding a long belt of bullets."
|
||||
BULLETBELTBRACER -> "A container holding a long belt of bullets."
|
||||
BATTERYPACK -> "A collection of batteries with a universal adapter."
|
||||
|
||||
AUTODETECTOR d -> "A device that detects " ++ detectorInfo d ++ " in an expanding radius. Pulses automatically. "
|
||||
|
||||
targetingInfo :: TargetType -> String
|
||||
@@ -146,10 +160,8 @@ craftInfo fit = case fit of
|
||||
TUBE -> "A wide rigid cylinder."
|
||||
HARDWARE -> "A collection of equipment and devices useful for general construction."
|
||||
SPRING -> "An object that exerts an opposing force when compressed or stretched."
|
||||
|
||||
HOSE -> "A flexible cylinder."
|
||||
TAPE -> "A strip of material with an adhesive side."
|
||||
|
||||
CAN -> "A small metal cylindrical container."
|
||||
TIN -> "A small metal continer."
|
||||
STEELDRUM -> "A metal cylindrical container."
|
||||
@@ -193,13 +205,10 @@ craftInfo fit = case fit of
|
||||
TIMEMODULE -> "A device that can affect temporality."
|
||||
SIZEMODULE -> "A device that can affect physical size."
|
||||
GRAVITYMODULE -> "A device that can affect gravitational fields."
|
||||
|
||||
TARGETMODULE _ -> "A targeting module."
|
||||
|
||||
FLAKCRAFT -> "Creates flak bullets."
|
||||
FRAGCRAFT -> "Creates fragmentation bullets."
|
||||
|
||||
|
||||
detectorInfo :: Detector -> String
|
||||
detectorInfo d = case d of
|
||||
ITEMDETECTOR -> "items"
|
||||
@@ -209,7 +218,8 @@ detectorInfo d = case d of
|
||||
itmUsageInfo :: Item -> String
|
||||
itmUsageInfo itm = case itm ^. itType . iyBase of
|
||||
HELD _ -> heldPositionInfo itm
|
||||
LEFT _ -> "This item can be equipped" ++ itmEquipSiteInfo itm
|
||||
LEFT _ ->
|
||||
"This item can be equipped" ++ itmEquipSiteInfo itm
|
||||
++ ". When equipped, it can be activated."
|
||||
EQUIP _ -> "This item can be equipped " ++ itmEquipSiteInfo itm ++ "."
|
||||
Consumable _ -> "This item can be consumed."
|
||||
@@ -224,6 +234,7 @@ aimStanceInfo as = case as of
|
||||
TwoHandTwist -> "It is held in two hands along its length."
|
||||
TwoHandFlat -> "It is held in two hands at its sides."
|
||||
OneHand -> "It is held in one hand."
|
||||
|
||||
-- LeaveHolstered -> "It is to be left holstered."
|
||||
|
||||
itmEquipSiteInfo :: Item -> String
|
||||
@@ -243,11 +254,15 @@ itmModuleInfo m
|
||||
| otherwise = mms ++ ems
|
||||
where
|
||||
(mademods, emptymods) = M.partition (/= EMPTYMODULE) m
|
||||
mms | mademods == mempty = ""
|
||||
| otherwise = " Modifications have been made "
|
||||
mms
|
||||
| mademods == mempty = ""
|
||||
| otherwise =
|
||||
" Modifications have been made "
|
||||
++ makeCommaList (map moduleInfo $ M.keys mademods)
|
||||
ems | emptymods == mempty = ""
|
||||
| otherwise = " Modifications can be made "
|
||||
ems
|
||||
| emptymods == mempty = ""
|
||||
| otherwise =
|
||||
" Modifications can be made "
|
||||
++ makeCommaList (map moduleInfo $ M.keys emptymods)
|
||||
|
||||
makeCommaList :: [String] -> String
|
||||
|
||||
@@ -79,6 +79,7 @@ import Geometry
|
||||
import LensHelp
|
||||
import RandomHelp
|
||||
import Sound.Data
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
type ChainEffect =
|
||||
(Item -> Creature -> World -> World) ->
|
||||
@@ -361,9 +362,18 @@ useAmmoUpTo amAmount eff item cr =
|
||||
useAmmoAmount :: Int -> ChainEffect
|
||||
useAmmoAmount amAmount eff item cr =
|
||||
eff item cr
|
||||
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itUse . heldConsumption . laSource . _InternalSource . iaLoaded -~ amAmount)
|
||||
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv %~ useAmmoAmount' itref amAmount) -- . _InternalSource . iaLoaded -~ amAmount)
|
||||
where
|
||||
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
||||
itref = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
||||
|
||||
useAmmoAmount' :: Int -> Int -> IM.IntMap Item -> IM.IntMap Item
|
||||
useAmmoAmount' itref x inv = case inv ^? ix itref . itUse . heldConsumption . laSource of
|
||||
Just InternalSource{}
|
||||
-> inv & ix itref . itUse . heldConsumption . laSource . _InternalSource . iaLoaded -~ x
|
||||
Just (ExternalSource (Just eqid))
|
||||
-> inv & ix eqid . itUse . equipEffect . eeUse . euseAmmoAmount -~ x
|
||||
_ -> inv
|
||||
-- . crInv . ix itRef . itUse . heldConsumption . laSource
|
||||
|
||||
{- |
|
||||
Applies a world effect after an item use cooldown check.
|
||||
|
||||
+29
-7
@@ -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
|
||||
|
||||
@@ -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) crToggleReloading uv
|
||||
ScancodeR -> over (uvWorld . cWorld . lWorld . creatures . ix 0) crUpdateLoadSource uv
|
||||
ScancodeT -> over uvWorld testEvent uv
|
||||
ScancodeX -> uv & uvWorld %~ toggleTweakInv
|
||||
ScancodeC -> toggleCombineInv uv
|
||||
|
||||
Reference in New Issue
Block a user