From 9c800680c47f993a0c27fb057302d481ed3da463 Mon Sep 17 00:00:00 2001 From: Mustafa Alperen Seki Date: Fri, 15 Dec 2023 19:40:23 +0300 Subject: [PATCH] Remove AS's copy of ResourcePurifier, update GCoRP. --- .../GrantConditionOnResourcePurify.cs | 17 ++-- OpenRA.Mods.AS/Traits/ResourcePurifier.cs | 78 ------------------- .../Traits/Buildings/Refinery.cs | 4 - .../TraitsInterfacesExternal.cs | 6 -- 4 files changed, 11 insertions(+), 94 deletions(-) delete mode 100644 OpenRA.Mods.AS/Traits/ResourcePurifier.cs diff --git a/OpenRA.Mods.AS/Traits/Conditions/GrantConditionOnResourcePurify.cs b/OpenRA.Mods.AS/Traits/Conditions/GrantConditionOnResourcePurify.cs index 529dbb20af74..11a2cf574695 100644 --- a/OpenRA.Mods.AS/Traits/Conditions/GrantConditionOnResourcePurify.cs +++ b/OpenRA.Mods.AS/Traits/Conditions/GrantConditionOnResourcePurify.cs @@ -8,6 +8,7 @@ */ #endregion +using System.Linq; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; @@ -24,30 +25,34 @@ public class GrantConditionOnResourcePurifyInfo : PausableConditionalTraitInfo [FieldLoader.Require] public readonly int Duration; - public override object Create(ActorInitializer init) { return new GrantConditionOnResourcePurify(init.Self, this); } + [Desc("ResourceTypes to grant this condition. When empty, all resources trigger.")] + public readonly string[] ResourceTypes = System.Array.Empty(); + + public override object Create(ActorInitializer init) { return new GrantConditionOnResourcePurify(this); } } - public class GrantConditionOnResourcePurify : PausableConditionalTrait, ITick, IResourcePurifier + public class GrantConditionOnResourcePurify : PausableConditionalTrait, ITick, INotifyResourceAccepted { - readonly Actor self; readonly GrantConditionOnResourcePurifyInfo info; int token = Actor.InvalidConditionToken; int ticks; - public GrantConditionOnResourcePurify(Actor self, GrantConditionOnResourcePurifyInfo info) + public GrantConditionOnResourcePurify(GrantConditionOnResourcePurifyInfo info) : base(info) { - this.self = self; this.info = info; } - void IResourcePurifier.RefineAmount(int amount) + void INotifyResourceAccepted.OnResourceAccepted(Actor self, Actor refinery, string resourceType, int count, int value) { if (IsTraitDisabled) return; + if (info.ResourceTypes.Length != 0 && !Info.ResourceTypes.Contains(resourceType)) + return; + ticks = info.Duration; if (token == Actor.InvalidConditionToken) diff --git a/OpenRA.Mods.AS/Traits/ResourcePurifier.cs b/OpenRA.Mods.AS/Traits/ResourcePurifier.cs deleted file mode 100644 index 32387adb179f..000000000000 --- a/OpenRA.Mods.AS/Traits/ResourcePurifier.cs +++ /dev/null @@ -1,78 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2015- OpenRA.Mods.AS Developers (see AUTHORS) - * This file is a part of a third-party plugin for 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. For more information, see COPYING. - */ -#endregion - -using OpenRA.Mods.Common; -using OpenRA.Mods.Common.Effects; -using OpenRA.Mods.Common.Traits; -using OpenRA.Traits; - -namespace OpenRA.Mods.AS.Traits -{ - [Desc("Gives additional cash when resources are delivered to refineries.")] - public class ResourcePurifierInfo : ConditionalTraitInfo - { - [FieldLoader.Require] - [Desc("Percentage value of the resource to grant as cash.")] - public readonly int Modifier = 25; - - public readonly bool ShowTicks = true; - public readonly int TickLifetime = 30; - public readonly int TickVelocity = 2; - public readonly int TickRate = 10; - - public override object Create(ActorInitializer init) { return new ResourcePurifier(init.Self, this); } - } - - public class ResourcePurifier : ConditionalTrait, ITick, IResourcePurifier, INotifyOwnerChanged - { - readonly ResourcePurifierInfo info; - - PlayerResources playerResources; - int currentDisplayTick = 0; - int currentDisplayValue = 0; - - public ResourcePurifier(Actor self, ResourcePurifierInfo info) - : base(info) - { - this.info = info; - - playerResources = self.Owner.PlayerActor.Trait(); - } - - void IResourcePurifier.RefineAmount(int amount) - { - if (IsTraitDisabled) - return; - - var cash = Util.ApplyPercentageModifiers(amount, new int[] { info.Modifier }); - playerResources.GiveCash(cash); - - if (info.ShowTicks) - currentDisplayValue += cash; - } - - void ITick.Tick(Actor self) - { - if (info.ShowTicks && currentDisplayValue > 0 && --currentDisplayTick <= 0) - { - var temp = currentDisplayValue; - if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) - self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(temp), 30))); - currentDisplayTick = info.TickRate; - currentDisplayValue = 0; - } - } - - void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) - { - playerResources = newOwner.PlayerActor.Trait(); - } - } -} diff --git a/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs b/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs index afa38eea5476..7d4ca6bd61f9 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs @@ -90,10 +90,6 @@ int IAcceptResources.AcceptResources(Actor self, string resourceType, int count) foreach (var rrd in refineryResourceDelivereds) rrd.ResourceGiven(self, value); - var purifiers = self.World.ActorsWithTrait().Where(x => x.Actor.Owner == self.Owner).Select(x => x.Trait); - foreach (var p in purifiers) - p.RefineAmount(value); - if (info.ShowTicks) currentDisplayValue += value; diff --git a/OpenRA.Mods.Common/TraitsInterfacesExternal.cs b/OpenRA.Mods.Common/TraitsInterfacesExternal.cs index 00bb5c2fb73d..a68116955521 100644 --- a/OpenRA.Mods.Common/TraitsInterfacesExternal.cs +++ b/OpenRA.Mods.Common/TraitsInterfacesExternal.cs @@ -18,12 +18,6 @@ namespace OpenRA.Mods.Common.Traits [RequireExplicitImplementation] public interface IBuildPaletteOrderModifierInfo : ITraitInfoInterface { int GetBuildPaletteOrderModifier(TechTree techTree, string queue); } - [RequireExplicitImplementation] - public interface IResourcePurifier - { - void RefineAmount(int amount); - } - [RequireExplicitImplementation] public interface IResourceLogicLayer {