Add upgrade support to DetectCloaked.

This commit is contained in:
Paul Chote
2015-03-29 18:43:45 +01:00
parent 4597895ea3
commit a9e1c09d82
3 changed files with 14 additions and 10 deletions

View File

@@ -123,7 +123,7 @@ namespace OpenRA.Mods.Common.Traits
if (!Cloaked || self.Owner.IsAlliedWith(viewer))
return true;
return self.World.ActorsWithTrait<DetectCloaked>().Any(a => a.Actor.Owner.IsAlliedWith(viewer)
return self.World.ActorsWithTrait<DetectCloaked>().Any(a => !a.Trait.IsTraitDisabled && a.Actor.Owner.IsAlliedWith(viewer)
&& Info.CloakTypes.Intersect(a.Trait.Info.CloakTypes).Any()
&& (self.CenterPosition - a.Actor.CenterPosition).Length <= WRange.FromCells(a.Trait.Info.Range).Range);
}

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Actor can reveal Cloak actors in a specified range.")]
public class DetectCloakedInfo : ITraitInfo
public class DetectCloakedInfo : UpgradableTraitInfo, ITraitInfo
{
[Desc("Specific cloak classifications I can reveal.")]
public readonly string[] CloakTypes = { "Cloak" };
@@ -24,13 +24,8 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new DetectCloaked(this); }
}
public class DetectCloaked
public class DetectCloaked : UpgradableTrait<DetectCloakedInfo>
{
public readonly DetectCloakedInfo Info;
public DetectCloaked(DetectCloakedInfo info)
{
Info = info;
}
public DetectCloaked(DetectCloakedInfo info) : base(info) { }
}
}

View File

@@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Traits;
@@ -32,9 +33,17 @@ namespace OpenRA.Mods.Common.Traits
if (self.Owner != self.World.LocalPlayer)
yield break;
var range = self.TraitsImplementing<DetectCloaked>()
.Where(a => !a.IsTraitDisabled)
.Select(a => WRange.FromCells(a.Info.Range))
.Append(WRange.Zero).Max();
if (range == WRange.Zero)
yield break;
yield return new RangeCircleRenderable(
self.CenterPosition,
WRange.FromCells(self.Info.Traits.Get<DetectCloakedInfo>().Range),
range,
0,
Color.FromArgb(128, Color.LimeGreen),
Color.FromArgb(96, Color.Black));