This commit is contained in:
2024-12-19 22:56:25 +00:00
parent 83e65fb1b0
commit 0a0db28e6d
4 changed files with 52 additions and 201 deletions
+46 -13
View File
@@ -7,14 +7,12 @@ module Dodge.HeldUse (
mcUseHeld,
) where
import NewInt
import Dodge.Creature.Action.Blink
import Dodge.RadarSweep
import Color
import Control.Monad
import Data.Maybe
import Dodge.Base.Collide
import Dodge.Base.Coordinate
import Dodge.Creature.Action.Blink
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Dodge.Data.MuzzleEffect
@@ -25,21 +23,31 @@ import Dodge.Item.HeldOffset
import Dodge.Item.Weapon.Shatter
import Dodge.Item.Weapon.TriggerType
import Dodge.Projectile.Create
import Dodge.RadarSweep
import Dodge.SoundLogic
import Dodge.Tesla.Arc
import Geometry
import LensHelp
import ListHelp
import NewInt
import Picture.Base
import RandomHelp
import qualified SDL
heldEffect :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
heldEffect = hammerCheck $ heldEffectNoHammerCheck
heldEffect = hammerCheck heldEffectNoHammerCheck
heldEffectNoHammerCheck :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
heldEffectNoHammerCheck ::
LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
heldEffectNoHammerCheck = useTimeCheck heldEffectMuzzles
type ChainEffect =
(LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World) ->
LabelDoubleTree ComposeLinkType Item ->
Creature ->
World ->
World
hammerCheck :: ChainEffect
hammerCheck f it cr w = case it ^? ldtValue . itUse . heldTriggerType of
Just HammerTrigger -> case w ^? input . mouseButtons . ix SDL.ButtonLeft of
@@ -47,6 +55,32 @@ hammerCheck f it cr w = case it ^? ldtValue . itUse . heldTriggerType of
_ -> w
_ -> f it cr w
-- | Applies a world effect after an item use cooldown check.
useTimeCheck :: ChainEffect
useTimeCheck f item cr w = case item ^? ldtValue . itUse . heldDelay of
Just (FixedRate _ 0) -> f item cr $ setUseRate w
Just (FixedRate _ _) -> w
Just (WarmUpNoDelay wt wm ws)
| wt < wm ->
w
& soundContinue (CrWeaponSound cid 0) (_crPos cr) ws (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . warmTime +~ 2
Just (WarmUpNoDelay _ wm _) ->
f item cr w
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . warmTime .~ (wm + 1)
Just NoDelay -> f item cr w
-- Just (VariableRate rmax rtime rmaxmax rminmax) -> undefined
Nothing -> w
where
cid = _crID cr
setUseRate =
cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . rateTime
+~ userate
-- the following is unsafe, but if ilInvID isn't correctly set we probably
-- will have problems elsewhere also
itRef = item ^?! ldtValue . itLocation . ilInvID
userate = fromMaybe 0 $ item ^? ldtValue . itUse . heldDelay . rateMax
heldEffectMuzzles :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
heldEffectMuzzles t cr w =
uncurry (applyCME (_ldtValue t) cr) cmew
@@ -147,13 +181,13 @@ loadMuzzle t@(LDT _ l _) mz = fromMaybe (t, Nothing) $ do
availableammo <- mag ^? ldtValue . itConsumables . magLoadStatus . iaLoaded
let usedammo = case amamount of
UseUpTo x -> min x availableammo
UseExactly x
UseExactly x
| x <= availableammo -> x
| otherwise -> 0
guard $ usedammo > 0
return
( t & ldtLeft . ix i . _2 . ldtValue . itConsumables . magLoadStatus . iaLoaded
-~ usedammo
( t & ldtLeft . ix i . _2 . ldtValue . itConsumables . magLoadStatus . iaLoaded
-~ usedammo
, Just (mz, usedammo, mag)
)
@@ -579,8 +613,8 @@ useTimeScrollGun itm _ =
timeFlow
.~ ItemScrollTimeFlow
{ _scrollSmoothing = 0
--, _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
, _reverseAmount = 100
, --, _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
_reverseAmount = 100
, _futureWorlds = []
, _scrollItemID = _itID itm
}
@@ -589,8 +623,8 @@ useRewindGun :: NewInt ItmInt -> World -> World
useRewindGun i =
timeFlow
.~ RewindLeftClick
-- { _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
{ _reverseAmount = 100
{ -- { _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
_reverseAmount = 100
, _scrollItemID = i
}
@@ -601,4 +635,3 @@ useRewindGun i =
-- .~ Just' w'
-- & cwTime . rewindWorlds .~ ws
-- _ -> w