From 0a88a6da8ea547b7438c7ea694a6204de60a5551 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 4 Oct 2011 23:19:41 +1300 Subject: [PATCH] fix #1083 -- allow rank crate to give multiple levels --- OpenRA.Mods.RA/Crates/LevelUpCrateAction.cs | 6 ++-- OpenRA.Mods.RA/GainsExperience.cs | 38 +++++++++------------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/OpenRA.Mods.RA/Crates/LevelUpCrateAction.cs b/OpenRA.Mods.RA/Crates/LevelUpCrateAction.cs index 0ce148faa1..f4590fbae7 100644 --- a/OpenRA.Mods.RA/Crates/LevelUpCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/LevelUpCrateAction.cs @@ -12,6 +12,8 @@ namespace OpenRA.Mods.RA { class LevelUpCrateActionInfo : CrateActionInfo { + public readonly int Levels = 1; + 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) { var ge = collector.TraitOrDefault(); - return ge != null && ge.Level < ge.MaxLevel ? info.SelectionShares : 0; + return ge != null && ge.CanGainLevel ? info.SelectionShares : 0; } public override void Activate(Actor collector) @@ -32,7 +34,7 @@ namespace OpenRA.Mods.RA { var gainsExperience = collector.TraitOrDefault(); if (gainsExperience != null) - gainsExperience.GiveOneLevel(); + gainsExperience.GiveLevels((info as LevelUpCrateActionInfo).Levels); }); base.Activate(collector); diff --git a/OpenRA.Mods.RA/GainsExperience.cs b/OpenRA.Mods.RA/GainsExperience.cs index 57c59b03e8..b405aa1fbc 100644 --- a/OpenRA.Mods.RA/GainsExperience.cs +++ b/OpenRA.Mods.RA/GainsExperience.cs @@ -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(); 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 { - [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; } } }