Clear ammo when reloading clip based weaons
This commit is contained in:
@@ -7,7 +7,7 @@ module Dodge.Creature.Action
|
||||
, setMinInvSize
|
||||
, dropUnselected
|
||||
, dropExcept
|
||||
, startReloadingWeapon
|
||||
-- , startReloadingWeapon
|
||||
, blinkAction
|
||||
, sizeSelf
|
||||
, crAutoReload
|
||||
@@ -144,17 +144,6 @@ performAction cr w ac = case ac of
|
||||
(imps , _) -> (imps, Just $ DoReplicatePartial sac (t-1) sac)
|
||||
NoAction -> ([],Nothing)
|
||||
|
||||
startReloadingWeapon :: Creature -> World -> Maybe World
|
||||
startReloadingWeapon cr w = case it of
|
||||
Weapon {_itConsumption = LoadableAmmo {_ammoMax=maxA,_ammoLoaded=lA ,_reloadState=rS,_reloadTime=rT}}
|
||||
| lA < maxA && rS == Nothing' ->
|
||||
Just -- $ set ( itRef . itConsumption . ammoLoaded) maxA
|
||||
$ set ( itRef . itConsumption . reloadState) (Just' rT) w
|
||||
_ -> Nothing
|
||||
where
|
||||
cid = _crID cr
|
||||
it = _crInv cr IM.! _crInvSel cr
|
||||
itRef = creatures . ix cid . crInv . ix (_crInvSel cr)
|
||||
{- | Start reloading if clip is empty. -}
|
||||
crAutoReload :: Creature -> Creature
|
||||
crAutoReload cr = case cr ^? ptrItConsumption' . ammoLoaded of
|
||||
|
||||
@@ -4,6 +4,7 @@ module Dodge.Creature.State
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Hammer
|
||||
import Dodge.Reloading
|
||||
import Dodge.Base
|
||||
import Dodge.Creature.State.WalkCycle
|
||||
--import Dodge.Creature.Test
|
||||
@@ -150,12 +151,12 @@ weaponReloadSounds cr w = case cr ^? crInv . ix (_crInvSel cr) . itConsumption o
|
||||
PassiveReload stype |Just' (_reloadTime am) == _reloadState am
|
||||
-> soundContinue (CrReloadSound 0) (_crPos cr) stype Nothing w
|
||||
PassiveReload _ -> w
|
||||
ActiveReload | _reloadState am == Just' 0 -> stopSoundFrom (CrReloadSound cid) w
|
||||
ActiveReload | _reloadState am == Nothing' -> w
|
||||
ActiveReload -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w
|
||||
PartialActive{} | _reloadState am == Just' 0 -> stopSoundFrom (CrReloadSound cid) w
|
||||
PartialActive{} | _reloadState am == Nothing' -> w
|
||||
PartialActive{} -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w
|
||||
ActiveClear | _reloadState am == Just' 0 -> stopSoundFrom (CrReloadSound cid) w
|
||||
ActiveClear | _reloadState am == Nothing' -> w
|
||||
ActiveClear -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w
|
||||
ActivePartial{} | _reloadState am == Just' 0 -> stopSoundFrom (CrReloadSound cid) w
|
||||
ActivePartial{} | _reloadState am == Nothing' -> w
|
||||
ActivePartial{} -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w
|
||||
Just ChargeableAmmo {} -> w
|
||||
Just ItemItselfConsumable {} -> w
|
||||
Nothing -> w
|
||||
@@ -189,19 +190,6 @@ isFrictionless cr = case cr ^? crStance . carriage of
|
||||
Just Floating -> True
|
||||
_ -> False
|
||||
|
||||
stepReloading :: Creature -> Creature
|
||||
stepReloading cr = case cr ^? crInv . ix isel . itConsumption . reloadState . _Just' of
|
||||
Just 0 -> cr & crInv . ix isel . itConsumption . reloadState .~ Nothing'
|
||||
& crInv . ix isel . itConsumption %~ doload
|
||||
Just _ -> cr & crInv . ix isel . itConsumption . reloadState . _Just' %~ decreaseToZero
|
||||
Nothing -> cr
|
||||
where
|
||||
isel = _crInvSel cr
|
||||
doload itcon = itcon & ammoLoaded %~ (min (_ammoMax itcon) . (+ amount))
|
||||
where
|
||||
amount = case _reloadType itcon of
|
||||
PartialActive x -> x
|
||||
_ -> _ammoMax itcon
|
||||
|
||||
|
||||
|
||||
|
||||
+3
-2
@@ -425,9 +425,10 @@ data ItemDimension = ItemDimension
|
||||
}
|
||||
|
||||
data ReloadType
|
||||
= ActiveReload
|
||||
| PartialActive Int
|
||||
= ActiveClear
|
||||
| ActivePartial Int
|
||||
| PassiveReload SoundID
|
||||
deriving Eq
|
||||
|
||||
-- I believe this is called every frame, not sure when though
|
||||
data ItEffect
|
||||
|
||||
@@ -20,7 +20,7 @@ defaultAmmo = LoadableAmmo
|
||||
, _ammoLoaded = 15
|
||||
, _reloadTime = 40
|
||||
, _reloadState = Nothing'
|
||||
, _reloadType = ActiveReload
|
||||
, _reloadType = ActiveClear
|
||||
}
|
||||
|
||||
ruseRate :: Int
|
||||
|
||||
@@ -5,6 +5,7 @@ module Dodge.Event.Keyboard
|
||||
import Dodge.Data
|
||||
import Dodge.Save
|
||||
import Dodge.Base
|
||||
import Dodge.Reloading
|
||||
import Dodge.Creature.Action
|
||||
import Dodge.Event.Test
|
||||
import Dodge.Event.Menu
|
||||
|
||||
@@ -95,8 +95,8 @@ pistol = defaultGun
|
||||
{ _aoType = basicBullet
|
||||
, _ammoMax = 15
|
||||
, _ammoLoaded = 15
|
||||
, _reloadTime = 10
|
||||
, _reloadType = PartialActive 1
|
||||
, _reloadTime = 15
|
||||
, _reloadType = ActivePartial 1
|
||||
}
|
||||
, _itUse = useAmmoParamsRate 8 upHammer
|
||||
[ ammoCheckI
|
||||
|
||||
@@ -38,7 +38,7 @@ module Dodge.Item.Weapon.TriggerType
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.Creature.Action (startReloadingWeapon)
|
||||
import Dodge.Reloading
|
||||
import Dodge.WorldEvent
|
||||
import Dodge.RandomHelp
|
||||
--import Dodge.Default
|
||||
@@ -96,8 +96,8 @@ withThickSmokeI eff item cr w = eff item cr
|
||||
ammoCheckI :: ChainEffect
|
||||
ammoCheckI eff item cr w
|
||||
| _ammoLoaded (_itConsumption item) <= 0 = fromMaybe w (startReloadingWeapon cr w)
|
||||
| _reloadState (_itConsumption item) /= Nothing' = w
|
||||
| otherwise = eff item cr w
|
||||
-- | _reloadState (_itConsumption item) /= Nothing' = w
|
||||
| otherwise = eff item cr $ w & creatures . ix (_crID cr) %~ crStopReloading
|
||||
|
||||
itUseAmmo :: Int -> Item -> Item
|
||||
itUseAmmo x = itConsumption . ammoLoaded %~ (max 0 . subtract x)
|
||||
|
||||
Reference in New Issue
Block a user