From 84e7eb144bf7a662e13222d44c0bdb74d79bace0 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Sun, 7 Aug 2022 15:24:55 +0300 Subject: [PATCH] Move RearmTick to Rearmable --- OpenRA.Mods.Common/Activities/Resupply.cs | 28 ++--------------------- OpenRA.Mods.Common/Traits/Rearmable.cs | 22 ++++++++++++++++++ 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Resupply.cs b/OpenRA.Mods.Common/Activities/Resupply.cs index bf8722aad6..189aa28a9c 100644 --- a/OpenRA.Mods.Common/Activities/Resupply.cs +++ b/OpenRA.Mods.Common/Activities/Resupply.cs @@ -162,8 +162,8 @@ namespace OpenRA.Mods.Common.Activities if (activeResupplyTypes.HasFlag(ResupplyType.Repair)) RepairTick(self); - if (activeResupplyTypes.HasFlag(ResupplyType.Rearm)) - RearmTick(self); + if (activeResupplyTypes.HasFlag(ResupplyType.Rearm) && rearmable.RearmTick(self)) + activeResupplyTypes &= ~ResupplyType.Rearm; foreach (var notifyResupply in notifyResupplies) notifyResupply.ResupplyTick(host.Actor, self, activeResupplyTypes); @@ -303,29 +303,5 @@ namespace OpenRA.Mods.Common.Activities else --remainingTicks; } - - void RearmTick(Actor self) - { - var rearmComplete = true; - foreach (var ammoPool in rearmable.RearmableAmmoPools) - { - if (!ammoPool.HasFullAmmo) - { - if (--ammoPool.RemainingTicks <= 0) - { - ammoPool.RemainingTicks = ammoPool.Info.ReloadDelay; - if (!string.IsNullOrEmpty(ammoPool.Info.RearmSound)) - Game.Sound.PlayToPlayer(SoundType.World, self.Owner, ammoPool.Info.RearmSound, self.CenterPosition); - - ammoPool.GiveAmmo(self, ammoPool.Info.ReloadCount); - } - - rearmComplete = false; - } - } - - if (rearmComplete) - activeResupplyTypes &= ~ResupplyType.Rearm; - } } } diff --git a/OpenRA.Mods.Common/Traits/Rearmable.cs b/OpenRA.Mods.Common/Traits/Rearmable.cs index e9be175904..fb4c67f9ca 100644 --- a/OpenRA.Mods.Common/Traits/Rearmable.cs +++ b/OpenRA.Mods.Common/Traits/Rearmable.cs @@ -53,5 +53,27 @@ namespace OpenRA.Mods.Common.Traits } void INotifyDockClient.Undocked(Actor self, Actor dock) { } + + public bool RearmTick(Actor self) + { + foreach (var ammoPool in RearmableAmmoPools) + { + if (!ammoPool.HasFullAmmo) + { + if (--ammoPool.RemainingTicks <= 0) + { + ammoPool.RemainingTicks = ammoPool.Info.ReloadDelay; + if (!string.IsNullOrEmpty(ammoPool.Info.RearmSound)) + Game.Sound.PlayToPlayer(SoundType.World, self.Owner, ammoPool.Info.RearmSound, self.CenterPosition); + + ammoPool.GiveAmmo(self, ammoPool.Info.ReloadCount); + } + + return false; + } + } + + return true; + } } }