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