Change weapon fixed rate delay not to require update every tick
This commit is contained in:
@@ -159,7 +159,7 @@ applyPastDamages cr w
|
||||
-- a map updating all inventory items
|
||||
updateInv :: Creature -> World -> World
|
||||
updateInv cr = cWorld . lWorld . creatures . ix (_crID cr) . crInv . each
|
||||
. itUse %~ useUpdate
|
||||
. itUse . heldDelay %~ useDelayUpdate
|
||||
|
||||
-- a loop going over all inventory items
|
||||
invSideEff :: Creature -> World -> World
|
||||
@@ -426,10 +426,8 @@ setRBCreatureTargeting cr w ituse
|
||||
cpos <- w ^? cWorld . lWorld . creatures . ix cid . crPos
|
||||
Just $ hasLOS cpos (_crPos cr) w
|
||||
|
||||
useUpdate :: ItemUse -> ItemUse
|
||||
useUpdate =
|
||||
(heldDelay . warmTime %~ decreaseToZero)
|
||||
. (heldDelay . rateTime %~ decreaseToZero)
|
||||
useDelayUpdate :: UseDelay -> UseDelay
|
||||
useDelayUpdate = ( warmTime %~ decreaseToZero)
|
||||
|
||||
--updateAutoRecharge :: Item -> Item
|
||||
--updateAutoRecharge it = case it ^? itUse . leftConsumption of
|
||||
|
||||
@@ -14,7 +14,7 @@ data UseDelay -- should just be Delay
|
||||
= NoDelay
|
||||
| FixedRate
|
||||
{ _rateMax :: Int
|
||||
, _rateTime :: Int
|
||||
, _rateTimeLastUsed :: Int -- set to be _lClock when used, starts at 0
|
||||
}
|
||||
-- | VariableRate
|
||||
-- { _rateMax :: Int
|
||||
|
||||
@@ -25,7 +25,7 @@ defaultEquipUse = UseEquip
|
||||
|
||||
defaultHeldUse :: ItemUse
|
||||
defaultHeldUse = UseHeld
|
||||
{ _heldDelay = FixedRate{_rateMax = 8, _rateTime = 0}
|
||||
{ _heldDelay = FixedRate{_rateMax = 8, _rateTimeLastUsed = 0}
|
||||
-- , _heldHammer = HammerUp
|
||||
, _heldAim = defaultAimParams
|
||||
, _heldParams = BulletShooterParams
|
||||
|
||||
+10
-15
@@ -91,8 +91,9 @@ hammerCheck pt f it cr w = case it ^? ldtValue . itUse . heldTriggerType of
|
||||
-- | 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 (FixedRate rate lastused)
|
||||
| w ^. cWorld . lWorld . lClock - rate > lastused -> f item cr $ setUseRate w
|
||||
Just FixedRate {} -> w
|
||||
Just (WarmUpNoDelay wt wm ws)
|
||||
| wt < wm ->
|
||||
w
|
||||
@@ -107,12 +108,11 @@ useTimeCheck f item cr w = case item ^? ldtValue . itUse . heldDelay of
|
||||
where
|
||||
cid = _crID cr
|
||||
setUseRate =
|
||||
cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . rateTime
|
||||
+~ userate
|
||||
cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . rateTimeLastUsed
|
||||
.~ w ^. cWorld . lWorld . lClock
|
||||
-- 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 =
|
||||
@@ -617,21 +617,16 @@ mcShootLaser _ mc = cWorld . lWorld . lasers .:~ lasRayAt yellow dam phasev pos
|
||||
|
||||
mcShootAuto :: Item -> Machine -> World -> World
|
||||
mcShootAuto itm mc w
|
||||
| Just (FixedRate x 0) <- mc ^? mcType . mctTurret . tuWeapon . itUse . heldDelay =
|
||||
| Just (FixedRate rate lastused) <- mc ^? mcType . mctTurret . tuWeapon . itUse . heldDelay
|
||||
, w ^. cWorld . lWorld . lClock - rate > lastused =
|
||||
w
|
||||
& cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon
|
||||
. itUse
|
||||
. heldDelay
|
||||
. rateTime
|
||||
.~ x
|
||||
. rateTimeLastUsed
|
||||
.~ w ^. cWorld . lWorld . lClock
|
||||
& makeBullet defaultBullet itm pos dir
|
||||
| otherwise =
|
||||
w
|
||||
& cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon
|
||||
. itUse
|
||||
. heldDelay
|
||||
. rateTime
|
||||
-~ 1
|
||||
| otherwise = w
|
||||
where
|
||||
pos = _mcPos mc +.+ 20 *.* unitVectorAtAngle dir
|
||||
dir = mc ^?! mcType . _McTurret . tuDir
|
||||
|
||||
@@ -31,7 +31,7 @@ flameSpitter =
|
||||
flameThrower
|
||||
& itType .~ HELD FLAMESPITTER
|
||||
& itUse . heldAim . aimStance .~ OneHand
|
||||
& itUse . heldDelay .~ FixedRate{_rateMax = 3, _rateTime = 0}
|
||||
& itUse . heldDelay .~ FixedRate{_rateMax = 3, _rateTimeLastUsed = 0}
|
||||
& itUse . heldParams . weaponInvLock .~ 10
|
||||
& itUse . heldParams . weaponRepeat .~ [1..9]
|
||||
& itUse . heldAim . aimMuzzles . ix 0 . mzEffect . nzPressure .~ UniRandFloat 3 4
|
||||
|
||||
Reference in New Issue
Block a user