Make optical scope relative to camera rotation

This commit is contained in:
2024-09-21 16:52:04 +01:00
parent 9dff2fcd7a
commit 27e07a10c4
11 changed files with 200 additions and 832 deletions
+2 -1
View File
@@ -12,7 +12,8 @@ zoomScope :: Item
zoomScope =
defaultHeldItem
& itType . iyBase .~ ATTACH (SCROLLATTACH ZOOMSCOPE)
& itUse .~ AttachUse (ScrollAttachParams (ZoomScrollParams{_opticPos = 0, _opticZoom = 1, _opticDefaultZoom = 0.5}))
-- & itUse .~ AttachUse (ScrollAttachParams (ZoomScrollParams{_opticPos = 0, _opticZoom = 1, _opticDefaultZoom = 0.5}))
& itScope .~ OpticScope{_opticPos = 0, _opticZoom = 1, _opticDefaultZoom = 0.5}
targetingScope :: TargetType -> Item
targetingScope tt =
+82 -82
View File
@@ -19,10 +19,10 @@ module Dodge.Item.Weapon.TriggerType (
withItemUpdate,
withItemUpdateFirst,
-- rateIncAB,
torqueBefore,
torqueBeforeAtLeast,
withTorqueAfter,
torqueSideEffect,
-- torqueBefore,
-- torqueBeforeAtLeast,
-- withTorqueAfter,
-- torqueSideEffect,
withRandomItemParams,
withRandomItem,
withRandomItemUpdate,
@@ -582,76 +582,76 @@ withRandomOffset f item cr w = f item (cr & crPos %~ (+.+ offV)) $ set randGen g
offV = rotateV (_crDir cr) (V2 0 offsetVal)
offsetAmount = fromMaybe 0 $ item ^? ldtValue . itUse . heldParams . randomOffset
-- | Rotates a creature
torqueBefore ::
-- | Max possible rotation
Float ->
ChainEffect
torqueBefore torque feff item cr w
| cid == 0 =
feff item (cr & crDir +~ rot) $
w
& randGen .~ g
& cWorld . lWorld . creatures . ix cid . crDir +~ rot
& wCam . camRot +~ rot
& rotateScope
| otherwise = feff item cr $ set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w
where
cid = _crID cr
(rot, g) = randomR (- torque, torque) $ _randGen w
rotateScope = fromMaybe id $ do
i <- yourScopeInvID w
return $ cWorld . lWorld . creatures . ix cid . crInv . ix i . itUse . attachParams . scrollAttachParams . opticPos %~ rotateV rot
---- | Rotates a creature
--torqueBefore ::
-- -- | Max possible rotation
-- Float ->
-- ChainEffect
--torqueBefore torque feff item cr w
-- | cid == 0 =
-- feff item (cr & crDir +~ rot) $
-- w
-- & randGen .~ g
-- & cWorld . lWorld . creatures . ix cid . crDir +~ rot
-- & wCam . camRot +~ rot
-- & rotateScope
-- | otherwise = feff item cr $ set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w
-- where
-- cid = _crID cr
-- (rot, g) = randomR (- torque, torque) $ _randGen w
-- rotateScope = fromMaybe id $ do
-- i <- yourScopeInvID w
-- return $ cWorld . lWorld . creatures . ix cid . crInv . ix i . itUse . attachParams . scrollAttachParams . opticPos %~ rotateV rot
{- | Rotates a creature with minimum rotation
Rotates the player creature before applying the effect, other creatures after.
-}
torqueBeforeAtLeast ::
-- | Minimal possible rotation
Float ->
-- | Extra possible rotation
Float ->
ChainEffect
torqueBeforeAtLeast minTorque exTorque feff item cr w
| cid == 0 =
feff item (cr & crDir +~ rot') $
w
& randGen .~ g
& cWorld . lWorld . creatures . ix cid . crDir +~ rot'
& wCam . camRot +~ rot'
& rotateScope
| otherwise = feff item cr $ set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot') w
where
cid = _crID cr
(rot, g) = randomR (- exTorque, exTorque) $ _randGen w
rot'
| rot < 0 = rot - minTorque
| otherwise = rot + minTorque
rotateScope = fromMaybe id $ do
i <- yourScopeInvID w
return $ cWorld . lWorld . creatures . ix cid . crInv . ix i . itUse . attachParams . scrollAttachParams . opticPos %~ rotateV rot
--{- | Rotates a creature with minimum rotation
-- Rotates the player creature before applying the effect, other creatures after.
---}
--torqueBeforeAtLeast ::
-- -- | Minimal possible rotation
-- Float ->
-- -- | Extra possible rotation
-- Float ->
-- ChainEffect
--torqueBeforeAtLeast minTorque exTorque feff item cr w
-- | cid == 0 =
-- feff item (cr & crDir +~ rot') $
-- w
-- & randGen .~ g
-- & cWorld . lWorld . creatures . ix cid . crDir +~ rot'
-- & wCam . camRot +~ rot'
-- & rotateScope
-- | otherwise = feff item cr $ set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot') w
-- where
-- cid = _crID cr
-- (rot, g) = randomR (- exTorque, exTorque) $ _randGen w
-- rot'
-- | rot < 0 = rot - minTorque
-- | otherwise = rot + minTorque
-- rotateScope = fromMaybe id $ do
-- i <- yourScopeInvID w
-- return $ cWorld . lWorld . creatures . ix cid . crInv . ix i . itUse . attachParams . scrollAttachParams . opticPos %~ rotateV rot
-- | Rotate a randomly creature after applying an effect.
withTorqueAfter :: ChainEffect
withTorqueAfter feff item cr w
-- | cid == 0 = rotateScope . set randGen g $ over (wCam . camRot) (+ rot) $ feff item cr w
-- | otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) $ feff item cr w
| cid == 0 = w
& feff item cr
& wCam . camRot +~ rot
& rotateScope
& randGen .~ g
| otherwise = w
& cWorld . lWorld . creatures . ix cid . crDir +~ rot
& randGen .~ g
where
cid = _crID cr
(rot, g) = randomR (- torque, torque) $ _randGen w
torque = fromMaybe 0 $ item ^? ldtValue . itUse . heldParams . torqueAfter
rotateScope = fromMaybe id $ do
i <- yourScopeInvID w
return $ cWorld . lWorld . creatures . ix cid . crInv . ix i . itUse . attachParams . scrollAttachParams . opticPos %~ rotateV rot
-- rotateScope = pointerYourItem . itScope . scopePos %~ rotateV rot
---- | Rotate a randomly creature after applying an effect.
--withTorqueAfter :: ChainEffect
--withTorqueAfter feff item cr w
---- | cid == 0 = rotateScope . set randGen g $ over (wCam . camRot) (+ rot) $ feff item cr w
---- | otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) $ feff item cr w
-- | cid == 0 = w
-- & feff item cr
-- & wCam . camRot +~ rot
-- & rotateScope
-- & randGen .~ g
-- | otherwise = w
-- & cWorld . lWorld . creatures . ix cid . crDir +~ rot
-- & randGen .~ g
-- where
-- cid = _crID cr
-- (rot, g) = randomR (- torque, torque) $ _randGen w
-- torque = fromMaybe 0 $ item ^? ldtValue . itUse . heldParams . torqueAfter
-- rotateScope = fromMaybe id $ do
-- i <- yourScopeInvID w
-- return $ cWorld . lWorld . creatures . ix cid . crInv . ix i . itUse . attachParams . scrollAttachParams . opticPos %~ rotateV rot
---- rotateScope = pointerYourItem . itScope . scopePos %~ rotateV rot
sideEffectOnFrame ::
Int ->
@@ -661,16 +661,16 @@ sideEffectOnFrame i sf f it cr w =
f it cr w
& cWorld . lWorld . delayedEvents .:~ (i, sf (_ldtValue it) cr)
torqueSideEffect :: Float -> Item -> Creature -> World -> World
torqueSideEffect torque _ cr w
| cid == 0 = set randGen g . rotateScope $ over (wCam . camRot) (+ rot) w
| otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w
where
cid = _crID cr
(rot, g) = randomR (- torque, torque) $ _randGen w
rotateScope = fromMaybe id $ do
i <- yourScopeInvID w
return $ cWorld . lWorld . creatures . ix cid . crInv . ix i . itUse . attachParams . scrollAttachParams . opticPos %~ rotateV rot
--torqueSideEffect :: Float -> Item -> Creature -> World -> World
--torqueSideEffect torque _ cr w
-- | cid == 0 = set randGen g . rotateScope $ over (wCam . camRot) (+ rot) w
-- | otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w
-- where
-- cid = _crID cr
-- (rot, g) = randomR (- torque, torque) $ _randGen w
-- rotateScope = fromMaybe id $ do
-- i <- yourScopeInvID w
-- return $ cWorld . lWorld . creatures . ix cid . crInv . ix i . itUse . attachParams . scrollAttachParams . opticPos %~ rotateV rot
-- pump the updated creature into the chain in later frames
repeatOnFrames :: [Int] -> HeldMod -> ChainEffect