Replace AmmoPool lookup methods with properties

And gave the more suitable names while at it.
This is more in line with how we do things in
other places.
This commit is contained in:
reaperrr
2019-10-19 17:25:25 +02:00
committed by reaperrr
parent c77aa4c8f9
commit ee00954f2e
9 changed files with 24 additions and 24 deletions

View File

@@ -67,34 +67,33 @@ namespace OpenRA.Mods.Common.Traits
public int RemainingTicks;
[Sync]
int currentAmmo;
public int CurrentAmmoCount { get; private set; }
public bool HasAmmo { get { return CurrentAmmoCount > 0; } }
public bool HasFullAmmo { get { return CurrentAmmoCount == Info.Ammo; } }
public AmmoPool(Actor self, AmmoPoolInfo info)
{
Info = info;
currentAmmo = Info.InitialAmmo < Info.Ammo && Info.InitialAmmo >= 0 ? Info.InitialAmmo : Info.Ammo;
CurrentAmmoCount = Info.InitialAmmo < Info.Ammo && Info.InitialAmmo >= 0 ? Info.InitialAmmo : Info.Ammo;
}
public int GetAmmoCount() { return currentAmmo; }
public bool FullAmmo() { return currentAmmo == Info.Ammo; }
public bool HasAmmo() { return currentAmmo > 0; }
public bool GiveAmmo(Actor self, int count)
{
if (currentAmmo >= Info.Ammo || count < 0)
if (CurrentAmmoCount >= Info.Ammo || count < 0)
return false;
currentAmmo = (currentAmmo + count).Clamp(0, Info.Ammo);
CurrentAmmoCount = (CurrentAmmoCount + count).Clamp(0, Info.Ammo);
UpdateCondition(self);
return true;
}
public bool TakeAmmo(Actor self, int count)
{
if (currentAmmo <= 0 || count < 0)
if (CurrentAmmoCount <= 0 || count < 0)
return false;
currentAmmo = (currentAmmo - count).Clamp(0, Info.Ammo);
CurrentAmmoCount = (CurrentAmmoCount - count).Clamp(0, Info.Ammo);
UpdateCondition(self);
return true;
}
@@ -121,10 +120,10 @@ namespace OpenRA.Mods.Common.Traits
if (conditionManager == null || string.IsNullOrEmpty(Info.AmmoCondition))
return;
while (currentAmmo > tokens.Count && tokens.Count < Info.Ammo)
while (CurrentAmmoCount > tokens.Count && tokens.Count < Info.Ammo)
tokens.Push(conditionManager.GrantCondition(self, Info.AmmoCondition));
while (currentAmmo < tokens.Count && tokens.Count > 0)
while (CurrentAmmoCount < tokens.Count && tokens.Count > 0)
conditionManager.RevokeCondition(self, tokens.Pop());
}
@@ -133,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits
var pips = Info.PipCount >= 0 ? Info.PipCount : Info.Ammo;
return Enumerable.Range(0, pips).Select(i =>
(currentAmmo * pips) / Info.Ammo > i ?
(CurrentAmmoCount * pips) / Info.Ammo > i ?
Info.PipType : Info.PipTypeEmpty);
}
}