diff --git a/OpenRA.Mods.RA/Effects/CrateEffect.cs b/OpenRA.Game/Effects/CrateEffect.cs similarity index 90% rename from OpenRA.Mods.RA/Effects/CrateEffect.cs rename to OpenRA.Game/Effects/CrateEffect.cs index 7a6049a6a7..1d36ddf2c6 100644 --- a/OpenRA.Mods.RA/Effects/CrateEffect.cs +++ b/OpenRA.Game/Effects/CrateEffect.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * This file is part of OpenRA. @@ -19,11 +19,10 @@ #endregion using System.Collections.Generic; -using OpenRA.Effects; using OpenRA.Graphics; using OpenRA.Traits; -namespace OpenRA.Mods.RA.Effects +namespace OpenRA.Effects { class CrateEffect : IEffect { diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index dc37a95caf..f9683d6296 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -286,6 +286,8 @@ + + diff --git a/OpenRA.Game/Traits/Crate.cs b/OpenRA.Game/Traits/Crate.cs index 81ebc31bbf..e3cc1a0196 100644 --- a/OpenRA.Game/Traits/Crate.cs +++ b/OpenRA.Game/Traits/Crate.cs @@ -62,7 +62,7 @@ namespace OpenRA.Traits public void OnCrush(Actor crusher) { - var shares = self.traits.WithInterface().Select(a => Pair.New(a, a.GetSelectionShares(crusher))); + var shares = self.traits.WithInterface().Select(a => Pair.New(a, a.GetSelectionShares(crusher))); var totalShares = shares.Sum(a => a.Second); var n = self.World.SharedRandom.Next(totalShares); diff --git a/OpenRA.Game/Traits/CrateAction.cs b/OpenRA.Game/Traits/CrateAction.cs new file mode 100644 index 0000000000..3365cdd064 --- /dev/null +++ b/OpenRA.Game/Traits/CrateAction.cs @@ -0,0 +1,60 @@ +#region Copyright & License Information +/* + * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. + * This file is part of OpenRA. + * + * OpenRA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OpenRA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OpenRA. If not, see . + */ +#endregion + +using OpenRA.Effects; + +namespace OpenRA.Traits +{ + public class CrateActionInfo : ITraitInfo + { + public int SelectionShares = 10; + public string Effect = null; + public string Notification = null; + public virtual object Create(Actor self) { return new CrateAction(self, this); } + } + + public class CrateAction + { + public Actor self; + public CrateActionInfo info; + + public CrateAction(Actor self, CrateActionInfo info) + { + this.self = self; + this.info = info; + } + + public virtual int GetSelectionShares(Actor collector) + { + return info.SelectionShares; + } + + public virtual void Activate(Actor collector) + { + Sound.PlayToPlayer(collector.Owner, info.Notification); + + collector.World.AddFrameEndTask(w => + { + if (info.Effect != null) + w.Add(new CrateEffect(collector, info.Effect)); + }); + } + } +} diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index a5f5e5d5ee..524262a40d 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -82,13 +82,7 @@ namespace OpenRA.Traits bool IsCrushableBy(UnitMovementType umt, Player player); bool IsPathableCrush(UnitMovementType umt, Player player); } - - public interface ICrateAction - { - int GetSelectionShares(Actor collector); - void Activate(Actor collector); - } - + public struct Renderable { public readonly Sprite Sprite; diff --git a/OpenRA.Mods.RA/Crates/ArmorUpgradeCrateAction.cs b/OpenRA.Mods.RA/Crates/ArmorUpgradeCrateAction.cs index 469fe5f80c..82350dd457 100644 --- a/OpenRA.Mods.RA/Crates/ArmorUpgradeCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/ArmorUpgradeCrateAction.cs @@ -18,43 +18,30 @@ */ #endregion -using OpenRA.Mods.RA.Effects; using OpenRA.Traits; namespace OpenRA.Mods.RA { - class ArmorUpgradeCrateActionInfo : ITraitInfo + class ArmorUpgradeCrateActionInfo : CrateActionInfo { public float Multiplier = 2.0f; - public int SelectionShares = 10; - public string Effect = null; - public string Notification = null; - public object Create(Actor self) { return new ArmorUpgradeCrateAction(self); } + public override object Create(Actor self) { return new ArmorUpgradeCrateAction(self, this); } } - class ArmorUpgradeCrateAction : ICrateAction + class ArmorUpgradeCrateAction : CrateAction { - Actor self; - public ArmorUpgradeCrateAction(Actor self) - { - this.self = self; - } + public ArmorUpgradeCrateAction(Actor self, ArmorUpgradeCrateActionInfo info) + : base(self, info) {} - public int GetSelectionShares(Actor collector) + public override void Activate(Actor collector) { - return self.Info.Traits.Get().SelectionShares; - } - - public void Activate(Actor collector) - { - Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get().Notification); - collector.World.AddFrameEndTask(w => { - var multiplier = self.Info.Traits.Get().Multiplier; + var multiplier = (info as ArmorUpgradeCrateActionInfo).Multiplier; collector.traits.Add(new ArmorUpgrade(multiplier)); - w.Add(new CrateEffect(collector, self.Info.Traits.Get().Effect)); }); + + base.Activate(collector); } } diff --git a/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs b/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs index 9b2b69d760..7037290bc1 100644 --- a/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs @@ -7,39 +7,24 @@ using OpenRA.Effects; namespace OpenRA.Mods.RA { - class ExplodeCrateActionInfo : ITraitInfo + class ExplodeCrateActionInfo : CrateActionInfo { public string Weapon = null; - public int SelectionShares = 5; - public string Effect = null; - public string Notification = null; - public object Create(Actor self) { return new ExplodeCrateAction(self, this); } + public override object Create(Actor self) { return new ExplodeCrateAction(self, this); } } - class ExplodeCrateAction : ICrateAction + class ExplodeCrateAction : CrateAction { - Actor self; - ExplodeCrateActionInfo info; - public ExplodeCrateAction(Actor self, ExplodeCrateActionInfo info) - { - this.self = self; - this.info = info; - } + : base(self, info) {} - public int GetSelectionShares(Actor collector) + public override void Activate(Actor collector) { - return info.SelectionShares; - } - - public void Activate(Actor collector) - { - Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get().Notification); - self.World.AddFrameEndTask( - w => w.Add(new Bullet(info.Weapon, self.Owner, + w => w.Add(new Bullet((info as ExplodeCrateActionInfo).Weapon, self.Owner, self, self.CenterLocation.ToInt2(), self.CenterLocation.ToInt2(), 0, 0))); + base.Activate(collector); } } } diff --git a/OpenRA.Mods.RA/Crates/FirepowerUpgradeCrateAction.cs b/OpenRA.Mods.RA/Crates/FirepowerUpgradeCrateAction.cs index bb44e4b607..208d054dc9 100644 --- a/OpenRA.Mods.RA/Crates/FirepowerUpgradeCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/FirepowerUpgradeCrateAction.cs @@ -18,45 +18,38 @@ */ #endregion -using OpenRA.Mods.RA.Effects; using OpenRA.Traits; namespace OpenRA.Mods.RA { - class FirepowerUpgradeCrateActionInfo : ITraitInfo + class FirepowerUpgradeCrateActionInfo : CrateActionInfo { public float Multiplier = 2.0f; - public int SelectionShares = 10; - public string Effect = null; - public string Notification = null; - public object Create(Actor self) { return new FirepowerUpgradeCrateAction(self); } + public override object Create(Actor self) { return new FirepowerUpgradeCrateAction(self, this); } } - class FirepowerUpgradeCrateAction : ICrateAction + class FirepowerUpgradeCrateAction : CrateAction { - Actor self; - public FirepowerUpgradeCrateAction(Actor self) - { - this.self = self; - } - - public int GetSelectionShares(Actor collector) + public FirepowerUpgradeCrateAction(Actor self, FirepowerUpgradeCrateActionInfo info) + : base(self, info) {} + + public override int GetSelectionShares(Actor collector) { if (collector.GetPrimaryWeapon() == null && collector.GetSecondaryWeapon() == null) return 0; - return self.Info.Traits.Get().SelectionShares; + return base.GetSelectionShares(collector); } - public void Activate(Actor collector) + public override void Activate(Actor collector) { - Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get().Notification); collector.World.AddFrameEndTask(w => { - var multiplier = self.Info.Traits.Get().Multiplier; + var multiplier = (info as FirepowerUpgradeCrateActionInfo).Multiplier; collector.traits.Add(new FirepowerUpgrade(multiplier)); - w.Add(new CrateEffect(collector, self.Info.Traits.Get().Effect)); }); + + base.Activate(collector); } } diff --git a/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs b/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs index e7c4ab6c1c..6337ac85fc 100644 --- a/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs @@ -18,43 +18,29 @@ */ #endregion -using OpenRA.Mods.RA.Effects; using OpenRA.Traits; namespace OpenRA.Mods.RA { - class GiveCashCrateActionInfo : ITraitInfo + class GiveCashCrateActionInfo : CrateActionInfo { public int Amount = 2000; - public int SelectionShares = 10; - public string Effect = null; - public string Notification = null; - public object Create(Actor self) { return new GiveCashCrateAction(self); } + public override object Create(Actor self) { return new GiveCashCrateAction(self, this); } } - class GiveCashCrateAction : ICrateAction + class GiveCashCrateAction : CrateAction { - Actor self; - public GiveCashCrateAction(Actor self) - { - this.self = self; - } + public GiveCashCrateAction(Actor self, GiveCashCrateActionInfo info) + : base(self, info) {} - public int GetSelectionShares(Actor collector) + public override void Activate(Actor collector) { - return self.Info.Traits.Get().SelectionShares; - } - - public void Activate(Actor collector) - { - Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get().Notification); - collector.World.AddFrameEndTask(w => { - var amount = self.Info.Traits.Get().Amount; + var amount = (info as GiveCashCrateActionInfo).Amount; collector.Owner.GiveCash(amount); - w.Add(new CrateEffect(collector, self.Info.Traits.Get().Effect)); }); + base.Activate(collector); } } } diff --git a/OpenRA.Mods.RA/Crates/SpeedUpgradeCrateAction.cs b/OpenRA.Mods.RA/Crates/SpeedUpgradeCrateAction.cs index 18d5444470..3eec26110c 100644 --- a/OpenRA.Mods.RA/Crates/SpeedUpgradeCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/SpeedUpgradeCrateAction.cs @@ -18,43 +18,29 @@ */ #endregion -using OpenRA.Mods.RA.Effects; using OpenRA.Traits; namespace OpenRA.Mods.RA { - class SpeedUpgradeCrateActionInfo : ITraitInfo + class SpeedUpgradeCrateActionInfo : CrateActionInfo { public float Multiplier = 1.7f; - public int SelectionShares = 10; - public string Effect = null; - public string Notification = null; - public object Create(Actor self) { return new SpeedUpgradeCrateAction(self); } + public override object Create(Actor self) { return new SpeedUpgradeCrateAction(self, this); } } - class SpeedUpgradeCrateAction : ICrateAction + class SpeedUpgradeCrateAction : CrateAction { - Actor self; - public SpeedUpgradeCrateAction(Actor self) + public SpeedUpgradeCrateAction(Actor self, SpeedUpgradeCrateActionInfo info) + : base(self, info) {} + + public override void Activate(Actor collector) { - this.self = self; - } - - public int GetSelectionShares(Actor collector) - { - return self.Info.Traits.Get().SelectionShares; - } - - public void Activate(Actor collector) - { - Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get().Notification); - collector.World.AddFrameEndTask(w => { - var multiplier = self.Info.Traits.Get().Multiplier; + var multiplier = (info as SpeedUpgradeCrateActionInfo).Multiplier; collector.traits.Add(new SpeedUpgrade(multiplier)); - w.Add(new CrateEffect(collector, self.Info.Traits.Get().Effect)); }); + base.Activate(collector); } } diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 2f3c1499ef..73fe0027ef 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -1,4 +1,4 @@ - + Debug @@ -56,7 +56,6 @@ - @@ -90,7 +89,7 @@ OpenRA.Game - +