Move RearmTick to Rearmable

This commit is contained in:
Gustas
2022-08-07 15:24:55 +03:00
committed by Pavel Penev
parent 75d65b3d20
commit 84e7eb144b
2 changed files with 24 additions and 26 deletions

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}