Continue weapon effect chain refactor
This commit is contained in:
+144
-129
@@ -1,5 +1,11 @@
|
||||
module Dodge.HeldUse where
|
||||
module Dodge.HeldUse
|
||||
-- ( heldEffect
|
||||
-- , mcUseHeld
|
||||
-- )
|
||||
where
|
||||
|
||||
import Dodge.WorldEvent.Cloud
|
||||
import Dodge.LightSource
|
||||
import qualified SDL
|
||||
import Dodge.Base.You
|
||||
import Dodge.Data.MuzzleEffect
|
||||
@@ -120,18 +126,18 @@ heldEffect effecttype = case effecttype of
|
||||
, ammoCheckI
|
||||
, blCheck
|
||||
]
|
||||
BangCaneMod -> bulletGunEffect
|
||||
[ withFlare
|
||||
, withSmoke 1 black 20 200 5
|
||||
, withRecoil
|
||||
, duplicateLoadedBarrels
|
||||
, withTorqueAfter
|
||||
, useAmmoAmount 1
|
||||
, withSoundStart tap3S
|
||||
, useTimeCheck
|
||||
, ammoCheckI
|
||||
, blCheck
|
||||
]
|
||||
-- BangCaneMod -> bulletGunEffect
|
||||
-- [ withFlare
|
||||
-- , withSmoke 1 black 20 200 5
|
||||
-- , withRecoil
|
||||
-- , duplicateLoadedBarrels
|
||||
-- , withTorqueAfter
|
||||
-- , useAmmoAmount 1
|
||||
-- , withSoundStart tap3S
|
||||
-- , useTimeCheck
|
||||
-- , ammoCheckI
|
||||
-- , blCheck
|
||||
-- ]
|
||||
VolleyGunMod -> bulletGunEffect
|
||||
[ withRecoil
|
||||
, withFlare
|
||||
@@ -154,18 +160,18 @@ heldEffect effecttype = case effecttype of
|
||||
, ammoCheckI
|
||||
, blCheck
|
||||
]
|
||||
AutoRifleMod -> bulletGunEffect
|
||||
-- note this is the same as BangCanemMod with the first changed
|
||||
[ withFlare
|
||||
, withSmoke 1 black 20 200 5
|
||||
, withRecoil
|
||||
, duplicateLoadedBarrels
|
||||
, withTorqueAfter
|
||||
, useAmmoAmount 1
|
||||
, withSoundStart tap3S
|
||||
, useTimeCheck
|
||||
, ammoCheckI
|
||||
]
|
||||
-- AutoRifleMod -> bulletGunEffect
|
||||
-- -- note this is the same as BangCanemMod with the first changed
|
||||
-- [ withFlare
|
||||
-- , withSmoke 1 black 20 200 5
|
||||
-- , withRecoil
|
||||
-- , duplicateLoadedBarrels
|
||||
-- , withTorqueAfter
|
||||
-- , useAmmoAmount 1
|
||||
-- , withSoundStart tap3S
|
||||
-- , useTimeCheck
|
||||
-- , ammoCheckI
|
||||
-- ]
|
||||
BangRodMod -> bulletGunEffect
|
||||
[ withRecoil
|
||||
, withFlare
|
||||
@@ -220,40 +226,28 @@ heldEffect effecttype = case effecttype of
|
||||
, blCheck
|
||||
]
|
||||
PistolMod -> bulGunEffect
|
||||
-- bulletGunEffect
|
||||
-- [ withSidePushI 50
|
||||
-- AutoPistolMod -> bulletGunEffect
|
||||
-- [ withFlare
|
||||
-- , withSidePushI 50
|
||||
-- , withRecoil
|
||||
-- , withFlare
|
||||
-- , withTorqueAfter
|
||||
-- , duplicateLoadedBarrels
|
||||
-- , withSoundStart tap3S
|
||||
-- , useAmmoAmount 1
|
||||
-- , useTimeCheck
|
||||
-- , ammoCheckI
|
||||
-- , blCheck
|
||||
-- ]
|
||||
AutoPistolMod -> bulletGunEffect
|
||||
[ withFlare
|
||||
, withSidePushI 50
|
||||
, withRecoil
|
||||
, withTorqueAfter
|
||||
, duplicateLoadedBarrels
|
||||
, withSoundStart tap3S
|
||||
, useAmmoAmount 1
|
||||
, useTimeCheck
|
||||
, ammoCheckI
|
||||
]
|
||||
MachinePistolMod -> bulletGunEffect
|
||||
[ withFlare
|
||||
, withRecoil
|
||||
, withSidePushI 50
|
||||
, withTorqueAfter
|
||||
, duplicateLoadedBarrels
|
||||
, withSoundStart tap1S
|
||||
, useAmmoAmount 1
|
||||
, useTimeCheck
|
||||
, ammoCheckI
|
||||
]
|
||||
-- MachinePistolMod -> bulletGunEffect
|
||||
-- [ withFlare
|
||||
-- , withRecoil
|
||||
-- , withSidePushI 50
|
||||
-- , withTorqueAfter
|
||||
-- , duplicateLoadedBarrels
|
||||
-- , withSoundStart tap1S
|
||||
-- , useAmmoAmount 1
|
||||
-- , useTimeCheck
|
||||
-- , ammoCheckI
|
||||
-- ]
|
||||
BurstRifleMod -> bulletGunEffect
|
||||
[ withRecoil
|
||||
, withFlare
|
||||
@@ -292,17 +286,17 @@ heldEffect effecttype = case effecttype of
|
||||
, withWarmUp crankSlowS
|
||||
, ammoCheckI
|
||||
]
|
||||
SmgMod -> bulletGunEffect
|
||||
[ withFlare
|
||||
, withSidePushI 30
|
||||
, withRecoil
|
||||
, withTorqueAfter
|
||||
, duplicateLoadedBarrels
|
||||
, withSoundStart tap3S
|
||||
, useAmmoAmount 1
|
||||
, useTimeCheck
|
||||
, ammoCheckI
|
||||
]
|
||||
-- SmgMod -> bulletGunEffect
|
||||
-- [ withFlare
|
||||
-- , withSidePushI 30
|
||||
-- , withRecoil
|
||||
-- , withTorqueAfter
|
||||
-- , duplicateLoadedBarrels
|
||||
-- , withSoundStart tap3S
|
||||
-- , useAmmoAmount 1
|
||||
-- , useTimeCheck
|
||||
-- , ammoCheckI
|
||||
-- ]
|
||||
BangConeMod -> bulletGunEffect
|
||||
[ withRandomItem coneRandItemParams
|
||||
, withRandomItemUpdate coneRandItemUpdate
|
||||
@@ -361,15 +355,28 @@ bulGunEffect' :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> Wo
|
||||
bulGunEffect' t cr w = fromMaybe (error "error in bulGunEffect") $ do
|
||||
muzzles <- t ^? ldtValue . itUse . heldAim . aimMuzzles
|
||||
let (_,loadedmuzzles) = mapAccumR loadMuzzle t muzzles
|
||||
cmew = foldl' (useLoadedAmmo (_ldtValue t) cr) (CME 0 0 False,w) loadedmuzzles
|
||||
-- let (_,loadedmuzzles) = ((),[])
|
||||
--cmew = foldl' (useLoadedAmmo (_ldtValue t) cr) (CME 0 0 False,w) loadedmuzzles
|
||||
cmew = foldl' (useLoadedAmmo (_ldtValue t) cr) (CME 0 0 False,w) $ loadedmuzzles
|
||||
return $ uncurry (applyCME (_ldtValue t) cr) cmew
|
||||
-- return $ snd cmew
|
||||
|
||||
applyCME :: Item -> Creature -> CumulativeMuzzleEffect -> World -> World
|
||||
applyCME itm cr cme
|
||||
| _cmeSound cme = applySidePush spush cr . applyTorqueCME itm cr . applyRecoil itm cr
|
||||
| otherwise = id
|
||||
| _cmeSound cme = applySoundCME itm cr . applySidePush spush cr . applyTorqueCME itm cr . applyRecoil itm cr
|
||||
| otherwise = failsound
|
||||
where
|
||||
spush = fromMaybe 0 $ itm ^? itUse . heldParams . sidePush
|
||||
failsound w = case w ^? input . mouseButtons . ix SDL.ButtonLeft of
|
||||
Just 0 -> soundStart (CrWeaponSound (_crID cr) 0) (_crPos cr) click1S Nothing w
|
||||
_ -> soundContinue (CrWeaponSound (_crID cr) 0) (_crPos cr) click1S Nothing w
|
||||
|
||||
applySoundCME :: Item -> Creature -> World -> World
|
||||
applySoundCME itm cr = fromMaybe id $ do
|
||||
soundid <- itm ^? itUse . heldParams . bulGunSound
|
||||
return $ soundMultiFrom [CrWeaponSound cid j | j <- [0..3]] (_crPos cr) soundid Nothing
|
||||
where
|
||||
cid = _crID cr
|
||||
|
||||
applyRecoil :: Item -> Creature -> World -> World
|
||||
applyRecoil itm cr = over (cWorld . lWorld . creatures . ix cid) pushback
|
||||
@@ -409,6 +416,7 @@ applyTorqueCME itm cr w
|
||||
-- (Muzzle,Int,Int) = (muzzle, amountloaded, id of mag taken from)
|
||||
loadMuzzle :: LabelDoubleTree ComposeLinkType Item
|
||||
-> Muzzle -> (LabelDoubleTree ComposeLinkType Item,(Muzzle, Int,Maybe Int))
|
||||
--loadMuzzle t@(LDT _ l _) mz = (t,(mz, 0,Nothing))
|
||||
loadMuzzle t@(LDT _ l _) mz = fromMaybe (t,(mz, 0,Nothing)) $ do
|
||||
let as = _mzAmmoSlot mz
|
||||
amamount = 1
|
||||
@@ -419,8 +427,26 @@ loadMuzzle t@(LDT _ l _) mz = fromMaybe (t,(mz, 0,Nothing)) $ do
|
||||
, (mz, usedammo, mag ^? ldtValue . itLocation . ipInvID)
|
||||
)
|
||||
|
||||
makeMuzzleFlare :: (Muzzle,Int,Maybe Int) -> Item -> Creature -> World -> World
|
||||
makeMuzzleFlare _ _ _ = id
|
||||
makeMuzzleFlare :: Muzzle -> Item -> Creature -> World -> World
|
||||
makeMuzzleFlare mz itm cr = case mz ^. mzFlareType of
|
||||
DefaultFlareType -> id
|
||||
PistolFlare -> makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) (pos `v2z` 20)
|
||||
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
|
||||
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
|
||||
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
|
||||
where
|
||||
pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
|
||||
dir = _crDir cr + _mzRot mz
|
||||
|
||||
makeMuzzleSmoke :: Muzzle -> Item -> Creature -> World -> World
|
||||
makeMuzzleSmoke mz itm cr w = case mz ^. mzFlareType of
|
||||
DefaultFlareType -> w
|
||||
PistolFlare -> foldl' (flip $ smokeCloudAt (greyN 0.5) 20 400 5 . (+.+.+ pos) . (* 8)) w ps
|
||||
|
||||
where
|
||||
ps = replicateM 2 randOnUnitSphere & evalState $ _randGen w
|
||||
pos = addZ 10 $ _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
|
||||
-- , withSmoke 1 black 20 200 5
|
||||
|
||||
isAmmoIntLink :: Int -> ComposeLinkType -> Bool
|
||||
isAmmoIntLink i (AmmoInLink j _) = i == j
|
||||
@@ -428,11 +454,9 @@ isAmmoIntLink _ _ = False
|
||||
|
||||
useLoadedAmmo :: Item -> Creature -> (CumulativeMuzzleEffect,World) -> (Muzzle,Int,Maybe Int)
|
||||
-> (CumulativeMuzzleEffect,World)
|
||||
useLoadedAmmo _ cr (cme,w) (_,0,_) = (cme,failsound w)
|
||||
where
|
||||
failsound = case w ^? input . mouseButtons . ix SDL.ButtonLeft of
|
||||
Just 0 -> soundStart (CrWeaponSound (_crID cr) 0) (_crPos cr) click1S Nothing
|
||||
_ -> soundContinue (CrWeaponSound (_crID cr) 0) (_crPos cr) click1S Nothing
|
||||
--useLoadedAmmo _ cr (cme,w) (_,0,_) = (cme,failsound w)
|
||||
useLoadedAmmo _ _ (cme,w) (_,0,_) = (cme, w)
|
||||
--useLoadedAmmo itm cr (cme,w) (mz,x,mid) = (cme,w)
|
||||
useLoadedAmmo itm cr (cme,w) (mz,x,mid) = fromMaybe (cme,w) $ do
|
||||
magid <- mid
|
||||
-- should be able to pass the magazine in from elsewhere?
|
||||
@@ -440,6 +464,8 @@ useLoadedAmmo itm cr (cme,w) (mz,x,mid) = fromMaybe (cme,w) $ do
|
||||
return $ (cme & cmeSound .~ True,
|
||||
w & cWorld . lWorld . creatures . ix cid . crInv . ix magid . itUse . amagLoadStatus . iaLoaded -~ x
|
||||
& flip (foldl' (&)) (replicate x (makeBullet thebullet itm cr mz))
|
||||
& makeMuzzleFlare mz itm cr
|
||||
& makeMuzzleSmoke mz itm cr
|
||||
)
|
||||
where
|
||||
cid = _crID cr
|
||||
@@ -586,18 +612,18 @@ useMod hm = case hm of
|
||||
-- , ammoCheckI
|
||||
-- , blCheck
|
||||
-- ]
|
||||
BangCaneMod ->
|
||||
[ withFlare
|
||||
, withSmoke 1 black 20 200 5
|
||||
, withRecoil
|
||||
, duplicateLoadedBarrels
|
||||
, withTorqueAfter
|
||||
, useAmmoAmount 1
|
||||
, withSoundStart tap3S
|
||||
, useTimeCheck
|
||||
, ammoCheckI
|
||||
, blCheck
|
||||
]
|
||||
-- BangCaneMod ->
|
||||
-- [ withFlare
|
||||
-- , withSmoke 1 black 20 200 5
|
||||
-- , withRecoil
|
||||
-- , duplicateLoadedBarrels
|
||||
-- , withTorqueAfter
|
||||
-- , useAmmoAmount 1
|
||||
-- , withSoundStart tap3S
|
||||
-- , useTimeCheck
|
||||
-- , ammoCheckI
|
||||
-- , blCheck
|
||||
-- ]
|
||||
VolleyGunMod ->
|
||||
[ withRecoil
|
||||
, withFlare
|
||||
@@ -620,18 +646,18 @@ useMod hm = case hm of
|
||||
, ammoCheckI
|
||||
, blCheck
|
||||
]
|
||||
AutoRifleMod ->
|
||||
-- note this is the same as BangCanemMod with the first changed
|
||||
[ withFlare
|
||||
, withSmoke 1 black 20 200 5
|
||||
, withRecoil
|
||||
, duplicateLoadedBarrels
|
||||
, withTorqueAfter
|
||||
, useAmmoAmount 1
|
||||
, withSoundStart tap3S
|
||||
, useTimeCheck
|
||||
, ammoCheckI
|
||||
]
|
||||
-- AutoRifleMod ->
|
||||
-- -- note this is the same as BangCanemMod with the first changed
|
||||
-- [ withFlare
|
||||
-- , withSmoke 1 black 20 200 5
|
||||
-- , withRecoil
|
||||
-- , duplicateLoadedBarrels
|
||||
-- , withTorqueAfter
|
||||
-- , useAmmoAmount 1
|
||||
-- , withSoundStart tap3S
|
||||
-- , useTimeCheck
|
||||
-- , ammoCheckI
|
||||
-- ]
|
||||
BangRodMod ->
|
||||
[ withRecoil
|
||||
, withFlare
|
||||
@@ -699,28 +725,17 @@ useMod hm = case hm of
|
||||
, ammoCheckI
|
||||
, blCheck
|
||||
]
|
||||
AutoPistolMod ->
|
||||
[ withFlare
|
||||
, withSidePushI 50
|
||||
, withRecoil
|
||||
, withTorqueAfter
|
||||
, duplicateLoadedBarrels
|
||||
, withSoundStart tap3S
|
||||
, useAmmoAmount 1
|
||||
, useTimeCheck
|
||||
, ammoCheckI
|
||||
]
|
||||
MachinePistolMod ->
|
||||
[ withFlare
|
||||
, withRecoil
|
||||
, withSidePushI 50
|
||||
, withTorqueAfter
|
||||
, duplicateLoadedBarrels
|
||||
, withSoundStart tap1S
|
||||
, useAmmoAmount 1
|
||||
, useTimeCheck
|
||||
, ammoCheckI
|
||||
]
|
||||
-- MachinePistolMod ->
|
||||
-- [ withFlare
|
||||
-- , withRecoil
|
||||
-- , withSidePushI 50
|
||||
-- , withTorqueAfter
|
||||
-- , duplicateLoadedBarrels
|
||||
-- , withSoundStart tap1S
|
||||
-- , useAmmoAmount 1
|
||||
-- , useTimeCheck
|
||||
-- , ammoCheckI
|
||||
-- ]
|
||||
BurstRifleMod ->
|
||||
[ withRecoil
|
||||
, withFlare
|
||||
@@ -759,17 +774,17 @@ useMod hm = case hm of
|
||||
, withWarmUp crankSlowS
|
||||
, ammoCheckI
|
||||
]
|
||||
SmgMod ->
|
||||
[ withFlare
|
||||
, withSidePushI 30
|
||||
, withRecoil
|
||||
, withTorqueAfter
|
||||
, duplicateLoadedBarrels
|
||||
, withSoundStart tap3S
|
||||
, useAmmoAmount 1
|
||||
, useTimeCheck
|
||||
, ammoCheckI
|
||||
]
|
||||
-- SmgMod ->
|
||||
-- [ withFlare
|
||||
-- , withSidePushI 30
|
||||
-- , withRecoil
|
||||
-- , withTorqueAfter
|
||||
-- , duplicateLoadedBarrels
|
||||
-- , withSoundStart tap3S
|
||||
-- , useAmmoAmount 1
|
||||
-- , useTimeCheck
|
||||
-- , ammoCheckI
|
||||
-- ]
|
||||
BangConeMod ->
|
||||
[ withRandomItem coneRandItemParams
|
||||
, withRandomItemUpdate coneRandItemUpdate
|
||||
|
||||
Reference in New Issue
Block a user