Make equipment effects use item locations

Move towards removing on/off equipment effects
This commit is contained in:
2024-12-19 11:15:21 +00:00
parent 3ffe61e6db
commit a669632226
9 changed files with 110 additions and 103 deletions
+2 -2
View File
@@ -91,8 +91,8 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
itmat i = _crInv cr IM.! i
itm = itmat itRef
itRef = cr ^?! crManipulation . manObject . imSelectedItem -- unsafe!! TODO change?
onequip itm' = useE ((_eeOnEquip . _uequipEffect . _itUse) itm') itm'
onremove itm' = useE ((_eeOnRemove . _uequipEffect . _itUse) itm') itm'
onequip itm' = doItmCrWdWd ((_eeOnEquip . _uequipEffect . _itUse) itm') itm'
onremove itm' = doItmCrWdWd ((_eeOnRemove . _uequipEffect . _itUse) itm') itm'
-- need to make sure that the root item is not erroneously selected in the
-- following
+6 -15
View File
@@ -72,6 +72,8 @@ crUpdate f =
, invSideEff
-- , equipmentEffects
]
-- I have changed the ordering of item/equipment effects, which may have
-- unforseen consequences, be aware
checkDeath :: Creature -> World -> World
checkDeath cr w
@@ -146,21 +148,10 @@ applyPastDamages cr w
& randGen .~ g
| otherwise = w
useEquipment :: Creature -> Int -> World -> World
useEquipment cr i = useE (_eeUse (_uequipEffect $ _itUse itm)) itm cr
where
itm = _crInv cr IM.! i
-- a map updating all inventory items
updateInv :: Creature -> World -> World
updateInv cr = cWorld . lWorld . creatures . ix (_crID cr) . crInv %~ IM.map itemUpdate
-- a loop going over equipped items
-- maybe this should be done during a different loop (invSideEff)?
equipmentEffects :: Creature -> World -> World
--equipmentEffects cr = flip (foldl' $ flip $ useEquipment cr) (IM.keys $ _crInvEquipped cr)
equipmentEffects cr = alaf Endo foldMap (useEquipment cr) (IM.keys $ _crInvEquipped cr)
-- a loop going over all inventory items
invSideEff :: Creature -> World -> World
invSideEff cr = alaf Endo foldMap f (_crInv cr) . updateHeldRootItem cr
@@ -176,7 +167,7 @@ invRootItemEffs cr =
(invLDT (_crInv cr))
invItemLocUpdate :: Creature -> LocationLDT ItemLink ComposedItem -> World -> World
invItemLocUpdate cr loc w = doAnyEquipmentEffect cr loc $ case itm ^. itType of
invItemLocUpdate cr loc w = doAnyEquipmentEffect loc cr $ case itm ^. itType of
ATTACH BULLETSYNTH -> trySynthBullet loc w
EQUIP WRIST_ECG | haspulse -> tryUseParent loc w
_ -> w
@@ -186,9 +177,9 @@ invItemLocUpdate cr loc w = doAnyEquipmentEffect cr loc $ case itm ^. itType of
== Just 0
itm = loc ^. locLDT . ldtValue . _1
doAnyEquipmentEffect :: Creature -> LocationLDT ItemLink ComposedItem -> World -> World
doAnyEquipmentEffect cr loc = case itm ^? itLocation . ilEquipPosition . _Just of
Just _ -> useE (_eeUse (_uequipEffect $ _itUse itm)) itm cr
doAnyEquipmentEffect :: LocationLDT ItemLink ComposedItem -> Creature -> World -> World
doAnyEquipmentEffect loc cr = case itm ^? itLocation . ilEquipPosition . _Just of
Just _ -> useE (_eeUse (_uequipEffect $ _itUse itm)) loc cr
_ -> id
where
itm = loc ^. locLDT . ldtValue . _1