Work on held item usage

This commit is contained in:
2023-05-27 12:32:09 +01:00
parent 4cfb7d431a
commit ec8317c14e
19 changed files with 150 additions and 173 deletions
+1 -1
View File
@@ -165,7 +165,7 @@ shootDualLaser it cr w =
itid = _itID it
dir = _crDir cr
pos = _crPos cr +.+ aimlength *.* unitVectorAtAngle dir
aimlength = aimingMuzzlePos cr it
aimlength = aimingMuzzleLength cr it
gap = _dbGap . _itParams $ it
posl = pos +.+ (- gap) *.* vNormal (unitVectorAtAngle dir)
posr = pos +.+ gap *.* vNormal (unitVectorAtAngle dir)
+1 -1
View File
@@ -19,7 +19,7 @@ shootShatter it cr w =
Opaque {} -> True
SeeThrough -> True
_ -> False
sp = _crPos cr +.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir
sp = _crPos cr +.+ aimingMuzzleLength cr it *.* unitVectorAtAngle dir
dir = _crDir cr
ep = sp +.+ 200 *.* unitVectorAtAngle dir
+60 -86
View File
@@ -44,30 +44,24 @@ module Dodge.Item.Weapon.TriggerType (
withSidePushAfterI,
withSidePushI,
withWarmUp,
--spreadNumI,
--spreadLoaded,
repeatOnFrames,
sideEffectOnFrame,
duplicateItem,
duplicateLoadedBarrels,
duplicateLoaded,
duplicateOffsets,
duplicateOffsetsV2,
duplicateOffsetsFocus,
hammerCheckL,
shootL,
useTimeCheck,
ammoCheckI,
applyInaccuracy,
modClock,
blCheck,
) where
import qualified SDL
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
@@ -76,10 +70,11 @@ import Dodge.Reloading
import Dodge.SoundLogic
import Dodge.WorldEvent
import Geometry
import qualified IntMapHelp as IM
import LensHelp
import RandomHelp
import qualified SDL
import Sound.Data
import qualified IntMapHelp as IM
type ChainEffect =
(Item -> Creature -> World -> World) ->
@@ -137,14 +132,16 @@ withThickSmokeI eff item cr w =
-- fire.
ammoCheckI :: ChainEffect
ammoCheckI eff itm cr w = case itm ^? itUse . heldConsumption . laSource of
Just (InternalSource ia) | _iaLoaded ia <= 0 || not (_iaPrimed ia)
-> failsound w
Just AboveSource | fromMaybe True $ do
Just (InternalSource ia)
| _iaLoaded ia <= 0 || not (_iaPrimed ia) ->
failsound w
Just AboveSource
| fromMaybe True $ do
invid <- itm ^? itLocation . ipInvID
x <- cr ^? crInv . ix (invid - 1) . itUse . equipEffect . eeUse . euseAmmoAmount
return $ x <= 0
-> failsound w
_ -> eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
return $ x <= 0 ->
failsound w
_ -> eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
where
failsound = case w ^? input . mouseButtons . ix SDL.ButtonLeft of
Just 0 -> soundStart (CrReloadSound (_crID cr)) (_crPos cr) click1S Nothing
@@ -360,11 +357,12 @@ useAmmoAmount amAmount eff item cr =
useAmmoAmount' :: Int -> Int -> IM.IntMap Item -> IM.IntMap Item
useAmmoAmount' itref x inv = case inv ^? ix itref . itUse . heldConsumption . laSource of
Just InternalSource{}
-> inv & ix itref . itUse . heldConsumption . laSource . _InternalSource . iaLoaded -~ x
Just AboveSource
-> inv & ix (itref - 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x
Just InternalSource{} ->
inv & ix itref . itUse . heldConsumption . laSource . _InternalSource . iaLoaded -~ x
Just AboveSource ->
inv & ix (itref - 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x
_ -> inv
-- . crInv . ix itRef . itUse . heldConsumption . laSource
{- |
@@ -380,7 +378,6 @@ useTimeCheck f item cr w = case item ^? itUse . heldDelay . rateTime of
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.
blCheck :: ChainEffect
blCheck f it cr w = case w ^? input . mouseButtons . ix SDL.ButtonLeft of
@@ -457,47 +454,44 @@ modClock n chainEff 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
makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) (cpos `v2z` 20)
. muzFlareAt (V4 5 5 0 2) (cpos `v2z` 20) cdir
$ 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
-- 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
cpos = _crPos 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
--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
withMuzPosShift p g f it cr = g thepos . f it cr
where
pos =
_crPos cr
+.+ rotateV dir p
+.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir
dir = _crDir cr
thepos = (_crPos cr `v2z` 20)
--thepos = (pos `v2z` 20)
--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 = fromMaybe 0 $ it ^? itParams . gunBarrels . ix 0 . barlInaccuracy
--crAtMuzPos f it cr = f it (cr & crPos +.+.~ (aimingMuzzlePos cr it *.* unitVectorAtAngle (_crDir cr)))
crAtMuzPos f it cr = f it cr
-- | Applies the effect to a randomly rotated creature.
withRandomDirI ::
@@ -612,27 +606,6 @@ withTorqueAfter feff item cr w
(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 = item ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
sideEffectOnFrame ::
Int ->
(Item -> Creature -> WdWd) ->
@@ -669,12 +642,19 @@ duplicateLoaded eff it cr w = foldr f w [1 .. numBul]
numBul = it ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
duplicateLoadedBarrels :: ChainEffect
duplicateLoadedBarrels eff itm cr w = foldr f w (take numbul $ itm ^?! itParams . gunBarrels)
duplicateLoadedBarrels eff itm cr w = foldr f w (take numbul $ itm ^?! itUse . heldAim . aimMuzzles)
where
numbul = itm ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
f brl = eff itm (cr & crPos +~ _barlPos brl
& crDir +~ _barlRot brl
) -- worry about inaccuracy later
f brl w' =
eff
itm
( cr & crPos +~ (rotateV (_crDir cr) (_mzPos brl))
& crDir +~ (_mzRot brl + a)
)
(w' & randGen .~ g)
where
inacc = _mzInaccuracy brl
(a,g) = randomR (-inacc,inacc) $ _randGen w'
duplicateOffsetsFocus :: [Float] -> ChainEffect
duplicateOffsetsFocus xs eff item cr w = foldr f w poss
@@ -686,13 +666,14 @@ duplicateOffsetsFocus xs eff item cr w = foldr f w poss
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))
--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))
thedir pos = argV (mouseWorldPos (w ^. input) (w ^. wCam) -.- (_crPos cr +.+ pos))
duplicateItem :: (Item -> [Item]) -> ChainEffect
duplicateItem fit eff itm cr w = foldr f w (fit itm)
@@ -704,10 +685,3 @@ 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)