Delete redundant weapon chain effect code

This commit is contained in:
2024-09-24 18:25:24 +01:00
parent 34c244a332
commit fbb60bf358
5 changed files with 6 additions and 310 deletions
+1 -1
View File
@@ -1 +1 @@
All good (620 modules, at 18:04:30)
All good (620 modules, at 18:25:19)
+2
View File
@@ -38,6 +38,8 @@ tryPutItemInInv cid flit w = case maybeInvSlot of
& updateItLocation i
-- I forget whether using "at" rather than "IM.insert" here caused problems
-- & cWorld . lWorld . creatures . ix cid . crInv . at i ?~ it
-- note item locations are updated twice: first for the ilInvID,
-- second for the root/selected item bools
& cWorld . lWorld %~ crUpdateItemLocations cid
& setInvPosFromSS
& cWorld . lWorld %~ crUpdateItemLocations cid
+1
View File
@@ -49,6 +49,7 @@ crUpdateInvidLocations mo crid lw invid itm = lw
-- this should be looked at, as it is sometimes used in functions that need not
-- concern the player creature
-- this might not work if the selpos is in the inventory but too large
setInvPosFromSS :: World -> World
setInvPosFromSS w =
w
+2
View File
@@ -103,6 +103,8 @@ invLDT = joinItemsInList (leftRightCombine leftIsParentCombine rightIsParentComb
-- this assumes the creature inventory is well formed, specifically the
-- location ids
-- consider explicitly reseting the inventory ids (but this probably really
-- should be done upstream anyway in the actually creature inventory)
invAdj' :: IM.IntMap Item -> Either String (IM.IntMap (Maybe (Int,Int),[Int],[Int]))
invAdj' im = do
l <- mapM g $ invLDT im
-309
View File
@@ -4,9 +4,6 @@
Weapon effects when pulling the trigger.
-}
module Dodge.Item.Weapon.TriggerType (
useAmmoAmount,
useAllAmmo,
-- useAmmoUpTo,
lockInvFor,
withFlare,
withMuzFlare,
@@ -16,16 +13,6 @@ module Dodge.Item.Weapon.TriggerType (
trigDoAlso,
withTempLight,
withItem,
-- withItemUpdate,
-- withItemUpdateFirst,
-- rateIncAB,
-- torqueBefore,
-- torqueBeforeAtLeast,
-- withTorqueAfter,
-- torqueSideEffect,
withRandomItemParams,
withRandomItem,
withRandomItemUpdate,
withSoundStart,
withSoundItemChoiceStart,
withSoundContinue,
@@ -37,21 +24,7 @@ module Dodge.Item.Weapon.TriggerType (
withPositionOffset,
withPositionWallCheck,
withPosDirWallCheck,
withRandomOffset,
withRandomDirI,
withRecoil,
afterRecoil,
withSidePushAfterI,
withSidePushI,
withWarmUp,
repeatOnFrames,
sideEffectOnFrame,
duplicateItem,
duplicateLoadedBarrels,
duplicateNumBarrels,
duplicateLoaded,
duplicateOffsetsV2,
duplicateOffsetsFocus,
hammerCheckL,
hammerCheck,
shootL,
@@ -292,86 +265,6 @@ withSoundForVol vol soundid playTime f item cr =
soundContinueVol vol (CrWeaponSound (_crID cr) 0) (_crPos cr) soundid (Just playTime)
. f item cr
afterRecoil ::
-- | Recoil amount
Float ->
ChainEffect
afterRecoil recoilAmount eff item cr = eff item (pushback cr) . over (cWorld . lWorld . creatures . ix cid) pushback
where
cid = _crID cr
pushback = over crPos (+.+ rotateV (_crDir cr) (V2 ((- recoilAmount) / _crMass cr) 0))
withRecoil :: ChainEffect
withRecoil eff it cr = eff it cr . over (cWorld . lWorld . creatures . ix cid) pushback
where
cid = _crID cr
recoilAmount = fromMaybe 0 $ it ^? ldtValue . itUse . heldParams . recoil
pushback = over crPos (+.+ rotateV (_crDir cr) (V2 ((- recoilAmount) / _crMass cr) 0))
{- | Pushes a creature sideways by a random amount.
Applied before the underlying effect.
-}
withSidePushI ::
-- | Maximal possible side push amount
Float ->
ChainEffect
withSidePushI maxSide eff item cr w =
eff item (push cr) $
w
& cWorld . lWorld . creatures . ix cid %~ push
& randGen .~ g
where
cid = _crID cr
push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr)))
(pushAmount, g) = randomR (- maxSide, maxSide) $ _randGen w
-- consider unifying the pushes using a direction vector
{- | Pushes a creature sideways by a random amount.
Applied after the underlying effect.
-}
withSidePushAfterI ::
-- | Maximal possible side push amount
Float ->
ChainEffect
withSidePushAfterI maxSide eff item cr w =
over (cWorld . lWorld . creatures . ix cid) push . eff item cr $
w
& randGen .~ g
where
cid = _crID cr
push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr)))
(pushAmount, g) = randomR (- maxSide, maxSide) $ _randGen w
useAllAmmo :: ChainEffect
useAllAmmo = error "use all ammo"
--useAllAmmo eff ams item cr w = fromMaybe w $ do
-- let invids = ams ^.. traverse . itLocation . ipInvID
-- return . eff ams item cr $ foldl' f w invids
-- where
-- f w' invid = w' & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid
-- . itUse . amagLoadStatus . iaLoaded .~ 0
--useAmmoUpTo :: Int -> ChainEffect
--useAmmoUpTo amAmount eff ams itm cr = fromMaybe id $ do
-- _ <- ams ^? ix 0 . itUse . amagLoadStatus . iaLoaded
-- invid <- ams ^? ix 0 . itLocation . ipInvID
-- return $ eff ams itm cr
-- . ( cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . amagLoadStatus . iaLoaded
-- %~ (max 0 . subtract amAmount)
-- )
useAmmoAmount :: Int -> ChainEffect
useAmmoAmount amAmount eff item cr = fromMaybe id $ do
atype <- item ^? ldtValue . itUse . heldAmmoTypes . ix 0
leftitms <- item ^? ldtLeft
mag <- lookup (AmmoInLink 0 atype) leftitms
magid <- mag ^? ldtValue . itLocation . ilInvID
return $ eff item cr
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix magid . itUse . amagLoadStatus . iaLoaded -~ amAmount)
-- . crInv . ix itRef . itUse . heldConsumption . laSource
{- |
Applies a world effect after an item use cooldown check.
-}
@@ -516,15 +409,6 @@ withCrPosShift p g f it cr = g thepos . f it cr
where
thepos = (_crPos cr +.+ rotateV (_crDir cr) p) `v2z` 20
-- | Applies the effect to a randomly rotated creature.
withRandomDirI ::
-- | Max possible rotation
Float ->
ChainEffect
withRandomDirI acc f it cr w = f it (cr & crDir +~ a) $ set randGen g w
where
(a, g) = randomR (- acc, acc) $ _randGen w
withOldDir ::
-- | The fraction of the old direction
Float ->
@@ -532,23 +416,6 @@ withOldDir ::
withOldDir aFrac eff item cr =
eff item (cr & crDir %~ tweenAngles aFrac (_crOldDir cr))
withRandomItemUpdate ::
State StdGen (Item -> Item) ->
ChainEffect
withRandomItemUpdate randItUp eff it cr w = eff (over ldtValue f it) cr $ w & randGen .~ g
where
(f, g) = runState randItUp (_randGen w)
withRandomItemParams :: State StdGen (ItemParams -> ItemParams) -> ChainEffect
withRandomItemParams rip eff it cr w = eff (it & ldtValue . itParams %~ f) cr $ w & randGen .~ g
where
(f, g) = runState rip (_randGen w)
withRandomItem :: State StdGen (Item -> Item) -> ChainEffect
withRandomItem rip eff it cr w = eff (over ldtValue f it) cr $ w & randGen .~ g
where
(f, g) = runState rip (_randGen w)
withPositionOffset ::
(Item -> Creature -> World -> (Point2, Float)) ->
ChainEffect
@@ -573,179 +440,3 @@ withPosDirWallCheck h f it cr w
| otherwise = w
where
(p, a) = h (_ldtValue it) cr w
-- | Apply the effect to a translated creature.
withRandomOffset :: ChainEffect
withRandomOffset f item cr w = f item (cr & crPos %~ (+.+ offV)) $ set randGen g w
where
(offsetVal, g) = randomR (- offsetAmount, offsetAmount) $ _randGen w
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 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
sideEffectOnFrame ::
Int ->
(Item -> Creature -> WdWd) ->
ChainEffect
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
-- pump the updated creature into the chain in later frames
repeatOnFrames :: [Int] -> HeldMod -> ChainEffect
--repeatOnFrames is hm f it cr w = f it cr w
repeatOnFrames is hm f it cr w =
f it cr $
w
& cWorld . lWorld . delayedEvents .++~ (is <&> (,WdWdFromItCrixWdWd (it & ldtValue . itUse . heldMods .~ hm) (_crID cr) ItCrWdItemEffect))
-- where
-- f' = fromMaybe w' $ do
-- cr' <- w' ^? creatures . ix (_crID cr)
-- return $ f it cr' w'
duplicateLoaded :: ChainEffect
duplicateLoaded = error "duplicateLoaded"
--duplicateLoaded :: ChainEffect
--duplicateLoaded eff ams it cr w = foldr f w (take numbul [1::Int .. ])
-- where
-- f _ = eff ams it cr
-- numbul = fromMaybe 0 $ do
-- i <- ams ^? ix 0 . itLocation . ipInvID
-- cr ^? crInv . ix i . itUse . amagLoadStatus . iaLoaded
duplicateNumBarrels :: Int -> ChainEffect
duplicateNumBarrels = error "duplicateNumBarrels"
--duplicateNumBarrels :: Int -> ChainEffect
--duplicateNumBarrels n eff ams itm cr w = foldr f w (take n $ itm ^?! itUse . heldAim . aimMuzzles)
-- where
-- f brl w' =
-- eff ams
-- itm
-- ( cr & crPos +~ rotateV (_crDir cr) (_mzPos brl + aimingWeaponZeroPos cr itm)
-- & crDir +~ (_mzRot brl + a)
-- )
-- (w' & randGen .~ g)
-- where
-- inacc = _mzInaccuracy brl
-- (a,g) = randomR (-inacc,inacc) $ _randGen w'
duplicateLoadedBarrels :: ChainEffect
duplicateLoadedBarrels eff itm cr = eff itm cr
-- = duplicateNumBarrels numbul eff ams itm cr
-- where
-- numbul :: Int
-- numbul = fromMaybe 0 $ do
-- i <- ams ^? ix 0 . itLocation . ipInvID
-- cr ^? crInv . ix i . itUse . amagLoadStatus . iaLoaded
duplicateOffsetsFocus :: [Float] -> ChainEffect
duplicateOffsetsFocus xs eff item cr w = foldr f w poss
where
poss :: [V2 Float]
poss = map (rotateV (_crDir cr) . V2 0) xs
f pos =
eff item $
cr
& crPos %~ (+.+ pos)
& crDir .~ thedir pos
--thedir pos
-- | dist (mouseWorldPos (w ^. input) (w ^. wCam)) (_crPos cr) < aimingMuzzlePos cr item =
-- argV
-- ( _crPos cr +.+ aimingMuzzlePos cr item *.* unitVectorAtAngle (_crDir cr)
-- -.- (_crPos cr +.+ pos)
-- )
-- | otherwise = argV (mouseWorldPos (w ^. input) (w ^. wCam) -.- (_crPos cr +.+ pos))
thedir pos = argV (mouseWorldPos (w ^. input) (w ^. wCam) -.- (_crPos cr +.+ pos))
duplicateItem :: (Item -> [Item]) -> ChainEffect
duplicateItem fit eff itm cr w = foldr f w (ldtValue fit itm)
where
f itm' = eff itm' cr
duplicateOffsetsV2 :: [Point2] -> ChainEffect
duplicateOffsetsV2 xs eff item cr w = foldr f w poss
where
poss = map (rotateV (_crDir cr)) xs
f pos = eff item (cr & crPos +.+.~ pos)