From 84ccff53448844ab5df01f78bf631205e9c95995 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 1 Dec 2021 18:37:16 +0000 Subject: [PATCH] Clear ammo when reloading clip based weaons --- src/Dodge/Creature/Action.hs | 13 +------------ src/Dodge/Creature/State.hs | 26 +++++++------------------- src/Dodge/Data.hs | 5 +++-- src/Dodge/Default/Weapon.hs | 2 +- src/Dodge/Event/Keyboard.hs | 1 + src/Dodge/Item/Weapon/BulletGuns.hs | 4 ++-- src/Dodge/Item/Weapon/TriggerType.hs | 6 +++--- 7 files changed, 18 insertions(+), 39 deletions(-) diff --git a/src/Dodge/Creature/Action.hs b/src/Dodge/Creature/Action.hs index 4487b8b55..d14668856 100644 --- a/src/Dodge/Creature/Action.hs +++ b/src/Dodge/Creature/Action.hs @@ -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 diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index cd12030b1..02901070f 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -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 diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index e18f0d5f3..52044b09a 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -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 diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index 2cda4ca54..e08fc7375 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -20,7 +20,7 @@ defaultAmmo = LoadableAmmo , _ammoLoaded = 15 , _reloadTime = 40 , _reloadState = Nothing' - , _reloadType = ActiveReload + , _reloadType = ActiveClear } ruseRate :: Int diff --git a/src/Dodge/Event/Keyboard.hs b/src/Dodge/Event/Keyboard.hs index 636577c82..f3c61caa2 100644 --- a/src/Dodge/Event/Keyboard.hs +++ b/src/Dodge/Event/Keyboard.hs @@ -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 diff --git a/src/Dodge/Item/Weapon/BulletGuns.hs b/src/Dodge/Item/Weapon/BulletGuns.hs index 8f8c91e64..d93e92006 100644 --- a/src/Dodge/Item/Weapon/BulletGuns.hs +++ b/src/Dodge/Item/Weapon/BulletGuns.hs @@ -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 diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 8b02586d0..a551226f1 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -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)