Implement RefineryResourceMultiplier.
This commit is contained in:
committed by
abcdefg30
parent
71acfaf014
commit
1e99075c70
@@ -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<RefineryResourceMultiplier>().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)
|
||||
|
||||
@@ -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<RefineryResourceMultiplierInfo>, Requires<RefineryInfo>
|
||||
{
|
||||
public RefineryResourceMultiplier(RefineryResourceMultiplierInfo info)
|
||||
: base(info) { }
|
||||
|
||||
public int GetModifier() { return IsTraitDisabled ? 100 : Info.Modifier; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user