From a07082069566552d935e16ed23a2a52cc0f778ba Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 27 May 2010 17:22:26 +1200 Subject: [PATCH] Hack in trait modifiers. Probably not the best approach. --- OpenRA.Mods.RA/GainsExperience.cs | 46 +++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.RA/GainsExperience.cs b/OpenRA.Mods.RA/GainsExperience.cs index fc63a54572..2c57b0b864 100644 --- a/OpenRA.Mods.RA/GainsExperience.cs +++ b/OpenRA.Mods.RA/GainsExperience.cs @@ -18,28 +18,35 @@ */ #endregion +using OpenRA.GameRules; using OpenRA.Traits; using System.Linq; using System.Collections.Generic; +using OpenRA.Mods.RA.Effects; namespace OpenRA.Mods.RA { public class GainsExperienceInfo : ITraitInfo { - //public readonly float[] LevelThresholds = {2,4,8}; - public readonly float[] LevelThresholds = {1, 1.5f, 2}; - public object Create(Actor self) { return new GainsExperience(self); } + //public readonly float[] CostThreshold = {2,4,8}; + public readonly float[] CostThreshold = {1, 1.5f, 2}; + public readonly float[] FirepowerModifier = {1.2f, 1.5f, 2}; + public readonly float[] ArmorModifier = {1.2f, 1.5f, 2}; + public readonly float[] SpeedModifier = {1.2f, 1.5f, 2}; + public object Create(Actor self) { return new GainsExperience(self, this); } } - public class GainsExperience + public class GainsExperience: IFirepowerModifier, ISpeedModifier, IDamageModifier { readonly Actor self; readonly List Levels; - public GainsExperience(Actor self) + readonly GainsExperienceInfo Info; + public GainsExperience(Actor self, GainsExperienceInfo info) { this.self = self; + this.Info = info; System.Console.WriteLine(self.Info.Name); var cost = self.Info.Traits.Get().Cost; - Levels = self.Info.Traits.Get().LevelThresholds.Select(t => t*cost).ToList(); + Levels = Info.CostThreshold.Select(t => t*cost).ToList(); } [Sync] @@ -61,7 +68,34 @@ namespace OpenRA.Mods.RA // TODO: Show an effect or play a sound or something System.Console.WriteLine("{0} became Level {1}",self.Info.Name, Level); + + self.World.AddFrameEndTask(w => + { + w.Add(new CrateEffect(self, "speed")); + }); } } + + public float GetDamageModifier( WarheadInfo warhead ) + { + if (Level == 0) + return 1.0f; + + return 1/Info.ArmorModifier[Level - 1]; + } + public float GetFirepowerModifier() + { + if (Level == 0) + return 1.0f; + + return Info.FirepowerModifier[Level - 1] ; + } + public float GetSpeedModifier() + { + if (Level == 0) + return 1.0f; + + return Info.SpeedModifier[Level - 1] ; + } } }