Unify item inventory effects somewhat

This commit is contained in:
2025-06-20 17:41:32 +01:00
parent fe1ac8f5a4
commit b920a2ec72
4 changed files with 262 additions and 280 deletions
+20 -4
View File
@@ -3,6 +3,9 @@ module Dodge.Creature.State (
doDamage,
) where
import Dodge.Item.BackgroundEffect
import Dodge.Item.Location
import Dodge.Inventory.SelectionList
import Control.Applicative
import Control.Monad
import qualified Data.Map.Strict as M
@@ -23,7 +26,6 @@ import Dodge.Data.World
import Dodge.DoubleTree
import Dodge.Euse
import Dodge.HeldUse
import Dodge.Item.BackgroundEffect
import Dodge.Item.Grammar
import Dodge.Item.HeldOffset
import Dodge.Item.MaxAmmo
@@ -145,9 +147,7 @@ applyPastDamages cr w
-- a loop going over all inventory items
invSideEff :: Creature -> World -> World
invSideEff cr = alaf Endo foldMap f (_crInv cr) . updateHeldRootItem cr
where
f it = itBackgroundEffect it cr
invSideEff cr = updateHeldRootItem cr
-- a loop going over all root inventory items
invRootItemEffs :: Creature -> World -> World
@@ -161,6 +161,11 @@ invItemLocUpdate :: Creature -> LocationLDT ItemLink ComposedItem -> World -> Wo
invItemLocUpdate cr loc w = doAnyEquipmentEffect loc cr $ case itm ^. itType of
ATTACH BULLETSYNTH -> trySynthBullet loc w
EQUIP WRIST_ECG | haspulse -> tryUseParent loc w
COPIER _ -> copierItemUpdate itm cr w
HELD FLATSHIELD -> rootNotrootEff createShieldWall removeShieldWall itm cr w
HELD MINIGUNX{} ->
w & pointerToItem itm . itParams . wTime
%~ (max 0 . subtract 1)
_ -> w
where
haspulse =
@@ -168,6 +173,17 @@ invItemLocUpdate cr loc w = doAnyEquipmentEffect loc cr $ case itm ^. itType of
== Just 0
itm = loc ^. locLDT . ldtValue . _1
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
doAnyEquipmentEffect :: LocationLDT ItemLink ComposedItem -> Creature -> World -> World
doAnyEquipmentEffect loc cr = case itm ^? itLocation . ilEquipSite . _Just of
Just _ -> equipBackgroundEffect loc cr