Move muzzles out of records
This commit is contained in:
+190
-34
@@ -10,17 +10,16 @@ module Dodge.HeldUse (
|
||||
heldEffectMuzzles,
|
||||
) where
|
||||
|
||||
import Dodge.Base
|
||||
import Color
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Data.Maybe
|
||||
import Dodge.Base.Collide
|
||||
import Dodge.BaseTriggerType
|
||||
import Dodge.Creature.Action
|
||||
import Dodge.Data.ComposedItem
|
||||
import Dodge.Data.DoubleTree
|
||||
import Dodge.Data.MuzzleEffect
|
||||
import Dodge.Data.World
|
||||
import Dodge.Gas
|
||||
import Dodge.Inventory.Lock
|
||||
@@ -102,10 +101,10 @@ hammerCheck f pt it cr
|
||||
id
|
||||
| otherwise = f it cr
|
||||
where
|
||||
-- g x = (x, WdWdFromItCrixWdWd (upitm x) (_crID cr) ItCrWdItemHeldEffectNoHammer)
|
||||
-- upitm x =
|
||||
-- it -- & ldtValue . itUse . heldParams . weaponRepeat .~ []
|
||||
-- & ldtValue . itUse . heldFrame .~ x
|
||||
-- g x = (x, WdWdFromItCrixWdWd (upitm x) (_crID cr) ItCrWdItemHeldEffectNoHammer)
|
||||
-- upitm x =
|
||||
-- it -- & ldtValue . itUse . heldParams . weaponRepeat .~ []
|
||||
-- & ldtValue . itUse . heldFrame .~ x
|
||||
|
||||
g x = (x, WdWdBurstFireRepetition (_crID cr) (it ^?! ldtValue . itLocation . ilInvID))
|
||||
|
||||
@@ -136,36 +135,191 @@ useTimeCheck f item cr w = case item ^? ldtValue . itUse . heldDelay of
|
||||
|
||||
heldEffectMuzzles :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
|
||||
heldEffectMuzzles t cr w =
|
||||
doHeldUseEffect t cr .
|
||||
uncurry (applyCME (_ldtValue t) cr) .
|
||||
foldl' (useLoadedAmmo t cr) (CME False, w) $ loadedmuzzles
|
||||
doHeldUseEffect t cr
|
||||
. uncurry (applyCME (_ldtValue t) cr)
|
||||
. foldl' (useLoadedAmmo t cr) (False, w)
|
||||
$ loadedmuzzles
|
||||
where
|
||||
-- & doWeaponRepetitions upitm cr
|
||||
|
||||
muzzles = t ^. ldtValue . itUse . heldMuzzles
|
||||
--muzzles = t ^. ldtValue . itUse . heldMuzzles
|
||||
muzzles = itemMuzzles $ t ^. ldtValue
|
||||
--(upitm, loadedmuzzles) = mapAccumR loadMuzzle t muzzles
|
||||
(_, loadedmuzzles) = mapAccumR loadMuzzle t muzzles
|
||||
|
||||
itemMuzzles :: Item -> [Muzzle]
|
||||
itemMuzzles itm = case itm ^. itType of
|
||||
HELD ALTERIFLE -> dbwMuzzles & ix 0 . mzPos .~ V2 25 0
|
||||
& ix 0 . mzAmmoSlot .~ _alteRifleSwitch (_itParams itm)
|
||||
HELD hit -> heldItemMuzzles hit
|
||||
DETECTOR {} -> dbwMuzzles & ix 0 . mzEffect .~ MuzzleDetector
|
||||
& ix 0 . mzAmmoPerShot .~ UseExactly 100
|
||||
_ -> []
|
||||
|
||||
heldItemMuzzles :: HeldItemType -> [Muzzle]
|
||||
heldItemMuzzles = \case
|
||||
BANGSTICK i -> [ Muzzle
|
||||
(V2 10 0)
|
||||
a
|
||||
0.01
|
||||
0
|
||||
NoFlare
|
||||
MuzzleShootBullet
|
||||
(UseExactly 1)
|
||||
0
|
||||
| a <- spreadAroundCenter i baseStickSpread
|
||||
]
|
||||
& ix 0 . mzFlareType .~ NoLightFlare
|
||||
& ix (i `div` 2) . mzFlareType .~ MiniGunFlare
|
||||
& ix (i-1) . mzFlareType .~ NoLightFlare
|
||||
PISTOL -> [Muzzle (V2 10 0) 0 0.05 0 BasicFlare MuzzleShootBullet (UseExactly 1) 0]
|
||||
AUTOPISTOL -> [Muzzle (V2 20 0) 0 0 0 BasicFlare MuzzleShootBullet (UseExactly 1) 0]
|
||||
SMG -> [Muzzle (V2 10 0) 0 0.05 0 BasicFlare MuzzleShootBullet (UseExactly 1) 0]
|
||||
RIFLE -> dbwMuzzles & ix 0 . mzPos .~ V2 25 0
|
||||
BURSTRIFLE -> dbwMuzzles & ix 0 . mzPos .~ V2 25 0
|
||||
& ix 0 . mzInaccuracy .~ 0.05
|
||||
MINIGUNX i ->
|
||||
replicate i
|
||||
(Muzzle (V2 30 0) 0 0.05 0 MiniGunFlare MuzzleShootBullet (UseExactly 1) 0)
|
||||
BANGROD -> dbwMuzzles
|
||||
& ix 0 . mzPos .~ V2 30 0
|
||||
& ix 0 . mzFlareType .~ HeavySmokeFlare
|
||||
ELEPHANTGUN -> dbwMuzzles
|
||||
& ix 0 . mzPos .~ V2 30 0
|
||||
& ix 0 . mzFlareType .~ HeavySmokeFlare
|
||||
& ix 0 . mzInaccuracy .~ 0.05
|
||||
AMR -> dbwMuzzles
|
||||
& ix 0 . mzPos .~ V2 30 0
|
||||
& ix 0 . mzFlareType .~ HeavySmokeFlare
|
||||
& ix 0 . mzInaccuracy .~ 0.05
|
||||
AUTOAMR -> dbwMuzzles
|
||||
& ix 0 . mzPos .~ V2 30 0
|
||||
& ix 0 . mzFlareType .~ HeavySmokeFlare
|
||||
& ix 0 . mzInaccuracy .~ 0.05
|
||||
SNIPERRIFLE -> dbwMuzzles
|
||||
& ix 0 . mzPos .~ V2 30 0
|
||||
& ix 0 . mzFlareType .~ HeavySmokeFlare
|
||||
& ix 0 . mzInaccuracy .~ 0
|
||||
BANGCONE -> [Muzzle (V2 15 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15) 0]
|
||||
BLUNDERBUSS -> [Muzzle (V2 30 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15) 0]
|
||||
GRAPECANNON _ -> [Muzzle (V2 30 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15) 0]
|
||||
TORCH -> dbwMuzzles & ix 0 . mzPos .~ V2 10 0
|
||||
VOLLEYGUN i -> vgunMuzzles i
|
||||
FLAMETHROWER -> flameMuzzles
|
||||
FLAMESPITTER -> flameMuzzles & ix 0 . mzEffect . nzPressure .~ UniRandFloat 3 4
|
||||
RLAUNCHER -> dbwMuzzles
|
||||
& ix 0 . mzInaccuracy .~ 0
|
||||
& ix 0 . mzEffect .~ MuzzleRLauncher
|
||||
& ix 0 . mzPos .~ V2 20 0
|
||||
GLAUNCHER -> dbwMuzzles
|
||||
& ix 0 . mzInaccuracy .~ 0
|
||||
& ix 0 . mzEffect .~ MuzzleGLauncher
|
||||
& ix 0 . mzPos .~ V2 20 0
|
||||
RLAUNCHERX i ->
|
||||
getZipList
|
||||
( ZipList [Muzzle (V2 20 0) a 0 | a <- take i [0, 2 * pi / fromIntegral i ..]]
|
||||
<*> ZipList [0 ..]
|
||||
<*> pure NoFlare
|
||||
<*> pure MuzzleRLauncher
|
||||
<*> pure (UseExactly 1)
|
||||
<*> pure 0
|
||||
)
|
||||
LASER -> dbwMuzzles
|
||||
& ix 0 . mzPos .~ V2 6 0
|
||||
& ix 0 . mzInaccuracy .~ 0
|
||||
& ix 0 . mzFlareType .~ LasGunFlare
|
||||
& ix 0 . mzEffect .~ MuzzleLaser
|
||||
TESLAGUN -> dbwMuzzles
|
||||
& ix 0 . mzPos .~ V2 10 0
|
||||
& ix 0 . mzInaccuracy .~ 0
|
||||
& ix 0 . mzFlareType .~ TeslaGunFlare
|
||||
& ix 0 . mzEffect .~ MuzzleTesla
|
||||
TRACTORGUN -> dbwMuzzles
|
||||
& ix 0 . mzPos .~ V2 30 0
|
||||
& ix 0 . mzInaccuracy .~ 0
|
||||
& ix 0 . mzFlareType .~ NoFlare
|
||||
& ix 0 . mzEffect .~ MuzzleTractor
|
||||
SHATTERGUN -> dbwMuzzles
|
||||
& ix 0 . mzPos .~ V2 30 0
|
||||
& ix 0 . mzInaccuracy .~ 0
|
||||
& ix 0 . mzEffect .~ MuzzleShatter
|
||||
BLINKER -> dbwMuzzles
|
||||
& ix 0 . mzEffect .~ MuzzleBlink
|
||||
& ix 0 . mzAmmoPerShot .~ UseExactly 10000000
|
||||
BLINKERUNSAFE -> dbwMuzzles
|
||||
& ix 0 . mzEffect .~ MuzzleUnsafeBlink
|
||||
& ix 0 . mzAmmoPerShot .~ UseExactly 10000000
|
||||
REWINDER -> dbwMuzzles
|
||||
& ix 0 . mzEffect .~ MuzzleRewind
|
||||
& ix 0 . mzAmmoPerShot .~ UseExactly 100000
|
||||
TIMESTOPPER -> dbwMuzzles
|
||||
& ix 0 . mzEffect .~ MuzzleStopper
|
||||
& ix 0 . mzAmmoPerShot .~ UseExactly 100000
|
||||
TIMESCROLLER -> dbwMuzzles
|
||||
& ix 0 . mzEffect .~ MuzzleScroller
|
||||
& ix 0 . mzAmmoPerShot .~ UseExactly 100000
|
||||
_ -> [ Muzzle
|
||||
{ _mzPos = V2 20 0
|
||||
, _mzRot = 0
|
||||
, _mzInaccuracy = 0.05
|
||||
, _mzAmmoSlot = 0
|
||||
, _mzFlareType = NoFlare
|
||||
, _mzEffect = MuzzleShootBullet
|
||||
, _mzAmmoPerShot = UseExactly 1
|
||||
, _mzFrame = 0
|
||||
}
|
||||
]
|
||||
|
||||
baseStickSpread :: Float
|
||||
baseStickSpread = 0.2
|
||||
|
||||
dbwMuzzles :: [Muzzle]
|
||||
dbwMuzzles = [Muzzle (V2 15 0) 0 0.01 0 BasicFlare MuzzleShootBullet (UseExactly 1) 0]
|
||||
|
||||
flameMuzzles :: [Muzzle]
|
||||
flameMuzzles =
|
||||
[ Muzzle (V2 18 0) 0 0 0 NoFlare MuzzleNozzle
|
||||
{ _nzPressure = ConstFloat 4
|
||||
, _nzMaxWalkAngle = 0.2
|
||||
, _nzWalkSpeed = 0.01
|
||||
}
|
||||
(UseExactly 1)
|
||||
0
|
||||
]
|
||||
|
||||
vgunMuzzles :: Int -> [Muzzle]
|
||||
vgunMuzzles i =
|
||||
getZipList
|
||||
(ZipList [Muzzle (V2 15 x) 0 0.01 | x <- spreadAroundCenter i 6]
|
||||
<*> ZipList [0..i-1]
|
||||
<*> pure MiniGunFlare
|
||||
<*> pure MuzzleShootBullet
|
||||
<*> pure (UseExactly 1)
|
||||
<*> ZipList [0..i-1]
|
||||
)
|
||||
|
||||
doHeldUseEffect :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
|
||||
doHeldUseEffect t cr w = case t ^. ldtValue . itType of
|
||||
HELD (VOLLEYGUN x) -> fromMaybe w $ do
|
||||
i <- t ^? ldtValue . itLocation . ilInvID
|
||||
let g = w ^. randGen
|
||||
(is, g') = runState (shuffle [0 .. x -1]) g
|
||||
return $
|
||||
w & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix i . itUse . heldMuzzles %~ zipWith (\j mz -> mz & mzFrame .~ j) is
|
||||
& randGen .~ g'
|
||||
-- HELD (VOLLEYGUN x) -> fromMaybe w $ do
|
||||
-- i <- t ^? ldtValue . itLocation . ilInvID
|
||||
-- let g = w ^. randGen
|
||||
-- (is, g') = runState (shuffle [0 .. x -1]) g
|
||||
-- return $
|
||||
-- w & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix i . itUse . heldMuzzles %~ zipWith (\j mz -> mz & mzFrame .~ j) is
|
||||
-- & randGen .~ g'
|
||||
HELD ALTERIFLE -> fromMaybe w $ do
|
||||
i <- t ^? ldtValue . itLocation . ilInvID
|
||||
return $
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix i
|
||||
. itUse
|
||||
. heldMuzzles
|
||||
. ix 0
|
||||
. mzAmmoSlot
|
||||
. itParams . alteRifleSwitch
|
||||
-- . itUse
|
||||
-- . heldMuzzles
|
||||
-- . ix 0
|
||||
-- . mzAmmoSlot
|
||||
%~ ((`mod` 2) . (+ 1))
|
||||
_ -> w
|
||||
|
||||
--doHeldUseEffect t cr w = case t ^? ldtValue . itUse . heldUseEffect of
|
||||
-- Just (RandomiseMuzzleFrames x) -> fromMaybe w $ do
|
||||
-- i <- t ^? ldtValue . itLocation . ilInvID
|
||||
@@ -198,9 +352,9 @@ doHeldUseEffect t cr w = case t ^. ldtValue . itType of
|
||||
-- itm & ldtValue . itUse . heldParams . weaponRepeat .~ []
|
||||
-- & ldtValue . itUse . heldFrame .~ x
|
||||
|
||||
applyCME :: Item -> Creature -> CumulativeMuzzleEffect -> World -> World
|
||||
applyCME :: Item -> Creature -> Bool -> World -> World
|
||||
applyCME itm cr cme
|
||||
| _cmeSound cme =
|
||||
| cme =
|
||||
applyInvLock itm cr
|
||||
. applySoundCME itm cr
|
||||
. applySidePush spush cr
|
||||
@@ -258,12 +412,12 @@ itemSidePush = \case
|
||||
BLINKERUNSAFE -> 0
|
||||
|
||||
applyInvLock :: Item -> Creature -> World -> World
|
||||
applyInvLock itm cr
|
||||
| i <- itemInvLock itm
|
||||
, i > 0 =
|
||||
(cWorld . lWorld . delayedEvents .:~ (i, UnlockInv cid))
|
||||
. lockInv cid
|
||||
| otherwise = id
|
||||
applyInvLock itm cr = case itemInvLock itm of
|
||||
i
|
||||
| i > 0 ->
|
||||
(cWorld . lWorld . delayedEvents .:~ (i, UnlockInv cid))
|
||||
. lockInv cid
|
||||
_ -> id
|
||||
where
|
||||
cid = _crID cr
|
||||
|
||||
@@ -445,7 +599,7 @@ heldTorqueAmount = \case
|
||||
FLAMEWALL -> 0
|
||||
BLOWTORCH -> 0
|
||||
SPARKGUN -> 0
|
||||
TESLAGUN -> 0
|
||||
TESLAGUN -> 0.01
|
||||
LASER -> 0
|
||||
TRACTORGUN -> 0
|
||||
RLAUNCHER -> 0
|
||||
@@ -557,11 +711,11 @@ isAmmoIntLink _ _ = False
|
||||
useLoadedAmmo ::
|
||||
LabelDoubleTree ComposeLinkType Item ->
|
||||
Creature ->
|
||||
(CumulativeMuzzleEffect, World) ->
|
||||
(Bool, World) ->
|
||||
Maybe (Muzzle, Int, LabelDoubleTree ComposeLinkType Item) ->
|
||||
(CumulativeMuzzleEffect, World)
|
||||
(Bool, World)
|
||||
useLoadedAmmo _ _ (cme, w) Nothing = (cme, w)
|
||||
useLoadedAmmo itmtree cr (cme, w) (Just (mz, x, magtree)) = (,) (cme & cmeSound .~ True) $
|
||||
useLoadedAmmo itmtree cr (_, w) (Just (mz, x, magtree)) = (,) True $
|
||||
removeAmmoFromMag x mid cr . makeMuzzleFlare mz itmtree cr $ case _mzEffect mz of
|
||||
MuzzleShootBullet -> shootBullet itmtree cr (mz, x, magtree) w
|
||||
MuzzleLaser -> creatureShootLaser itmtree cr mz w
|
||||
@@ -622,7 +776,9 @@ walkNozzle mz itm cr w = fromMaybe w $ do
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix (_crID cr) . crInv
|
||||
. ix invid
|
||||
. itParams . nzAngle %~ f
|
||||
. itParams
|
||||
. nzAngle
|
||||
%~ f
|
||||
& randGen .~ g
|
||||
where
|
||||
nz = _mzEffect mz
|
||||
|
||||
Reference in New Issue
Block a user