diff --git a/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs b/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs index 503037acbf..57991cb696 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs @@ -52,11 +52,13 @@ namespace OpenRA.Mods.Common.Traits public virtual object Create(ActorInitializer init) { return new Refinery(init.Self, this); } } - public class Refinery : ITick, IAcceptResources, INotifySold, INotifyCapture, INotifyOwnerChanged, ISync, INotifyActorDisposing + public class Refinery : INotifyCreated, ITick, IAcceptResources, INotifySold, INotifyCapture, + INotifyOwnerChanged, ISync, INotifyActorDisposing { readonly Actor self; readonly RefineryInfo info; PlayerResources playerResources; + RefineryResourceMultiplier[] resourceMultipliers; int currentDisplayTick = 0; int currentDisplayValue = 0; @@ -79,6 +81,11 @@ namespace OpenRA.Mods.Common.Traits currentDisplayTick = info.TickRate; } + void INotifyCreated.Created(Actor self) + { + resourceMultipliers = self.TraitsImplementing().ToArray(); + } + public virtual Activity DockSequence(Actor harv, Actor self) { return new SpriteHarvesterDockSequence(harv, self, DeliveryAngle, IsDragRequired, DragOffset, DragLength); @@ -94,6 +101,8 @@ namespace OpenRA.Mods.Common.Traits public void GiveResource(int amount) { + amount = Util.ApplyPercentageModifiers(amount, resourceMultipliers.Select(m => m.GetModifier())); + if (info.UseStorage) { if (info.DiscardExcessResources) diff --git a/OpenRA.Mods.Common/Traits/Multipliers/RefineryResourceMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/RefineryResourceMultiplier.cs new file mode 100644 index 0000000000..556ecf3a10 --- /dev/null +++ b/OpenRA.Mods.Common/Traits/Multipliers/RefineryResourceMultiplier.cs @@ -0,0 +1,33 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you 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. For more + * information, see COPYING. + */ +#endregion + +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Modifies the bale values delivered to this refinery.")] + public class RefineryResourceMultiplierInfo : ConditionalTraitInfo + { + [FieldLoader.Require] + [Desc("Percentage modifier to apply.")] + public readonly int Modifier = 100; + + public override object Create(ActorInitializer init) { return new RefineryResourceMultiplier(this); } + } + + public class RefineryResourceMultiplier : ConditionalTrait, Requires + { + public RefineryResourceMultiplier(RefineryResourceMultiplierInfo info) + : base(info) { } + + public int GetModifier() { return IsTraitDisabled ? 100 : Info.Modifier; } + } +}