Separate out bullet effects, allow for tweaking to change these

This commit is contained in:
2021-11-30 13:11:34 +00:00
parent e75cbdf6cb
commit 4d21c0f31a
13 changed files with 207 additions and 81 deletions
+35 -17
View File
@@ -345,6 +345,7 @@ data Item
, _itDimension :: ItemDimension
, _itCurseStatus :: CurseStatus
, _itParams :: ItemParams
, _itTweaks :: ItemTweaks
}
| Consumable
{ _itName :: String
@@ -515,31 +516,47 @@ data AmmoType
| DroneAmmo
{ _amString :: String }
| GenericAmmo
data ItemParams
= NoParams
| ShellLauncher
data ItemTweaks
= NoTweaks
| Tweakable
{ _tweakParams :: IM.IntMap TweakParam
, _tweakSel :: Int
, _shellSpinDrag :: Int
, _shellSpinAmount :: Int
, _shellThrustDelay :: Int
}
| Refracting {_phaseVel :: Float}
| MultiBarrel
{ _barrelSpread :: BarrelSpread
, _barrelNum :: Int
}
| SingleBarrel {_inaccuracy :: Float}
| AngleWalk
{ _maxWalkAngle :: Float
, _currentWalkAngle :: Float
, _walkSpeed :: Float
}
data TweakParam = TweakParam
{ _doTweak :: Int -> Item -> Item
, _curTweak :: Int
, _maxTweak :: Int
, _showTweak :: Int -> String
, _nameTweak :: String
}
data GunBarrels
= MultiBarrel
{ _brlSpread :: BarrelSpread
, _brlNum :: Int
}
| SingleBarrel {_brlInaccuracy :: Float}
data ItemParams
= NoParams
| ShellLauncher
{ _shellSpinDrag :: Int
, _shellSpinAmount :: Int
, _shellThrustDelay :: Int
}
| Refracting {_phaseV :: Float}
| BulletShooter
{ _muzVel :: Float
, _bore :: Float
, _gunBarrels :: GunBarrels
}
| Sprayer
{ _nozzleSpread :: Float
, _nozzleNum :: Int
}
| AngleWalk
{ _maxWalkAngle :: Float
, _currentWalkAngle :: Float
, _walkSpeed :: Float
}
data Modification
= ModIDTimerPoint3Bool
@@ -897,3 +914,4 @@ makeLenses ''Vocalization
makeLenses ''Universe
makeLenses ''LSParam
makeLenses ''ItemParams
makeLenses ''ItemTweaks
+3
View File
@@ -8,7 +8,9 @@ import ShapePicture
import Shape
import Geometry.Vector3D
import Geometry
--import Dodge.TweakBullet
--import qualified Data.IntMap.Strict as IM
import Control.Lens
defaultAmmo :: ItemConsumption
@@ -101,6 +103,7 @@ defaultGun = Weapon
, _itTargeting = Nothing
, _itParams = NoParams
, _itDimension = defaultItemDimension
, _itTweaks = NoTweaks
}
defaultItemDimension :: ItemDimension
defaultItemDimension = ItemDimension
+6 -6
View File
@@ -125,17 +125,17 @@ wheelEvent y w = case (_carteDisplay w, _inventoryMode w) of
invKeyDown = ScancodeCapsLock `S.member` _keys w
moveTweakSel :: Int -> World -> World
moveTweakSel i w = case yourItem w ^? itParams . tweakParams of
moveTweakSel i w = case yourItem w ^? itTweaks . tweakParams of
Just l -> w & creatures . ix (_yourID w) . crInv . ix (_crInvSel (you w))
. itParams . tweakSel %~ (`mod` length l) . subtract i
. itTweaks . tweakSel %~ (`mod` length l) . subtract i
_ -> w
changeTweakParam :: Int -> World -> World
changeTweakParam i w = w
& creatures . ix (_yourID w) . crInv . ix (_crInvSel (you w)) %~
( (itParams . tweakParams . ix paramid . curTweak .~ x)
( (itTweaks . tweakParams . ix paramid . curTweak .~ x)
. _doTweak params x)
where
it = yourItem w
params = _tweakParams (_itParams it) IM.! paramid
tweaks = _itTweaks $ yourItem w
params = _tweakParams tweaks IM.! paramid
x = (_curTweak params + i) `mod` _maxTweak params
paramid = _tweakSel $ _itParams $ yourItem w
paramid = _tweakSel tweaks
+2 -1
View File
@@ -32,8 +32,9 @@ defaultAimParams = AimParams
}
useAmmoParams :: Item -> Creature -> World -> World
useAmmoParams it = withVelWthHiteff (_amBulVel b) (_amBulWth b) (_amBulEff b)
useAmmoParams it = withVelWthHiteff (muzvel *.* _amBulVel b) (_amBulWth b) (_amBulEff b)
where
muzvel = _muzVel $ _itParams it
b = _aoType $ _itConsumption it
useAmmoParamsVelMod :: Float -> Item -> Creature -> World -> World
+41 -24
View File
@@ -11,11 +11,11 @@ import Dodge.SoundLogic.LoadSound
import Dodge.WorldEvent
import Dodge.WorldEvent.Damage
--import Dodge.Default
import Dodge.Item.Weapon.InventoryDisplay
--import Dodge.Item.Weapon.InventoryDisplay
import Dodge.Item.Weapon.TriggerType
import Dodge.Item.Weapon.AmmoParams
import Dodge.Default.Weapon
import Dodge.Item.Attachment
--import Dodge.Item.Attachment
import Dodge.WorldEvent.HelperParticle
import Dodge.Base
import Dodge.Zone
@@ -26,11 +26,11 @@ import ShapePicture
import Dodge.Picture
import Data.Function
import qualified Data.Sequence as Seq
--import qualified Data.Sequence as Seq
import Data.List
import Control.Lens
import System.Random
import Data.Maybe
--import Data.Maybe
import Data.Tuple
import qualified Data.IntMap.Strict as IM
teslaGun :: Item
@@ -51,7 +51,6 @@ teslaGun = defaultGun
& useAim . aimSpeed .~ 0.4
& useAim . aimStance .~ TwoHandFlat
, _itFloorPict = teslaGunPic
-- , _itZoom = defaultItZoom
}
teslaGunPic :: Item -> SPic
teslaGunPic _ = noPic $ colorSH blue $
@@ -80,11 +79,30 @@ lasGun = defaultAutoGun
& useAim . aimRange .~ 1
& useAim . aimStance .~ TwoHandTwist
, _itFloorPict = lasGunPic
, _itAttachment = ItCharMode $ Seq.fromList "/VZ"
, _itScroll = scrollCharMode
, _itInvDisplay = basicWeaponDisplay
, _itParams = Refracting {_phaseVel = 1}
, _itParams = Refracting {_phaseV = 1}
, _itTweaks = Tweakable
{ _tweakParams = IM.fromList [(0,lasGunTweak)]
, _tweakSel = 0
}
}
lasGunTweak :: TweakParam
lasGunTweak = TweakParam
{ _doTweak = thetweak
, _curTweak = 1
, _maxTweak = 3
, _showTweak = showPhaseV
, _nameTweak = "PHASE VELOCITY"
}
where
thetweak 0 = itParams . phaseV .~ 0.2
thetweak 1 = itParams . phaseV .~ 1
thetweak 2 = itParams . phaseV .~ 5
thetweak _ = id
showPhaseV 0 = "V"
showPhaseV 1 = "/"
showPhaseV 2 = "Z"
showPhaseV i = "THIS SHOULD NOT BE POSSIBLE" ++ show i
lasGunPic :: Item -> SPic
lasGunPic it =
( colorSH blue $
@@ -133,24 +151,23 @@ aTeslaArc cr w = set randGen g w
chooseColor _ = cyan
aLaser :: Creature -> World -> World
aLaser cr = particles %~ (makeLaserAt phaseV pos dir : )
aLaser cr = particles %~ (makeLaserAt phasev pos dir : )
where
pos = _crPos cr +.+ ((_crRad cr +3) *.* unitVectorAtAngle dir)
dir = _crDir cr
phaseV = charToPhaseV
$ fromMaybe '/' $ Seq.lookup 0 =<< cr ^? crInv . ix j . itAttachment . itCharMode
phasev = _phaseV . _itParams $ _crInv cr IM.! j
j = _crInvSel cr
charToPhaseV :: Fractional p => Char -> p
charToPhaseV 'V' = 0.2
charToPhaseV '/' = 1
charToPhaseV 'Z' = 5
charToPhaseV _ = error "Trying to set an undefined phaseV"
--charToPhaseV :: Fractional p => Char -> p
--charToPhaseV 'V' = 0.2
--charToPhaseV '/' = 1
--charToPhaseV 'Z' = 5
--charToPhaseV _ = error "Trying to set an undefined phaseV"
makeLaserAt :: Float -> Point2 -> Float -> Particle
makeLaserAt phaseV pos dir = Particle
makeLaserAt phasev pos dir = Particle
{ _ptDraw = const blank
, _ptUpdate = moveLaser phaseV pos dir
, _ptUpdate = moveLaser phasev pos dir
}
moveLaser
:: Float -- ^ Phase velocity, controls deflection through windows
@@ -159,7 +176,7 @@ moveLaser
-> World
-> Particle
-> (World, Maybe Particle)
moveLaser phaseV pos dir w pt
moveLaser phasev pos dir w pt
= ( hitEffect w
, Just pt {_ptDraw = const pic ,_ptUpdate = ptSimpleTime 0 }
)
@@ -183,7 +200,7 @@ moveLaser phaseV pos dir w pt
angleInc = piRange $ argV wlNormal - argV (x -.- y)
angleRef
| reflectExternal = angleInc
| otherwise = asin $ sin angleInc / phaseV
| otherwise = asin $ sin angleInc / phasev
piRange a'
| a' > pi = a' - 2 * pi
| a' > negate pi = a'
@@ -194,9 +211,9 @@ moveLaser phaseV pos dir w pt
angleInc' = piRange $ argV wlNormal' - argV (x -.- y)
angleRef'
| reflectInternal = angleInc'
| otherwise = asin $ phaseV * sin angleInc'
reflectInternal = 1 < abs (phaseV * sin angleInc')
reflectExternal = 1 < abs (sin angleInc / phaseV)
| otherwise = asin $ phasev * sin angleInc'
reflectInternal = 1 < abs (phasev * sin angleInc')
reflectExternal = 1 < abs (sin angleInc / phasev)
h' ws (_,Right wl) = not $ any (\w' -> _wlID w' == _wlID wl) ws
h' _ _ = True
+25 -1
View File
@@ -1,5 +1,8 @@
module Dodge.Item.Weapon.Bullet
( basicBullet
, incBullet
, conBullet
, bounceBullet
, ltBullet
, hvBullet
) where
@@ -10,11 +13,32 @@ import Dodge.Particle.Bullet.HitEffect
import Geometry.Data
basicBullet :: AmmoType
basicBullet = BulletAmmo
{ _amString = "BULLET"
{ _amString = "BASIC"
, _amBulEff = destroyOnImpact bulHitCr bulHitWall
, _amBulWth = 2
, _amBulVel = V2 50 0
}
incBullet :: AmmoType
incBullet = BulletAmmo
{ _amString = "INCENDIARY"
, _amBulEff = destroyOnImpact bulIncCr bulIncWall
, _amBulWth = 2
, _amBulVel = V2 50 0
}
conBullet :: AmmoType
conBullet = BulletAmmo
{ _amString = "CONCUSSIVE"
, _amBulEff = destroyOnImpact bulConCr bulConWall
, _amBulWth = 2
, _amBulVel = V2 50 0
}
bounceBullet :: AmmoType
bounceBullet = BulletAmmo
{ _amString = "BOUNCING"
, _amBulEff = destroyOnImpact bulHitCr bulBounceWall
, _amBulWth = 2
, _amBulVel = V2 10 0
}
ltBullet :: AmmoType
ltBullet = BulletAmmo
{ _amString = "LTBULLET"
+36 -9
View File
@@ -12,6 +12,7 @@ module Dodge.Item.Weapon.BulletGuns
)
where
import Dodge.Data
import Dodge.TweakBullet
import Dodge.Default.Weapon
import Dodge.Default
import Dodge.Item.Attachment
@@ -67,7 +68,12 @@ autoGun = defaultAutoGun
, _itAttachment = ItCharMode $ Seq.fromList "MS"
, _itScroll = scrollCharMode
, _itInvDisplay = basicWeaponDisplay
, _itParams = SingleBarrel autogunSpread
, _itParams = BulletShooter
{ _muzVel = 1
, _bore = 2
, _gunBarrels = SingleBarrel 0.1
}
, _itTweaks = defaultBulletSelTweak
}
autoGunPic :: Item -> SPic
autoGunPic it = noPic $
@@ -105,7 +111,12 @@ pistol = defaultGun
, _itInvDisplay = basicWeaponDisplay
, _itInvColor = white
, _itTargeting = Nothing
, _itParams = SingleBarrel 0.05
, _itParams = BulletShooter
{ _muzVel = 0.8
, _bore = 2
, _gunBarrels = SingleBarrel 0.05
}
, _itTweaks = defaultBulletSelTweak
}
pistolPic :: Item -> SPic
pistolPic it = noPic $ colorSH green (prismPoly
@@ -177,7 +188,12 @@ ltAutoGun = defaultAutoGun
, modClock 2 withMuzFlareI
]
, _itFloorPict = ltAutoGunPic
, _itParams = SingleBarrel 0.1
, _itParams = BulletShooter
{ _muzVel = 1
, _bore = 2
, _gunBarrels = SingleBarrel autogunSpread
}
, _itTweaks = defaultBulletSelTweak
}
& itDimension . muzzleLength .~ 10
ltAutoGunPic :: Item -> SPic
@@ -239,6 +255,7 @@ miniGun = defaultAutoGun
& useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5}
, _itFloorPict = miniGunPictItem
, _itEquipPict = pictureWeaponAim miniGunPictItem
, _itTweaks = defaultBulletSelTweak
} & itDimension . muzzleLength .~ 15
where
recoilAmount = 5
@@ -299,11 +316,16 @@ spreadGun = defaultGun
, withMuzFlareI
, spreadNumI
]
, _itParams = MultiBarrel
{_barrelNum = 5
,_barrelSpread = SpreadBarrels 0.5
, _itParams = BulletShooter
{ _muzVel = 0.7
, _bore = 2
, _gunBarrels = MultiBarrel
{_brlNum = 5
,_brlSpread = SpreadBarrels 0.5
}
}
, _itFloorPict = spreadGunPic
, _itTweaks = defaultBulletSelTweak
}
spreadGunPic :: Item -> SPic
spreadGunPic it =
@@ -338,10 +360,15 @@ multGun = defaultGun
& useAim . aimStance .~ TwoHandTwist
& useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5}
, _itFloorPict = multGunSPic
, _itParams = MultiBarrel
{_barrelNum = 5
,_barrelSpread = AlignedBarrels
, _itParams = BulletShooter
{ _muzVel = 1
, _bore = 3
, _gunBarrels = MultiBarrel
{_brlNum = 5
,_brlSpread = AlignedBarrels
}
}
, _itTweaks = defaultBulletSelTweak
}
multGunSPic :: Item -> SPic
multGunSPic it =
+12 -9
View File
@@ -21,7 +21,7 @@ import Dodge.Picture.Layer
import Geometry
import Picture
import qualified IntMapHelp as IM
import Padding
--import Padding
import ShapePicture
import Shape
@@ -59,12 +59,14 @@ launcher = defaultGun
, _itFloorPict = launcherPic
, _itEffect = NoItEffect
, _itParams = ShellLauncher
{ _tweakSel = 0
, _tweakParams = basicAmPjMoves
, _shellSpinDrag = 1
{ _shellSpinDrag = 1
, _shellSpinAmount = 2
, _shellThrustDelay = 1
}
, _itTweaks = Tweakable
{ _tweakSel = 0
, _tweakParams = basicAmPjMoves
}
}
defaultShellAmmo :: AmmoType
@@ -92,24 +94,25 @@ spinDrag :: TweakParam
spinDrag = TweakParam
{ _doTweak = \i -> itParams . shellSpinDrag .~ i
, _curTweak = 1
, _showTweak = pjPadText "SPIN SLOWDOWN" . show
, _showTweak = show
, _maxTweak = 5
, _nameTweak = "SPIN SLOWDOWN"
}
pjPadText :: String -> String -> String
pjPadText s = (rightPad 12 ' ' s ++ ) . (' ':)
spinStart :: TweakParam
spinStart = TweakParam
{ _doTweak = \i -> itParams . shellSpinAmount .~ i
, _curTweak = 2
, _showTweak = pjPadText "SPIN AMOUNT" . show
, _showTweak = show
, _maxTweak = 5
, _nameTweak = "SPIN AMOUNT"
}
thrustParam :: TweakParam
thrustParam = TweakParam
{ _doTweak = \i -> itParams . shellThrustDelay .~ i
, _curTweak = 1
, _showTweak = pjPadText "THRUST DELAY" . show
, _showTweak = show
, _maxTweak = 5
, _nameTweak = "THRUST DELAY"
}
pjThrust :: Int -> Prop -> World -> World
+3 -2
View File
@@ -48,8 +48,9 @@ poisonSprayer = defaultAutoGun
& useAim . aimSpeed .~ 0.2
& useAim . aimRange .~ 0
& useAim . aimStance .~ TwoHandTwist
, _itParams = MultiBarrel {_barrelSpread = SpreadBarrels 0.2
, _barrelNum = 3
, _itParams = Sprayer
{ _nozzleSpread = 0.2
, _nozzleNum = 3
}
, _itFloorPict = flamerPic
}
+4 -4
View File
@@ -320,7 +320,7 @@ withMuzFlareI f it cr w = makeTlsTimeRadColPos 3 100 (V3 1 1 0.5) flashPos
applyInaccuracy :: ChainEffect
applyInaccuracy f it cr w = f it (cr & crDir +~ a) $ set randGen g w
where
acc = _inaccuracy $ _itParams it
acc = _brlInaccuracy . _gunBarrels $ _itParams it
(a, g) = randomR (-acc,acc) $ _randGen w
{- | Applies the effect to a randomly rotated creature. -}
withRandomDirI
@@ -391,8 +391,8 @@ spreadNumI eff item cr w = foldr f w dirs
[-spread,-spread+(2*spread/fromIntegral numBul)..spread]
(randomRs (0,spread/fromIntegral numBul) (_randGen w))
f dir = eff item (cr & crDir +~ dir)
spread = _spreadAngle . _barrelSpread $ _itParams item
numBul = _barrelNum $ _itParams item
spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item
numBul = _brlNum . _gunBarrels $ _itParams item
numI :: ChainEffect
numI eff item cr w = foldr f w poss
where
@@ -401,7 +401,7 @@ numI eff item cr w = foldr f w poss
poss :: [V2 Float]
poss = map (rotateV (_crDir cr) . V2 0 . (*5) . (+ cp) . fromIntegral) [0 .. numBul - 1]
f pos = eff item (cr & crPos %~ (+.+ pos))
numBul = _barrelNum $ _itParams item
numBul = _brlNum . _gunBarrels $ _itParams item
{- | Uses '_wpSpread' as a parameter for the current offset angle. -}
randWalkAngle
:: (Creature -> World -> World) -- ^ Underlying effect
+2 -2
View File
@@ -102,8 +102,8 @@ hvBulHitCr bt p cr w
sp = head $ _btTrail' bt
ep = sp +.+ _btVel' bt
{- | Create a flamelet when hitting a creature. -}
bulIncCr' :: Particle -> Point2 -> Creature -> World -> World
bulIncCr' bt p cr w
bulIncCr :: Particle -> Point2 -> Creature -> World -> World
bulIncCr bt p cr w
= over (creatures . ix cid . crState . crDamage)
( Piercing 60 sp p ep : )
$ bulletHitSound p
+6 -6
View File
@@ -58,7 +58,7 @@ subInventoryDisplay cfig w = case _inventoryMode w of
col = itCol it
cursorsZ :: Configuration -> Int -> Item -> Picture
cursorsZ cfig ipos it = case it ^? itParams . tweakSel of
cursorsZ cfig ipos it = case it ^? itTweaks . tweakSel of
Nothing -> f $ zConnect sp (V2 (155- hw) ( hh - 77.5))
Just jpos -> f $ zConnect sp (V2 (155 - hw) ( hh - (20 * fromIntegral jpos + 77.5)))
where
@@ -75,12 +75,12 @@ topInvCursor col iPos cfig w
| otherwise = mainListCursor col iPos cfig
ammoTweakStrings :: Item -> [String]
ammoTweakStrings it = case it ^? itParams . tweakParams of
Just l -> map pjTweakString $ IM.elems l
ammoTweakStrings it = case it ^? itTweaks . tweakParams of
Just l -> map tweakString $ IM.elems l
_ -> ["NOT TWEAKABLE"]
mCurs :: Item -> Configuration -> World -> Picture
mCurs it cfig w = case it ^? itParams . tweakSel of
mCurs it cfig w = case it ^? itTweaks . tweakSel of
Nothing -> []
Just i
| ButtonRight `S.member` _mouseButtons w ->
@@ -93,8 +93,8 @@ mCurs it cfig w = case it ^? itParams . tweakSel of
x = 117.5
y = 155
pjTweakString :: TweakParam -> String
pjTweakString pj = _showTweak pj $ _curTweak pj
tweakString :: TweakParam -> String
tweakString tp = rightPad 12 ' ' (_nameTweak tp) ++ " " ++ _showTweak tp (_curTweak tp)
displayMidList :: Configuration -> [String] -> String -> Picture
displayMidList cfig strs s = invHead cfig s
+32
View File
@@ -0,0 +1,32 @@
module Dodge.TweakBullet where
import Dodge.Data
import Dodge.Item.Weapon.Bullet
import qualified Data.IntMap.Strict as IM
import Control.Lens
defaultBulletSelTweak :: ItemTweaks
defaultBulletSelTweak = Tweakable
{_tweakSel = 0
,_tweakParams = IM.fromList $ zip [0..]
[ bulSelTweak
]
}
bulSelTweak :: TweakParam
bulSelTweak = TweakParam
{_doTweak = intToBulAmmo
,_curTweak = 0
,_maxTweak = 4
,_showTweak = _amString . (bulletTypes IM.!)
,_nameTweak = "BULLET TYPE"
}
intToBulAmmo :: Int -> Item -> Item
intToBulAmmo i = itConsumption . aoType .~ bulletTypes IM.! i
bulletTypes :: IM.IntMap AmmoType
bulletTypes = IM.fromList $ zip [0..]
[ basicBullet
, incBullet
, conBullet
, bounceBullet
]