Add CaptureTypes to GiveCashOnCapture.
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -27,6 +29,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Amount of money awarded for capturing the actor.")]
|
||||
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); }
|
||||
}
|
||||
|
||||
@@ -42,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
if (IsTraitDisabled || !IsValidCaptor(captor))
|
||||
return;
|
||||
|
||||
var resources = newOwner.PlayerActor.Trait<PlayerResources>();
|
||||
@@ -66,5 +71,21 @@ namespace OpenRA.Mods.Common.Traits
|
||||
self.World.AddFrameEndTask(w => w.Add(
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user