Merge pull request #13202 from reaperrr/UpgradeRejectsOrders
Add Reject field to RejectsOrders for blacklisting orders.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
@@ -17,7 +18,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Can be used to make a unit partly uncontrollable by the player.")]
|
[Desc("Can be used to make a unit partly uncontrollable by the player.")]
|
||||||
public class RejectsOrdersInfo : ConditionalTraitInfo
|
public class RejectsOrdersInfo : ConditionalTraitInfo
|
||||||
{
|
{
|
||||||
[Desc("Possible values include Attack, AttackMove, Guard, Move.")]
|
[Desc("Explicit list of rejected orders. Leave empty to reject all minus those listed under Except.")]
|
||||||
|
public readonly HashSet<string> Reject = new HashSet<string>();
|
||||||
|
|
||||||
|
[Desc("List of orders that should *not* be rejected.",
|
||||||
|
"Also overrides other instances of this trait's Reject fields.")]
|
||||||
public readonly HashSet<string> Except = new HashSet<string>();
|
public readonly HashSet<string> Except = new HashSet<string>();
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new RejectsOrders(this); }
|
public override object Create(ActorInitializer init) { return new RejectsOrders(this); }
|
||||||
@@ -25,6 +30,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public class RejectsOrders : ConditionalTrait<RejectsOrdersInfo>
|
public class RejectsOrders : ConditionalTrait<RejectsOrdersInfo>
|
||||||
{
|
{
|
||||||
|
public HashSet<string> Reject { get { return Info.Reject; } }
|
||||||
public HashSet<string> Except { get { return Info.Except; } }
|
public HashSet<string> Except { get { return Info.Except; } }
|
||||||
|
|
||||||
public RejectsOrders(RejectsOrdersInfo info)
|
public RejectsOrders(RejectsOrdersInfo info)
|
||||||
@@ -35,8 +41,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
public static bool AcceptsOrder(this Actor self, string orderString)
|
public static bool AcceptsOrder(this Actor self, string orderString)
|
||||||
{
|
{
|
||||||
var r = self.TraitOrDefault<RejectsOrders>();
|
var r = self.TraitsImplementing<RejectsOrders>().Where(Exts.IsTraitEnabled).ToList();
|
||||||
return r == null || r.IsTraitDisabled || r.Except.Contains(orderString);
|
return !r.Any() || r.Any(t => t.Reject.Any() && !t.Reject.Contains(orderString)) || r.Any(t => t.Except.Contains(orderString));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user