fix #1083 -- allow rank crate to give multiple levels
This commit is contained in:
@@ -12,6 +12,8 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
class LevelUpCrateActionInfo : CrateActionInfo
|
class LevelUpCrateActionInfo : CrateActionInfo
|
||||||
{
|
{
|
||||||
|
public readonly int Levels = 1;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new LevelUpCrateAction(init.self, this); }
|
public override object Create(ActorInitializer init) { return new LevelUpCrateAction(init.self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +25,7 @@ namespace OpenRA.Mods.RA
|
|||||||
public override int GetSelectionShares(Actor collector)
|
public override int GetSelectionShares(Actor collector)
|
||||||
{
|
{
|
||||||
var ge = collector.TraitOrDefault<GainsExperience>();
|
var ge = collector.TraitOrDefault<GainsExperience>();
|
||||||
return ge != null && ge.Level < ge.MaxLevel ? info.SelectionShares : 0;
|
return ge != null && ge.CanGainLevel ? info.SelectionShares : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Activate(Actor collector)
|
public override void Activate(Actor collector)
|
||||||
@@ -32,7 +34,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
var gainsExperience = collector.TraitOrDefault<GainsExperience>();
|
var gainsExperience = collector.TraitOrDefault<GainsExperience>();
|
||||||
if (gainsExperience != null)
|
if (gainsExperience != null)
|
||||||
gainsExperience.GiveOneLevel();
|
gainsExperience.GiveLevels((info as LevelUpCrateActionInfo).Levels);
|
||||||
});
|
});
|
||||||
|
|
||||||
base.Activate(collector);
|
base.Activate(collector);
|
||||||
|
|||||||
@@ -52,27 +52,31 @@ namespace OpenRA.Mods.RA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Sync]
|
[Sync] int Experience = 0;
|
||||||
int Experience = 0;
|
[Sync] public int Level { get; private set; }
|
||||||
[Sync]
|
|
||||||
public int Level { get; private set; }
|
int MaxLevel { get { return Levels.Length; } }
|
||||||
public int MaxLevel { get { return Levels.Length; } }
|
public bool CanGainLevel { get { return Level < MaxLevel; } }
|
||||||
|
|
||||||
public void GiveOneLevel()
|
public void GiveOneLevel()
|
||||||
{
|
{
|
||||||
if (Level < Levels.Length)
|
if (Level < MaxLevel)
|
||||||
GiveExperience(Levels[Level] - Experience);
|
GiveExperience(Levels[Level] - Experience);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void GiveLevels(int numLevels)
|
||||||
|
{
|
||||||
|
for( var i = 0; i < numLevels; i++ )
|
||||||
|
GiveOneLevel();
|
||||||
|
}
|
||||||
|
|
||||||
public void GiveExperience(int amount)
|
public void GiveExperience(int amount)
|
||||||
{
|
{
|
||||||
Experience += amount;
|
Experience += amount;
|
||||||
|
|
||||||
while (Level < Levels.Length && Experience >= Levels[Level])
|
while (Level < MaxLevel && Experience >= Levels[Level])
|
||||||
{
|
{
|
||||||
Level++;
|
Level++;
|
||||||
|
|
||||||
// Game.Debug("{0} became Level {1}".F(self.Info.Name, Level));
|
|
||||||
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
||||||
Sound.PlayToPlayer(self.Owner, eva.LevelUp, self.CenterLocation);
|
Sound.PlayToPlayer(self.Owner, eva.LevelUp, self.CenterLocation);
|
||||||
self.World.AddFrameEndTask(w => w.Add(new CrateEffect(self, "levelup", new int2(0,-24))));
|
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>
|
class ExperienceInit : IActorInit<int>
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey]
|
[FieldFromYamlKey] public readonly int value = 0;
|
||||||
public readonly int value = 0;
|
|
||||||
|
|
||||||
public ExperienceInit() { }
|
public ExperienceInit() { }
|
||||||
|
public ExperienceInit(int init) { value = init; }
|
||||||
public ExperienceInit(int init)
|
public int Value(World world) { return value; }
|
||||||
{
|
|
||||||
value = init;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Value(World world)
|
|
||||||
{
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user