Make item use mods an external function

This commit is contained in:
2022-07-20 17:06:45 +01:00
parent 795c4c1987
commit 12246462fe
22 changed files with 232 additions and 297 deletions
+157 -8
View File
@@ -1,6 +1,11 @@
module Dodge.HeldUse where
import Dodge.Data
import Dodge.Base.Coordinate
import Sound.Data
import Dodge.Bullet
import Dodge.Item.Weapon.TriggerType
import Dodge.SoundLogic
import Dodge.WorldEvent.Flash
import Dodge.Item.Location
import Dodge.Item.Weapon.Radar
import Dodge.Item.Weapon.BatteryGuns
@@ -14,7 +19,9 @@ import Geometry
import qualified IntMapHelp as IM
import LensHelp
import RandomHelp
import Color
import Data.Maybe
import Data.Traversable
useMod :: HeldMod -> [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World]
@@ -61,23 +68,23 @@ useMod hm = case hm of
, withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withSoundForI tone440sawtoothquietS 2
, useAmmoAmount 1
, withItemUpdate' increasecycle
, duplicateItem f
, withItemUpdate' increasecycleLasCircle
, duplicateItem fLasCircle
]
LasWideMod ->
LasWideMod n ->
[ ammoCheckI
, withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
, withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withSoundForI tone440sawtoothquietS 2
, useAmmoAmount 1
, crAtMuzPos
, withItemUpdate' increasecycle
, withItem $ \it -> duplicateOffsetsV2 (xs it)
, withItemUpdate' (increasecycleLasWide n)
, withItem $ \it -> duplicateOffsetsV2 (xsLasWide it)
]
DualBeamMod ->
[ ammoCheckI
, withItem $ \it -> withMuzPosShift (V2 0 (thegap it)) $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withItem $ \it -> withMuzPosShift (V2 0 (-thegap it)) $ flareCircleAt (_lasColor2 $ _itParams it) 0.8
, withItem $ \it -> withMuzPosShift (V2 0 (thegapDualBeam it)) $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withItem $ \it -> withMuzPosShift (V2 0 (-thegapDualBeam it)) $ flareCircleAt (_lasColor2 $ _itParams it) 0.8
, withSoundForI tone440sawtoothquietS 2
, useAmmoAmount 1
]
@@ -89,7 +96,7 @@ useMod hm = case hm of
, useAmmoAmount 1
, crAtMuzPos
]
LauncherXMod ->
LauncherXMod i ->
[ hammerCheckI
, ammoCheckI
, useTimeCheck
@@ -195,10 +202,129 @@ useMod hm = case hm of
-- , applyInaccuracy
, withRecoil
]
PistolMod ->
[ ammoHammerCheck
, useTimeCheck
, useAmmoAmount 1
, withSoundStart tap3S
, applyInaccuracy
, withTorqueAfter
, withRecoil
, withSidePushI 50
, withMuzFlareI
]
AutoPistolMod ->
[ ammoCheckI
, useTimeCheck
, useAmmoAmount 1
, withSoundStart tap3S
, applyInaccuracy
, withTorqueAfter
, withRecoil
, withSidePushI 50
, withMuzFlareI
]
MachinePistolMod ->
[ ammoCheckI
, useTimeCheck
, useAmmoAmount 1
, withSoundStart tap1S
, applyInaccuracy
, withTorqueAfter
, withSidePushI 50
, withRecoil
, withMuzFlareI
]
BurstRifleMod ->
[ ammoHammerCheck
, useTimeCheck
, sideEffectOnFrame 7 (torqueSideEffect 0.2)
, lockInvFor 7
, \f' it -> repeatOnFrames (take (_laLoaded (_itConsumption it) - 1) [3,6]) f' it
, withSoundStart tap3S
, useAmmoAmount 1
, applyInaccuracy
, withMuzFlareI
, withRecoil
]
MiniGunMod i ->
[ ammoCheckI
, withWarmUp crankSlowS
, withSoundForI mini1S 2
--, withThinSmokeI
, withSmoke 1 black 20 200 5
, withMuzFlareI
, useAmmoAmount i
, withSidePushI (fromIntegral i * 50)
, torqueBefore (fromIntegral i * 0.05)
, afterRecoil (fromIntegral i * 5)
] <>
[ trigDoAlso' (moddelay x) (modcrpos x) useAmmoParams
| x <- map ((/fromIntegral i) . fromIntegral) [1..i-1]
]
SmgMod ->
[ ammoCheckI
, useTimeCheck
, useAmmoAmount 1
, withSoundStart tap3S
, applyInaccuracy
, withTorqueAfter
, withRecoil
, withSidePushI 30
, withMuzFlareI
]
RevolverXMod ->
[ ammoHammerCheck
, useTimeCheck
-- rather than locking the inventory, a better solution may be to check
-- that the weapon is still in your hands in the repeated frames
, lockInvFor 10
, \f' it -> repeatOnFrames (take (_laLoaded (_itConsumption it) - 1) [2,4,6,8,10]) f' it
, withSoundStart tap3S
, useAmmoUpTo 1
, applyInaccuracy
, withMuzFlareI
-- , spreadLoaded
, withTorqueAfter
, withRecoil
]
BangConeMod ->
[ ammoCheckI
, hammerCheckI
, useTimeCheck
, withSoundStart bangEchoS
, useAllAmmo
, withTorqueAfter
, withRecoil
, duplicateLoaded
, withMuzFlareI
, applyInaccuracy
, withRandomOffset
, withRandomItemUpdate coneRandItemUpdate
, withRandomItemParams coneRandItemParams
]
where
f = do
nzpres <- state $ randomR (3,4)
return $ sprayNozzles . ix 0 . nzPressure .~ nzpres
increasecycleLasCircle it = it & itParams . lasCycle %~ (flip mod 2000 . (+ 1))
--f it = [it & itParams . lasCycle +~ x | x <- [0,100 .. 1900] ]
fLasCircle it = [it & itParams . lasCycle +~ x | x <- [0,50 .. 1999] ]
increasecycleLasWide n it = case _useHammer (_itUse it) of
HammerUp -> it & itParams . lasCycle .~ 1
_ -> it & itParams . lasCycle %~ (min (n * 5) . (+ 1))
xsLasWide it = [ V2 ((0.2*yoff x) ^ (2::Int)) (yoff x) | x <- [(0::Int)..n'-1] ]
where
yoff x = fromIntegral x - fromIntegral (n'-1) / 2
n' = _lasCycle (_itParams it)
thegapDualBeam = _dbGap . _itParams
directedTelPos it cr w = (p,a)
where
p = fromMaybe (_crPos cr) $ it ^? itTargeting . tgPos . _Just
a = argV (mouseWorldPos w -.- p)
moddelay x = itConsumption . laAmmoType . amBullet . buState .~ DelayedBullet x
modcrpos x cr = cr & crDir %~ tweenAngles x (_crOldDir cr)
& crPos %~ tweenPoints x (_crOldPos cr)
useHeld :: HeldUse -> Item -> Creature -> World -> World
useHeld hu = case hu of
@@ -274,3 +400,26 @@ fireRemoteShell it cr w = set (creatures . ix cid . crInv . ix j . itUse . rUse)
, PJRemoteDirection 340 0 cid itid
]
j = crSel cr
caneStickSoundChoice :: Item -> SoundID
caneStickSoundChoice it
| _laLoaded (_itConsumption it) < 2 = tap3S
| otherwise = shotgunS
bangStickSoundChoice :: Item -> SoundID
bangStickSoundChoice it
| _laLoaded (_itConsumption it) < 2 = tap3S
| otherwise = shotgunS
coneRandItemUpdate :: State StdGen (Item -> Item)
coneRandItemUpdate = do
wth <- state $ randomR (1,5)
return (itConsumption . laAmmoType . amBullet . buWidth .~ wth)
coneRandItemParams :: State StdGen (ItemParams -> ItemParams)
coneRandItemParams = do
muzv <- state $ randomR (0.5,1)
rifl <- state $ randomR (0.3,0.9)
return $ \itparams -> itparams
{ _muzVel = muzv
, _rifling = rifl
}