Support multiple capture types on Capturable.

This commit is contained in:
Paul Chote
2017-10-21 13:29:07 +00:00
committed by reaperrr
parent 77feb3f76d
commit 1caf982c1f
3 changed files with 14 additions and 8 deletions

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Scripting
if (capturable != null) if (capturable != null)
{ {
if (captures.Any(x => !x.IsTraitDisabled && x.Info.CaptureTypes.Contains(capturable.Type))) if (captures.Any(x => !x.IsTraitDisabled && x.Info.CaptureTypes.Overlaps(capturable.Types)))
{ {
Self.QueueActivity(new CaptureActor(Self, target)); Self.QueueActivity(new CaptureActor(Self, target));
return; return;
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Scripting
var externalCapturable = target.Info.TraitInfoOrDefault<ExternalCapturableInfo>(); var externalCapturable = target.Info.TraitInfoOrDefault<ExternalCapturableInfo>();
if (externalInfo != null && externalCapturable != null && externalInfo.CaptureTypes.Contains(externalCapturable.Type)) if (externalInfo != null && externalCapturable != null && externalInfo.CaptureTypes.Overlaps(externalCapturable.Types))
Self.QueueActivity(new ExternalCaptureActor(Self, Target.FromActor(target))); Self.QueueActivity(new ExternalCaptureActor(Self, Target.FromActor(target)));
else else
throw new LuaException("Actor '{0}' cannot capture actor '{1}'!".F(Self, target)); throw new LuaException("Actor '{0}' cannot capture actor '{1}'!".F(Self, target));

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
@@ -16,11 +17,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("This actor can be captured by a unit with Captures: trait.")] [Desc("This actor can be captured by a unit with Captures: trait.")]
public class CapturableInfo : ITraitInfo public class CapturableInfo : ITraitInfo
{ {
[Desc("Type listed under Types in Captures: trait of actors that can capture this).")] [Desc("CaptureTypes (from the Captures trait) that are able to capture this.")]
public readonly string Type = "building"; public readonly HashSet<string> Types = new HashSet<string>() { "building" };
public readonly bool AllowAllies = false; public readonly bool AllowAllies = false;
public readonly bool AllowNeutral = true; public readonly bool AllowNeutral = true;
public readonly bool AllowEnemies = true; public readonly bool AllowEnemies = true;
[Desc("Health percentage the target must be at (or below) before it can be captured.")] [Desc("Health percentage the target must be at (or below) before it can be captured.")]
public readonly int CaptureThreshold = 50; public readonly int CaptureThreshold = 50;
public readonly bool CancelActivity = false; public readonly bool CancelActivity = false;
@@ -43,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
if (playerRelationship == Stance.Neutral && !AllowNeutral) if (playerRelationship == Stance.Neutral && !AllowNeutral)
return false; return false;
if (!c.CaptureTypes.Contains(Type)) if (!c.CaptureTypes.Overlaps(Types))
return false; return false;
return true; return true;

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
@@ -16,11 +17,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("This actor can be captured by a unit with ExternalCaptures: trait.")] [Desc("This actor can be captured by a unit with ExternalCaptures: trait.")]
public class ExternalCapturableInfo : ITraitInfo public class ExternalCapturableInfo : ITraitInfo
{ {
[Desc("Type of actor (the ExternalCaptures: trait defines what Types it can capture).")] [Desc("CaptureTypes (from the ExternalCaptures trait) that are able to capture this.")]
public readonly string Type = "building"; public readonly HashSet<string> Types = new HashSet<string>() { "building" };
public readonly bool AllowAllies = false; public readonly bool AllowAllies = false;
public readonly bool AllowNeutral = true; public readonly bool AllowNeutral = true;
public readonly bool AllowEnemies = true; public readonly bool AllowEnemies = true;
[Desc("Seconds it takes to change the owner.", "You might want to add a ExternalCapturableBar: trait, too.")] [Desc("Seconds it takes to change the owner.", "You might want to add a ExternalCapturableBar: trait, too.")]
public readonly int CaptureCompleteTime = 15; public readonly int CaptureCompleteTime = 15;
@@ -43,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
if (playerRelationship == Stance.Neutral && !AllowNeutral) if (playerRelationship == Stance.Neutral && !AllowNeutral)
return false; return false;
if (!c.CaptureTypes.Contains(Type)) if (!c.CaptureTypes.Overlaps(Types))
return false; return false;
return true; return true;