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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user