Add IBlocksProjectiles interface to avoid using BlocksProjectiles directly
This commit is contained in:
@@ -9,9 +9,16 @@
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[RequireExplicitImplementation]
|
||||
public interface IBlocksProjectiles
|
||||
{
|
||||
WDist BlockingHeight { get; }
|
||||
}
|
||||
|
||||
[Desc("This actor blocks bullets and missiles with 'Blockable' property.")]
|
||||
public class BlocksProjectilesInfo : UpgradableTraitInfo
|
||||
{
|
||||
@@ -20,17 +27,20 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public override object Create(ActorInitializer init) { return new BlocksProjectiles(init.Self, this); }
|
||||
}
|
||||
|
||||
public class BlocksProjectiles : UpgradableTrait<BlocksProjectilesInfo>
|
||||
public class BlocksProjectiles : UpgradableTrait<BlocksProjectilesInfo>, IBlocksProjectiles
|
||||
{
|
||||
public BlocksProjectiles(Actor self, BlocksProjectilesInfo info)
|
||||
: base(info) { }
|
||||
|
||||
WDist IBlocksProjectiles.BlockingHeight { get { return Info.Height; } }
|
||||
|
||||
public static bool AnyBlockingActorAt(World world, WPos pos)
|
||||
{
|
||||
var dat = world.Map.DistanceAboveTerrain(pos);
|
||||
|
||||
return world.ActorMap.GetActorsAt(world.Map.CellContaining(pos))
|
||||
.Any(a => a.TraitsImplementing<BlocksProjectiles>()
|
||||
.Where(t => t.Info.Height.Length >= dat.Length)
|
||||
.Any(a => a.TraitsImplementing<IBlocksProjectiles>()
|
||||
.Where(t => t.BlockingHeight >= dat)
|
||||
.Any(Exts.IsTraitEnabled));
|
||||
}
|
||||
|
||||
@@ -41,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var a in actors)
|
||||
{
|
||||
var blockers = a.TraitsImplementing<BlocksProjectiles>()
|
||||
var blockers = a.TraitsImplementing<IBlocksProjectiles>()
|
||||
.Where(Exts.IsTraitEnabled).ToList();
|
||||
|
||||
if (!blockers.Any())
|
||||
@@ -49,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var hitPos = WorldExtensions.MinimumPointLineProjection(start, end, a.CenterPosition);
|
||||
var dat = world.Map.DistanceAboveTerrain(hitPos);
|
||||
if ((hitPos - start).Length < length && blockers.Any(t => t.Info.Height.Length >= dat.Length))
|
||||
if ((hitPos - start).Length < length && blockers.Any(t => t.BlockingHeight >= dat))
|
||||
{
|
||||
hit = hitPos;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user