fix #1083 -- allow rank crate to give multiple levels

This commit is contained in:
Chris Forbes
2011-10-04 23:19:41 +13:00
parent 84234e8794
commit 0a88a6da8e
2 changed files with 20 additions and 24 deletions

View File

@@ -52,27 +52,31 @@ namespace OpenRA.Mods.RA
}
}
[Sync]
int Experience = 0;
[Sync]
public int Level { get; private set; }
public int MaxLevel { get { return Levels.Length; } }
[Sync] int Experience = 0;
[Sync] public int Level { get; private set; }
int MaxLevel { get { return Levels.Length; } }
public bool CanGainLevel { get { return Level < MaxLevel; } }
public void GiveOneLevel()
{
if (Level < Levels.Length)
if (Level < MaxLevel)
GiveExperience(Levels[Level] - Experience);
}
public void GiveLevels(int numLevels)
{
for( var i = 0; i < numLevels; i++ )
GiveOneLevel();
}
public void GiveExperience(int amount)
{
Experience += amount;
while (Level < Levels.Length && Experience >= Levels[Level])
while (Level < MaxLevel && Experience >= Levels[Level])
{
Level++;
// Game.Debug("{0} became Level {1}".F(self.Info.Name, Level));
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
Sound.PlayToPlayer(self.Owner, eva.LevelUp, self.CenterLocation);
self.World.AddFrameEndTask(w => w.Add(new CrateEffect(self, "levelup", new int2(0,-24))));
@@ -116,19 +120,9 @@ namespace OpenRA.Mods.RA
class ExperienceInit : IActorInit<int>
{
[FieldFromYamlKey]
public readonly int value = 0;
[FieldFromYamlKey] public readonly int value = 0;
public ExperienceInit() { }
public ExperienceInit(int init)
{
value = init;
}
public int Value(World world)
{
return value;
}
public ExperienceInit(int init) { value = init; }
public int Value(World world) { return value; }
}
}