Add more weapons to attachment chain effects

This commit is contained in:
2024-09-18 19:06:57 +01:00
parent 2c96a514ea
commit 765e08117a
11 changed files with 263 additions and 183 deletions
+4 -4
View File
@@ -3,15 +3,15 @@ module Dodge.Bullet (
-- shootBullet,
) where
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
--import Dodge.Data.ComposedItem
--import Dodge.Data.DoubleTree
import Linear
import Dodge.Item.Weapon.Bullet
import System.Random
import Data.Foldable
import Data.Maybe
import Dodge.Base.Coordinate
import Dodge.Creature.HandPos
--import Dodge.Base.Coordinate
--import Dodge.Creature.HandPos
import Dodge.Creature.Test
import Dodge.Data.World
import Dodge.EnergyBall
+3 -5
View File
@@ -269,12 +269,10 @@ testInventory =
stackedInventory :: [Item]
stackedInventory =
[ burstRifle
, bangCone
, megaTinMag
, volleyGun 3
, tinMag
, tinMag
, tinMag
, teslaGun
, lasGun
, megaBattery
, bulletSynthesizer
, drumMag
, launcher
+3 -3
View File
@@ -21,7 +21,7 @@ data Huse
| HeldFireRemoteShell
| HeldExplodeRemoteShell Int Int
| HeldDetectorEffect Detector
| HeldTeslaArc
-- | HeldTeslaArc
| HeldLaser
| HeldCircleLaser
| HeldDualLaser
@@ -71,7 +71,7 @@ data HeldMod
| FlameSpitterRepeatMod
| FlameThrowerMod
| LauncherMod
| TeslaMod
-- | TeslaMod
-- | CircleLaserMod
| LasWideMod Int
| DualBeamMod
@@ -88,7 +88,7 @@ data HeldMod
-- | BangRodMod
-- | ElephantGunMod
-- | AutoAmrMod
| MachineGunMod
-- | MachineGunMod
-- | ModWithDirectedTeleport HeldMod
-- | BangStickMod
| PistolMod
+1
View File
@@ -139,6 +139,7 @@ data FlareType = DefaultFlareType
| MiniGunFlare
| HeavySmokeFlare
| LasGunFlare
| TeslaGunFlare
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data MuzzleEffect
= MuzzleShootBullet
+80 -30
View File
@@ -5,6 +5,7 @@ module Dodge.HeldUse
-- )
where
import Dodge.Base.Collide
import Dodge.Inventory.Lock
import Dodge.WorldEvent.Cloud
import Dodge.LightSource
@@ -79,12 +80,12 @@ heldEffect effecttype = case effecttype of
-- , ammoCheckI
, blCheck
]
TeslaMod -> foldl' (&) (shootTeslaArc . _ldtValue)
[ useAmmoAmount 1
, withSoundForI elecCrackleS 1
, withTempLight 1 100 (V3 0 0 1)
, ammoCheckI
]
-- TeslaMod -> foldl' (&) (shootTeslaArc . _ldtValue)
-- [ useAmmoAmount 1
-- , withSoundForI elecCrackleS 1
-- , withTempLight 1 100 (V3 0 0 1)
-- , ammoCheckI
-- ]
LasWideMod n -> foldl' (&) (shootLaser . _ldtValue)
[ useAmmoAmount 1
, withItem $ \it ->
@@ -454,6 +455,8 @@ makeMuzzleFlare mz itm cr = case mz ^. mzFlareType of
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
HeavySmokeFlare -> basicMuzFlare pos dir
LasGunFlare -> flareCircleAt (_lasColor $ _itParams itm) 0.8 (pos `v2z` 20)
TeslaGunFlare -> cWorld . lWorld . tempLightSources .:~
tlsTimeRadColPos 1 100 (V3 0 0 1) (pos `v2z` 10)
where
pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
dir = _crDir cr + _mzRot mz
@@ -464,6 +467,7 @@ basicMuzFlare pos dir = 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
-- need to add these to muzzle flare
makeMuzzleSmoke :: Muzzle -> Item -> Creature -> World -> World
makeMuzzleSmoke mz itm cr w = case mz ^. mzFlareType of
DefaultFlareType -> w
@@ -471,6 +475,7 @@ makeMuzzleSmoke mz itm cr w = case mz ^. mzFlareType of
MiniGunFlare -> smokeCloudAt (greyN 0.5) 5 400 5 pos w
HeavySmokeFlare -> foldl' (flip $ smokeCloudAt black 20 400 5 . (+.+.+ pos) . (* 8)) w ps'
LasGunFlare -> w
TeslaGunFlare -> w
where
ps = replicateM 2 randOnUnitSphere & evalState $ _randGen w
ps' = replicateM 4 randOnUnitSphere & evalState $ _randGen w
@@ -484,20 +489,65 @@ isAmmoIntLink _ _ = False
useLoadedAmmo :: Item -> Creature -> (CumulativeMuzzleEffect,World) -> (Muzzle,Int,Maybe Int)
-> (CumulativeMuzzleEffect,World)
useLoadedAmmo _ _ (cme,w) (_,0,_) = (cme, w)
useLoadedAmmo itm cr (cme,w) (mz,x,mid) = case _mzEffect mz of
MuzzleShootBullet ->
useLoadedAmmo itm cr (cme,w) (mz,x,mid) = (,) (cme & cmeSound .~ True) $
removeAmmoFromMag x mid cr . makeMuzzleFlare mz itm cr $ case _mzEffect mz of
MuzzleShootBullet -> shootBullet itm cr w (mz,x,mid)
MuzzleLaser -> shootLaser' itm cr mz w
MuzzleTesla -> shootTeslaArc itm cr mz w
MuzzleTractor -> shootTractorBeam itm cr w
MuzzleLauncher -> createProjectile' mid mz itm cr w
shootTractorBeam :: Item -> Creature -> World -> World
shootTractorBeam _ cr w = w & cWorld . lWorld . tractorBeams .:~ tractorBeamAt' spos outpos dir power
where
cpos = _crPos cr
spos = cpos +.+ (_crRad cr + 10) *.* unitVectorAtAngle dir
xpos = cpos +.+ 400 *.* unitVectorAtAngle dir
dir = _crDir cr
outpos = fst $ collidePointWallsFilter (const True) cpos xpos w
power = _attractionPower . _itParams $ _crInv cr IM.! itRef
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
fromMaybe (cme,w) $ do
tractorBeamAt' :: Point2 -> Point2 -> Float -> Point2 -> TractorBeam
tractorBeamAt' pos outpos dir power =
TractorBeam
{ _tbPos = pos
, _tbStartPos = outpos
, _tbVel = d
, _tbTime = 10
}
where
d = unitVectorAtAngle dir * power
shootLaser' :: Item -> Creature -> Muzzle -> World -> World
shootLaser' itm cr mz w = w
& randGen .~ g
&
cWorld . lWorld . lasers
.:~ lasRayAt
(_lasColor $ _itParams itm)
(_lasDamage $ _itParams itm)
(_phaseV $ _itParams itm)
pos
dir
where
pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
(a,g) = randomR (-inacc,inacc) $ _randGen w
inacc = _mzInaccuracy mz
dir = _crDir cr + _mzRot mz + a
removeAmmoFromMag x mid cr = fromMaybe id $ do
magid <- mid
return $ cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix magid . itUse . amagLoadStatus . iaLoaded -~ x
shootBullet :: Item -> Creature -> World -> (Muzzle,Int,Maybe Int) -> World
shootBullet itm cr w (mz,x,mid) = fromMaybe w $ do
magid <- mid
-- should be able to pass the magazine in from elsewhere?
thebullet <- cr ^? crInv . ix magid . itUse . amagParams . ampBullet
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))
return $ w & flip (foldl' (&)) (replicate x (makeBullet thebullet itm cr mz))
& makeMuzzleFlare mz itm cr
& makeMuzzleSmoke mz itm cr
)
where
cid = _crID cr
@@ -543,7 +593,7 @@ useMod :: HeldMod ->
[(LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World)
-> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World]
useMod hm = case hm of
TractorMod -> undefined
-- TractorMod -> undefined
FireRemoteShellMod -> undefined
ExplodeRemoteShellMod -> undefined
DoNothingMod -> undefined
@@ -586,12 +636,12 @@ useMod hm = case hm of
-- , ammoCheckI
, blCheck
]
TeslaMod ->
[ useAmmoAmount 1
, withSoundForI elecCrackleS 1
, withTempLight 1 100 (V3 0 0 1)
, ammoCheckI
]
-- TeslaMod ->
-- [ useAmmoAmount 1
-- , withSoundForI elecCrackleS 1
-- , withTempLight 1 100 (V3 0 0 1)
-- , ammoCheckI
-- ]
-- CircleLaserMod ->
-- [ duplicateItem fLasCircle
-- , useAmmoAmount 1
@@ -733,13 +783,13 @@ useMod hm = case hm of
-- , useTimeCheck
-- , ammoCheckI -- cf ElephantGun
-- ]
MachineGunMod ->
[ withFlare
, withThinSmokeI
, withSoundStart bangEchoS
, rateIncAB (torqueBeforeAtLeast 0.1 0.1) withTorqueAfter
, ammoCheckI
]
-- MachineGunMod ->
-- [ withFlare
-- , withThinSmokeI
-- , withSoundStart bangEchoS
-- , rateIncAB (torqueBeforeAtLeast 0.1 0.1) withTorqueAfter
-- , ammoCheckI
-- ]
-- ModWithDirectedTeleport hm' ->
-- reverse $ withPosDirWallCheck directedTelPos : useMod hm'
-- BangStickMod ->
@@ -878,7 +928,7 @@ useHeld hu = case hu of
HeldPJCreationX _ -> usePjCreationX
HeldFireRemoteShell -> fireRemoteShell
HeldDetectorEffect dt -> detectorEffect dt . _ldtValue
HeldTeslaArc -> shootTeslaArc . _ldtValue
-- HeldTeslaArc -> shootTeslaArc . _ldtValue
HeldLaser -> shootLaser . _ldtValue
HeldCircleLaser -> circleLaser . _ldtValue
HeldDualLaser -> shootDualLaser . _ldtValue
@@ -1029,8 +1079,8 @@ mcShootLaser it mc = cWorld . lWorld . lasers .:~ lasRayAt (_lasColor $ _itParam
dam = _lasDamage $ _itParams it
-- | assumes that the item is held
shootTeslaArc :: Item -> Creature -> World -> World
shootTeslaArc it cr w =
shootTeslaArc :: Item -> Creature -> Muzzle -> World -> World
shootTeslaArc it cr mz w =
w'
& cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itParams .~ ip
where
+4
View File
@@ -63,6 +63,10 @@ shellMag =
}
, _amagType = ProjectileAmmo
}
megaBattery :: Item
megaBattery = battery
& itUse . amagLoadStatus . iaMax .~ 1000000
& itUse . amagLoadStatus . iaLoaded .~ 1000000
battery :: Item
battery =
+5 -2
View File
@@ -22,17 +22,20 @@ sparkGun =
teslaGun :: Item
teslaGun =
defaultBatteryGun
& itUse . heldParams .~ BeamShooterParams (elecCrackleS,2)
& itDimension . dimRad .~ 9
& itDimension . dimCenter .~ V3 4 0 0
& itParams .~ teslaParams
-- & itUse . heldUse .~ HeldTeslaArc --shootTeslaArc
& itUse . heldDelay .~ NoDelay
& itUse . heldMods .~ TeslaMod
& itUse . heldMods .~ PistolMod
& itUse . heldAim . aimWeight .~ 6
& itUse . heldAim . aimStance .~ TwoHandFlat
-- & itUse . heldAim . aimMuzPos .~ 4
& itUse . heldAim . aimMuzzles .~ [Muzzle (V2 4 0) 0 0 0 DefaultFlareType MuzzleTesla]
& itUse . heldAim . aimMuzzles .~ [Muzzle (V2 4 0) 0 0 0 TeslaGunFlare MuzzleTesla]
& itType . iyBase .~ HELD TESLAGUN
& itUse . heldAmmoTypes .~ singleAmmo ElectricalAmmo
& itUse . heldTriggerType .~ AutoTrigger
lasGun :: Item
lasGun =
+23
View File
@@ -32,6 +32,29 @@ createProjectile ammoitem muz itm cr = fromMaybe failsound $ do
Just 0 -> soundStart (CrWeaponSound (_crID cr) 0) (_crPos cr) click1S Nothing w'
_ -> soundContinue (CrWeaponSound (_crID cr) 0) (_crPos cr) click1S Nothing w'
createProjectile' :: Maybe Int -> Muzzle -> Item -> Creature -> World -> World
createProjectile' mmagid muz itm cr = fromMaybe failsound $ do
magid <- mmagid
ammoitem <- cr ^? crInv . ix magid
matype <- ammoitem ^? itUse . amagType
guard $ matype == ProjectileAmmo
j <- ammoitem ^? itLocation . ipInvID
pt <- ammoitem ^? itUse . amagParams . ampPjCreation
return $ case pt of
CreateShell -> fireShell ammoitem muz itm cr . extrafuncs j
CreateTrackingShell -> fireTrackingShell ammoitem muz itm cr . extrafuncs j
where
--extrafuncs j = cancelanyreloading . startthesound . useammo j
extrafuncs j = startthesound . useammo j
useammo j = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix j . itUse . amagLoadStatus . iaLoaded -~ 1
--cancelanyreloading = cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
-- the sound should be moved to the projectile firing
startthesound = soundMultiFrom [CrWeaponSound (_crID cr) j | j <- [0..3]] (_crPos cr) tap4S Nothing
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'
fireShell :: Item -> Muzzle -> Item -> Creature -> World -> World
fireShell ammoitem muz it cr =
makeShell