Refactor, try to limit dependencies
This commit is contained in:
+127
-97
@@ -1,41 +1,41 @@
|
||||
module Dodge.HeldUse where
|
||||
import Dodge.Data
|
||||
|
||||
import Color
|
||||
import Data.Maybe
|
||||
import Data.Traversable
|
||||
import Dodge.Base.Coordinate
|
||||
import Sound.Data
|
||||
import Dodge.Bullet
|
||||
import Dodge.Data.World
|
||||
import Dodge.Gas
|
||||
import Dodge.Item.Location
|
||||
import Dodge.Item.Weapon.BatteryGuns
|
||||
import Dodge.Item.Weapon.Launcher
|
||||
import Dodge.Item.Weapon.Radar
|
||||
import Dodge.Item.Weapon.Shatter
|
||||
import Dodge.Item.Weapon.TriggerType
|
||||
import Dodge.Item.Weapon.Utility
|
||||
import Dodge.Projectile.Create
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.WorldEvent.Flash
|
||||
import Dodge.Item.Location
|
||||
import Dodge.Item.Weapon.Radar
|
||||
import Dodge.Item.Weapon.BatteryGuns
|
||||
import Dodge.Item.Weapon.Utility
|
||||
import Dodge.Item.Weapon.Shatter
|
||||
import Dodge.Item.Weapon.Launcher
|
||||
import Dodge.Projectile.Create
|
||||
import Dodge.Gas
|
||||
import Geometry
|
||||
import qualified IntMapHelp as IM
|
||||
import LensHelp
|
||||
import RandomHelp
|
||||
import Color
|
||||
|
||||
import Data.Maybe
|
||||
import Data.Traversable
|
||||
import Sound.Data
|
||||
|
||||
useMod :: HeldMod -> [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World]
|
||||
useMod hm = case hm of
|
||||
HeldModNothing -> []
|
||||
PoisonSprayerMod ->
|
||||
PoisonSprayerMod ->
|
||||
[ ammoCheckI
|
||||
, withSoundForI foamSprayLoopS 5
|
||||
, useAmmoAmount 1
|
||||
]
|
||||
]
|
||||
FlameSpitterMod ->
|
||||
[ ammoCheckI
|
||||
, useTimeCheck
|
||||
, lockInvFor 10
|
||||
, repeatOnFrames [1..9] FlameSpitterRepeatMod
|
||||
, repeatOnFrames [1 .. 9] FlameSpitterRepeatMod
|
||||
, withRandomItemParams f
|
||||
, useAmmoAmount 1
|
||||
, withSidePushI 5
|
||||
@@ -52,8 +52,8 @@ useMod hm = case hm of
|
||||
[ ammoCheckI
|
||||
, useAmmoAmount 1
|
||||
, withSidePushI 5
|
||||
--, withTempLight 1 100 (V3 1 0 0)
|
||||
, withSidePushAfterI 20
|
||||
, --, withTempLight 1 100 (V3 1 0 0)
|
||||
withSidePushAfterI 20
|
||||
]
|
||||
LauncherMod ->
|
||||
[ hammerCheckI
|
||||
@@ -89,8 +89,8 @@ useMod hm = case hm of
|
||||
]
|
||||
DualBeamMod ->
|
||||
[ ammoCheckI
|
||||
, 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
|
||||
, 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
|
||||
]
|
||||
@@ -112,11 +112,11 @@ useMod hm = case hm of
|
||||
ShatterMod ->
|
||||
[ ammoHammerCheck
|
||||
, useTimeCheck
|
||||
-- , withSoundStart tap3S
|
||||
, useAmmoAmount 1
|
||||
, -- , withSoundStart tap3S
|
||||
useAmmoAmount 1
|
||||
]
|
||||
AmmoCheckMod -> [ ammoCheckI ]
|
||||
AmmoUseCheckMod -> [ ammoUseCheck ]
|
||||
AmmoCheckMod -> [ammoCheckI]
|
||||
AmmoUseCheckMod -> [ammoUseCheck]
|
||||
AmmoHammerTimeUseOneMod ->
|
||||
[ ammoHammerCheck
|
||||
, useTimeCheck
|
||||
@@ -144,7 +144,8 @@ useMod hm = case hm of
|
||||
, withMuzFlareI
|
||||
, withRecoil
|
||||
]
|
||||
AutoRifleMod -> -- note this is the same as BangCanemMod with the first changed
|
||||
AutoRifleMod ->
|
||||
-- note this is the same as BangCanemMod with the first changed
|
||||
[ ammoCheckI
|
||||
, useTimeCheck
|
||||
, withSoundStart tap3S
|
||||
@@ -205,14 +206,14 @@ useMod hm = case hm of
|
||||
, withMuzFlareI
|
||||
, withTorqueAfter
|
||||
, spreadLoaded
|
||||
-- , applyInaccuracy
|
||||
, withRecoil
|
||||
, -- , applyInaccuracy
|
||||
withRecoil
|
||||
]
|
||||
PistolMod ->
|
||||
[ ammoHammerCheck
|
||||
[ ammoHammerCheck
|
||||
, useTimeCheck
|
||||
, useAmmoAmount 1
|
||||
, withSoundStart tap3S
|
||||
, withSoundStart tap3S
|
||||
, applyInaccuracy
|
||||
, withTorqueAfter
|
||||
, withRecoil
|
||||
@@ -220,10 +221,10 @@ useMod hm = case hm of
|
||||
, withMuzFlareI
|
||||
]
|
||||
AutoPistolMod ->
|
||||
[ ammoCheckI
|
||||
[ ammoCheckI
|
||||
, useTimeCheck
|
||||
, useAmmoAmount 1
|
||||
, withSoundStart tap3S
|
||||
, withSoundStart tap3S
|
||||
, applyInaccuracy
|
||||
, withTorqueAfter
|
||||
, withRecoil
|
||||
@@ -234,7 +235,7 @@ useMod hm = case hm of
|
||||
[ ammoCheckI
|
||||
, useTimeCheck
|
||||
, useAmmoAmount 1
|
||||
, withSoundStart tap1S
|
||||
, withSoundStart tap1S
|
||||
, applyInaccuracy
|
||||
, withTorqueAfter
|
||||
, withSidePushI 50
|
||||
@@ -246,7 +247,7 @@ useMod hm = case hm of
|
||||
, useTimeCheck
|
||||
, sideEffectOnFrame 7 (\_ cr -> TorqueCr 0.2 (_crID cr)) --(torqueSideEffect 0.2)
|
||||
, lockInvFor 7
|
||||
, repeatOnFrames [3,6] BurstRifleRepeatMod
|
||||
, repeatOnFrames [3, 6] BurstRifleRepeatMod
|
||||
, withSoundStart tap3S
|
||||
, useAmmoAmount 1
|
||||
, applyInaccuracy
|
||||
@@ -266,22 +267,22 @@ useMod hm = case hm of
|
||||
[ ammoCheckI
|
||||
, withWarmUp crankSlowS
|
||||
, withSoundForI mini1S 2
|
||||
--, withThinSmokeI
|
||||
, withSmoke 1 black 20 200 5
|
||||
, --, 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]
|
||||
]
|
||||
<> [ trigDoAlso' (moddelay x) (modcrpos x) useAmmoParams
|
||||
| x <- map ((/ fromIntegral i) . fromIntegral) [1 .. i -1]
|
||||
]
|
||||
SmgMod ->
|
||||
[ ammoCheckI
|
||||
, useTimeCheck
|
||||
, useAmmoAmount 1
|
||||
, withSoundStart tap3S
|
||||
, withSoundStart tap3S
|
||||
, applyInaccuracy
|
||||
, withTorqueAfter
|
||||
, withRecoil
|
||||
@@ -291,28 +292,28 @@ useMod hm = case hm of
|
||||
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
|
||||
, repeatOnFrames [2,4,6,8,10] RevolverXRepeatMod
|
||||
, withSoundStart tap3S
|
||||
, -- 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
|
||||
, repeatOnFrames [2, 4, 6, 8, 10] RevolverXRepeatMod
|
||||
, withSoundStart tap3S
|
||||
, useAmmoUpTo 1
|
||||
, applyInaccuracy
|
||||
, withMuzFlareI
|
||||
-- , spreadLoaded
|
||||
, withTorqueAfter
|
||||
, -- , spreadLoaded
|
||||
withTorqueAfter
|
||||
, withRecoil
|
||||
]
|
||||
RevolverXRepeatMod ->
|
||||
[ ammoCheckI
|
||||
-- rather than locking the inventory, a better solution may be to check
|
||||
-- that the weapon is still in your hands in the repeated frames
|
||||
, withSoundStart tap3S
|
||||
, -- rather than locking the inventory, a better solution may be to check
|
||||
-- that the weapon is still in your hands in the repeated frames
|
||||
withSoundStart tap3S
|
||||
, useAmmoUpTo 1
|
||||
, applyInaccuracy
|
||||
, withMuzFlareI
|
||||
-- , spreadLoaded
|
||||
, withTorqueAfter
|
||||
, -- , spreadLoaded
|
||||
withTorqueAfter
|
||||
, withRecoil
|
||||
]
|
||||
BangConeMod ->
|
||||
@@ -332,26 +333,27 @@ useMod hm = case hm of
|
||||
]
|
||||
where
|
||||
f = do
|
||||
nzpres <- state $ randomR (3,4)
|
||||
nzpres <- state $ randomR (3, 4)
|
||||
return $ sprayNozzles . ix 0 . nzPressure .~ nzpres
|
||||
increasecycleLasCircle it = it & itParams . lasCycle %~ (flip mod 2000 . (+ 1))
|
||||
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
|
||||
fLasCircle it = [it & itParams . lasCycle +~ x | x <- [0, 50 .. 1999]]
|
||||
increasecycleLasWide n it = case _heldHammer (_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] ]
|
||||
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
|
||||
yoff x = fromIntegral x - fromIntegral (n' -1) / 2
|
||||
n' = _lasCycle (_itParams it)
|
||||
thegapDualBeam = _dbGap . _itParams
|
||||
directedTelPos it cr w = (p,a)
|
||||
directedTelPos it cr w = (p, a)
|
||||
where
|
||||
p = fromMaybe (_crPos cr) $ it ^? itTargeting . tgPos . _Just
|
||||
a = argV (mouseWorldPos w -.- p)
|
||||
moddelay x = itUse . heldConsumption . laAmmoType . amBullet . buDelayFraction .~ x
|
||||
modcrpos x cr = cr & crDir %~ tweenAngles x (_crOldDir cr)
|
||||
& crPos %~ tweenPoints x (_crOldPos cr)
|
||||
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
|
||||
@@ -367,7 +369,7 @@ useHeld hu = case hu of
|
||||
HeldCircleLaser -> circleLaser
|
||||
HeldDualLaser -> shootDualLaser
|
||||
HeldTractor -> aTractorBeam
|
||||
-- HeldSonicWave -> aSonicWave
|
||||
-- HeldSonicWave -> aSonicWave
|
||||
HeldForceField -> useForceFieldGun
|
||||
HeldShatter -> shootShatter
|
||||
HeldExplodeRemoteShell itid pjid -> const $ const $ explodeRemoteRocket itid pjid
|
||||
@@ -376,77 +378,105 @@ usePjCreation :: Item -> Creature -> World -> World
|
||||
usePjCreation it = createProjectile (_amPjCreation (_laAmmoType (_heldConsumption (_itUse it)))) it
|
||||
|
||||
usePjCreationX :: Int -> Item -> Creature -> World -> World
|
||||
usePjCreationX i it cr = foldr f
|
||||
(createProjectile (_amPjCreation (_laAmmoType (_heldConsumption (_itUse it)))) it cr)
|
||||
[1..i-1]
|
||||
usePjCreationX i it cr =
|
||||
foldr
|
||||
f
|
||||
(createProjectile (_amPjCreation (_laAmmoType (_heldConsumption (_itUse it)))) it cr)
|
||||
[1 .. i -1]
|
||||
where
|
||||
f n = (. createProjectile (_amPjCreation (_laAmmoType (_heldConsumption (_itUse it)))) it (cr & crDir +~ (2*pi*fromIntegral n / fromIntegral i)))
|
||||
f n = (. createProjectile (_amPjCreation (_laAmmoType (_heldConsumption (_itUse it)))) it (cr & crDir +~ (2 * pi * fromIntegral n / fromIntegral i)))
|
||||
|
||||
overNozzles :: (Nozzle -> Item -> Creature -> World -> World)
|
||||
-> Item -> Creature -> World -> World
|
||||
overNozzles ::
|
||||
(Nozzle -> Item -> Creature -> World -> World) ->
|
||||
Item ->
|
||||
Creature ->
|
||||
World ->
|
||||
World
|
||||
overNozzles = overNozzles' . overNozzle
|
||||
|
||||
overNozzles' :: (Item -> Creature -> World -> Nozzle -> (World,Nozzle))
|
||||
-> Item -> Creature -> World -> World
|
||||
overNozzles' ::
|
||||
(Item -> Creature -> World -> Nozzle -> (World, Nozzle)) ->
|
||||
Item ->
|
||||
Creature ->
|
||||
World ->
|
||||
World
|
||||
overNozzles' eff it cr w = neww & cWorld . creatures . ix cid . crInv . ix i . itParams . sprayNozzles .~ newNozzles
|
||||
where
|
||||
cid = _crID cr
|
||||
i = crSel $ _creatures (_cWorld w) IM.! cid
|
||||
(neww,newNozzles) = mapAccumR (eff it cr) w $ _sprayNozzles (_itParams it)
|
||||
(neww, newNozzles) = mapAccumR (eff it cr) w $ _sprayNozzles (_itParams it)
|
||||
|
||||
overNozzle :: (Nozzle -> Item -> Creature -> World -> World)
|
||||
-> Item -> Creature -> World -> Nozzle -> (World, Nozzle)
|
||||
overNozzle eff it cr w nz =
|
||||
overNozzle ::
|
||||
(Nozzle -> Item -> Creature -> World -> World) ->
|
||||
Item ->
|
||||
Creature ->
|
||||
World ->
|
||||
Nozzle ->
|
||||
(World, Nozzle)
|
||||
overNozzle eff it cr w nz =
|
||||
( eff nz it (cr & crDir +~ wa + na) w & randGen .~ g
|
||||
, nz & nzCurrentWalkAngle .~ wa)
|
||||
, nz & nzCurrentWalkAngle .~ wa
|
||||
)
|
||||
where
|
||||
na = _nzDir nz
|
||||
(walkamount, g) = randomR (-aspeed,aspeed) (_randGen w)
|
||||
(walkamount, g) = randomR (- aspeed, aspeed) (_randGen w)
|
||||
aspeed = _nzWalkSpeed nz
|
||||
maxa = _nzMaxWalkAngle nz
|
||||
wa = min maxa $ max (negate maxa) (_nzCurrentWalkAngle nz + walkamount)
|
||||
|
||||
useGasParams :: Nozzle -> Item -> Creature -> World -> World
|
||||
useGasParams nz it cr = createGas (_amCreateGas (_laAmmoType (_heldConsumption (_itUse it))))
|
||||
(_nzPressure nz) pos dir cr
|
||||
where
|
||||
useGasParams nz it cr =
|
||||
createGas
|
||||
(_amCreateGas (_laAmmoType (_heldConsumption (_itUse it))))
|
||||
(_nzPressure nz)
|
||||
pos
|
||||
dir
|
||||
cr
|
||||
where
|
||||
dir = _crDir cr
|
||||
pos = _crPos cr +.+ (_nzLength nz *.* unitVectorAtAngle (_crDir cr))
|
||||
|
||||
fireRemoteShell :: Item -> Creature -> World -> World
|
||||
fireRemoteShell it cr w = set (cWorld . creatures . ix cid . crInv . ix j . itUse . rUse)
|
||||
fireRemoteShell it cr w =
|
||||
set
|
||||
(cWorld . creatures . ix cid . crInv . ix j . itUse . heldUse)
|
||||
(HeldExplodeRemoteShell itid i)
|
||||
$ addRemRocket w'
|
||||
$ addRemRocket w'
|
||||
where
|
||||
(w',itid) = getHeldItemLoc cr w
|
||||
i = IM.newKey $ _props (_cWorld w)
|
||||
(w', itid) = getHeldItemLoc cr w
|
||||
i = IM.newKey $ _props (_cWorld w)
|
||||
cid = _crID cr
|
||||
addRemRocket = makeShell it cr
|
||||
[ PJSetScope itid
|
||||
, PJThrust 330 0
|
||||
, PJRemoteDirection 340 0 cid itid
|
||||
]
|
||||
addRemRocket =
|
||||
makeShell
|
||||
it
|
||||
cr
|
||||
[ PJSetScope itid
|
||||
, PJThrust 330 0
|
||||
, PJRemoteDirection 340 0 cid itid
|
||||
]
|
||||
j = crSel cr
|
||||
|
||||
caneStickSoundChoice :: Item -> SoundID
|
||||
caneStickSoundChoice it
|
||||
| _laLoaded (_heldConsumption (_itUse it)) < 2 = tap3S
|
||||
| _laLoaded (_heldConsumption (_itUse it)) < 2 = tap3S
|
||||
| otherwise = shotgunS
|
||||
|
||||
bangStickSoundChoice :: Item -> SoundID
|
||||
bangStickSoundChoice it
|
||||
| _laLoaded (_heldConsumption (_itUse it)) < 2 = tap3S
|
||||
| _laLoaded (_heldConsumption (_itUse it)) < 2 = tap3S
|
||||
| otherwise = shotgunS
|
||||
|
||||
coneRandItemUpdate :: State StdGen (Item -> Item)
|
||||
coneRandItemUpdate = do
|
||||
wth <- state $ randomR (1,5)
|
||||
wth <- state $ randomR (1, 5)
|
||||
return (itUse . heldConsumption . 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
|
||||
}
|
||||
muzv <- state $ randomR (0.5, 1)
|
||||
rifl <- state $ randomR (0.3, 0.9)
|
||||
return $ \itparams ->
|
||||
itparams
|
||||
{ _muzVel = muzv
|
||||
, _rifling = rifl
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user