Add ValidStances checks to BlocksProjectiles and Gate.

This commit is contained in:
abc013
2020-10-31 15:30:52 +01:00
committed by teinarss
parent d10c592987
commit 8fede9d6ba
9 changed files with 22 additions and 8 deletions

View File

@@ -10,6 +10,7 @@
#endregion
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
@@ -18,6 +19,9 @@ namespace OpenRA.Mods.Common.Traits
{
public readonly WDist Height = WDist.FromCells(1);
[Desc("Determines what projectiles to block based on their allegiance to the wall owner.")]
public readonly PlayerRelationship ValidRelationships = PlayerRelationship.Ally | PlayerRelationship.Neutral | PlayerRelationship.Enemy;
public override object Create(ActorInitializer init) { return new BlocksProjectiles(init.Self, this); }
}
@@ -28,6 +32,8 @@ namespace OpenRA.Mods.Common.Traits
WDist IBlocksProjectiles.BlockingHeight => Info.Height;
PlayerRelationship IBlocksProjectiles.ValidRelationships { get { return Info.ValidRelationships; } }
public static bool AnyBlockingActorAt(World world, WPos pos)
{
var dat = world.Map.DistanceAboveTerrain(pos);
@@ -38,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
.Any(Exts.IsTraitEnabled));
}
public static bool AnyBlockingActorsBetween(World world, WPos start, WPos end, WDist width, out WPos hit)
public static bool AnyBlockingActorsBetween(World world, Player owner, WPos start, WPos end, WDist width, out WPos hit)
{
var actors = world.FindBlockingActorsOnLine(start, end, width);
var length = (end - start).Length;
@@ -46,7 +52,8 @@ namespace OpenRA.Mods.Common.Traits
foreach (var a in actors)
{
var blockers = a.TraitsImplementing<IBlocksProjectiles>()
.Where(Exts.IsTraitEnabled).ToList();
.Where(Exts.IsTraitEnabled).Where(t => t.ValidRelationships.HasRelationship(a.Owner.RelationshipWith(owner)))
.ToList();
if (!blockers.Any())
continue;