Start keeping track of item equip status internally (partially done)

This commit is contained in:
2024-12-19 00:55:14 +00:00
parent 5600b29714
commit 331a9a2f9b
17 changed files with 209 additions and 202 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ useItemLeftClick cr w = fromMaybe w $ do
UseConsume eff -> return $ useC eff itm cr w
UseEquip{} -> return $ doequipmentchange invid
UseHotkey{} -> return $ doequipmentchange invid
UseAmmoMag{} -> return w
UseNothing{} -> return w
UseAttach{} -> do
return $ selectUse itm cr w
_ -> Nothing
+1 -1
View File
@@ -25,7 +25,7 @@ data EquipPosition
| OnRightWrist
| OnLegs
| OnSpecial
deriving (Eq, Ord)
deriving (Eq, Ord,Show,Read)
--deriving (Eq, Ord, Show, Read) --Generic, Flat)
data Hotkey = HotkeyQ
| HotkeyE
+1 -1
View File
@@ -24,7 +24,7 @@ data Euse
| ECamouflage {_euseCamouflageStatus :: CamouflageStatus}
| EonWristShield
| EoffWristShield
| EFuelSource {_euseFuelAmount :: Int, _euseFuelMax :: Int}
-- | EFuelSource {_euseFuelAmount :: Int, _euseFuelMax :: Int}
| EBatterySource {_euseBatteryAmount :: Int, _euseBatteryMax :: Int}
| EAmmoSource
{ _euseAmmoAmount :: Int
+2
View File
@@ -5,6 +5,7 @@
{-# LANGUAGE EmptyDataDeriving #-}
module Dodge.Data.Item.Location where
import Dodge.Data.Equipment.Misc
import Control.Lens
import Data.Aeson
import Data.Aeson.TH
@@ -31,6 +32,7 @@ data ItemLocation
, _ilIsRoot :: Bool
, _ilIsSelected :: Bool
, _ilIsAttached :: Bool
, _ilEquipPosition :: Maybe EquipPosition
}
| OnTurret {_ilTuID :: Int}
| OnFloor {_ilFlID :: NewInt FloorInt}
+1 -6
View File
@@ -50,13 +50,8 @@ data ItemUse
}
| UseConsume { _cUse :: Cuse }
| UseEquip { _uequipEffect :: EquipEffect }
| UseCraft
| UseAttach {_uaParams :: AttachParams}
| UseAmmoMag
-- { _amagLoadStatus :: ReloadStatus
-- , _amagParams :: AmmoParams
-- , _amagType :: AmmoType
-- }
| UseNothing
| UseScope { _uScope :: Scope }
| UseBulletMod { _ubMod :: BulletMod }
deriving (Eq, Show, Read)
+1 -1
View File
@@ -32,7 +32,7 @@ defaultLeftItem :: Item
defaultLeftItem = defaultHeldItem & itUse .~ defaultLeftUse
defaultCraftItem :: Item
defaultCraftItem = defaultHeldItem & itUse .~ UseCraft
defaultCraftItem = defaultHeldItem & itUse .~ UseNothing
singleAmmo :: a -> IM.IntMap a
singleAmmo x = IM.insert 0 x mempty
+2 -2
View File
@@ -26,8 +26,8 @@ useE eo = case eo of
ECamouflage vis -> overCID (crCamouflage .~ vis)
EonWristShield -> onEquipWristShield
EoffWristShield -> onRemoveWristShield
EFuelSource 0 _ -> const . const id
EFuelSource{} -> const . const id
-- EFuelSource 0 _ -> const . const id
-- EFuelSource{} -> const . const id
EBatterySource{} -> tryChargeBattery
EAmmoSource{} -> tryAttachBulletBelt
+1
View File
@@ -72,6 +72,7 @@ tryPutItemInInv cid flit w = case maybeInvSlot of
, _ilIsRoot = False
, _ilIsSelected = False
, _ilIsAttached = False
, _ilEquipPosition = Nothing
}
---- should select the item on the floor if no inventory space?
+1
View File
@@ -72,6 +72,7 @@ crUpdateInvidLocations mo crid lw invid itm =
, _ilIsRoot = Just invid == mo ^? imRootSelectedItem
, _ilIsSelected = Just invid == mo ^? imSelectedItem
, _ilIsAttached = invid `IS.member` (mo ^. imAttachedItems)
, _ilEquipPosition = lw ^? creatures . ix crid . crInvEquipped . ix invid
}
-- this should be looked at, as it is sometimes used in functions that need not
+4 -8
View File
@@ -27,8 +27,7 @@ megaTinMag x =
tinMag :: Item
tinMag =
defaultHeldItem & itType .~ AMMOMAG TINMAG
& itUse
.~ UseAmmoMag
& itUse .~ UseNothing
& itConsumables .~ AmmoMag
{ _magParams = BulletParams defaultBullet
, _magType = BulletAmmo
@@ -68,8 +67,7 @@ megaShellMag =
shellMag :: Item
shellMag =
defaultHeldItem & itType .~ AMMOMAG SHELLMAG
& itUse
.~ UseAmmoMag
& itUse .~ UseNothing
& itConsumables
.~ AmmoMag
{ _magParams =
@@ -99,8 +97,7 @@ smallBattery =
battery :: Item
battery =
defaultHeldItem & itType .~ AMMOMAG BATTERY
& itUse
.~ UseAmmoMag
& itUse .~ UseNothing
& itConsumables
.~ AmmoMag
{ _magParams = BulletParams defaultBullet
@@ -115,8 +112,7 @@ battery =
chemFuelPouch :: Item
chemFuelPouch =
defaultHeldItem & itType .~ AMMOMAG CHEMFUELPOUCH
& itUse
.~ UseAmmoMag
& itUse .~ UseNothing
& itConsumables
.~ AmmoMag
{ _magParams = GasParams ChemFuel
+5 -4
View File
@@ -84,19 +84,20 @@ itemNumberDisplay cr ci = case (ci ^. _2, itm ^?! itUse, itm ^. itType) of
(_,_,EQUIP WRIST_ECG) -> [displayPulse $ cr ^?! crType . avatarPulse . pulseProgress]
(WeaponTargetingSF,_,_)
-> [maybe "" (const "!TARG!") (itm ^? itTargeting . itTgPos . _Just)]
_ | hasammo -> [maybe "" shortShow
$ itm ^? itConsumables . magLoadStatus . iaLoaded]
(_,UseHeld{},_) -> []
(_,UseHotkey{_leftConsumption=lc},_) -> [showAutoRechargeProgress lc]
(_,UseEquip{},_) -> showEquipmentNumber cr itm
(_,UseCraft,_) -> []
(_,UseNothing,_) -> []
(_,UseConsume {},_) -> []
(_,UseAttach (APInt i),_) -> [show i]
(_,UseAttach {},_) -> []
(_,UseAmmoMag {},_) -> [maybe "" shortShow
$ itm ^? itConsumables . magLoadStatus . iaLoaded]
(_,UseScope OpticScope {_opticZoom = x},_) -> [shortShow x]
(_,UseBulletMod {},_) -> mempty
where
itm = ci ^. _1
hasammo = isJust $ itm ^? itConsumables . magLoadStatus . iaLoaded
displayPulse :: Int -> String
displayPulse 0 = "*****"
@@ -106,7 +107,7 @@ displayPulse x = take 5 $ drop y "----^-----"
showEquipmentNumber :: Creature -> Item -> [String]
showEquipmentNumber _ itm = case _eeUse ee of
EFuelSource x _ -> [show x]
-- EFuelSource x _ -> [show x]
EAmmoSource{_euseAmmoAmount = x} -> [show x]--showAmmoSource cr itm
EBatterySource{_euseBatteryAmount = x} -> [show x]
_ -> [""]
+11 -1
View File
@@ -67,8 +67,18 @@ fuelPack =
defaultEquipment
& itUse . uequipEffect . eeSite .~ GoesOnBack
& itUse . uequipEffect . eeAttachPos .~ V3 (-9) 0 10
& itUse . uequipEffect . eeUse .~ EFuelSource 10000 10000
-- & itUse . uequipEffect . eeUse .~ EFuelSource 10000 10000
& itType .~ EQUIP FUELPACK
& itConsumables
.~ AmmoMag
{ _magParams = GasParams ChemFuel
, _magType = GasAmmo
, _magLoadStatus =
ReloadStatus
{ _iaMax = 100000
, _iaLoaded = 100000
}
}
bulletBeltPack :: Item
bulletBeltPack =
+2 -2
View File
@@ -25,13 +25,13 @@ pointerToItemLocation _ = const pure
pointerYourSelectedItem :: Applicative a => (Item -> a Item) -> World -> a World
pointerYourSelectedItem f w = fromMaybe (pure w) $ do
itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imSelectedItem
Just $ pointerToItemLocation (InInv 0 itinvid True True True) f w
Just $ pointerToItemLocation (InInv 0 itinvid True True True Nothing) f w
-- note the ilIsRoot/Selected/Attached booleans are irrelevant
pointerYourRootItem :: Applicative a => (Item -> a Item) -> World -> a World
pointerYourRootItem f w = fromMaybe (pure w) $ do
itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imRootSelectedItem
Just $ pointerToItemLocation (InInv 0 itinvid True True True) f w
Just $ pointerToItemLocation (InInv 0 itinvid True True True Nothing) f w
pointerToItem ::
Applicative f =>
+1
View File
@@ -50,6 +50,7 @@ initCrItemLocation cr invid w it = (w & itemLocations . at locid ?~ loc
, _ilIsRoot = False
, _ilIsSelected = False
, _ilIsAttached = False
, _ilEquipPosition = Nothing
}
+1 -1
View File
@@ -22,7 +22,7 @@ zoomScope = defaultHeldItem
targetingScope :: TargetingType -> Item
targetingScope tt = defaultHeldItem
& itType .~ TARGETING tt
& itUse .~ UseCraft
& itUse .~ UseNothing
& itTargeting .~ ItTargeting
{ _itTgPos = Nothing
, _itTgID = Nothing