|
|
|
@@ -1,32 +1,32 @@
|
|
|
|
|
{- |
|
|
|
|
|
Weapon effects when pulling the trigger. -}
|
|
|
|
|
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
|
|
|
|
|
( 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
|
|
|
|
|
, ammoCheckI
|
|
|
|
|
)
|
|
|
|
|
where
|
|
|
|
|
import Dodge.Data
|
|
|
|
|
import Dodge.SoundLogic
|
|
|
|
@@ -46,6 +46,15 @@ import Data.Maybe
|
|
|
|
|
import qualified Data.IntMap.Strict as IM
|
|
|
|
|
import Data.Foldable
|
|
|
|
|
|
|
|
|
|
type ChainEffect =
|
|
|
|
|
(Item -> Creature -> World -> World)
|
|
|
|
|
-> Item
|
|
|
|
|
-> Creature -- ^ Creature id
|
|
|
|
|
-> World
|
|
|
|
|
-> World
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
withThinSmokeI
|
|
|
|
|
:: (Item -> Creature -> World -> World) -- ^ Underlying effect
|
|
|
|
|
-> Item
|
|
|
|
@@ -58,17 +67,6 @@ withThinSmokeI eff item cr w = eff item cr $ foldl' (flip $ makeThinSmokeAt . (+
|
|
|
|
|
pos = _crPos cr +.+ (_crRad cr +0.5) *.* unitVectorAtAngle dir
|
|
|
|
|
ps = (replicateM 5 . randInCirc) 8 & evalState $ _randGen w
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
withThickSmokeI
|
|
|
|
|
:: (Item -> Creature -> World -> World) -- ^ Underlying effect
|
|
|
|
|
-> Item
|
|
|
|
@@ -80,57 +78,16 @@ withThickSmokeI eff item cr w = eff item cr $ foldl' (flip $ makeThickSmokeAt .
|
|
|
|
|
dir = _crDir cr
|
|
|
|
|
pos = _crPos cr +.+ (_crRad cr + 15) *.* unitVectorAtAngle dir
|
|
|
|
|
ps = (replicateM 20 . 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
|
|
|
|
|
-- TODO create a trigger that does different things on first and continued
|
|
|
|
|
-- fire.
|
|
|
|
|
{- |
|
|
|
|
|
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) -> Creature -> World -> World) -- ^ Extra effect on first fire
|
|
|
|
|
-> ((Creature -> World -> World) -> Creature -> World -> World) -- ^ Extra effect on continued fire
|
|
|
|
|
-> (Creature -> World -> World) -- ^ Extra effect (always applied)
|
|
|
|
|
-> Creature -- ^ Creature id
|
|
|
|
|
-> World
|
|
|
|
|
-> World
|
|
|
|
|
rateIncAB startRate fastRate exeffFirst exeffCont eff cr w
|
|
|
|
|
| repeatFire = w
|
|
|
|
|
& pointItem %~ ( (itUseRate .~ max fastRate (currentRate - 1))
|
|
|
|
|
. (wpLoadedAmmo -~ 1)
|
|
|
|
|
. (itUseTime .~ currentRate) )
|
|
|
|
|
& exeffCont eff cr
|
|
|
|
|
| firstFire = w
|
|
|
|
|
& pointItem %~ ( (itUseRate .~ startRate - 1)
|
|
|
|
|
. (wpLoadedAmmo -~ 1)
|
|
|
|
|
. (itUseTime .~ startRate) )
|
|
|
|
|
& exeffFirst eff 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ammoCheckI :: ChainEffect
|
|
|
|
|
ammoCheckI eff item cr w
|
|
|
|
|
| _wpLoadedAmmo item == 0
|
|
|
|
|
= fromMaybe w (startReloadingWeapon cr w)
|
|
|
|
|
| otherwise = eff item cr w
|
|
|
|
|
|
|
|
|
|
{- |
|
|
|
|
|
Fires at an increasing rate.
|
|
|
|
|
Has different effect after first fire.
|
|
|
|
@@ -156,7 +113,6 @@ rateIncABI startRate fastRate exeffFirst exeffCont eff item cr w
|
|
|
|
|
. (wpLoadedAmmo -~ 1)
|
|
|
|
|
. (itUseTime .~ startRate) )
|
|
|
|
|
& exeffFirst eff item cr
|
|
|
|
|
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
|
|
|
|
| otherwise = w
|
|
|
|
|
where
|
|
|
|
|
cid = _crID cr
|
|
|
|
@@ -165,11 +121,8 @@ rateIncABI startRate fastRate exeffFirst exeffCont eff item cr w
|
|
|
|
|
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
|
|
|
|
|
{- | Apply effect after a warm up. -}
|
|
|
|
|
withWarmUpI
|
|
|
|
|
:: Int -- ^ warm up sound id
|
|
|
|
@@ -180,7 +133,6 @@ withWarmUpI
|
|
|
|
|
-> World
|
|
|
|
|
-> World
|
|
|
|
|
withWarmUpI soundID f item cr w
|
|
|
|
|
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
|
|
|
|
| _wpReloadState item /= 0 = w
|
|
|
|
|
| curWarmUp < maxWarmUp = w
|
|
|
|
|
& pointerToItem . wpCurWarmUp +~ 2
|
|
|
|
@@ -194,40 +146,6 @@ withWarmUpI soundID f item cr w
|
|
|
|
|
pointerToItem = creatures . ix cid . crInv . ix itRef
|
|
|
|
|
curWarmUp = _wpCurWarmUp item
|
|
|
|
|
maxWarmUp = _wpMaxWarmUp item
|
|
|
|
|
reloadCondition = _wpLoadedAmmo item == 0
|
|
|
|
|
{- | Apply effect after a warm up. -}
|
|
|
|
|
withWarmUp
|
|
|
|
|
:: Int -- ^ warm up sound id
|
|
|
|
|
-> (Creature -> World -> World)
|
|
|
|
|
-- ^ underlying effect
|
|
|
|
|
-> Creature
|
|
|
|
|
-> World
|
|
|
|
|
-> World
|
|
|
|
|
withWarmUp soundID f 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 cr
|
|
|
|
|
where
|
|
|
|
|
cid = _crID cr
|
|
|
|
|
itRef = _crInvSel cr
|
|
|
|
|
item = _crInv cr IM.! itRef
|
|
|
|
|
pointerToItem = creatures . ix cid . crInv . ix itRef
|
|
|
|
|
curWarmUp = _wpCurWarmUp item
|
|
|
|
|
maxWarmUp = _wpMaxWarmUp 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
|
|
|
|
|
{- | Adds a sound to a creature based world effect.
|
|
|
|
|
The sound is emitted from the creature's position. -}
|
|
|
|
|
withSoundI
|
|
|
|
@@ -248,16 +166,6 @@ withRecoilI recoilAmount eff item cr = eff item cr . over (creatures . ix cid) p
|
|
|
|
|
where
|
|
|
|
|
cid = _crID cr
|
|
|
|
|
pushback = over crPos (+.+ rotateV (_crDir cr) (V2 ((-recoilAmount) / _crMass cr ) 0))
|
|
|
|
|
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. -}
|
|
|
|
|
withSidePushI
|
|
|
|
@@ -273,19 +181,6 @@ withSidePushI maxSide eff item cr w = eff item cr $
|
|
|
|
|
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 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. -}
|
|
|
|
@@ -300,19 +195,6 @@ withSidePushAfterI maxSide eff item cr w = over (creatures . ix cid) push . eff
|
|
|
|
|
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
|
|
|
|
|
:: 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. -}
|
|
|
|
|
shootWithSoundForI
|
|
|
|
|
:: Int -- ^ Sound identifier
|
|
|
|
@@ -343,56 +225,6 @@ shootWithSoundForI soundid playTime f item cr w
|
|
|
|
|
&& _wpLoadedAmmo item > 0
|
|
|
|
|
reloadCondition = _wpLoadedAmmo item == 0
|
|
|
|
|
{- | Applies a world effect and sound effect after an ammo check. -}
|
|
|
|
|
shootWithSoundFor
|
|
|
|
|
:: Int -- ^ Sound identifier
|
|
|
|
|
-> Int -- ^ Frames to play
|
|
|
|
|
-> (Creature -> World -> World)
|
|
|
|
|
-- ^ Shoot effect, takes creature id as input
|
|
|
|
|
-> Creature
|
|
|
|
|
-> World
|
|
|
|
|
-> World
|
|
|
|
|
shootWithSoundFor soundid playTime f cr w
|
|
|
|
|
| fireCondition = over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1)
|
|
|
|
|
$ soundFromPos (CrWeaponSound cid) cpos soundid playTime 0
|
|
|
|
|
$ set (pointerToItem . itUseTime) (_itUseRate item)
|
|
|
|
|
$ f cr w
|
|
|
|
|
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
|
|
|
|
| otherwise = w
|
|
|
|
|
where
|
|
|
|
|
cid = _crID cr
|
|
|
|
|
cpos = _crPos 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. -}
|
|
|
|
|
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)
|
|
|
|
@@ -418,21 +250,6 @@ shootWithSoundI soundid f item cr w
|
|
|
|
|
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 an item use cooldown check. -}
|
|
|
|
|
useTimeCheckI
|
|
|
|
|
:: (Item -> Creature -> World -> World) -- ^ Underlying effect
|
|
|
|
|
-> Item
|
|
|
|
@@ -446,19 +263,6 @@ useTimeCheckI f item cr w = case item ^? itUseTime of
|
|
|
|
|
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. -}
|
|
|
|
|
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
|
|
|
|
@@ -493,27 +297,6 @@ ammoUseCheckI f item cr w
|
|
|
|
|
&& _itUseTime item == 0
|
|
|
|
|
&& _wpLoadedAmmo item > 0
|
|
|
|
|
reloadCondition = _wpLoadedAmmo item == 0
|
|
|
|
|
{- | 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
|
|
|
|
@@ -550,17 +333,6 @@ shootL f cr invid w
|
|
|
|
|
&& _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
|
|
|
|
@@ -572,17 +344,6 @@ withMuzFlareI f it cr w = tempLightForAt 3 pos . muzzleFlashAt pos2 $ f it cr w
|
|
|
|
|
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)
|
|
|
|
@@ -621,18 +382,6 @@ withRandomOffsetI offsetAmount f item cr w = f item (cr & crPos %~ (+.+ offV)) $
|
|
|
|
|
where
|
|
|
|
|
(offsetVal , g) = randomR (-offsetAmount,offsetAmount) $ _randGen w
|
|
|
|
|
offV = rotateV (_crDir cr) (V2 0 offsetVal)
|
|
|
|
|
{- | 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.
|
|
|
|
|
torqueBeforeForcedI
|
|
|
|
@@ -654,43 +403,6 @@ torqueBeforeForcedI torque feff item cr w
|
|
|
|
|
(rot, g) = randomR (-torque,torque) $ _randGen w
|
|
|
|
|
rot' | rot < 0 = rot - 0.1
|
|
|
|
|
| otherwise = rot + 0.1
|
|
|
|
|
-- | 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.
|
|
|
|
|
torqueAfterI
|
|
|
|
|
:: Float -- ^ Max possible rotation
|
|
|
|
@@ -707,21 +419,6 @@ torqueAfterI torque feff item cr w
|
|
|
|
|
(rot, g) = randomR (-torque,torque) $ _randGen w
|
|
|
|
|
rotateScope = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
|
|
|
|
. itAttachment . _Just . scopePos %~ rotateV rot
|
|
|
|
|
-- | 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
|
|
|
|
|
spreadNumI
|
|
|
|
|
:: (Item -> Creature -> World -> World)
|
|
|
|
|
-> Item
|
|
|
|
@@ -736,28 +433,6 @@ spreadNumI eff item cr w = foldr f w dirs
|
|
|
|
|
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,
|
|
|
|
|
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))
|
|
|
|
|
numI
|
|
|
|
|
:: (Item -> Creature -> World -> World)
|
|
|
|
|
-> Item
|
|
|
|
@@ -772,25 +447,6 @@ numI eff item cr w = foldr f w poss
|
|
|
|
|
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,
|
|
|
|
|
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
|
|
|
|
|