diff --git a/OpenRA.Mods.Common/Traits/Sellable.cs b/OpenRA.Mods.Common/Traits/Sellable.cs index 9bbfb3cc23..c2af65272f 100644 --- a/OpenRA.Mods.Common/Traits/Sellable.cs +++ b/OpenRA.Mods.Common/Traits/Sellable.cs @@ -8,8 +8,10 @@ */ #endregion +using System; using System.Linq; using OpenRA.Mods.Common.Activities; +using OpenRA.Mods.Common.Orders; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -20,13 +22,20 @@ namespace OpenRA.Mods.Common.Traits public readonly int RefundPercent = 50; public readonly string[] SellSounds = { }; - public object Create(ActorInitializer init) { return new Sellable(this); } + public object Create(ActorInitializer init) { return new Sellable(init.Self, this); } } - public class Sellable : UpgradableTrait, IResolveOrder + public class Sellable : UpgradableTrait, IResolveOrder, IProvideTooltipInfo { - public Sellable(SellableInfo info) - : base(info) { } + readonly Actor self; + readonly Lazy health; + + public Sellable(Actor self, SellableInfo info) + : base(info) + { + this.self = self; + health = Exts.Lazy(() => self.TraitOrDefault()); + } public void ResolveOrder(Actor self, Order order) { @@ -57,5 +66,27 @@ namespace OpenRA.Mods.Common.Traits else self.QueueActivity(false, new Sell()); } + + public bool IsTooltipVisible(Player forPlayer) + { + if (self.World.OrderGenerator is SellOrderGenerator) + return forPlayer == self.Owner; + return false; + } + + public string TooltipText + { + get + { + var sellValue = self.GetSellValue() * Info.RefundPercent / 100; + if (health.Value != null) + { + sellValue *= health.Value.HP; + sellValue /= health.Value.MaxHP; + } + + return "Refund: " + sellValue; + } + } } }