Add attached/aiming checks on item usage

This commit is contained in:
2025-01-01 11:36:33 +00:00
parent 99114c7351
commit 91111fc89c
10 changed files with 393 additions and 423 deletions
+49 -60
View File
@@ -1,10 +1,11 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Creature.Impulse.UseItem ( module Dodge.Creature.Impulse.UseItem (
useItem, useItem,
-- useSelectedItem,
) where ) where
import Control.Lens import Control.Lens
--import Control.Monad import Control.Monad
import Data.Maybe import Data.Maybe
import Dodge.Data.ComposedItem import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree import Dodge.Data.DoubleTree
@@ -22,69 +23,56 @@ useItem :: Int -> PressType -> World -> World
useItem invid pt w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w $ do useItem invid pt w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix 0 cr <- w ^? cWorld . lWorld . creatures . ix 0
itmloc <- allInvLocs (_crInv cr) ^? ix invid . _2 itmloc <- allInvLocs (_crInv cr) ^? ix invid . _2
usedloc <- useLocation itmloc let usedloc = useLocation itmloc
useItemLoc cr usedloc pt w useItemLoc cr usedloc pt w
useItemLoc :: Creature -> LocationLDT ItemLink ComposedItem -> PressType useItemLoc ::
-> World -> Maybe World Creature ->
LocationLDT ItemLink ComposedItem ->
PressType ->
World ->
Maybe World
useItemLoc cr loc pt w = case loc ^. locLDT . ldtValue . _2 of useItemLoc cr loc pt w = case loc ^. locLDT . ldtValue . _2 of
HeldPlatformSF -> HeldPlatformSF -> do
return $ guard $ fromMaybe False $ loc ^? locLDT . ldtValue . _1 . itLocation . ilIsRoot
heldEffect pt (bimap _iatType (^. _1) ldt) cr w guard $ cr ^. crStance . posture == Aiming
-- & pointerToItem itm . itUse . heldHammer .~ HammerDown return $ heldEffect pt (bimap _iatType (^. _1) ldt) cr w
GadgetPlatformSF -> GadgetPlatformSF ->
return $ return $
heldEffect pt (bimap _iatType (^. _1) ldt) cr w heldEffect pt (bimap _iatType (^. _1) ldt) cr w
-- & pointerToItem itm . itUse . heldHammer .~ HammerDown UnderBarrelPlatformSF -> do
RemoteDetonatorSF -> do guard $ fromMaybe False $ loc ^? locLDT . ldtValue . _1 . itLocation . ilIsAttached
return $ activateDetonator ldt w guard $ cr ^. crStance . posture == Aiming
-- & pointerToItem itm . itUse . heldHammer .~ HammerDown return $ heldEffect pt (bimap _iatType (^. _1) ldt) cr w
_ | isJust $ itm ^? itUse . uequipEffect -> do RemoteDetonatorSF -> do
invid' <- itm ^? itLocation . ilInvID guard $ pt == InitialPress
return $ toggleEquipmentAt invid' cr w return $ activateDetonator ldt w
_ -> Nothing _ | isJust $ itm ^? itUse . uequipEffect -> do
guard $ pt == InitialPress
invid' <- itm ^? itLocation . ilInvID
return $ toggleEquipmentAt invid' cr w
_ -> Nothing
where where
ldt = loc ^. locLDT ldt = loc ^. locLDT
itm = ldt ^. ldtValue . _1 itm = ldt ^. ldtValue . _1
useLocation :: LocationLDT ItemLink ComposedItem useLocation ::
-> Maybe (LocationLDT ItemLink ComposedItem) LocationLDT ItemLink ComposedItem ->
LocationLDT ItemLink ComposedItem
useLocation loc useLocation loc
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uequipEffect = return loc | isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uequipEffect = loc
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apLinkedProjectile . _Just | isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0 =
= return loc loc
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0 | sf <- loc ^. locLDT . ldtValue . _2
= return loc , structureUseAtLoc sf =
| otherwise = return $ locToTop loc loc
| otherwise = locToTop loc
--useSelectedItem :: Int -> World -> World structureUseAtLoc :: ItemStructuralFunction -> Bool
--useSelectedItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w $ do structureUseAtLoc = \case
-- cr <- w ^? cWorld . lWorld . creatures . ix crid HeldPlatformSF -> True
-- invid <- cr ^? crManipulation . manObject . imSelectedItem UnderBarrelPlatformSF -> True
-- itmloc <- allInvLocs (_crInv cr) ^? ix invid . _2 _ -> False
-- let usedloc = case useLocation itmloc of
-- UseFromLocation -> itmloc ^. locLDT
-- UseFromRoot -> locToTop itmloc ^. locLDT
-- let itm = usedloc ^. ldtValue . _1
-- case usedloc ^. ldtValue . _2 of
-- HeldPlatformSF ->
-- return $
-- heldEffect (bimap _iatType fst3 usedloc) cr w
-- & pointerToItem itm . itUse . heldHammer .~ HammerDown
-- GadgetPlatformSF ->
-- return $
-- heldEffect (bimap _iatType fst3 usedloc) cr w
-- & pointerToItem itm . itUse . heldHammer .~ HammerDown
-- RemoteDetonatorSF -> do
-- return $ activateDetonator usedloc w
-- & pointerToItem itm . itUse . heldHammer .~ HammerDown
-- _ | isJust $ itm ^? itUse . uequipEffect -> do
---- guard (_crHammerPosition cr == HammerUp)
-- invid' <- itm ^? itLocation . ilInvID
-- return $ toggleEquipmentAt invid' cr w
-- _ -> Nothing
-- where
-- fst3 (x, _, _) = x
activateDetonator :: activateDetonator ::
LabelDoubleTree ItemLink ComposedItem -> LabelDoubleTree ItemLink ComposedItem ->
@@ -102,7 +90,7 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
& crpoint . crEquipment . at newp ?~ invid & crpoint . crEquipment . at newp ?~ invid
& crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp & crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp
& onequip itm cr & onequip itm cr
-- & cWorld . lWorld %~ assignNewHotkey invid -- & cWorld . lWorld %~ assignNewHotkey invid
MoveEquipment{_allocNewPos = newp, _allocOldPos = oldp} -> MoveEquipment{_allocNewPos = newp, _allocOldPos = oldp} ->
w w
& crpoint . crEquipment . at newp ?~ invid & crpoint . crEquipment . at newp ?~ invid
@@ -121,15 +109,16 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
& crpoint . crInv . ix rid . itLocation . ilEquipSite .~ Nothing & crpoint . crInv . ix rid . itLocation . ilEquipSite .~ Nothing
& onremove (itmat rid) cr & onremove (itmat rid) cr
& onequip itm cr & onequip itm cr
-- & cWorld . lWorld %~ removeHotkey rid -- & cWorld . lWorld %~ removeHotkey rid
-- & cWorld . lWorld %~ assignNewHotkey invid -- & cWorld . lWorld %~ assignNewHotkey invid
RemoveEquipment{_allocOldPos = oldp} -> RemoveEquipment{_allocOldPos = oldp} ->
w w
& crpoint . crEquipment . at oldp .~ Nothing & crpoint . crEquipment . at oldp .~ Nothing
& crpoint . crInv . ix invid . itLocation . ilEquipSite .~ Nothing & crpoint . crInv . ix invid . itLocation . ilEquipSite .~ Nothing
& onremove itm cr & onremove itm cr
-- & cWorld . lWorld %~ removeHotkey invid
where where
-- & cWorld . lWorld %~ removeHotkey invid
crpoint = cWorld . lWorld . creatures . ix (_crID cr) crpoint = cWorld . lWorld . creatures . ix (_crID cr)
itmat i = _crInv cr IM.! i itmat i = _crInv cr IM.! i
itm = itmat itRef itm = itmat itRef
-3
View File
@@ -53,9 +53,6 @@ useHotkey w (NInt itid, pt) = fromMaybe w $ do
invid <- w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID invid <- w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID
return $ useItem invid pt w return $ useItem invid pt w
--allHotkeys :: [SDL.Scancode]
--allHotkeys = map hotkeyToScancode [minBound .. maxBound]
hotkeyToScancode :: Hotkey -> SDL.Scancode hotkeyToScancode :: Hotkey -> SDL.Scancode
hotkeyToScancode x = case x of hotkeyToScancode x = case x of
HotkeyQ -> SDL.ScancodeQ HotkeyQ -> SDL.ScancodeQ
-8
View File
@@ -1,5 +1,4 @@
{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveAnyClass #-}
--{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StrictData #-} {-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
@@ -15,7 +14,6 @@ import Dodge.Data.Item.Targeting
data ItemType data ItemType
= HELD {_ibtHeld :: HeldItemType} = HELD {_ibtHeld :: HeldItemType}
-- | LEFT {_ibtLeft :: LeftItemType}
| EQUIP {_ibtEquip :: EquipItemType} | EQUIP {_ibtEquip :: EquipItemType}
| CRAFT {_ibtCraft :: CraftType} | CRAFT {_ibtCraft :: CraftType}
| ATTACH {_ibtAttach :: AttachType} | ATTACH {_ibtAttach :: AttachType}
@@ -115,12 +113,6 @@ data EquipItemType
| WRIST_ECG | WRIST_ECG
deriving (Eq, Ord, Show, Read) deriving (Eq, Ord, Show, Read)
--data LeftItemType
-- = STOPWATCH
-- | SCROLLWATCH
-- | SPAWNER
-- deriving (Eq, Ord, Show, Read) --Generic, Flat)
data HeldItemType data HeldItemType
= BANGSTICK {_xNum :: Int} = BANGSTICK {_xNum :: Int}
| REWINDER | REWINDER
+1 -3
View File
@@ -65,9 +65,7 @@ data TriggerType = AutoTrigger | HammerTrigger
deriving (Eq, Show, Read) deriving (Eq, Show, Read)
data AttachParams data AttachParams
= APLinkProjectile = APProjectiles
{_apLinkedProjectile :: Maybe Int}
| APProjectiles
{_apProjectiles :: [Int]} {_apProjectiles :: [Int]}
| APInt {_apInt :: Int} | APInt {_apInt :: Int}
| APNothing | APNothing
+1 -1
View File
@@ -102,7 +102,7 @@ itemNumberDisplay cr ci
["!TARG!"] ["!TARG!"]
| Just x <- ci ^? _1 . itConsumables . magLoadStatus . iaLoaded = [shortShow x] | Just x <- ci ^? _1 . itConsumables . magLoadStatus . iaLoaded = [shortShow x]
| UseAttach (APInt i) <- ci ^. _1 . itUse = [show i] | UseAttach (APInt i) <- ci ^. _1 . itUse = [show i]
| UseAttach (APLinkProjectile i) <- ci ^. _1 . itUse = [show i] -- | UseAttach (APLinkProjectile i) <- ci ^. _1 . itUse = [show i]
| UseAttach (APProjectiles x) <- ci ^. _1 . itUse = [show x] | UseAttach (APProjectiles x) <- ci ^. _1 . itUse = [show x]
| UseScope OpticScope{_opticZoom = x} <- ci ^. _1 . itUse = [shortShow x] | UseScope OpticScope{_opticZoom = x} <- ci ^. _1 . itUse = [shortShow x]
| otherwise = mempty | otherwise = mempty
+2 -1
View File
@@ -69,7 +69,8 @@ augmentedHUD = makeAttach AUGMENTEDHUD
remoteScreen :: Item remoteScreen :: Item
remoteScreen = makeAttach REMOTESCREEN remoteScreen = makeAttach REMOTESCREEN
& itUse . uaParams .~ APLinkProjectile Nothing -- & itUse . uaParams .~ APLinkProjectile Nothing
& itUse . uaParams .~ APProjectiles []
remoteDetonator :: Item remoteDetonator :: Item
remoteDetonator = makeAttach REMOTEDETONATOR remoteDetonator = makeAttach REMOTEDETONATOR
+4 -2
View File
@@ -72,8 +72,10 @@ createShell mdetonator mscreen stab pjtype payload muz cr w = w
updatescreen = fromMaybe id $ do updatescreen = fromMaybe id $ do
screenid <- mscreen screenid <- mscreen
return $ pointerToItemID screenid . itUse . uaParams return $ pointerToItemID screenid . itUse . uaParams
. apLinkedProjectile . apProjectiles
?~ i .:~ i
-- . apLinkedProjectile
-- ?~ i
i = IM.newKey $ w ^. cWorld . lWorld . projectiles i = IM.newKey $ w ^. cWorld . lWorld . projectiles
dir = _crDir cr + _mzRot muz dir = _crDir cr + _mzRot muz
pos = _crPos cr +.+ rotateV dir (_mzPos muz) pos = _crPos cr +.+ rotateV dir (_mzPos muz)
+1 -4
View File
@@ -3,7 +3,6 @@ module Dodge.Projectile.Update (
updateProjectile, updateProjectile,
) where ) where
import Control.Monad
import Data.Foldable import Data.Foldable
import Data.List (delete) import Data.List (delete)
import Data.Maybe import Data.Maybe
@@ -118,9 +117,7 @@ destroyProjectile mitid pjid w =
removelink = fromMaybe id $ do removelink = fromMaybe id $ do
itid <- fmap _unNInt mitid itid <- fmap _unNInt mitid
loc <- w ^? cWorld . lWorld . itemLocations . ix itid loc <- w ^? cWorld . lWorld . itemLocations . ix itid
itm <- w ^? pointerToItemLocation loc . itUse . uaParams . apLinkedProjectile . _Just return $ pointerToItemLocation loc . itUse . uaParams . apProjectiles %~ delete pjid
guard $ itm == pjid
return $ pointerToItemLocation loc . itUse . uaParams . apLinkedProjectile .~ Nothing
doThrust :: Projectile -> Maybe RocketSmoke -> World -> World doThrust :: Projectile -> Maybe RocketSmoke -> World -> World
doThrust pj smoke w = doThrust pj smoke w =
+3 -2
View File
@@ -58,7 +58,7 @@ translateFloatingCamera theinput cam = fromMaybe cam $ do
cam & camCenter +~ thetran cam & camCenter +~ thetran
& camViewFrom +~ thetran & camViewFrom +~ thetran
else do else do
a <- (theinput ^. heldPos . at SDL.ButtonRight) a <- theinput ^. heldPos . at SDL.ButtonRight
return $ cam & camRot -~ angleBetween (theinput ^. mousePos) a return $ cam & camRot -~ angleBetween (theinput ^. mousePos) a
translateFloatingCameraKeys :: Input -> Camera -> Camera translateFloatingCameraKeys :: Input -> Camera -> Camera
@@ -93,7 +93,8 @@ moveZoomCamera cfig theinput cr w campos =
where where
mremotepos = do mremotepos = do
i <- cr ^? crManipulation . manObject . imSelectedItem i <- cr ^? crManipulation . manObject . imSelectedItem
j <- cr ^? crInv . ix i . itUse . uaParams . apLinkedProjectile . _Just j <- cr ^? crInv . ix i . itUse . uaParams . apProjectiles . ix 0
guard $ Just REMOTESCREEN == cr ^? crInv . ix i . itType . ibtAttach
w ^? cWorld . lWorld . projectiles . ix j . pjPos w ^? cWorld . lWorld . projectiles . ix j . pjPos
docamrot = rotateV (campos ^. camRot) docamrot = rotateV (campos ^. camRot)
offset = fromMaybe noscopeoffset $ do offset = fromMaybe noscopeoffset $ do
+332 -339
View File
File diff suppressed because it is too large Load Diff