Implement copier, an item that copies the value displayed by other items

This commit is contained in:
2025-01-08 14:29:25 +00:00
parent 47aa8655b1
commit 21b7b863c7
12 changed files with 184 additions and 142 deletions
+1
View File
@@ -120,6 +120,7 @@ inventoryX c = case c of
[ flameThrower
, fuelPack
, chemFuelPouch
, copier ABSOLUTE
]
'B' ->
[ wristArmour
+8 -6
View File
@@ -3,6 +3,8 @@ module Dodge.Creature.State (
doDamage,
) where
--import Dodge.Inventory.SelectionList
--import Dodge.Item.Location
import Control.Applicative
import Dodge.HeldUse
import Control.Monad
@@ -288,13 +290,13 @@ updateItemWithOrientation ::
LocationLDT ItemLink ComposedItem ->
World ->
World
updateItemWithOrientation cr m loc@(LocLDT _ itmtree) =
updateItemWithOrientation cr m loc@(LocLDT _ itmtree) w =
case (ci ^. _1 . itType, ci ^. _2) of
(HELD TORCH, _) -> shineTorch cr itmtree m
(HELD LASER, WeaponTargetingSF) -> shineTargetLaser cr itmtree m
(TARGETING tt, _) -> updateItemTargeting tt cr itm
(ARHUD, _) -> drawARHUD loc
_ -> id
(HELD TORCH, _) -> shineTorch cr itmtree m w
(HELD LASER, WeaponTargetingSF) -> shineTargetLaser cr itmtree m w
(TARGETING tt, _) -> updateItemTargeting tt cr itm w
(ARHUD, _) -> drawARHUD loc w
_ -> w
where
ci = itmtree ^. ldtValue
itm = ci ^. _1
+1 -1
View File
@@ -25,7 +25,7 @@ data ItemType
| MAPPER
| DROPPER InventoryPathing
| CLICKER InventoryPathing
| COPIER InventoryPathing
| COPIER {_ibtPathing :: InventoryPathing}
| UGATE
| BGATE
| INTROSCAN {_ibtIntroScanType :: IntroScanType}
+1
View File
@@ -29,6 +29,7 @@ data ItInvEffect
| EffectWhileAttached ItInvEffect
| ItemUseToggle BlBl
| ItemCancelExamineInventory
| ItemCopierUpdate
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data ItDropEffect = NoDropEffect
+1
View File
@@ -43,6 +43,7 @@ data ItemUse
| UseAttach {_uaParams :: AttachParams}
| UseInt {_uInt :: Int}
| UseNothing
| UseValue {_uValue :: Either Int String}
| UseScope {_uScope :: Scope}
| UseBulletMod {_ubMod :: BulletMod}
| UseToggle {_useToggle :: Bool}
+18 -12
View File
@@ -8,6 +8,7 @@ module Dodge.HeldUse (
mcUseHeld,
) where
import Dodge.Inventory.Path
import Color
import Control.Applicative
import Control.Monad
@@ -790,18 +791,23 @@ dropInventoryPath ::
Creature ->
World ->
World
dropInventoryPath i ip loc cr w = case ip of
ABSOLUTE -> fromMaybe w $ do
guard $ i `IM.member` (cr ^. crInv)
return $ dropItem cr i w
RELCURS -> fromMaybe w $ do
j <- cr ^? crManipulation . manObject . imSelectedItem
guard $ (i + j) `IM.member` (cr ^. crInv)
return $ dropItem cr (i + j) w
RELITEM -> fromMaybe w $ do
j <- loc ^? locLDT . ldtValue . _1 . itLocation . ilInvID
guard $ (i + j) `IM.member` (cr ^. crInv)
return $ dropItem cr (i + j) w
dropInventoryPath i ip loc cr = fromMaybe id $ do
invid <- loc ^? locLDT . ldtValue . _1 . itLocation . ilInvID
j <- getInventoryPath i ip invid cr
return $ dropItem cr j
--dropInventoryPath i ip loc cr w = case ip of
-- ABSOLUTE -> fromMaybe w $ do
-- guard $ i `IM.member` (cr ^. crInv)
-- return $ dropItem cr i w
-- RELCURS -> fromMaybe w $ do
-- j <- cr ^? crManipulation . manObject . imSelectedItem
-- guard $ (i + j) `IM.member` (cr ^. crInv)
-- return $ dropItem cr (i + j) w
-- RELITEM -> fromMaybe w $ do
-- j <- loc ^? locLDT . ldtValue . _1 . itLocation . ilInvID
-- guard $ (i + j) `IM.member` (cr ^. crInv)
-- return $ dropItem cr (i + j) w
useInventoryPath ::
PressType ->
+35 -24
View File
@@ -4,8 +4,12 @@ module Dodge.Inventory.SelectionList (
invSelectionItem,
closeItemToSelectionItem,
closeButtonToSelectionItem,
getInventoryPath,
getItemValue,
) where
import Dodge.Inventory.Path
import Control.Applicative
import ShortShow
import Data.Maybe
import Dodge.Data.DoubleTree
@@ -48,8 +52,7 @@ itemDisplay w cr ci = -- f
itm = ci ^. _1
NInt itid = itm ^. itID
--f (x:xs) (y:_) = itemDisplayPad x y : xs
f (x:xs) (y:_) = (x ++ ' ': y) : xs
f xs _ = xs
--f xs _ = xs
--g (x:xs) (y:_) = (rightPad 15 ' ' x ++ y) : xs
g (x:xs) (y:_) = (x ++ y) : xs
g xs _ = xs
@@ -83,6 +86,11 @@ itemExternalValue itm w cr
| ITEMSCAN <- itm ^. itType
, Just ExamineInventory <- w ^? hud . hudElement . subInventory
= Just (Right "ON")
-- , Just x <- itm ^? itScroll . itsInt
-- , Just invid <- itm ^? itLocation . ilInvID
-- , Just i <- getInventoryPath x ip invid cr
-- , Just itm' <- cr ^? crInv . ix i
-- = getItemValue itm' w cr
| otherwise = mempty
itemScrollDisplay :: Item -> Maybe String
@@ -96,30 +104,33 @@ itemScrollDisplay itm
| ItemScrollIntRange _ i <- itm ^. itScroll = Just $ show i
| otherwise = Nothing
itemDisplayPad :: [Char] -> String -> [Char]
itemDisplayPad ls rs
| rs == "" = ls
| otherwise = midPadL 15 ' ' ls (' ' : rs)
getItemValue :: Item -> World -> Creature -> Maybe (Either Int String)
getItemValue itm w cr = itemInternalValue itm <|> itemExternalValue itm w cr
itemNumberDisplay :: World -> Creature -> ComposedItem -> [String]
itemNumberDisplay w cr ci
| Just x <- ci ^? _1 . itUse . uInt = [show x]
| Just x <- ci ^? _1 . itUse . useToggle = [show x]
| ITEMSCAN <- ci ^. _1 . itType
, Just ExamineInventory <- w ^? hud . hudElement . subInventory = ["ACTIVE"]
| EQUIP WRIST_ECG <- ci ^. _1 . itType =
[displayPulse $ cr ^?! crType . avatarPulse . pulseProgress]
| isJust $ ci ^? _1 . itTargeting . itTgPos . _Just = ["!TARG!"]
| Just x <- ci ^? _1 . itConsumables . magLoadStatus . iaLoaded = [shortShow x]
| Just i <- ci ^? _1 . itUse . uaParams . apInt = [show i]
| Just x <- ci ^? _1 . itUse . uaParams . apProjectiles = [show x]
| Just t <- ci ^? _1 . itType . ibtIntroScanType = [introScanDisplay cr t]
| otherwise = mempty
--itemDisplayPad :: [Char] -> String -> [Char]
--itemDisplayPad ls rs
-- | rs == "" = ls
-- | otherwise = midPadL 15 ' ' ls (' ' : rs)
introScanDisplay :: Creature -> IntroScanType -> String
introScanDisplay cr = \case
HEALTH -> shortShow (cr ^. crHP)
MAXHEALTH -> shortShow (cr ^. crMaxHP)
--itemNumberDisplay :: World -> Creature -> ComposedItem -> [String]
--itemNumberDisplay w cr ci
-- | Just x <- ci ^? _1 . itUse . uInt = [show x]
-- | Just x <- ci ^? _1 . itUse . useToggle = [show x]
-- | ITEMSCAN <- ci ^. _1 . itType
-- , Just ExamineInventory <- w ^? hud . hudElement . subInventory = ["ACTIVE"]
-- | EQUIP WRIST_ECG <- ci ^. _1 . itType =
-- [displayPulse $ cr ^?! crType . avatarPulse . pulseProgress]
-- | isJust $ ci ^? _1 . itTargeting . itTgPos . _Just = ["!TARG!"]
-- | Just x <- ci ^? _1 . itConsumables . magLoadStatus . iaLoaded = [shortShow x]
-- | Just i <- ci ^? _1 . itUse . uaParams . apInt = [show i]
-- | Just x <- ci ^? _1 . itUse . uaParams . apProjectiles = [show x]
-- | Just t <- ci ^? _1 . itType . ibtIntroScanType = [introScanDisplay cr t]
-- | otherwise = mempty
--introScanDisplay :: Creature -> IntroScanType -> String
--introScanDisplay cr = \case
-- HEALTH -> shortShow (cr ^. crHP)
-- MAXHEALTH -> shortShow (cr ^. crMaxHP)
displayPulse :: Int -> String
displayPulse 0 = "*****"
+19 -4
View File
@@ -1,13 +1,17 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.ItEffect (
doInvEffect,
) where
import Dodge.BlBl
import Dodge.Item.Location
import Control.Lens
import Data.Maybe
import Dodge.BlBl
import Dodge.Data.World
import Dodge.Euse
import Dodge.Inventory.Path
import Dodge.Inventory.SelectionList
import Dodge.Item.Location
doInvEffect :: ItInvEffect -> Item -> Creature -> World -> World
doInvEffect = \case
@@ -17,9 +21,20 @@ doInvEffect = \case
RemoveShieldWall -> removeShieldWall
EffectWhileRoot f -> rootNotrootEff f NoInvEffect
EffectWhileAttached f -> effectWhileAttached f
ItemUseToggle f -> \itm _
-> pointerToItemID (itm ^. itID) . itUse . useToggle %~ doBlBl f
ItemUseToggle f -> \itm _ ->
pointerToItemID (itm ^. itID) . itUse . useToggle %~ doBlBl f
ItemCancelExamineInventory -> \_ _ -> cancelExamineInventory
ItemCopierUpdate -> copierItemUpdate
copierItemUpdate :: Item -> Creature -> World -> World
copierItemUpdate itm cr w = fromMaybe w $ do
x <- itm ^? itScroll . itsInt
invid <- itm ^? itLocation . ilInvID
ip <- itm ^? itType . ibtPathing
i <- getInventoryPath x ip invid cr
itm' <- cr ^? crInv . ix i
v <- getItemValue itm' w cr
return $ w & pointerToItem itm . itUse . uValue .~ v
cancelExamineInventory :: World -> World
cancelExamineInventory = hud . hudElement . subInventory %~ f
+2 -1
View File
@@ -4,6 +4,7 @@ module Dodge.Item.Display (
itemBaseName,
itemString,
basicItemDisplay,
itemInternalValue,
) where
import ShortShow
@@ -36,7 +37,7 @@ itemInternalValue itm
| Just x <- itm ^? itConsumables . magLoadStatus . iaLoaded = Just $ Left x
| UseAttach (APInt i) <- itm ^. itUse = Just $ Left i
| UseAttach (APProjectiles x) <- itm ^. itUse = Just . Right $ show x
| otherwise = mempty
| v <- itm ^? itUse . uValue = v
maybeWarmupStatus :: Item -> Maybe String
+2 -1
View File
@@ -88,8 +88,9 @@ copier :: InventoryPathing -> Item
copier x =
defaultHeldItem
& itType .~ COPIER x
& itUse .~ UseInt 0
& itUse .~ UseValue (Left 0)
& itScroll .~ ItemScrollInt 0
& itEffect . ieInv .~ ItemCopierUpdate
bgate :: Item
bgate =
+4 -1
View File
@@ -49,7 +49,7 @@ selectedItemScroll yi w = do
itemScroll :: Int -> Int -> Item -> World -> World
itemScroll yi invid itm w
| isJust $ itm ^? itUse . uInt = w & itmlens . itUse . uInt +~ yi
-- | isJust $ itm ^? itUse . uInt = w & itmlens . itUse . uInt +~ yi
| Just xs <- itm ^? itUse . uaParams . apProjectiles = w
& itmlens . itUse . uaParams . apProjectiles .~ rotateList yi xs
| ATTACH ZOOMSCOPE <- itm ^. itType = updateScopeZoom invid w
@@ -58,6 +58,9 @@ itemScroll yi invid itm w
w
& itmlens . itUse . heldAim . aimMuzzles . ix 0 . mzAmmoSlot
%~ ((`mod` 2) . (+ 1))
| isJust $ itm ^? itScroll . itsInt = w & itmlens . itScroll . itsInt +~ yi
| Just y <- itm ^? itScroll . itsMax = w & itmlens . itScroll . itsRangeInt
%~ ((`mod` y) . (+ yi))
| otherwise = w
where
itmlens = cWorld . lWorld . creatures . ix 0 . crInv . ix invid