Commit before using item structural function more prominently

This commit is contained in:
2024-10-05 16:38:14 +01:00
parent 164beeea6d
commit 7c324a03f6
5 changed files with 38 additions and 63 deletions
+7 -12
View File
@@ -161,9 +161,7 @@ equipmentEffects cr = alaf Endo foldMap (useEquipment cr) (IM.keys $ _crInvEquip
invSideEff :: Creature -> World -> World
invSideEff cr = alaf Endo foldMap f (_crInv cr) . updateHeldRootItem cr
where
f it =
itemInvSideEffect cr it
. maybe id (\g -> doInvEffect g it cr) (it ^? itEffect . ieInv)
f it = maybe id (\g -> doInvEffect g it cr) (it ^? itEffect . ieInv)
updateHeldRootItem :: Creature -> World -> World
updateHeldRootItem cr = fromMaybe id $ do
@@ -200,7 +198,8 @@ updateItemWithOrientation ::
World
updateItemWithOrientation cr m loc@(LocLDT _ itmtree) = case _itType itm of
HELD TORCH -> shineTorch cr itmtree m
TARGETING TARGETLASER -> makeTargetLaser cr itmtree m
TARGETING TARGETLASER -> shineTargetLaser cr itmtree m
TARGETING tt -> updateItemTargeting tt cr itm
ATTACH AUGMENTEDHUD -> drawAugmentedHUD loc
_ -> id
where
@@ -211,16 +210,17 @@ drawAugmentedHUD (LocLDT con _) w = fromMaybe w $ do
itm <- con ^? cldtParent
return $ w & cWorld . lWorld . flares <>~ drawTargeting itm w
makeTargetLaser :: Creature -> LabelDoubleTree ItemLink Item -> (Point3, Q.Quaternion Float)
shineTargetLaser :: Creature -> LabelDoubleTree ItemLink Item -> (Point3, Q.Quaternion Float)
-> World -> World
makeTargetLaser cr itmtree (p,q) w = fromMaybe (w & pointItUse . tgPos .~ Nothing) $ do
shineTargetLaser cr itmtree (p,q) w = fromMaybe (w & pointItUse . tgPos .~ Nothing) $ do
guard (crIsAiming cr)
(_, mag) <- find (isammolink . _iatType . fst) (itmtree ^. ldtLeft)
i <- mag ^? ldtValue . itUse . amagLoadStatus . iaLoaded
guard $ i >= x
maginvid <- mag ^? ldtValue . itLocation . ilInvID
return $ w
& cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix maginvid . itUse . amagLoadStatus . iaLoaded -~ x
& cWorld . lWorld . creatures . ix (_crID cr)
. crInv . ix maginvid . itUse . amagLoadStatus . iaLoaded -~ x
& cWorld . lWorld . lasers .:~ LaserStart
{ _lpPhaseV = 1
, _lpDir = _crDir cr + argV (Q.qToV2 q)
@@ -258,11 +258,6 @@ shineTorch cr itmtree (p, q) = fromMaybe id $ do
cdir = _crDir cr
d = _crDir cr + argV (Q.qToV2 q)
itemInvSideEffect :: Creature -> Item -> World -> World
itemInvSideEffect cr itm = case _itType itm of
TARGETING tt -> updateItemTargeting tt cr itm
_ -> id
-- this probably needs to be set to null when dropped as well?
-- does this need to be updated if it is not attached to the used root item?
updateItemTargeting :: TargetingType -> Creature -> Item -> World -> World