Change config serialisation folder, cleanup unused files
This commit is contained in:
@@ -5,3 +5,4 @@ loop.cabal
|
|||||||
*.lock
|
*.lock
|
||||||
keys.json
|
keys.json
|
||||||
log/*
|
log/*
|
||||||
|
generated/*
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
# Changelog for loop
|
|
||||||
|
|
||||||
## Unreleased changes
|
|
||||||
+1
-2
@@ -10,8 +10,7 @@ import qualified Data.Map.Strict as M
|
|||||||
--import Data.Preload.Render
|
--import Data.Preload.Render
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Dodge.Concurrent
|
import Dodge.Concurrent
|
||||||
import Dodge.Config.Load
|
import Dodge.Config
|
||||||
import Dodge.Config.Update
|
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.Event
|
import Dodge.Event
|
||||||
import Dodge.Initialisation
|
import Dodge.Initialisation
|
||||||
|
|||||||
@@ -1,483 +0,0 @@
|
|||||||
{- |
|
|
||||||
Weapon effects when pulling the trigger. -}
|
|
||||||
module Dodge.Item.Weapon.TriggerType
|
|
||||||
where
|
|
||||||
import Dodge.Data
|
|
||||||
import Dodge.SoundLogic
|
|
||||||
import Dodge.Creature.Action (startReloadingWeapon)
|
|
||||||
import Dodge.WorldEvent (muzzleFlashAt,tempLightForAt)
|
|
||||||
import Dodge.WorldEvent.Cloud
|
|
||||||
import Dodge.RandomHelp
|
|
||||||
import Dodge.Particle.Bullet.Spawn
|
|
||||||
import Dodge.Item.Attachment.Data
|
|
||||||
import Dodge.Item.Data
|
|
||||||
import Geometry
|
|
||||||
|
|
||||||
import System.Random
|
|
||||||
import Control.Lens
|
|
||||||
import Control.Monad.State
|
|
||||||
import Data.Maybe
|
|
||||||
import qualified Data.IntMap.Strict as IM
|
|
||||||
import Data.Foldable
|
|
||||||
|
|
||||||
withThinSmoke
|
|
||||||
:: (Creature -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
withThinSmoke eff cr w = eff 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
|
|
||||||
|
|
||||||
withThickSmoke
|
|
||||||
:: (Creature -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
withThickSmoke eff cr w = eff 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
|
|
||||||
{- |
|
|
||||||
Fires at an increasing rate.
|
|
||||||
Has different effect after first fire.
|
|
||||||
Applies ammo check and use cooldown check. -}
|
|
||||||
rateIncAB
|
|
||||||
:: Int -- ^ Start rate
|
|
||||||
-> Int -- ^ End rate
|
|
||||||
-> (Creature -> World -> World) -- ^ Effect on first fire
|
|
||||||
-> (Creature -> World -> World) -- ^ Effect on continued fire
|
|
||||||
-> Creature -- ^ Creature id
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
rateIncAB startRate fastRate shooteff1 shooteff2 cr w
|
|
||||||
| repeatFire = w
|
|
||||||
& pointItem %~ ( (itUseRate .~ max fastRate (currentRate - 1))
|
|
||||||
. (wpLoadedAmmo -~ 1)
|
|
||||||
. (itUseTime .~ currentRate) )
|
|
||||||
& shooteff2 cr
|
|
||||||
| firstFire = w
|
|
||||||
& pointItem %~ ( (itUseRate .~ startRate - 1)
|
|
||||||
. (wpLoadedAmmo -~ 1)
|
|
||||||
. (itUseTime .~ startRate) )
|
|
||||||
& shooteff1 cr
|
|
||||||
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
|
||||||
| otherwise = w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
itRef = _crInvSel cr
|
|
||||||
item = _crInv cr IM.! itRef
|
|
||||||
pointItem = creatures . ix cid . crInv . ix itRef
|
|
||||||
currentRate = _itUseRate item
|
|
||||||
repeatFire = _wpReloadState item == 0
|
|
||||||
&& _itUseTime item == 1
|
|
||||||
&& _wpLoadedAmmo item > 0
|
|
||||||
firstFire = _wpReloadState item == 0
|
|
||||||
&& _itUseTime item == 0
|
|
||||||
&& _wpLoadedAmmo item > 0
|
|
||||||
reloadCondition = _wpLoadedAmmo item == 0
|
|
||||||
{- |
|
|
||||||
Shoot a weapon rapidly after a warm up.
|
|
||||||
Applies ammo check as well. -}
|
|
||||||
withWarmUp
|
|
||||||
:: Int -- ^ Warm up time (in frames)
|
|
||||||
-> (Creature -> World -> World)
|
|
||||||
-- ^ Shoot effect
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
withWarmUp t f cr w
|
|
||||||
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
|
||||||
| _wpReloadState item /= 0 = w
|
|
||||||
| fState == 0 = w
|
|
||||||
& pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp 100 f)) . (itUseTime .~ 2) )
|
|
||||||
| t > 2 = w
|
|
||||||
& pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp (t-1) f)) . (itUseTime .~ 2) )
|
|
||||||
& soundFrom (CrWeaponSound cid) 26 2 0
|
|
||||||
| t > 0 = w
|
|
||||||
& pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp (t-1) f)) . (itUseTime .~ 2) )
|
|
||||||
| otherwise = w
|
|
||||||
& pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp 1 f)) . (wpLoadedAmmo -~ 1) . (itUseTime .~ 2) )
|
|
||||||
& f cr
|
|
||||||
& soundFrom (CrWeaponSound cid) 28 2 0
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
itRef = _crInvSel cr
|
|
||||||
item = _crInv cr IM.! itRef
|
|
||||||
pointerToItem = creatures . ix cid . crInv . ix itRef
|
|
||||||
fState = _itUseTime item
|
|
||||||
reloadCondition = _wpLoadedAmmo item == 0
|
|
||||||
{- | Adds a sound to a creature based world effect.
|
|
||||||
The sound is emitted from the creature's position. -}
|
|
||||||
withSound
|
|
||||||
:: Int -- ^ Sound id
|
|
||||||
-> (Creature -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> World -> World
|
|
||||||
withSound soundid f cr = soundOncePos soundid (_crPos cr) . f cr
|
|
||||||
|
|
||||||
withRecoil
|
|
||||||
:: Float -- ^ Recoil amount
|
|
||||||
-> (Creature -> World -> World)
|
|
||||||
-- ^ Underlying world effect, takes creature id as input
|
|
||||||
-> Creature
|
|
||||||
-> World -> World
|
|
||||||
withRecoil recoilAmount eff cr = eff cr . over (creatures . ix cid) pushback
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
pushback = over crPos (+.+ rotateV (_crDir cr) (V2 ((-recoilAmount) / _crMass cr ) 0))
|
|
||||||
{- | Pushes a creature sideways by a random amount.
|
|
||||||
Applied before the underlying effect. -}
|
|
||||||
withSidePush
|
|
||||||
:: Float -- ^ Maximal possible side push amount
|
|
||||||
-> (Creature -> World -> World)
|
|
||||||
-- ^ Underlying world effect, takes creature id as input
|
|
||||||
-> Creature
|
|
||||||
-> World -> World
|
|
||||||
withSidePush maxSide eff cr w = eff cr . over (creatures . ix cid) push $ w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr)))
|
|
||||||
(pushAmount, _) = randomR (-maxSide,maxSide) $ _randGen w
|
|
||||||
-- consider unifying the pushes using a direction vector
|
|
||||||
{- | Pushes a creature sideways by a random amount.
|
|
||||||
Applied after the underlying effect. -}
|
|
||||||
withSidePushAfter
|
|
||||||
:: Float -- ^ Maximal possible side push amount
|
|
||||||
-> (Creature -> World -> World)
|
|
||||||
-- ^ Underlying world effect, takes creature id as input
|
|
||||||
-> Creature -- ^ Creature id
|
|
||||||
-> World -> World
|
|
||||||
withSidePushAfter maxSide eff cr w = over (creatures . ix cid) push . eff cr $ w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr)))
|
|
||||||
(pushAmount, _) = randomR (-maxSide,maxSide) $ _randGen w
|
|
||||||
{- | Applies a world effect and sound effect after an ammo check. -}
|
|
||||||
shootWithSound
|
|
||||||
:: Int -- ^ Sound identifier
|
|
||||||
-> (Creature -> World -> World)
|
|
||||||
-- ^ Shoot effect, takes creature id as input
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
shootWithSound soundid f cr w
|
|
||||||
| fireCondition = over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1)
|
|
||||||
$ soundOncePos soundid (_crPos cr)
|
|
||||||
$ set (pointerToItem . itUseTime) (_itUseRate item)
|
|
||||||
$ f cr w
|
|
||||||
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
|
||||||
| otherwise = w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
itRef = _crInvSel cr
|
|
||||||
item = _crInv cr IM.! itRef
|
|
||||||
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 and sound effect after an ammo check. -}
|
|
||||||
shootWithSoundI
|
|
||||||
:: Int -- ^ Sound identifier
|
|
||||||
-> (Item -> Creature -> World -> World)
|
|
||||||
-- ^ Shoot effect, takes creature id as input
|
|
||||||
-> Item
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
shootWithSoundI soundid f item cr w
|
|
||||||
| fireCondition = over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1)
|
|
||||||
$ soundOncePos soundid (_crPos cr)
|
|
||||||
$ set (pointerToItem . itUseTime) (_itUseRate item)
|
|
||||||
$ f item cr w
|
|
||||||
| 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 item use cooldown check. -}
|
|
||||||
useTimeCheck
|
|
||||||
:: (Creature -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
useTimeCheck f cr w = case theItem ^? itUseTime of
|
|
||||||
Just 0 -> f cr $ setUseTime w
|
|
||||||
_ -> w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUseTime +~ useRate
|
|
||||||
theItem = _crInv cr IM.! _crInvSel cr
|
|
||||||
useRate = fromMaybe 0 $ theItem ^? itUseRate
|
|
||||||
{- | Applies a world effect after a hammer position check. -}
|
|
||||||
hammerCheck
|
|
||||||
:: (Creature -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
hammerCheck f cr w = case (_crInv cr IM.! _crInvSel cr) ^? itHammer of
|
|
||||||
Just HammerUp -> f cr $ setHammerDown w
|
|
||||||
_ -> setHammerDown w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
setHammerDown = creatures . ix cid . crInv . ix (_crInvSel cr) . itHammer .~ HammerDown
|
|
||||||
{- | Applies a world effect after a hammer position check. -}
|
|
||||||
hammerCheckI
|
|
||||||
:: (Item -> Creature -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Item
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
hammerCheckI f it cr w = case it ^? itHammer of
|
|
||||||
Just HammerUp -> f it cr $ setHammerDown w
|
|
||||||
_ -> setHammerDown w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
setHammerDown = creatures . ix cid . crInv . ix (_crInvSel cr) . itHammer .~ HammerDown
|
|
||||||
{- | Applies a world effect after an ammo check. -}
|
|
||||||
shoot
|
|
||||||
:: (Creature -> World -> World)
|
|
||||||
-- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
shoot f cr w
|
|
||||||
| fireCondition = f cr w & pointerToItem %~
|
|
||||||
( (wpLoadedAmmo -~ 1) . (itUseTime .~ _itUseRate item) )
|
|
||||||
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
|
||||||
| otherwise = w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
itRef = _crInvSel cr
|
|
||||||
item = _crInv cr IM.! itRef
|
|
||||||
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 a hammer position check.
|
|
||||||
Arbitrary inventory position. -}
|
|
||||||
hammerCheckL
|
|
||||||
:: (Creature -> Int -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> Int
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
hammerCheckL f cr invid w = case (_crInv cr IM.! invid) ^? itHammer of
|
|
||||||
Just HammerUp -> f cr invid $ setHammerDown w
|
|
||||||
_ -> setHammerDown w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
setHammerDown = creatures . ix cid . crInv . ix invid . itHammer .~ HammerDown
|
|
||||||
{- | Applies a world effect after an ammo check.
|
|
||||||
Arbitrary inventory position. -}
|
|
||||||
shootL
|
|
||||||
:: (Creature -> Int -> World -> World)
|
|
||||||
-- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> Int -- ^ Inventory position
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
shootL f cr invid w
|
|
||||||
| fireCondition = f cr invid w & pointerToItem %~
|
|
||||||
( (wpLoadedAmmo -~ 1) . (itUseTime .~ _itUseRate item) )
|
|
||||||
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
|
||||||
| otherwise = w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
item = _crInv cr IM.! invid
|
|
||||||
pointerToItem = creatures . ix cid . crInv . ix invid
|
|
||||||
fireCondition = _wpReloadState item == 0
|
|
||||||
&& _itUseTime item == 0
|
|
||||||
&& _wpLoadedAmmo item > 0
|
|
||||||
reloadCondition = _wpLoadedAmmo item == 0
|
|
||||||
|
|
||||||
withMuzFlare
|
|
||||||
:: (Creature -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
withMuzFlare f cr w = tempLightForAt 3 pos . muzzleFlashAt pos2 $ f cr w
|
|
||||||
where
|
|
||||||
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
|
|
||||||
pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr)
|
|
||||||
|
|
||||||
withMuzFlareI
|
|
||||||
:: (Item -> Creature -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Item
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
withMuzFlareI f it cr w = tempLightForAt 3 pos . muzzleFlashAt pos2 $ f it cr w
|
|
||||||
where
|
|
||||||
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
|
|
||||||
pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr)
|
|
||||||
{- | Applies the effect to a randomly rotated creature. -}
|
|
||||||
withRandomDir
|
|
||||||
:: Float -- ^ Max possible rotation
|
|
||||||
-> (Creature -> World -> World)
|
|
||||||
-- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
withRandomDir acc f cr w = f (cr & crDir +~ a) $ set randGen g w
|
|
||||||
where
|
|
||||||
(a, g) = randomR (-acc,acc) $ _randGen w
|
|
||||||
{- | Applies the effect to a randomly rotated creature. -}
|
|
||||||
withRandomDirI
|
|
||||||
:: Float -- ^ Max possible rotation
|
|
||||||
-> (Item -> Creature -> World -> World)
|
|
||||||
-- ^ Underlying effect
|
|
||||||
-> Item
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
withRandomDirI acc f it cr w = f it (cr & crDir +~ a) $ set randGen g w
|
|
||||||
where
|
|
||||||
(a, g) = randomR (-acc,acc) $ _randGen w
|
|
||||||
{- | Creates a bullet with a given velocity, width, and 'HitEffect' -}
|
|
||||||
withVelWthHiteff
|
|
||||||
:: Point2 -- ^ Velocity, x direction is forward with respect to the creature
|
|
||||||
-> Float -- ^ Bullet width
|
|
||||||
-> HitEffect -- ^ Bullet effect when hitting creature, wall etc
|
|
||||||
-> Creature -- ^ Creature id
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
withVelWthHiteff vel width hiteff cr = over particles (newbul : )
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
newbul = aGenBulAt (Just cid) pos (rotateV dir vel) hiteff width
|
|
||||||
dir = _crDir cr
|
|
||||||
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
|
|
||||||
{- | Apply the effect to a translated creature. -}
|
|
||||||
withRandomOffset
|
|
||||||
:: Float -- ^ Max possible translate
|
|
||||||
-> (Creature -> World -> World)
|
|
||||||
-- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
withRandomOffset offsetAmount f cr w = f (cr & crPos %~ (+.+ offV)) $ set randGen g w
|
|
||||||
where
|
|
||||||
(offsetVal , g) = randomR (-offsetAmount,offsetAmount) $ _randGen w
|
|
||||||
offV = rotateV (_crDir cr) (V2 0 offsetVal)
|
|
||||||
-- | Rotates a creature with minimum rotation at least 0.1.
|
|
||||||
-- Rotates the player creature before applying the effect, other creatures after.
|
|
||||||
torqueBeforeForced
|
|
||||||
:: Float -- ^ Max possible rotation (less the 0.1 forced rotation)
|
|
||||||
-> (Creature -> World -> World)
|
|
||||||
-- ^ Underlying effect
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
torqueBeforeForced torque feff cr w
|
|
||||||
| cid == 0 = feff (cr & crDir +~ rot') $ w
|
|
||||||
& randGen .~ g
|
|
||||||
& creatures . ix cid . crDir +~ rot'
|
|
||||||
& cameraRot +~ rot'
|
|
||||||
| otherwise = feff cr $ set randGen g $ over (creatures . ix cid . crDir) (+rot') w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
(rot, g) = randomR (-torque,torque) $ _randGen w
|
|
||||||
rot' | rot < 0 = rot - 0.1
|
|
||||||
| otherwise = rot + 0.1
|
|
||||||
-- | Rotates the player creature before applying an effect.
|
|
||||||
-- Note this currently (29/4/2021) rotates other creatures /after/ applying the effect.
|
|
||||||
torqueBefore
|
|
||||||
:: Float -- ^ Max possible rotation
|
|
||||||
-> (Creature -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Creature -- ^ Creature id
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
torqueBefore torque feff cr w
|
|
||||||
| cid == 0 = feff (cr & crDir +~ rot) $ w
|
|
||||||
& randGen .~ g
|
|
||||||
& creatures . ix cid . crDir +~ rot
|
|
||||||
& cameraRot +~ rot
|
|
||||||
| otherwise = set randGen g $ over (creatures . ix cid . crDir) (+rot) $ feff cr w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
(rot, g) = randomR (-torque,torque) $ _randGen w
|
|
||||||
-- | Rotate a randomly creature after applying an effect.
|
|
||||||
torqueAfter
|
|
||||||
:: Float -- ^ Max possible rotation
|
|
||||||
-> (Creature -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Creature -- ^ Creature id
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
torqueAfter torque feff cr w
|
|
||||||
| cid == 0 = rotateScope $ set randGen g $ over cameraRot (+rot) $ feff cr w
|
|
||||||
| otherwise = set randGen g $ over (creatures . ix cid . crDir) (+rot) $ feff cr w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
(rot, g) = randomR (-torque,torque) $ _randGen w
|
|
||||||
rotateScope = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
|
||||||
. itAttachment . _Just . scopePos %~ rotateV rot
|
|
||||||
{- | Create multiple bullets with a given spread, a given amount, given velocity,
|
|
||||||
given width and given 'HitEffect'. -}
|
|
||||||
spreadNumVelWthHiteff
|
|
||||||
:: Float -- ^ Spread
|
|
||||||
-> Int -- ^ Number of bullets
|
|
||||||
-> Point2 -- ^ Velocity, x is direction of creature
|
|
||||||
-> Float -- ^ Bullet width
|
|
||||||
-> HitEffect -- ^ Effect when hitting creature, wall etc
|
|
||||||
-> Creature -- ^ Creature id
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
spreadNumVelWthHiteff spread num vel wth eff cr w = over particles (newbuls ++) w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
newbuls = zipWith
|
|
||||||
(\pos d -> aGenBulAt (Just cid) pos (rotateV d vel) eff wth)
|
|
||||||
poss dirs
|
|
||||||
poss = map ((+.+) $ _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr))
|
|
||||||
$ (replicateM num . randInCirc) 5 & evalState $ _randGen w
|
|
||||||
dirs = map (_crDir cr +) $ zipWith (+)
|
|
||||||
[-spread,-spread+(2*spread/fromIntegral num)..]
|
|
||||||
(randomRs (0,spread/5) (_randGen w))
|
|
||||||
{- | Create a number of bullets side by side with a given velocity,
|
|
||||||
given width and given 'HitEffect'. -}
|
|
||||||
numVelWthHitEff
|
|
||||||
:: Int -- ^ Amount of bullets
|
|
||||||
-> Point2 -- ^ Velocity, x axis is direction of creature
|
|
||||||
-> Float -- ^ Bullet width
|
|
||||||
-> HitEffect -- ^ Effect when hitting creature, wall etc
|
|
||||||
-> Creature
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
numVelWthHitEff num vel wth eff cr = over particles (newbuls ++)
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
newbuls = map (\p -> aGenBulAt (Just cid) p (rotateV d vel) eff wth) poss
|
|
||||||
d = _crDir cr
|
|
||||||
poss = map (+.+ pos) $ take num offsets
|
|
||||||
maxOffset = fromIntegral num * 2.5 - 2.5
|
|
||||||
offsets = map (rotateV d . V2 0) [-maxOffset,5-maxOffset..]
|
|
||||||
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle d
|
|
||||||
{- | Uses '_wpSpread' as a parameter for the current offset angle. -}
|
|
||||||
randWalkAngle
|
|
||||||
:: Float -- ^ Max offset angle
|
|
||||||
-> Float -- ^ Walk speed
|
|
||||||
-> (Creature -> World -> World) -- ^ Underlying effect
|
|
||||||
-> Creature -- ^ Creature id
|
|
||||||
-> World
|
|
||||||
-> World
|
|
||||||
randWalkAngle ma aspeed f cr w = w
|
|
||||||
& f (cr & crDir +~ a)
|
|
||||||
& creatures . ix cid . crInv . ix i . wpSpread .~ newa
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
a = _wpSpread $ _crInv (_creatures w IM.! cid) IM.! i
|
|
||||||
(walka, _) = randomR (-aspeed,aspeed) (_randGen w)
|
|
||||||
newa = min ma $ max (negate ma) (a + walka)
|
|
||||||
i = _crInvSel $ _creatures w IM.! cid
|
|
||||||
+3
-3
@@ -6,9 +6,9 @@ author: "Author name here"
|
|||||||
maintainer: "example@example.com"
|
maintainer: "example@example.com"
|
||||||
copyright: "2021 Author name here"
|
copyright: "2021 Author name here"
|
||||||
|
|
||||||
extra-source-files:
|
# extra-source-files:
|
||||||
- README.md
|
# - README.md
|
||||||
- ChangeLog.md
|
# - ChangeLog.md
|
||||||
|
|
||||||
# Metadata used when publishing your package
|
# Metadata used when publishing your package
|
||||||
# synopsis: A basic game loop
|
# synopsis: A basic game loop
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
module Dodge.Config.Load (
|
|
||||||
loadDodgeConfig,
|
|
||||||
) where
|
|
||||||
|
|
||||||
import Data.Aeson
|
|
||||||
import Dodge.Data.Config
|
|
||||||
import System.Directory
|
|
||||||
|
|
||||||
loadDodgeConfig :: IO Config
|
|
||||||
loadDodgeConfig = do
|
|
||||||
fExists <- doesFileExist "data/dodge.config.json"
|
|
||||||
if fExists
|
|
||||||
then do
|
|
||||||
mayConfig <- decodeFileStrict "data/dodge.config.json"
|
|
||||||
case mayConfig of
|
|
||||||
Just config -> return config
|
|
||||||
Nothing -> do
|
|
||||||
putStrLn "invalid data/dodge.config.json, loading defaults"
|
|
||||||
return defaultConfig
|
|
||||||
else do
|
|
||||||
putStrLn "No data/data/dodge.config.json found, loading defaults"
|
|
||||||
return defaultConfig
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
{- |
|
|
||||||
IO actions that apply config side effects and save configuration settings to disk.
|
|
||||||
-}
|
|
||||||
module Dodge.Config.Update (
|
|
||||||
saveConfig,
|
|
||||||
applyWorldConfig,
|
|
||||||
setVol,
|
|
||||||
) where
|
|
||||||
|
|
||||||
import qualified Data.Aeson.Encode.Pretty as AEP
|
|
||||||
import qualified Data.ByteString.Lazy as BS
|
|
||||||
import Data.Preload
|
|
||||||
import Dodge.Data.Config
|
|
||||||
import Preload.Update
|
|
||||||
import Sound
|
|
||||||
|
|
||||||
{- |
|
|
||||||
Write the current world configuration to disk as a json file.
|
|
||||||
-}
|
|
||||||
saveConfig :: Config -> (a -> IO a) -> a -> IO a
|
|
||||||
saveConfig cfig f x = do
|
|
||||||
-- putStrLn "Saving config to data/dodge.config.json"
|
|
||||||
BS.writeFile "data/dodge.config.json" $
|
|
||||||
AEP.encodePretty' (AEP.Config (AEP.Spaces 2) compare AEP.Generic False) cfig
|
|
||||||
f x
|
|
||||||
|
|
||||||
{- |
|
|
||||||
Apply the volume settings from the world configuration to the running game.
|
|
||||||
-}
|
|
||||||
setVol :: Config -> IO ()
|
|
||||||
setVol cfig = do
|
|
||||||
setSoundVolume (_volume_master cfig * _volume_sound cfig)
|
|
||||||
setMusicVolume (_volume_master cfig * _volume_music cfig)
|
|
||||||
|
|
||||||
{- |
|
|
||||||
Apply /all/ of the values in the world configuration to the running game.
|
|
||||||
-}
|
|
||||||
applyWorldConfig ::
|
|
||||||
Config ->
|
|
||||||
PreloadData ->
|
|
||||||
IO PreloadData
|
|
||||||
applyWorldConfig cfig pdata = do
|
|
||||||
setVol cfig
|
|
||||||
renderData (renderDataResizeUpdate cfig) pdata
|
|
||||||
+1
-1
@@ -10,7 +10,7 @@ import Data.ByteString.Lazy.Char8 (unpack)
|
|||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Dodge.Base.Coordinate
|
import Dodge.Base.Coordinate
|
||||||
import Dodge.Concurrent
|
import Dodge.Concurrent
|
||||||
import Dodge.Config.Update
|
import Dodge.Config
|
||||||
import Dodge.Data.Universe
|
import Dodge.Data.Universe
|
||||||
import Dodge.Menu.Option
|
import Dodge.Menu.Option
|
||||||
import Dodge.Menu.OptionType
|
import Dodge.Menu.OptionType
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
module Dodge.Room.Tutorial where
|
module Dodge.Room.Tutorial where
|
||||||
|
|
||||||
import Dodge.Item.Held.Utility
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import qualified Data.IntMap.Strict as IM
|
import qualified Data.IntMap.Strict as IM
|
||||||
import qualified Data.IntSet as IS
|
import qualified Data.IntSet as IS
|
||||||
|
|||||||
@@ -2657,7 +2657,7 @@ applyToRandomNode src/TreeHelp.hs 151;" f
|
|||||||
applyToSubforest src/TreeHelp.hs 78;" f
|
applyToSubforest src/TreeHelp.hs 78;" f
|
||||||
applyToSubtree src/TreeHelp.hs 71;" f
|
applyToSubtree src/TreeHelp.hs 71;" f
|
||||||
applyTorqueCME src/Dodge/HeldUse.hs 562;" f
|
applyTorqueCME src/Dodge/HeldUse.hs 562;" f
|
||||||
applyWorldConfig src/Dodge/Config/Update.hs 38;" f
|
applyWorldConfig src/Dodge/Config.hs 55;" f
|
||||||
aquamarine src/Color.hs 23;" f
|
aquamarine src/Color.hs 23;" f
|
||||||
arHUD src/Dodge/Item/Scope.hs 134;" f
|
arHUD src/Dodge/Item/Scope.hs 134;" f
|
||||||
arc src/Picture/Base.hs 287;" f
|
arc src/Picture/Base.hs 287;" f
|
||||||
@@ -4070,7 +4070,7 @@ litCorridor90 src/Dodge/Room/RoadBlock.hs 26;" f
|
|||||||
lmt src/MatrixHelper.hs 43;" f
|
lmt src/MatrixHelper.hs 43;" f
|
||||||
lnkBothAnd src/Dodge/Room/Procedural.hs 124;" f
|
lnkBothAnd src/Dodge/Room/Procedural.hs 124;" f
|
||||||
lnkMidPosInvSelsCol src/Dodge/Render/HUD.hs 387;" f
|
lnkMidPosInvSelsCol src/Dodge/Render/HUD.hs 387;" f
|
||||||
loadDodgeConfig src/Dodge/Config/Load.hs 9;" f
|
loadDodgeConfig src/Dodge/Config.hs 29;" f
|
||||||
loadMusic src/Dodge/SoundLogic/LoadSound.hs 30;" f
|
loadMusic src/Dodge/SoundLogic/LoadSound.hs 30;" f
|
||||||
loadMuzzle src/Dodge/HeldUse.hs 622;" f
|
loadMuzzle src/Dodge/HeldUse.hs 622;" f
|
||||||
loadSaveSlot src/Dodge/Save.hs 74;" f
|
loadSaveSlot src/Dodge/Save.hs 74;" f
|
||||||
@@ -4805,7 +4805,7 @@ roomCritLS src/Dodge/Room/RunPast.hs 24;" f
|
|||||||
roomCross src/Dodge/Room/Boss.hs 85;" f
|
roomCross src/Dodge/Room/Boss.hs 85;" f
|
||||||
roomGlassOctogon src/Dodge/Room/Boss.hs 21;" f
|
roomGlassOctogon src/Dodge/Room/Boss.hs 21;" f
|
||||||
roomMiniIntro src/Dodge/Room/Room.hs 121;" f
|
roomMiniIntro src/Dodge/Room/Room.hs 121;" f
|
||||||
roomNgon src/Dodge/Room/Ngon.hs 15;" f
|
roomNgon src/Dodge/Room/Ngon.hs 16;" f
|
||||||
roomPadCut src/Dodge/Room/Room.hs 61;" f
|
roomPadCut src/Dodge/Room/Room.hs 61;" f
|
||||||
roomPillars src/Dodge/Room/Pillar.hs 106;" f
|
roomPillars src/Dodge/Room/Pillar.hs 106;" f
|
||||||
roomPillarsContaining src/Dodge/Room/Containing.hs 39;" f
|
roomPillarsContaining src/Dodge/Room/Containing.hs 39;" f
|
||||||
@@ -4866,7 +4866,7 @@ safeNormalizeV src/Geometry/Vector.hs 164;" f
|
|||||||
safeSwapKeys src/IntMapHelp.hs 77;" f
|
safeSwapKeys src/IntMapHelp.hs 77;" f
|
||||||
safeUncons src/ListHelp.hs 72;" f
|
safeUncons src/ListHelp.hs 72;" f
|
||||||
safeUpdateSingleNode src/TreeHelp.hs 116;" f
|
safeUpdateSingleNode src/TreeHelp.hs 116;" f
|
||||||
saveConfig src/Dodge/Config/Update.hs 20;" f
|
saveConfig src/Dodge/Config.hs 22;" f
|
||||||
saveQuit src/Dodge/Menu.hs 76;" f
|
saveQuit src/Dodge/Menu.hs 76;" f
|
||||||
saveQuitConc src/Dodge/Menu.hs 79;" f
|
saveQuitConc src/Dodge/Menu.hs 79;" f
|
||||||
saveSlotPath src/Dodge/Save.hs 63;" f
|
saveSlotPath src/Dodge/Save.hs 63;" f
|
||||||
@@ -4966,7 +4966,7 @@ setTreeInts src/Dodge/Room/Tutorial.hs 67;" f
|
|||||||
setViewDistance src/Dodge/Update/Camera.hs 236;" f
|
setViewDistance src/Dodge/Update/Camera.hs 236;" f
|
||||||
setViewPos src/Dodge/Creature/ReaderUpdate.hs 63;" f
|
setViewPos src/Dodge/Creature/ReaderUpdate.hs 63;" f
|
||||||
setViewport src/Dodge/Render.hs 440;" f
|
setViewport src/Dodge/Render.hs 440;" f
|
||||||
setVol src/Dodge/Config/Update.hs 30;" f
|
setVol src/Dodge/Config.hs 47;" f
|
||||||
setWristShieldPos src/Dodge/Equipment.hs 48;" f
|
setWristShieldPos src/Dodge/Equipment.hs 48;" f
|
||||||
setWristShieldPos src/Dodge/Euse.hs 35;" f
|
setWristShieldPos src/Dodge/Euse.hs 35;" f
|
||||||
setupConLoop src/Loop.hs 102;" f
|
setupConLoop src/Loop.hs 102;" f
|
||||||
|
|||||||
@@ -1,734 +0,0 @@
|
|||||||
{-# LANGUAGE TupleSections #-}
|
|
||||||
|
|
||||||
{- |
|
|
||||||
Weapon effects when pulling the trigger.
|
|
||||||
-}
|
|
||||||
module Dodge.Item.Weapon.TriggerType (
|
|
||||||
useAmmoAmount,
|
|
||||||
useAllAmmo,
|
|
||||||
useAmmoUpTo,
|
|
||||||
lockInvFor,
|
|
||||||
withMuzFlareI,
|
|
||||||
withMuzPos,
|
|
||||||
withMuzPosShift,
|
|
||||||
crAtMuzPos,
|
|
||||||
withOldDir,
|
|
||||||
trigDoAlso,
|
|
||||||
trigDoAlso',
|
|
||||||
withTempLight,
|
|
||||||
withItem,
|
|
||||||
withItemUpdate,
|
|
||||||
withItemUpdate',
|
|
||||||
ammoUseCheck,
|
|
||||||
rateIncAB,
|
|
||||||
torqueBefore,
|
|
||||||
torqueBeforeAtLeast,
|
|
||||||
withTorqueAfter,
|
|
||||||
torqueSideEffect,
|
|
||||||
withRandomItemParams,
|
|
||||||
withRandomItemUpdate,
|
|
||||||
withSoundStart,
|
|
||||||
withSoundItemChoiceStart,
|
|
||||||
withSoundContinue,
|
|
||||||
withSoundForI,
|
|
||||||
withSoundForVol,
|
|
||||||
withSmoke,
|
|
||||||
withThickSmokeI,
|
|
||||||
withThinSmokeI,
|
|
||||||
withPositionOffset,
|
|
||||||
withPositionWallCheck,
|
|
||||||
withPosDirWallCheck,
|
|
||||||
withRandomOffset,
|
|
||||||
withRandomDirI,
|
|
||||||
withRecoil,
|
|
||||||
afterRecoil,
|
|
||||||
withSidePushAfterI,
|
|
||||||
withSidePushI,
|
|
||||||
withWarmUp,
|
|
||||||
spreadNumI,
|
|
||||||
spreadLoaded,
|
|
||||||
repeatOnFrames,
|
|
||||||
sideEffectOnFrame,
|
|
||||||
duplicateItem,
|
|
||||||
duplicateLoadedBarrels,
|
|
||||||
duplicateLoaded,
|
|
||||||
duplicateOffsets,
|
|
||||||
duplicateOffsetsV2,
|
|
||||||
duplicateOffsetsFocus,
|
|
||||||
hammerCheckI,
|
|
||||||
hammerCheckL,
|
|
||||||
shootL,
|
|
||||||
useTimeCheck,
|
|
||||||
ammoCheckI,
|
|
||||||
applyInaccuracy,
|
|
||||||
modClock,
|
|
||||||
ammoHammerCheck,
|
|
||||||
) where
|
|
||||||
|
|
||||||
import Data.Foldable
|
|
||||||
import Data.Maybe
|
|
||||||
import Dodge.Base
|
|
||||||
import Dodge.Creature.HandPos
|
|
||||||
import Dodge.Creature.Test
|
|
||||||
import Dodge.Data.World
|
|
||||||
import Dodge.Inventory.Lock
|
|
||||||
import Dodge.LightSource
|
|
||||||
import Dodge.Reloading
|
|
||||||
import Dodge.SoundLogic
|
|
||||||
import Dodge.WorldEvent
|
|
||||||
import Geometry
|
|
||||||
import LensHelp
|
|
||||||
import RandomHelp
|
|
||||||
import Sound.Data
|
|
||||||
|
|
||||||
type ChainEffect =
|
|
||||||
(Item -> Creature -> World -> World) ->
|
|
||||||
Item ->
|
|
||||||
Creature ->
|
|
||||||
World ->
|
|
||||||
World
|
|
||||||
|
|
||||||
lockInvFor :: Int -> ChainEffect
|
|
||||||
lockInvFor i f it cr =
|
|
||||||
f it cr . (cWorld . lWorld . delayedEvents .:~ (i, UnlockInv (_crID cr)))
|
|
||||||
. lockInv (_crID cr)
|
|
||||||
|
|
||||||
trigDoAlso' ::
|
|
||||||
(Item -> Item) ->
|
|
||||||
(Creature -> Creature) ->
|
|
||||||
(Item -> Creature -> World -> World) ->
|
|
||||||
ChainEffect
|
|
||||||
trigDoAlso' fit fcr f g itm cr = g itm cr . f (fit itm) (fcr cr)
|
|
||||||
|
|
||||||
-- Note that this uses the "base" creature and item values
|
|
||||||
trigDoAlso ::
|
|
||||||
(Item -> Creature -> World -> World) ->
|
|
||||||
ChainEffect
|
|
||||||
trigDoAlso afterEff eff item cr = afterEff item cr . eff item cr
|
|
||||||
|
|
||||||
withSmoke :: Int -> Point4 -> Float -> Int -> Float -> ChainEffect
|
|
||||||
withSmoke num col rad t alt eff item cr w =
|
|
||||||
eff item cr $
|
|
||||||
foldl' (flip $ smokeCloudAt col rad t alt . (+.+.+ pos) . (* 8)) w ps
|
|
||||||
where
|
|
||||||
dir = _crDir cr
|
|
||||||
pos = addZ 0 $ _crPos cr +.+ (_crRad cr + 15) *.* unitVectorAtAngle dir
|
|
||||||
ps = replicateM num randOnUnitSphere & evalState $ _randGen w
|
|
||||||
|
|
||||||
withThinSmokeI :: ChainEffect
|
|
||||||
withThinSmokeI eff item cr w =
|
|
||||||
eff item cr $
|
|
||||||
foldl' (flip $ makeThinSmokeAt . (+.+.+ pos) . (* 8)) w ps
|
|
||||||
where
|
|
||||||
dir = _crDir cr
|
|
||||||
pos = addZ 0 $ _crPos cr +.+ (_crRad cr + 0.5) *.* unitVectorAtAngle dir
|
|
||||||
ps = replicateM 5 randOnUnitSphere & evalState $ _randGen w
|
|
||||||
|
|
||||||
withThickSmokeI :: ChainEffect
|
|
||||||
withThickSmokeI eff item cr w =
|
|
||||||
eff item cr $
|
|
||||||
foldl' (flip $ makeThickSmokeAt . (+.+.+ pos) . (* 8)) w ps
|
|
||||||
where
|
|
||||||
dir = _crDir cr
|
|
||||||
pos = addZ 0 $ _crPos cr +.+ (_crRad cr + 15) *.* unitVectorAtAngle dir
|
|
||||||
ps = replicateM 20 randOnUnitSphere & evalState $ _randGen w
|
|
||||||
|
|
||||||
-- TODO create a trigger that does different things on first and continued
|
|
||||||
-- fire.
|
|
||||||
ammoCheckI :: ChainEffect
|
|
||||||
ammoCheckI eff itm cr w
|
|
||||||
| _laLoaded ic <= 0 || not (_laPrimed ic) = w
|
|
||||||
| otherwise = eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
|
|
||||||
where
|
|
||||||
ic = _heldConsumption $ _itUse itm
|
|
||||||
|
|
||||||
-- combined ammo and hammer check: want to be able to auto-reload even if the
|
|
||||||
-- hammer is down?
|
|
||||||
ammoHammerCheck :: ChainEffect
|
|
||||||
ammoHammerCheck eff it cr w
|
|
||||||
| _laLoaded ic <= 0 || not (_laPrimed ic) = w -- fromMaybe w (startReloadingWeapon cr w)
|
|
||||||
| otherwise = case it ^? itUse . heldHammer of
|
|
||||||
Just HammerUp -> eff it cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
|
|
||||||
_ -> w
|
|
||||||
where
|
|
||||||
ic = _heldConsumption $ _itUse it
|
|
||||||
|
|
||||||
itUseCharge :: Int -> Item -> Item
|
|
||||||
itUseCharge x = itUse . leftConsumption . arLoaded %~ (max 0 . subtract x)
|
|
||||||
|
|
||||||
itUseAmmo :: Int -> Item -> Item
|
|
||||||
itUseAmmo x = itUse . heldConsumption . laLoaded %~ (max 0 . subtract x)
|
|
||||||
|
|
||||||
{- | Fires at an increasing rate.
|
|
||||||
Has different effect after first fire.
|
|
||||||
Applies ammo check and use cooldown check.
|
|
||||||
-}
|
|
||||||
rateIncAB ::
|
|
||||||
-- | Extra effect on first fire
|
|
||||||
ChainEffect ->
|
|
||||||
-- | Extra effect on continued fire
|
|
||||||
ChainEffect ->
|
|
||||||
ChainEffect
|
|
||||||
rateIncAB exeffFirst exeffCont eff item cr w
|
|
||||||
| repeatFire =
|
|
||||||
w
|
|
||||||
& pointItem
|
|
||||||
%~ ( (itUse . heldDelay . rateMax .~ max fastRate (currentRate - 1))
|
|
||||||
. itUseAmmo 1
|
|
||||||
. (itUse . heldDelay . rateTime .~ currentRate)
|
|
||||||
)
|
|
||||||
& exeffCont eff item cr
|
|
||||||
| firstFire =
|
|
||||||
w
|
|
||||||
& pointItem
|
|
||||||
%~ ( (itUse . heldDelay . rateMax .~ startRate - 1)
|
|
||||||
. itUseAmmo 1
|
|
||||||
. (itUse . heldDelay . rateTime .~ startRate)
|
|
||||||
)
|
|
||||||
& exeffFirst eff item cr
|
|
||||||
| otherwise = w
|
|
||||||
where
|
|
||||||
fastRate = _rateMinMax . _heldDelay $ _itUse item
|
|
||||||
startRate = _rateMaxMax . _heldDelay $ _itUse item
|
|
||||||
cid = _crID cr
|
|
||||||
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
|
||||||
pointItem = cWorld . lWorld . creatures . ix cid . crInv . ix itRef
|
|
||||||
currentRate = _rateMax (_heldDelay (_itUse item))
|
|
||||||
repeatFire = crWeaponReady cr && _rateTime (_heldDelay (_itUse item)) == 1
|
|
||||||
firstFire = crWeaponReady cr && _rateTime (_heldDelay (_itUse item)) == 0
|
|
||||||
|
|
||||||
-- | Apply effect after a warm up.
|
|
||||||
|
|
||||||
-- note this is quite unsafe, requires the item to have the correct delay type
|
|
||||||
withWarmUp ::
|
|
||||||
-- | warm up sound id
|
|
||||||
SoundID ->
|
|
||||||
ChainEffect
|
|
||||||
withWarmUp soundID f item cr w
|
|
||||||
| curWarmUp < maxWarmUp && crWeaponReady cr =
|
|
||||||
w
|
|
||||||
& pointerToItem . itUse . heldDelay . warmTime +~ 2
|
|
||||||
& soundContinue (CrWeaponSound cid 0) (_crPos cr) soundID (Just 2)
|
|
||||||
| otherwise =
|
|
||||||
w
|
|
||||||
& pointerToItem . itUse . heldDelay . warmTime .~ maxWarmUp
|
|
||||||
& f item cr
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
|
||||||
pointerToItem = cWorld . lWorld . creatures . ix cid . crInv . ix itRef
|
|
||||||
curWarmUp = _warmTime . _heldDelay $ _itUse item
|
|
||||||
maxWarmUp = _warmMax . _heldDelay $ _itUse item
|
|
||||||
|
|
||||||
withSoundItemChoiceStart ::
|
|
||||||
(Item -> SoundID) ->
|
|
||||||
ChainEffect
|
|
||||||
withSoundItemChoiceStart soundf f it cr =
|
|
||||||
soundMultiFrom
|
|
||||||
[CrWeaponSound cid 0, CrWeaponSound cid 1, CrWeaponSound cid 2]
|
|
||||||
(_crPos cr)
|
|
||||||
(soundf it)
|
|
||||||
Nothing
|
|
||||||
. f it cr
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
|
|
||||||
{- | Adds a sound to a creature based world effect.
|
|
||||||
The sound is emitted from the creature's position.
|
|
||||||
-}
|
|
||||||
withSoundStart ::
|
|
||||||
-- | Sound id
|
|
||||||
SoundID ->
|
|
||||||
ChainEffect
|
|
||||||
withSoundStart soundid f item cr =
|
|
||||||
soundMultiFrom [CrWeaponSound cid 0, CrWeaponSound cid 1, CrWeaponSound cid 2] (_crPos cr) soundid Nothing
|
|
||||||
. f item cr
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
|
|
||||||
{- | Adds a sound to a creature based world effect.
|
|
||||||
The sound is emitted from the creature's position.
|
|
||||||
-}
|
|
||||||
withSoundContinue ::
|
|
||||||
-- | Sound id
|
|
||||||
SoundID ->
|
|
||||||
ChainEffect
|
|
||||||
withSoundContinue soundid f item cr =
|
|
||||||
soundContinue (CrWeaponSound cid 0) (_crPos cr) soundid Nothing
|
|
||||||
. f item cr
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
|
|
||||||
{- | Adds a sound to a creature based world effect.
|
|
||||||
The sound is emitted from the creature's position.
|
|
||||||
-}
|
|
||||||
withSoundForI ::
|
|
||||||
-- | Sound id
|
|
||||||
SoundID ->
|
|
||||||
-- | Frames to play
|
|
||||||
Int ->
|
|
||||||
ChainEffect
|
|
||||||
withSoundForI soundid playTime f item cr =
|
|
||||||
soundContinue (CrWeaponSound (_crID cr) 0) (_crPos cr) soundid (Just playTime)
|
|
||||||
. f item cr
|
|
||||||
|
|
||||||
{- | Adds a sound to a creature based world effect.
|
|
||||||
The sound is emitted from the creature's position.
|
|
||||||
-}
|
|
||||||
withSoundForVol ::
|
|
||||||
-- | volume
|
|
||||||
Float ->
|
|
||||||
-- | Sound id
|
|
||||||
SoundID ->
|
|
||||||
-- | Frames to play
|
|
||||||
Int ->
|
|
||||||
ChainEffect
|
|
||||||
withSoundForVol vol soundid playTime f item cr =
|
|
||||||
soundContinueVol vol (CrWeaponSound (_crID cr) 0) (_crPos cr) soundid (Just playTime)
|
|
||||||
. f item cr
|
|
||||||
|
|
||||||
afterRecoil ::
|
|
||||||
-- | Recoil amount
|
|
||||||
Float ->
|
|
||||||
ChainEffect
|
|
||||||
afterRecoil recoilAmount eff item cr = eff item (pushback cr) . over (cWorld . lWorld . creatures . ix cid) pushback
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
pushback = over crPos (+.+ rotateV (_crDir cr) (V2 ((- recoilAmount) / _crMass cr) 0))
|
|
||||||
|
|
||||||
withRecoil :: ChainEffect
|
|
||||||
withRecoil eff it cr = eff it cr . over (cWorld . lWorld . creatures . ix cid) pushback
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
recoilAmount = fromMaybe 0 $ it ^? itParams . recoil
|
|
||||||
pushback = over crPos (+.+ rotateV (_crDir cr) (V2 ((- recoilAmount) / _crMass cr) 0))
|
|
||||||
|
|
||||||
{- | Pushes a creature sideways by a random amount.
|
|
||||||
Applied before the underlying effect.
|
|
||||||
-}
|
|
||||||
withSidePushI ::
|
|
||||||
-- | Maximal possible side push amount
|
|
||||||
Float ->
|
|
||||||
ChainEffect
|
|
||||||
withSidePushI maxSide eff item cr w =
|
|
||||||
eff item (push cr) $
|
|
||||||
w
|
|
||||||
& cWorld . lWorld . creatures . ix cid %~ push
|
|
||||||
& randGen .~ g
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr)))
|
|
||||||
(pushAmount, g) = randomR (- maxSide, maxSide) $ _randGen w
|
|
||||||
|
|
||||||
-- consider unifying the pushes using a direction vector
|
|
||||||
|
|
||||||
{- | Pushes a creature sideways by a random amount.
|
|
||||||
Applied after the underlying effect.
|
|
||||||
-}
|
|
||||||
withSidePushAfterI ::
|
|
||||||
-- | Maximal possible side push amount
|
|
||||||
Float ->
|
|
||||||
ChainEffect
|
|
||||||
withSidePushAfterI maxSide eff item cr w =
|
|
||||||
over (cWorld . lWorld . creatures . ix cid) push . eff item cr $
|
|
||||||
w
|
|
||||||
& randGen .~ g
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr)))
|
|
||||||
(pushAmount, g) = randomR (- maxSide, maxSide) $ _randGen w
|
|
||||||
|
|
||||||
useAllAmmo :: ChainEffect
|
|
||||||
useAllAmmo eff item cr =
|
|
||||||
eff item cr
|
|
||||||
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itUse . heldConsumption . laLoaded .~ 0)
|
|
||||||
where
|
|
||||||
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
|
||||||
|
|
||||||
useAmmoUpTo :: Int -> ChainEffect
|
|
||||||
useAmmoUpTo amAmount eff item cr =
|
|
||||||
eff item cr
|
|
||||||
. ( cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itUse . heldConsumption . laLoaded
|
|
||||||
%~ (max 0 . subtract amAmount)
|
|
||||||
)
|
|
||||||
where
|
|
||||||
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
|
||||||
|
|
||||||
useAmmoAmount :: Int -> ChainEffect
|
|
||||||
useAmmoAmount amAmount eff item cr =
|
|
||||||
eff item cr
|
|
||||||
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itUse . heldConsumption . laLoaded -~ amAmount)
|
|
||||||
where
|
|
||||||
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
|
||||||
|
|
||||||
{- |
|
|
||||||
Applies a world effect after an item use cooldown check.
|
|
||||||
-}
|
|
||||||
useTimeCheck :: ChainEffect
|
|
||||||
useTimeCheck f item cr w = case item ^? itUse . heldDelay . rateTime of
|
|
||||||
Just 0 -> f item cr $ setUseTime w
|
|
||||||
_ -> w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
setUseTime = cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . rateTime +~ userate
|
|
||||||
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
|
||||||
userate = fromMaybe 0 $ item ^? itUse . heldDelay . rateMax
|
|
||||||
|
|
||||||
-- | Applies a world effect after a hammer position check.
|
|
||||||
hammerCheckI :: ChainEffect
|
|
||||||
hammerCheckI f it cr w = case it ^? itUse . heldHammer of
|
|
||||||
Just HammerUp
|
|
||||||
| _laPrimed (_heldConsumption (_itUse it)) ->
|
|
||||||
f it cr w
|
|
||||||
_ -> w
|
|
||||||
|
|
||||||
-- | Applies a world effect after an ammo check.
|
|
||||||
|
|
||||||
-- this should be made "safe" incase there is no _rateTime
|
|
||||||
ammoUseCheck :: ChainEffect
|
|
||||||
ammoUseCheck f item cr w
|
|
||||||
| fireCondition =
|
|
||||||
f item cr w & pointerToItem
|
|
||||||
%~ ( itUseAmmo 1
|
|
||||||
. (itUse . heldDelay . rateTime .~ _rateMax (_heldDelay (_itUse item)))
|
|
||||||
)
|
|
||||||
-- | reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
|
||||||
| otherwise = w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
|
||||||
pointerToItem = cWorld . lWorld . creatures . ix cid . crInv . ix itRef
|
|
||||||
fireCondition =
|
|
||||||
crWeaponReady cr
|
|
||||||
&& _rateTime (_heldDelay (_itUse item)) == 0
|
|
||||||
&& _laLoaded (_heldConsumption (_itUse item)) > 0
|
|
||||||
|
|
||||||
-- reloadCondition = _laLoaded (_itConsumption item) == 0
|
|
||||||
|
|
||||||
{- | Applies a world effect after a hammer position check.
|
|
||||||
Arbitrary inventory position.
|
|
||||||
-}
|
|
||||||
hammerCheckL ::
|
|
||||||
-- | Underlying effect
|
|
||||||
(Item -> Creature -> World -> World) ->
|
|
||||||
Item ->
|
|
||||||
Creature ->
|
|
||||||
World ->
|
|
||||||
World
|
|
||||||
hammerCheckL f itm cr w = case itm ^? itUse . leftHammer of
|
|
||||||
Just HammerUp -> f itm cr w
|
|
||||||
_ -> w
|
|
||||||
|
|
||||||
{- | Applies a world effect after an ammo check.
|
|
||||||
Arbitrary inventory position -- cannot be replaced with ammoUseCheck.
|
|
||||||
-}
|
|
||||||
shootL ::
|
|
||||||
-- | Underlying effect
|
|
||||||
(Item -> Creature -> World -> World) ->
|
|
||||||
Item ->
|
|
||||||
Creature ->
|
|
||||||
World ->
|
|
||||||
World
|
|
||||||
shootL f item cr w
|
|
||||||
| fireCondition =
|
|
||||||
f item cr w & pointerToItem
|
|
||||||
%~ ( itUseCharge 1
|
|
||||||
. (itUse . leftDelay . rateTime .~ _rateMax (_leftDelay (_itUse item)))
|
|
||||||
)
|
|
||||||
-- | reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
|
||||||
| otherwise = w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
invid = _ipInvID $ _itLocation item
|
|
||||||
pointerToItem = cWorld . lWorld . creatures . ix cid . crInv . ix invid
|
|
||||||
fireCondition =
|
|
||||||
_rateTime (_leftDelay (_itUse item)) == 0
|
|
||||||
&& _arLoaded (_leftConsumption (_itUse item)) > 0
|
|
||||||
|
|
||||||
-- reloadCondition = _laLoaded (_itConsumption item) == 0
|
|
||||||
withItem :: (Item -> ChainEffect) -> ChainEffect
|
|
||||||
withItem g f it = g it f it
|
|
||||||
|
|
||||||
-- not ideal
|
|
||||||
withItemUpdate' :: (Item -> Item) -> ChainEffect
|
|
||||||
withItemUpdate' up f it cr = f (up it) cr . (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef %~ up)
|
|
||||||
where
|
|
||||||
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
|
||||||
|
|
||||||
withItemUpdate :: (Item -> Item) -> (Item -> ChainEffect) -> ChainEffect
|
|
||||||
withItemUpdate up g f it cr = g it f it cr . (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef %~ up)
|
|
||||||
where
|
|
||||||
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
|
||||||
|
|
||||||
withTempLight :: Int -> Float -> V3 Float -> ChainEffect
|
|
||||||
withTempLight time rad col eff item cr =
|
|
||||||
eff item cr
|
|
||||||
. over (cWorld . lWorld . tempLightSources) (theTLS :)
|
|
||||||
where
|
|
||||||
theTLS = tlsTimeRadColPos time rad col (V3 x y 10)
|
|
||||||
V2 x y = _crPos cr +.+ 15 *.* unitVectorAtAngle (_crDir cr)
|
|
||||||
|
|
||||||
modClock :: Int -> ChainEffect -> ChainEffect
|
|
||||||
modClock n chainEff eff it cr w
|
|
||||||
| (w ^. cWorld . lWorld . lClock) `mod` n == 0 = chainEff eff it cr w
|
|
||||||
| otherwise = eff it cr w
|
|
||||||
|
|
||||||
withMuzFlareI :: ChainEffect
|
|
||||||
withMuzFlareI f it cr w =
|
|
||||||
makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) flashPos
|
|
||||||
. muzFlareAt (V4 5 5 0 2) flarePos cdir
|
|
||||||
$ f it cr w
|
|
||||||
where
|
|
||||||
flarePos = addZ 0 (_crPos cr) +.+.+ rotate3z cdir (muzzleOffset cr it +.+.+ V3 0 0 20)
|
|
||||||
flashPos = addZ 0 (_crPos cr) +.+.+ rotate3z cdir (muzzleOffset cr it +.+.+ V3 5 0 20)
|
|
||||||
-- muzzleOffset = V3 (_muzPos (_dimPortage (_itDimension it))) 0 0
|
|
||||||
cdir = _crDir cr
|
|
||||||
|
|
||||||
muzzleOffset :: Creature -> Item -> Point3
|
|
||||||
muzzleOffset cr it = V3 (holdOffset + 5 + _aimMuzPos dimPort - _aimHandlePos dimPort) 0 0
|
|
||||||
where
|
|
||||||
dimPort = _heldAim $ _itUse it
|
|
||||||
holdOffset
|
|
||||||
| crInAimStance OneHand cr = 10
|
|
||||||
| otherwise = 0
|
|
||||||
|
|
||||||
withMuzPos :: (Point3 -> World -> World) -> ChainEffect
|
|
||||||
withMuzPos = withMuzPosShift (V2 0 0)
|
|
||||||
|
|
||||||
withMuzPosShift :: Point2 -> (Point3 -> World -> World) -> ChainEffect
|
|
||||||
withMuzPosShift p g f it cr w =
|
|
||||||
g (pos `v2z` 20) $
|
|
||||||
f it cr w
|
|
||||||
where
|
|
||||||
pos =
|
|
||||||
_crPos cr
|
|
||||||
+.+ rotateV dir p
|
|
||||||
+.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir
|
|
||||||
dir = _crDir cr
|
|
||||||
|
|
||||||
crAtMuzPos :: ChainEffect
|
|
||||||
crAtMuzPos f it cr = f it (cr & crPos +.+.~ (aimingMuzzlePos cr it *.* unitVectorAtAngle (_crDir cr)))
|
|
||||||
|
|
||||||
{- | Applies the effect to a randomly rotated creature,
|
|
||||||
- rotation amount given by inaccuracy in itParams
|
|
||||||
-}
|
|
||||||
applyInaccuracy :: ChainEffect
|
|
||||||
applyInaccuracy f it = withRandomDirI acc f it
|
|
||||||
where
|
|
||||||
acc = _brlInaccuracy . _gunBarrels $ _itParams it
|
|
||||||
|
|
||||||
-- | Applies the effect to a randomly rotated creature.
|
|
||||||
withRandomDirI ::
|
|
||||||
-- | Max possible rotation
|
|
||||||
Float ->
|
|
||||||
ChainEffect
|
|
||||||
withRandomDirI acc f it cr w = f it (cr & crDir +~ a) $ set randGen g w
|
|
||||||
where
|
|
||||||
(a, g) = randomR (- acc, acc) $ _randGen w
|
|
||||||
|
|
||||||
withOldDir ::
|
|
||||||
-- | The fraction of the old direction
|
|
||||||
Float ->
|
|
||||||
ChainEffect
|
|
||||||
withOldDir aFrac eff item cr =
|
|
||||||
eff item (cr & crDir %~ tweenAngles aFrac (_crOldDir cr))
|
|
||||||
|
|
||||||
withRandomItemUpdate ::
|
|
||||||
State StdGen (Item -> Item) ->
|
|
||||||
ChainEffect
|
|
||||||
withRandomItemUpdate randItUp eff it cr w = eff (f it) cr $ w & randGen .~ g
|
|
||||||
where
|
|
||||||
(f, g) = runState randItUp (_randGen w)
|
|
||||||
|
|
||||||
withRandomItemParams :: State StdGen (ItemParams -> ItemParams) -> ChainEffect
|
|
||||||
withRandomItemParams rip eff it cr w = eff (it & itParams %~ f) cr $ w & randGen .~ g
|
|
||||||
where
|
|
||||||
(f, g) = runState rip (_randGen w)
|
|
||||||
|
|
||||||
withPositionOffset ::
|
|
||||||
(Item -> Creature -> World -> (Point2, Float)) ->
|
|
||||||
ChainEffect
|
|
||||||
withPositionOffset h f it cr w = f it (cr & crPos .+.+~ p & crDir +~ a) w
|
|
||||||
where
|
|
||||||
(p, a) = h it cr w
|
|
||||||
|
|
||||||
withPositionWallCheck ::
|
|
||||||
(Item -> Creature -> World -> Point2) ->
|
|
||||||
ChainEffect
|
|
||||||
withPositionWallCheck h f it cr w
|
|
||||||
| hasLOS p (_crPos cr) w = f it (cr & crPos .~ p) w
|
|
||||||
| otherwise = w
|
|
||||||
where
|
|
||||||
p = h it cr w
|
|
||||||
|
|
||||||
withPosDirWallCheck ::
|
|
||||||
(Item -> Creature -> World -> (Point2, Float)) ->
|
|
||||||
ChainEffect
|
|
||||||
withPosDirWallCheck h f it cr w
|
|
||||||
| hasLOS p (_crPos cr) w = f it (cr & crPos .~ p & crDir .~ a) w
|
|
||||||
| otherwise = w
|
|
||||||
where
|
|
||||||
(p, a) = h it cr w
|
|
||||||
|
|
||||||
-- | Apply the effect to a translated creature.
|
|
||||||
withRandomOffset :: ChainEffect
|
|
||||||
withRandomOffset 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)
|
|
||||||
offsetAmount = fromMaybe 0 $ item ^? itParams . randomOffset
|
|
||||||
|
|
||||||
-- | Rotates a creature
|
|
||||||
torqueBefore ::
|
|
||||||
-- | Max possible rotation
|
|
||||||
Float ->
|
|
||||||
ChainEffect
|
|
||||||
torqueBefore torque feff item cr w
|
|
||||||
| cid == 0 =
|
|
||||||
feff item (cr & crDir +~ rot) $
|
|
||||||
w
|
|
||||||
& randGen .~ g
|
|
||||||
& cWorld . lWorld . creatures . ix cid . crDir +~ rot
|
|
||||||
& wCam . camRot +~ rot
|
|
||||||
| otherwise = feff item cr $ set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
(rot, g) = randomR (- torque, torque) $ _randGen w
|
|
||||||
|
|
||||||
{- | Rotates a creature with minimum rotation
|
|
||||||
Rotates the player creature before applying the effect, other creatures after.
|
|
||||||
-}
|
|
||||||
torqueBeforeAtLeast ::
|
|
||||||
-- | Minimal possible rotation
|
|
||||||
Float ->
|
|
||||||
-- | Extra possible rotation
|
|
||||||
Float ->
|
|
||||||
ChainEffect
|
|
||||||
torqueBeforeAtLeast minTorque exTorque feff item cr w
|
|
||||||
| cid == 0 =
|
|
||||||
feff item (cr & crDir +~ rot') $
|
|
||||||
w
|
|
||||||
& randGen .~ g
|
|
||||||
& cWorld . lWorld . creatures . ix cid . crDir +~ rot'
|
|
||||||
& wCam . camRot +~ rot'
|
|
||||||
| otherwise = feff item cr $ set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot') w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
(rot, g) = randomR (- exTorque, exTorque) $ _randGen w
|
|
||||||
rot'
|
|
||||||
| rot < 0 = rot - minTorque
|
|
||||||
| otherwise = rot + minTorque
|
|
||||||
|
|
||||||
-- | Rotate a randomly creature after applying an effect.
|
|
||||||
withTorqueAfter :: ChainEffect
|
|
||||||
withTorqueAfter feff item cr w
|
|
||||||
-- | cid == 0 = rotateScope $ set randGen g $ over cameraRot (+rot) $ feff item cr w
|
|
||||||
| cid == 0 = set randGen g $ over (wCam . camRot) (+ rot) $ feff item cr w
|
|
||||||
| otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) $ feff item cr w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
(rot, g) = randomR (- torque, torque) $ _randGen w
|
|
||||||
torque = fromMaybe 0 $ item ^? itParams . torqueAfter
|
|
||||||
|
|
||||||
spreadNumI :: ChainEffect
|
|
||||||
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 = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item
|
|
||||||
numBul = _brlNum . _gunBarrels $ _itParams item
|
|
||||||
|
|
||||||
spreadLoaded :: ChainEffect
|
|
||||||
spreadLoaded eff item cr w = foldr f w dirs
|
|
||||||
where
|
|
||||||
cd = 0.5 * spread * fromIntegral (numBulLoaded -1)
|
|
||||||
dirs = subtract cd . (spread *) . fromIntegral <$> [0 .. numBulLoaded - 1]
|
|
||||||
f dir = eff item (cr & crDir +~ dir)
|
|
||||||
spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item
|
|
||||||
numBulLoaded = _laLoaded $ _heldConsumption (_itUse item)
|
|
||||||
|
|
||||||
sideEffectOnFrame ::
|
|
||||||
Int ->
|
|
||||||
(Item -> Creature -> WdWd) ->
|
|
||||||
ChainEffect
|
|
||||||
sideEffectOnFrame i sf f it cr w =
|
|
||||||
f it cr w
|
|
||||||
& cWorld . lWorld . delayedEvents .:~ (i, sf it cr)
|
|
||||||
|
|
||||||
torqueSideEffect :: Float -> Item -> Creature -> World -> World
|
|
||||||
torqueSideEffect torque _ cr w
|
|
||||||
| cid == 0 = set randGen g $ over (wCam . camRot) (+ rot) w
|
|
||||||
| otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w
|
|
||||||
where
|
|
||||||
cid = _crID cr
|
|
||||||
(rot, g) = randomR (- torque, torque) $ _randGen w
|
|
||||||
|
|
||||||
-- pump the updated creature into the chain in later frames
|
|
||||||
repeatOnFrames :: [Int] -> HeldMod -> ChainEffect
|
|
||||||
--repeatOnFrames is hm f it cr w = f it cr w
|
|
||||||
repeatOnFrames is hm f it cr w =
|
|
||||||
f it cr $
|
|
||||||
w
|
|
||||||
& cWorld . lWorld . delayedEvents .++~ (is <&> (,WdWdFromItCrixWdWd (it & itUse . heldMods .~ hm) (_crID cr) ItCrWdItemEffect))
|
|
||||||
|
|
||||||
-- where
|
|
||||||
-- f' = fromMaybe w' $ do
|
|
||||||
-- cr' <- w' ^? creatures . ix (_crID cr)
|
|
||||||
-- return $ f it cr' w'
|
|
||||||
|
|
||||||
duplicateLoaded :: ChainEffect
|
|
||||||
duplicateLoaded eff it cr w = foldr f w [1 .. numBul]
|
|
||||||
where
|
|
||||||
f _ = eff it cr
|
|
||||||
numBul = _laLoaded $ _heldConsumption (_itUse it)
|
|
||||||
|
|
||||||
duplicateLoadedBarrels :: ChainEffect
|
|
||||||
duplicateLoadedBarrels eff item cr w = foldr f w poss
|
|
||||||
where
|
|
||||||
cp :: Float
|
|
||||||
cp = -0.5 * (fromIntegral numBar - 1)
|
|
||||||
poss :: [V2 Float]
|
|
||||||
poss = map (rotateV (_crDir cr) . V2 0 . (* 5) . (+ cp) . fromIntegral) [0 .. numBul - 1]
|
|
||||||
f pos = eff item (cr & crPos %~ (+.+ pos))
|
|
||||||
numBar = _brlNum . _gunBarrels $ _itParams item
|
|
||||||
numBul = _laLoaded $ _heldConsumption (_itUse item)
|
|
||||||
|
|
||||||
duplicateOffsetsFocus :: [Float] -> ChainEffect
|
|
||||||
duplicateOffsetsFocus xs eff item cr w = foldr f w poss
|
|
||||||
where
|
|
||||||
poss :: [V2 Float]
|
|
||||||
poss = map (rotateV (_crDir cr) . V2 0) xs
|
|
||||||
f pos =
|
|
||||||
eff item $
|
|
||||||
cr
|
|
||||||
& crPos %~ (+.+ pos)
|
|
||||||
& crDir .~ thedir pos
|
|
||||||
thedir pos
|
|
||||||
| dist (mouseWorldPos (w ^. input) (w ^. wCam)) (_crPos cr) < aimingMuzzlePos cr item =
|
|
||||||
argV
|
|
||||||
( _crPos cr +.+ aimingMuzzlePos cr item *.* unitVectorAtAngle (_crDir cr)
|
|
||||||
-.- (_crPos cr +.+ pos)
|
|
||||||
)
|
|
||||||
| otherwise = argV (mouseWorldPos (w ^. input) (w ^. wCam) -.- (_crPos cr +.+ pos))
|
|
||||||
|
|
||||||
duplicateItem :: (Item -> [Item]) -> ChainEffect
|
|
||||||
duplicateItem fit eff itm cr w = foldr f w (fit itm)
|
|
||||||
where
|
|
||||||
f itm' = eff itm' cr
|
|
||||||
|
|
||||||
duplicateOffsetsV2 :: [Point2] -> ChainEffect
|
|
||||||
duplicateOffsetsV2 xs eff item cr w = foldr f w poss
|
|
||||||
where
|
|
||||||
poss = map (rotateV (_crDir cr)) xs
|
|
||||||
f pos = eff item (cr & crPos +.+.~ pos)
|
|
||||||
|
|
||||||
duplicateOffsets :: [Float] -> ChainEffect
|
|
||||||
duplicateOffsets xs eff item cr w = foldr f w poss
|
|
||||||
where
|
|
||||||
poss :: [V2 Float]
|
|
||||||
poss = map (rotateV (_crDir cr) . V2 0) xs
|
|
||||||
f pos = eff item (cr & crPos +.+.~ pos)
|
|
||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
||||||
|
|
||||||
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
|
|
||||||
QNQrWh9rAcMIGT+b1le0
|
|
||||||
=4lsa
|
|
||||||
-----END PGP PUBLIC KEY BLOCK-----
|
|
||||||
Reference in New Issue
Block a user