Add CaptureTypes to GiveCashOnCapture.

This commit is contained in:
Paul Chote
2018-04-23 03:22:31 +00:00
committed by abcdefg30
parent c3bfd32192
commit 160ade1060

View File

@@ -10,6 +10,8 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Effects; using OpenRA.Mods.Common.Effects;
using OpenRA.Traits; using OpenRA.Traits;
@@ -27,6 +29,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Amount of money awarded for capturing the actor.")] [Desc("Amount of money awarded for capturing the actor.")]
public readonly int Amount = 0; public readonly int Amount = 0;
[Desc("Award cash only if the capturer's CaptureTypes overlap with these types. Leave empty to allow all types.")]
public readonly HashSet<string> CaptureTypes = new HashSet<string>();
public override object Create(ActorInitializer init) { return new GivesCashOnCapture(this); } public override object Create(ActorInitializer init) { return new GivesCashOnCapture(this); }
} }
@@ -42,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{ {
if (IsTraitDisabled) if (IsTraitDisabled || !IsValidCaptor(captor))
return; return;
var resources = newOwner.PlayerActor.Trait<PlayerResources>(); var resources = newOwner.PlayerActor.Trait<PlayerResources>();
@@ -66,5 +71,21 @@ namespace OpenRA.Mods.Common.Traits
self.World.AddFrameEndTask(w => w.Add( self.World.AddFrameEndTask(w => w.Add(
new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), info.DisplayDuration))); new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), info.DisplayDuration)));
} }
bool IsValidCaptor(Actor captor)
{
if (!info.CaptureTypes.Any())
return true;
var capturesInfo = captor.Info.TraitInfoOrDefault<CapturesInfo>();
if (capturesInfo != null && info.CaptureTypes.Overlaps(capturesInfo.CaptureTypes))
return true;
var externalCapturesInfo = captor.Info.TraitInfoOrDefault<ExternalCapturesInfo>();
if (externalCapturesInfo != null && info.CaptureTypes.Overlaps(externalCapturesInfo.CaptureTypes))
return true;
return false;
}
} }
} }