Refactor weapon usages

This commit is contained in:
2021-08-27 16:31:43 +01:00
parent cb8613036f
commit dd44a93476
11 changed files with 308 additions and 60 deletions
+1 -1
View File
@@ -159,7 +159,7 @@ startCr = defaultCreature
startInventory :: IM.IntMap Item startInventory :: IM.IntMap Item
startInventory = IM.fromList (zip [0..20] startInventory = IM.fromList (zip [0..20]
( (
[ltAutoGun [spreadGun
,autoGun ,autoGun
,hvAutoGun ,hvAutoGun
,pistol ,pistol
+1 -1
View File
@@ -33,7 +33,7 @@ itemEffect
-> World -> World
itemEffect cr Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID cr)) (eff (_crID cr) w) itemEffect cr Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID cr)) (eff (_crID cr) w)
itemEffect cr it@Weapon{_itUse=eff} w = foldr ($) eff (_itUseModifiers it) it cr w itemEffect cr it@Weapon{_itUse=eff} w = foldr ($) eff (_itUseModifiers it) it cr w
itemEffect cr it@Throwable{_itUse = eff} w = eff it cr w itemEffect cr it@Throwable{_itUse = eff} w = foldr ($) eff (_itUseModifiers it) it cr w
itemEffect _ _ w = w itemEffect _ _ w = w
useLeftItem useLeftItem
+2
View File
@@ -247,6 +247,7 @@ data Item
, _itTargeting :: Maybe (World -> Maybe Point2, Int -> Item -> Creature -> World -> Picture) , _itTargeting :: Maybe (World -> Maybe Point2, Int -> Item -> Creature -> World -> Picture)
, _itWorldTrigger :: Maybe (Int -> World -> Bool) , _itWorldTrigger :: Maybe (Int -> World -> Bool)
, _itAimStance :: AimStance , _itAimStance :: AimStance
, _wpNumBarrels :: Int
} }
| Consumable | Consumable
{ _itName :: String { _itName :: String
@@ -302,6 +303,7 @@ data Item
, _itUse :: Item -> Creature -> World -> World , _itUse :: Item -> Creature -> World -> World
, _itUseRate :: Int , _itUseRate :: Int
, _itUseTime :: Int , _itUseTime :: Int
, _itUseModifiers :: [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World]
, _itAimingSpeed :: Float , _itAimingSpeed :: Float
, _itAimingRange :: Float , _itAimingRange :: Float
, _itZoom :: ItZoom , _itZoom :: ItZoom
+1
View File
@@ -43,6 +43,7 @@ defaultGun = Weapon
, _itTargeting = Nothing , _itTargeting = Nothing
, _itWorldTrigger = Nothing , _itWorldTrigger = Nothing
, _itAimStance = OneHand , _itAimStance = OneHand
, _wpNumBarrels = 1
} }
defaultAutoGun :: Item defaultAutoGun :: Item
defaultAutoGun = defaultGun defaultAutoGun = defaultGun
+13
View File
@@ -52,6 +52,19 @@ charFiringStrat strats cr w = case w ^? creatures . ix cid . crInv
_ -> w _ -> w
where where
cid = _crID cr cid = _crID cr
charFiringStratI
:: [(Char, (Item -> Creature -> World -> World) -> Item -> Creature -> World -> World)] -- ^ Different firing effects for different characters
-> (Item -> Creature -> World -> World)
-> Item
-> Creature
-> World
-> World
charFiringStratI strats eff item cr w = case w ^? creatures . ix cid . crInv
. ix (_crInvSel $ _creatures w IM.! cid) . itAttachment . _Just . itCharMode of
Just (c :<| _) -> fromJust (Prelude.lookup c strats) eff item cr w
_ -> w
where
cid = _crID cr
increaseFuse increaseFuse
:: Int -- ^ Old fuse time :: Int -- ^ Old fuse time
+89 -49
View File
@@ -14,7 +14,7 @@ import Dodge.WorldEvent
import Dodge.Default import Dodge.Default
--import Dodge.Default.Shell --import Dodge.Default.Shell
import Dodge.Item.Draw import Dodge.Item.Draw
import Dodge.Particle.Bullet.HitEffect --import Dodge.Particle.Bullet.HitEffect
import Dodge.Item.Data import Dodge.Item.Data
import Dodge.Item.Weapon.InventoryDisplay import Dodge.Item.Weapon.InventoryDisplay
import Dodge.Item.Weapon.TriggerType import Dodge.Item.Weapon.TriggerType
@@ -23,6 +23,7 @@ import Dodge.Item.Weapon.UseEffect
import Dodge.Item.Weapon.Laser import Dodge.Item.Weapon.Laser
import Dodge.Item.Weapon.Shell import Dodge.Item.Weapon.Shell
import Dodge.Item.Weapon.Bullet import Dodge.Item.Weapon.Bullet
import Dodge.Item.Weapon.AmmoParams
import Dodge.Default.Weapon import Dodge.Default.Weapon
import Dodge.Item.Weapon.Booster import Dodge.Item.Weapon.Booster
import Dodge.Item.Weapon.Grenade import Dodge.Item.Weapon.Grenade
@@ -87,10 +88,6 @@ pistol = defaultGun
pistolPic :: Picture pistolPic :: Picture
pistolPic = color green $ polygon $ rectNESW 5 5 (-5) (-5) pistolPic = color green $ polygon $ rectNESW 5 5 (-5) (-5)
useAmmoParams :: Item -> Creature -> World -> World
useAmmoParams it = withVelWthHiteff (_amBulVel b) (_amBulWth b) (_amBulEff b)
where
b = _wpAmmo it
effectGun :: String -> (Creature -> World -> World) -> Item effectGun :: String -> (Creature -> World -> World) -> Item
effectGun name eff = defaultGun effectGun name eff = defaultGun
@@ -111,7 +108,9 @@ rezGun = defaultGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 0 , _itUseRate = 0
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \_ -> shoot aTeslaArc , _itUse = \_ -> aTeslaArc
, _itUseModifiers =
[]
, _wpSpread = 0.001 , _wpSpread = 0.001
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer $ color chartreuse $ pictures , _itFloorPict = onLayer FlItLayer $ color chartreuse $ pictures
@@ -228,7 +227,10 @@ tractorGun = defaultAutoGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 0 , _itUseRate = 0
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \_ -> shoot $ aTractorBeam 0 , _itUse = \_ -> aTractorBeam 0
, _itUseModifiers =
[ ammoUseCheckI
]
, _wpSpread = 0.00001 , _wpSpread = 0.00001
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer $ color blue $ pictures [polygon $ rectNESW 1.5 6 (-1.5) 0 ] , _itFloorPict = onLayer FlItLayer $ color blue $ pictures [polygon $ rectNESW 1.5 6 (-1.5) 0 ]
@@ -275,9 +277,12 @@ hvAutoGun = defaultAutoGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 25 , _itUseRate = 25
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \it -> mkHvBul it , _itUse = useAmmoParams
, _itUseModifiers = , _itUseModifiers =
[ rateIncABI 24 10 (torqueBeforeForcedI 0.1) (torqueAfterI 0.2) [ rateIncABI 24 10 (torqueBeforeForcedI 0.1) (torqueAfterI 0.2)
, withSoundI longGunSound
, withThinSmokeI
, withMuzFlareI
] ]
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer hvAutoGunPic , _itFloorPict = onLayer FlItLayer hvAutoGunPic
@@ -286,11 +291,6 @@ hvAutoGun = defaultAutoGun
, _itEquipPict = pictureWeaponOnAim hvAutoGunPic , _itEquipPict = pictureWeaponOnAim hvAutoGunPic
, _wpAmmo = hvBullet , _wpAmmo = hvBullet
} }
where
mkHvBul it = withSound longGunSound
. withThinSmoke
. withMuzFlare
$ useAmmoParams it
hvAutoGunPic :: Picture hvAutoGunPic :: Picture
hvAutoGunPic = color orange $ polygon $ rectNESW 5 12 (-5) (-12) hvAutoGunPic = color orange $ polygon $ rectNESW 5 12 (-5) (-12)
ltAutoGun :: Item ltAutoGun :: Item
@@ -336,16 +336,15 @@ miniGun = defaultAutoGun
, _wpMaxWarmUp = 100 , _wpMaxWarmUp = 100
, _itUseRate = 1 , _itUseRate = 1
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \it -> withWarmUp 26 , _itUse = useAmmoParams
. shootWithSoundFor 28 2 , _itUseModifiers =
. torqueBefore 0.1 [ withWarmUpI 26
-- . torqueBefore 0.03 , shootWithSoundForI 28 2
. withSidePush 50 , torqueBeforeForcedI 0.1
. withRecoil 15 , withSidePushI 50
-- . withRandomDir 0.1 , withRandomOffsetI 9
. withRandomOffset 9 , withMuzFlareI
. withMuzFlare ]
$ useAmmoParams it
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer miniGunPict , _itFloorPict = onLayer FlItLayer miniGunPict
, _itAimingSpeed = 0.4 , _itAimingSpeed = 0.4
@@ -358,7 +357,6 @@ miniGunPict = pictures
[ translate 5 0 . color red $ polygon $ rectNESW 9 7 (-9) (-5) [ translate 5 0 . color red $ polygon $ rectNESW 9 7 (-9) (-5)
, color red . polygon $ rectNESW 4 12 (-4) (-12) , color red . polygon $ rectNESW 4 12 (-4) (-12)
] ]
spreadGun :: Item spreadGun :: Item
spreadGun = defaultGun spreadGun = defaultGun
{ _itName = "SPREAD" { _itName = "SPREAD"
@@ -369,17 +367,25 @@ spreadGun = defaultGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 20 , _itUseRate = 20
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \_ -> shootWithSound shotgunSound --, _itUse = \_ -> spreadNumVelWthHiteff spreadGunSpread 9 (V2 30 0) 2 basicBulletEffect
. withRecoil 100 , _itUse = useAmmoParams
. withMuzFlare , _itUseModifiers =
$ spreadNumVelWthHiteff spreadGunSpread 9 (V2 30 0) 2 basicBulletEffect [ shootWithSoundI shotgunSound
, withRecoilI 100
, withMuzFlareI
, spreadNumI
]
, _wpSpread = spreadGunSpread , _wpSpread = spreadGunSpread
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer $ color green $ pictures [ polygon $ map toV2[(-3,0),(3,6),(3,-6)] ] , _itFloorPict = onLayer FlItLayer $ spreadGunPic
, _itAimingSpeed = 1 , _itAimingSpeed = 1
, _itAimingRange = 0 , _itAimingRange = 0
, _itEquipPict = pictureWeaponOnAim $ color green $ pictures [ polygon $ map toV2[(-3,0),(3,6),(3,-6)] ] , _itEquipPict = pictureWeaponOnAim $ spreadGunPic
, _wpAmmo = basicBullet
, _wpNumBarrels = 50
} }
spreadGunPic :: Picture
spreadGunPic = color green $ pictures [ polygon $ map toV2[(-3,0),(3,6),(3,-6)] ]
multGun :: Item multGun :: Item
multGun = defaultGun multGun = defaultGun
{ _itName = "MULTGUN" { _itName = "MULTGUN"
@@ -390,10 +396,13 @@ multGun = defaultGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 20 , _itUseRate = 20
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \_ -> shootWithSound shotgunSound , _itUse = useAmmoParams
. withRecoil 200 , _itUseModifiers =
. withMuzFlare [ shootWithSoundI shotgunSound
$ numVelWthHitEff 5 (V2 50 0) 5 basicBulletEffect , withRecoilI 200
, withMuzFlareI
, numI
]
, _wpSpread = spreadGunSpread , _wpSpread = spreadGunSpread
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer multGunPic , _itFloorPict = onLayer FlItLayer multGunPic
@@ -402,6 +411,8 @@ multGun = defaultGun
, _itZoom = defaultItZoom {_itAimZoomFac = 1.5} , _itZoom = defaultItZoom {_itAimZoomFac = 1.5}
, _itEquipPict = pictureWeaponOnAim multGunPic , _itEquipPict = pictureWeaponOnAim multGunPic
, _itAimStance = TwoHandTwist , _itAimStance = TwoHandTwist
, _wpAmmo = basicBullet
, _wpNumBarrels = 5
} }
multGunPic :: Picture multGunPic :: Picture
multGunPic = color red $ pictures multGunPic = color red $ pictures
@@ -426,11 +437,13 @@ longGun = defaultGun
, _wpReloadType = PassiveReload skwareFadeTwoSecSound , _wpReloadType = PassiveReload skwareFadeTwoSecSound
, _itUseRate = 100 , _itUseRate = 100
, _itUseTime = 0 , _itUseTime = 0
, _itUse = shootWithSound longGunSound , _itUse = useAmmoParams
. withThickSmoke , _itUseModifiers =
. torqueAfter 0.05 [ shootWithSoundI longGunSound
. withMuzFlare , withThickSmokeI
. useAmmoParams , torqueAfterI 0.05
, withMuzFlareI
]
, _wpRange = 200 , _wpRange = 200
, _itFloorPict = onLayer FlItLayer longGunPic , _itFloorPict = onLayer FlItLayer longGunPic
, _itAimingSpeed = 0.2 , _itAimingSpeed = 0.2
@@ -468,7 +481,10 @@ poisonSprayer = defaultAutoGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 0 , _itUseRate = 0
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \_ -> shoot aGasCloud , _itUse = \_ -> aGasCloud
, _itUseModifiers =
[shootWithSoundI buzzSound
]
, _wpSpread = 0.3 , _wpSpread = 0.3
, _wpRange = 8 , _wpRange = 8
, _itFloorPict = onLayer FlItLayer $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4) , _itFloorPict = onLayer FlItLayer $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4)
@@ -487,7 +503,12 @@ flamer = defaultAutoGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 0 , _itUseRate = 0
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \_ -> shoot $ withSidePush 5 $ withSidePushAfter 10 $ randWalkAngle 0.2 0.01 aFlame , _itUse = \_ -> randWalkAngle 0.2 0.01 aFlame
, _itUseModifiers =
[ ammoUseCheckI
, withSidePushI 5
, withSidePushAfterI 10
]
, _wpSpread = 0 , _wpSpread = 0
, _wpRange = 8 , _wpRange = 8
, _itFloorPict = onLayer FlItLayer flamerPic , _itFloorPict = onLayer FlItLayer flamerPic
@@ -512,7 +533,11 @@ blinkGun = defaultGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 0 , _itUseRate = 0
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \_ -> hammerCheck $ shoot aSelf , _itUse = \_ -> aSelf
, _itUseModifiers =
[ hammerCheckI
, ammoUseCheckI
]
, _itLeftClickUse = Just $ hammerCheckL $ shootL aSelfL , _itLeftClickUse = Just $ hammerCheckL $ shootL aSelfL
, _wpSpread = 0.05 , _wpSpread = 0.05
, _wpRange = 20 , _wpRange = 20
@@ -630,7 +655,7 @@ retireRemoteBomb itid 0 pjid w = w
& pointToItem (_itemPositions w IM.! itid) %~ & pointToItem (_itemPositions w IM.! itid) %~
( (itAttachment . _Just . scopePos .~ V2 0 0) ( (itAttachment . _Just . scopePos .~ V2 0 0)
. (itZoom .~ defaultItZoom) . (itZoom .~ defaultItZoom)
. (itUse .~ (\_ -> hammerCheck throwRemoteBomb)) . (itUse .~ (\_ -> throwRemoteBomb))
) )
& projectiles %~ IM.delete pjid & projectiles %~ IM.delete pjid
retireRemoteBomb itid t pjid w = setScope w retireRemoteBomb itid t pjid w = setScope w
@@ -707,7 +732,10 @@ grenade = Throwable
, _itFloorPict = onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _twMaxRange = 150 , _twMaxRange = 150
, _twAccuracy = 30 , _twAccuracy = 30
, _itUse = \_ -> useTimeCheck $ throwGrenade makeExplosionAt , _itUse = \_ -> throwGrenade makeExplosionAt
, _itUseModifiers =
[ useTimeCheckI
]
, _itAimingSpeed = 1 , _itAimingSpeed = 1
, _itAimingRange = 0 , _itAimingRange = 0
, _itZoom = defaultItZoom {_itAimZoomMax = f fuseTime, _itAimZoomMin = f fuseTime} , _itZoom = defaultItZoom {_itAimZoomMax = f fuseTime, _itAimZoomMin = f fuseTime}
@@ -757,7 +785,10 @@ remoteBomb = defaultThrowable
, _itFloorPict = onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _twMaxRange = 150 , _twMaxRange = 150
, _twAccuracy = 30 , _twAccuracy = 30
, _itUse = \_ -> hammerCheck throwRemoteBomb , _itUse = \_ -> throwRemoteBomb
, _itUseModifiers =
[ hammerCheckI
]
, _itAttachment = Just $ ItScope (V2 0 0) 0 1 True , _itAttachment = Just $ ItScope (V2 0 0) 0 1 True
, _itEquipPict = pictureWeaponOnAim remoteBombUnarmedPic , _itEquipPict = pictureWeaponOnAim remoteBombUnarmedPic
} }
@@ -881,7 +912,7 @@ throwRemoteBomb cr w = setLocation
resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTE" resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTE"
removePict = set (creatures . ix cid . crInv . ix j . itEquipPict) $ \ _ _ -> blank removePict = set (creatures . ix cid . crInv . ix j . itEquipPict) $ \ _ _ -> blank
resetFire = set (creatures . ix cid . crInv . ix j . itUse) resetFire = set (creatures . ix cid . crInv . ix j . itUse)
$ \_ -> hammerCheck $ explodeRemoteBomb itid i $ \_ -> explodeRemoteBomb itid i
p' = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr) 0) p' = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr) 0)
p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr-4) 0) p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr-4) 0)
| otherwise = p' | otherwise = p'
@@ -949,7 +980,10 @@ radar = defaultGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 120 , _itUseRate = 120
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \_ -> shoot aRadarPulse , _itUse = \_ -> aRadarPulse
, _itUseModifiers =
[ ammoUseCheckI
]
, _wpSpread = autogunSpread , _wpSpread = autogunSpread
, _wpRange = 20 , _wpRange = 20
, _itHammer = HammerUp , _itHammer = HammerUp
@@ -972,7 +1006,10 @@ sonar = defaultGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 120 , _itUseRate = 120
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \_ -> shoot aSonarPulse , _itUse = \_ -> aSonarPulse
, _itUseModifiers =
[ ammoUseCheckI
]
, _wpRange = 20 , _wpRange = 20
, _itHammer = HammerUp , _itHammer = HammerUp
, _itFloorPict = onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) , _itFloorPict = onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
@@ -1024,7 +1061,10 @@ spawnGun cr = defaultGun
, _wpReloadTime = 80 , _wpReloadTime = 80
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 100 , _itUseRate = 100
, _itUse = \_ -> hammerCheck $ spawnCrNextTo cr , _itUse = \_ -> spawnCrNextTo cr
, _itUseModifiers =
[ hammerCheckI
]
} }
spawnCrNextTo spawnCrNextTo
:: Creature -- ^ Creature to spawn :: Creature -- ^ Creature to spawn
+9 -3
View File
@@ -7,6 +7,7 @@ import Dodge.Item.Attachment
import Dodge.Item.Attachment.Data import Dodge.Item.Attachment.Data
import Dodge.Item.Weapon.ExtraEffect import Dodge.Item.Weapon.ExtraEffect
import Dodge.Item.Weapon.InventoryDisplay import Dodge.Item.Weapon.InventoryDisplay
import Dodge.Item.Weapon.AmmoParams
import Dodge.Item.Data import Dodge.Item.Data
import Dodge.Picture.Layer import Dodge.Picture.Layer
import Dodge.Item.Draw import Dodge.Item.Draw
@@ -30,9 +31,14 @@ autoGun = defaultAutoGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 5 , _itUseRate = 5
, _itUseTime = 0 , _itUseTime = 0
, _itUse = \_ -> charFiringStrat , _itUse = useAmmoParams
[('M',autoFireMode) , _itUseModifiers =
,('S',singleFireMode) [ charFiringStratI
[('M',shootWithSoundI autoGunSound . torqueBeforeForcedI 0.05)
,('S',hammerCheckI . shootWithSoundI autoGunSound)
]
, withRandomDirI (autogunSpread/2)
, withMuzFlareI
] ]
, _wpSpread = autogunSpread , _wpSpread = autogunSpread
, _wpRange = 20 , _wpRange = 20
+4 -1
View File
@@ -37,7 +37,10 @@ launcher = defaultGun
, _wpReloadState = 0 , _wpReloadState = 0
, _itUseRate = 20 , _itUseRate = 20
, _itUseTime = 0 , _itUseTime = 0
, _itUse = shootWithSound launcherSound . aRocketWithItemParams , _itUse = aRocketWithItemParams
, _itUseModifiers =
[ shootWithSoundI launcherSound
]
, _wpSpread = 0.02 , _wpSpread = 0.02
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer launcherPic , _itFloorPict = onLayer FlItLayer launcherPic
+185 -3
View File
@@ -1,6 +1,32 @@
{- | {- |
Weapon effects when pulling the trigger. -} Weapon effects when pulling the trigger. -}
module Dodge.Item.Weapon.TriggerType module Dodge.Item.Weapon.TriggerType
-- ( hammerCheckI
-- , shootWithSoundI
-- , shootWithSoundForI
-- , withMuzFlareI
-- , withVelWthHiteff
-- , ammoUseCheckI
-- , rateIncABI
-- , torqueBeforeForcedI
-- , torqueAfterI
-- , withSoundI
-- , withThickSmokeI
-- , withThinSmokeI
-- , withRandomOffsetI
-- , withRandomDirI
-- , withRecoilI
-- , withSidePushAfterI
-- , withSidePushI
-- , withWarmUpI
-- , spreadNumI
-- , numI
-- , randWalkAngle -- ^ should be made into a modifier, perhaps
-- , hammerCheckI
-- , hammerCheckL
-- , shootL
-- , useTimeCheckI
-- ) where
where where
import Dodge.Data import Dodge.Data
import Dodge.SoundLogic import Dodge.SoundLogic
@@ -20,6 +46,18 @@ import Data.Maybe
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
import Data.Foldable import Data.Foldable
withThinSmokeI
:: (Item -> Creature -> World -> World) -- ^ Underlying effect
-> Item
-> Creature
-> World
-> World
withThinSmokeI eff item cr w = eff item cr $ foldl' (flip $ makeThinSmokeAt . (+.+ pos)) w ps
where
dir = _crDir cr
pos = _crPos cr +.+ (_crRad cr +0.5) *.* unitVectorAtAngle dir
ps = (replicateM 5 . randInCirc) 8 & evalState $ _randGen w
withThinSmoke withThinSmoke
:: (Creature -> World -> World) -- ^ Underlying effect :: (Creature -> World -> World) -- ^ Underlying effect
-> Creature -> Creature
@@ -31,6 +69,17 @@ withThinSmoke eff cr w = eff cr $ foldl' (flip $ makeThinSmokeAt . (+.+ pos)) w
pos = _crPos cr +.+ (_crRad cr +0.5) *.* unitVectorAtAngle dir pos = _crPos cr +.+ (_crRad cr +0.5) *.* unitVectorAtAngle dir
ps = (replicateM 5 . randInCirc) 8 & evalState $ _randGen w ps = (replicateM 5 . randInCirc) 8 & evalState $ _randGen w
withThickSmokeI
:: (Item -> Creature -> World -> World) -- ^ Underlying effect
-> Item
-> Creature
-> World
-> World
withThickSmokeI eff item cr w = eff item cr $ foldl' (flip $ makeThickSmokeAt . (+.+ pos)) w ps
where
dir = _crDir cr
pos = _crPos cr +.+ (_crRad cr + 15) *.* unitVectorAtAngle dir
ps = (replicateM 20 . randInCirc) 8 & evalState $ _randGen w
withThickSmoke withThickSmoke
:: (Creature -> World -> World) -- ^ Underlying effect :: (Creature -> World -> World) -- ^ Underlying effect
-> Creature -> Creature
@@ -121,9 +170,32 @@ rateIncABI startRate fastRate exeffFirst exeffCont eff item cr w
&& _itUseTime item == 0 && _itUseTime item == 0
&& _wpLoadedAmmo item > 0 && _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0 reloadCondition = _wpLoadedAmmo item == 0
{- | {- | Apply effect after a warm up. -}
Shoot a weapon rapidly after a warm up. withWarmUpI
Applies ammo check as well. -} :: Int -- ^ warm up sound id
-> (Item -> Creature -> World -> World)
-- ^ underlying effect
-> Item
-> Creature
-> World
-> World
withWarmUpI soundID f item cr w
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| _wpReloadState item /= 0 = w
| curWarmUp < maxWarmUp = w
& pointerToItem . wpCurWarmUp +~ 2
& soundFrom (CrWeaponSound cid) soundID 2 0
| otherwise = w
& pointerToItem . wpCurWarmUp .~ maxWarmUp
& f item cr
where
cid = _crID cr
itRef = _crInvSel cr
pointerToItem = creatures . ix cid . crInv . ix itRef
curWarmUp = _wpCurWarmUp item
maxWarmUp = _wpMaxWarmUp item
reloadCondition = _wpLoadedAmmo item == 0
{- | Apply effect after a warm up. -}
withWarmUp withWarmUp
:: Int -- ^ warm up sound id :: Int -- ^ warm up sound id
-> (Creature -> World -> World) -> (Creature -> World -> World)
@@ -156,7 +228,26 @@ withSound
-> Creature -> Creature
-> World -> World -> World -> World
withSound soundid f cr = soundOncePos soundid (_crPos cr) . f cr withSound soundid f cr = soundOncePos soundid (_crPos cr) . f cr
{- | Adds a sound to a creature based world effect.
The sound is emitted from the creature's position. -}
withSoundI
:: Int -- ^ Sound id
-> (Item -> Creature -> World -> World) -- ^ Underlying effect
-> Item
-> Creature
-> World -> World
withSoundI soundid f item cr = soundOncePos soundid (_crPos cr) . f item cr
withRecoilI
:: Float -- ^ Recoil amount
-> (Item -> Creature -> World -> World)
-> Item
-> Creature
-> World -> World
withRecoilI recoilAmount eff item cr = eff item cr . over (creatures . ix cid) pushback
where
cid = _crID cr
pushback = over crPos (+.+ rotateV (_crDir cr) (V2 ((-recoilAmount) / _crMass cr ) 0))
withRecoil withRecoil
:: Float -- ^ Recoil amount :: Float -- ^ Recoil amount
-> (Creature -> World -> World) -> (Creature -> World -> World)
@@ -198,6 +289,19 @@ withSidePush maxSide eff cr w = eff cr . over (creatures . ix cid) push $ w
-- consider unifying the pushes using a direction vector -- consider unifying the pushes using a direction vector
{- | Pushes a creature sideways by a random amount. {- | Pushes a creature sideways by a random amount.
Applied after the underlying effect. -} Applied after the underlying effect. -}
withSidePushAfterI
:: Float -- ^ Maximal possible side push amount
-> (Item -> Creature -> World -> World)
-> Item
-> Creature -- ^ Creature id
-> World -> World
withSidePushAfterI maxSide eff item cr w = over (creatures . ix cid) push . eff item cr $ w
where
cid = _crID cr
push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr)))
(pushAmount, _) = randomR (-maxSide,maxSide) $ _randGen w
{- | Pushes a creature sideways by a random amount.
Applied after the underlying effect. -}
withSidePushAfter withSidePushAfter
:: Float -- ^ Maximal possible side push amount :: Float -- ^ Maximal possible side push amount
-> (Creature -> World -> World) -> (Creature -> World -> World)
@@ -327,6 +431,22 @@ useTimeCheck f cr w = case theItem ^? itUseTime of
setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUseTime +~ useRate setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUseTime +~ useRate
theItem = _crInv cr IM.! _crInvSel cr theItem = _crInv cr IM.! _crInvSel cr
useRate = fromMaybe 0 $ theItem ^? itUseRate useRate = fromMaybe 0 $ theItem ^? itUseRate
{- |
Applies a world effect after an item use cooldown check. -}
useTimeCheckI
:: (Item -> Creature -> World -> World) -- ^ Underlying effect
-> Item
-> Creature
-> World
-> World
useTimeCheckI f item cr w = case item ^? itUseTime of
Just 0 -> f item cr $ setUseTime w
_ -> w
where
cid = _crID cr
setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUseTime +~ useRate
useRate = fromMaybe 0 $ item ^? itUseRate
{- | Applies a world effect after a hammer position check. -} {- | Applies a world effect after a hammer position check. -}
hammerCheck hammerCheck
:: (Creature -> World -> World) -- ^ Underlying effect :: (Creature -> World -> World) -- ^ Underlying effect
@@ -353,6 +473,27 @@ hammerCheckI f it cr w = case it ^? itHammer of
cid = _crID cr cid = _crID cr
setHammerDown = creatures . ix cid . crInv . ix (_crInvSel cr) . itHammer .~ HammerDown setHammerDown = creatures . ix cid . crInv . ix (_crInvSel cr) . itHammer .~ HammerDown
{- | Applies a world effect after an ammo check. -} {- | Applies a world effect after an ammo check. -}
ammoUseCheckI
:: (Item -> Creature -> World -> World)
-- ^ Underlying effect
-> Item
-> Creature
-> World
-> World
ammoUseCheckI f item cr w
| fireCondition = f item cr w & pointerToItem %~
( (wpLoadedAmmo -~ 1) . (itUseTime .~ _itUseRate item) )
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| otherwise = w
where
cid = _crID cr
itRef = _crInvSel cr
pointerToItem = creatures . ix cid . crInv . ix itRef
fireCondition = _wpReloadState item == 0
&& _itUseTime item == 0
&& _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0
{- | Applies a world effect after an ammo check. -}
shoot shoot
:: (Creature -> World -> World) :: (Creature -> World -> World)
-- ^ Underlying effect -- ^ Underlying effect
@@ -468,6 +609,19 @@ withVelWthHiteff vel width hiteff cr = over particles (newbul : )
dir = _crDir cr dir = _crDir cr
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr) pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
{- | Apply the effect to a translated creature. -} {- | Apply the effect to a translated creature. -}
withRandomOffsetI
:: Float -- ^ Max possible translate
-> (Item -> Creature -> World -> World)
-- ^ Underlying effect
-> Item
-> Creature
-> World
-> World
withRandomOffsetI offsetAmount f item cr w = f item (cr & crPos %~ (+.+ offV)) $ set randGen g w
where
(offsetVal , g) = randomR (-offsetAmount,offsetAmount) $ _randGen w
offV = rotateV (_crDir cr) (V2 0 offsetVal)
{- | Apply the effect to a translated creature. -}
withRandomOffset withRandomOffset
:: Float -- ^ Max possible translate :: Float -- ^ Max possible translate
-> (Creature -> World -> World) -> (Creature -> World -> World)
@@ -568,6 +722,20 @@ torqueAfter torque feff cr w
(rot, g) = randomR (-torque,torque) $ _randGen w (rot, g) = randomR (-torque,torque) $ _randGen w
rotateScope = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0)) rotateScope = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
. itAttachment . _Just . scopePos %~ rotateV rot . itAttachment . _Just . scopePos %~ rotateV rot
spreadNumI
:: (Item -> Creature -> World -> World)
-> Item
-> Creature
-> World
-> World
spreadNumI eff item cr w = foldr f w dirs
where
dirs = zipWith (+)
[-spread,-spread+(2*spread/fromIntegral numBul)..spread]
(randomRs (0,spread/fromIntegral numBul) (_randGen w))
f dir = eff item (cr & crDir +~ dir)
spread = _wpSpread item
numBul = _wpNumBarrels item
{- | Create multiple bullets with a given spread, a given amount, given velocity, {- | Create multiple bullets with a given spread, a given amount, given velocity,
given width and given 'HitEffect'. -} given width and given 'HitEffect'. -}
spreadNumVelWthHiteff spreadNumVelWthHiteff
@@ -590,6 +758,20 @@ spreadNumVelWthHiteff spread num vel wth eff cr w = over particles (newbuls ++)
dirs = map (_crDir cr +) $ zipWith (+) dirs = map (_crDir cr +) $ zipWith (+)
[-spread,-spread+(2*spread/fromIntegral num)..] [-spread,-spread+(2*spread/fromIntegral num)..]
(randomRs (0,spread/5) (_randGen w)) (randomRs (0,spread/5) (_randGen w))
numI
:: (Item -> Creature -> World -> World)
-> Item
-> Creature
-> World
-> World
numI eff item cr w = foldr f w poss
where
cp :: Float
cp = -0.5 * fromIntegral numBul
poss :: [V2 Float]
poss = map (rotateV (_crDir cr) . V2 0 . (*5) . (+ cp) . fromIntegral) [0 .. numBul - 1]
f pos = eff item (cr & crPos %~ (+.+ pos))
numBul = _wpNumBarrels item
{- | Create a number of bullets side by side with a given velocity, {- | Create a number of bullets side by side with a given velocity,
given width and given 'HitEffect'. -} given width and given 'HitEffect'. -}
numVelWthHitEff numVelWthHitEff
+2 -2
View File
@@ -9,7 +9,7 @@ import Dodge.Base.Zone
import Dodge.Base.Collide import Dodge.Base.Collide
import Dodge.Picture.Layer import Dodge.Picture.Layer
--import Dodge.Item.Weapon.Decoration --import Dodge.Item.Weapon.Decoration
import Dodge.Item.Weapon.TriggerType --import Dodge.Item.Weapon.TriggerType
--import Dodge.WorldEvent.Flash --import Dodge.WorldEvent.Flash
--import Dodge.WorldEvent.ThingsHit --import Dodge.WorldEvent.ThingsHit
import Picture import Picture
@@ -114,7 +114,7 @@ aTractorBeam
-> World -> World
aTractorBeam col cr w aTractorBeam col cr w
= set (creatures . ix cid . crInv . ix itRef . itUse) = set (creatures . ix cid . crInv . ix itRef . itUse)
(\_ -> shoot $ aTractorBeam ((col + 1) `mod` 10)) (\_ -> aTractorBeam ((col + 1) `mod` 10))
$ over projectiles (IM.insert i (tractorBeamAt col i pos dir)) w $ over projectiles (IM.insert i (tractorBeamAt col i pos dir)) w
where where
i = newProjectileKey w i = newProjectileKey w
+1
View File
@@ -258,6 +258,7 @@ ssaTri ab bc a
-- the point which lies between pa and pc' on a line from pb of length bc. -- the point which lies between pa and pc' on a line from pb of length bc.
-- Note that there are likely two such points, this should return the point -- Note that there are likely two such points, this should return the point
-- closer to pc'. -- closer to pc'.
-- TODO this still causes errors, should be made error free
ssaTriPoint :: Point2 -> Point2 -> Point2 -> Float -> Point2 ssaTriPoint :: Point2 -> Point2 -> Point2 -> Float -> Point2
ssaTriPoint pa pb pc' bc ssaTriPoint pa pb pc' bc
= let ab = magV (pa -.- pb) = let ab = magV (pa -.- pb)