Make lasGun have multiple functions when attached differently

This commit is contained in:
2024-10-06 11:19:19 +01:00
parent 3b54f00cc7
commit 9860a88c0c
11 changed files with 155 additions and 112 deletions
+24 -3
View File
@@ -26,11 +26,33 @@ useRootItem :: Int -> World -> World
useRootItem crid w = fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix crid
itRef <- cr ^? crManipulation . manObject . imRootItem
it <- invTrees (_crInv cr) ^? ix itRef
it <- invRootTrees (_crInv cr) ^? ix itRef
return $
itemUseEffect cr it w
itemUseEffect' cr it w
& worldEventFlags . at InventoryChange ?~ ()
itemUseEffect' :: Creature -> LabelDoubleTree ItemLink ComposedItem -> World -> World
itemUseEffect' cr itmtree w = case itmtree ^. ldtValue . cItemFunction of
WeaponPlatformSF -> heldEffect (bimap _iatType _cItem itmtree) cr w
& pointerToItem itm . itUse . heldHammer .~ HammerDown
_ -> w
-- UseHotkey{} -> doequipmentchange
-- UseEquip{} -> doequipmentchange
-- (UseConsume eff) -> useC eff (_ldtValue itmtree) cr w
-- UseCraft{} -> w
-- UseAttach{} -> selectUse itmtree cr w
-- UseAmmoMag{} -> w
-- UseScope{} -> w
-- UseBulletMod{} -> w
where
itm :: Item
itm = itmtree ^. ldtValue . cItem
-- doequipmentchange = fromMaybe w $ do
-- guard (_crHammerPosition cr == HammerUp)
-- invid <- itm ^? itLocation . ilInvID
-- return $ toggleEquipmentAt invid cr w
itemUseEffect :: Creature -> LabelDoubleTree ComposeLinkType Item -> World -> World
itemUseEffect cr itmtree w = case itmtree ^. ldtValue . itUse of
UseHeld{} -> heldEffect itmtree cr w
@@ -40,7 +62,6 @@ itemUseEffect cr itmtree w = case itmtree ^. ldtValue . itUse of
(UseConsume eff) -> useC eff (_ldtValue itmtree) cr w
UseCraft{} -> w
UseAttach{} -> selectUse itmtree cr w
-- UseTargeting {} -> w
UseAmmoMag{} -> w
UseScope{} -> w
UseBulletMod{} -> w
+2 -1
View File
@@ -9,6 +9,7 @@ module Dodge.Creature.Picture (
deadFeet,
) where
import Dodge.Data.ComposedItem
import Control.Lens
import Dodge.Creature.HandPos (translateToLeftHand, translateToRightHand)
import Dodge.Creature.Test
@@ -138,4 +139,4 @@ shoulderSH = translateSHz 20
drawEquipment :: Creature -> SPic
{-# INLINE drawEquipment #-}
drawEquipment cr = foldMap (itemEquipPict cr . fmap (\(a, b, _) -> (a, b))) (invLDT $ _crInv cr)
drawEquipment cr = foldMap (itemEquipPict cr . fmap (\(a, b, _) -> CItem a b)) (invLDT $ _crInv cr)
+9 -9
View File
@@ -175,7 +175,7 @@ updateAttachedItems itmtree cr =
chainLinkOrientation
chainLinkOrientation
(updateItemWithOrientation cr)
(heldItemRelativeOrient (fst $ _ldtValue itmtree) cr (0, Q.qID))
(heldItemRelativeOrient (_cItem $ _ldtValue itmtree) cr (0, Q.qID))
(LocLDT TopLDT itmtree)
-- need to check rotation
@@ -185,7 +185,7 @@ chainLinkOrientation ::
ItemLink ->
ComposedItem ->
(Point3, Q.Quaternion Float)
chainLinkOrientation mo (par,_) (ILink lt f) (child,_) = (p + Q.rotate q p1, q * q1)
chainLinkOrientation mo (CItem par _) (ILink lt f) (CItem child _) = (p + Q.rotate q p1, q * q1)
where
(p, q) = mo
(p1, q1) = f par lt child
@@ -203,11 +203,11 @@ updateItemWithOrientation cr m loc@(LocLDT _ itmtree) = case _itType itm of
ATTACH AUGMENTEDHUD -> drawAugmentedHUD loc
_ -> id
where
itm = itmtree ^. ldtValue . _1
itm = itmtree ^. ldtValue . cItem
drawAugmentedHUD :: LocationLDT ItemLink ComposedItem -> World -> World
drawAugmentedHUD (LocLDT con _) w = fromMaybe w $ do
itm <- con ^? cldtParent . _1
itm <- con ^? cldtParent . cItem
return $ w & cWorld . lWorld . flares <>~ drawTargeting itm w
shineTargetLaser :: Creature -> LabelDoubleTree ItemLink ComposedItem -> (Point3, Q.Quaternion Float)
@@ -215,9 +215,9 @@ shineTargetLaser :: Creature -> LabelDoubleTree ItemLink ComposedItem -> (Point3
shineTargetLaser cr itmtree (p,q) w = fromMaybe (w & pointittarg . itTgPos .~ Nothing) $ do
guard (crIsAiming cr)
(_, mag) <- find (isammolink . _iatType . fst) (itmtree ^. ldtLeft)
i <- mag ^? ldtValue . _1 . itUse . amagLoadStatus . iaLoaded
i <- mag ^? ldtValue . cItem . itUse . amagLoadStatus . iaLoaded
guard $ i >= x
maginvid <- mag ^? ldtValue . _1 . itLocation . ilInvID
maginvid <- mag ^? ldtValue . cItem . itLocation . ilInvID
return $ w
& cWorld . lWorld . creatures . ix (_crID cr)
. crInv . ix maginvid . itUse . amagLoadStatus . iaLoaded -~ x
@@ -234,7 +234,7 @@ shineTargetLaser cr itmtree (p,q) w = fromMaybe (w & pointittarg . itTgPos .~ No
isammolink _ = False
pos = _crPos cr + xyV3 (rotate3 cdir (p + V3 5 0 0))
cdir = _crDir cr
itm = itmtree ^. ldtValue . _1
itm = itmtree ^. ldtValue . cItem
--pointItUse = cWorld . lWorld . creatures . ix cid . crInv . ix invid . itUse
pointittarg = cWorld . lWorld . creatures . ix cid . crInv . ix invid . itTargeting
cid = _crID cr
@@ -244,9 +244,9 @@ shineTargetLaser cr itmtree (p,q) w = fromMaybe (w & pointittarg . itTgPos .~ No
shineTorch :: Creature -> LabelDoubleTree ItemLink ComposedItem -> (Point3, Q.Quaternion Float) -> World -> World
shineTorch cr itmtree (p, q) = fromMaybe id $ do
(_, mag) <- find (isammolink . _iatType . fst) (itmtree ^. ldtLeft)
i <- mag ^? ldtValue . _1 . itUse . amagLoadStatus . iaLoaded
i <- mag ^? ldtValue . cItem . itUse . amagLoadStatus . iaLoaded
guard $ i >= x
invid <- mag ^? ldtValue . _1 . itLocation . ilInvID
invid <- mag ^? ldtValue . cItem . itLocation . ilInvID
return $
(cWorld . lWorld . tempLightSources .:~ tlsTimeRadColPos 1 250 0.7 pos'')
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . amagLoadStatus . iaLoaded -~ x)