Fix a crash when MaxLevel of GainsExperience is zero

This commit is contained in:
abcdefg30
2019-10-05 00:08:26 +02:00
committed by reaperrr
parent d34bce9eab
commit 321c891bc0

View File

@@ -96,6 +96,9 @@ namespace OpenRA.Mods.Common.Traits
public void GiveLevels(int numLevels, bool silent = false)
{
if (MaxLevel == 0)
return;
var newLevel = Math.Min(Level + numLevels, MaxLevel);
GiveExperience(nextLevel[newLevel - 1].First - experience, silent);
}
@@ -105,6 +108,9 @@ namespace OpenRA.Mods.Common.Traits
if (amount < 0)
throw new ArgumentException("Revoking experience is not implemented.", "amount");
if (MaxLevel == 0)
return;
experience = (experience + amount).Clamp(0, nextLevel[MaxLevel - 1].First);
while (Level < MaxLevel && experience >= nextLevel[Level].First)