Make TargetableUnit upgradable
This commit is contained in:
@@ -35,8 +35,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return (self.CenterPosition.Z > 0) ? info.TargetTypes
|
return IsTraitDisabled ? None
|
||||||
: info.GroundedTargetTypes;
|
: (self.CenterPosition.Z > 0 ? info.TargetTypes : info.GroundedTargetTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Actor can be targeted.")]
|
[Desc("Actor can be targeted.")]
|
||||||
public class TargetableUnitInfo : ITraitInfo, ITargetableInfo
|
public class TargetableUnitInfo : UpgradableTraitInfo, ITargetableInfo
|
||||||
{
|
{
|
||||||
[Desc("Target type. Used for filtering (in)valid targets.")]
|
[Desc("Target type. Used for filtering (in)valid targets.")]
|
||||||
public readonly string[] TargetTypes = { };
|
public readonly string[] TargetTypes = { };
|
||||||
@@ -22,35 +22,37 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public bool RequiresForceFire = false;
|
public bool RequiresForceFire = false;
|
||||||
|
|
||||||
public virtual object Create(ActorInitializer init) { return new TargetableUnit(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new TargetableUnit(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TargetableUnit : ITargetable
|
public class TargetableUnit : UpgradableTrait<TargetableUnitInfo>, ITargetable
|
||||||
{
|
{
|
||||||
readonly TargetableUnitInfo info;
|
protected static readonly string[] None = new string[] { };
|
||||||
protected Cloak cloak;
|
protected Cloak cloak;
|
||||||
|
|
||||||
public TargetableUnit(Actor self, TargetableUnitInfo info)
|
public TargetableUnit(Actor self, TargetableUnitInfo info)
|
||||||
|
: base(info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
|
||||||
cloak = self.TraitOrDefault<Cloak>();
|
cloak = self.TraitOrDefault<Cloak>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool TargetableBy(Actor self, Actor viewer)
|
public virtual bool TargetableBy(Actor self, Actor viewer)
|
||||||
{
|
{
|
||||||
|
if (IsTraitDisabled)
|
||||||
|
return false;
|
||||||
if (cloak == null || (!viewer.IsDead && viewer.HasTrait<IgnoresCloak>()))
|
if (cloak == null || (!viewer.IsDead && viewer.HasTrait<IgnoresCloak>()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return cloak.IsVisible(self, viewer.Owner);
|
return cloak.IsVisible(self, viewer.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual string[] TargetTypes { get { return info.TargetTypes; } }
|
public virtual string[] TargetTypes { get { return IsTraitDisabled ? None : Info.TargetTypes; } }
|
||||||
|
|
||||||
public virtual IEnumerable<WPos> TargetablePositions(Actor self)
|
public virtual IEnumerable<WPos> TargetablePositions(Actor self)
|
||||||
{
|
{
|
||||||
yield return self.CenterPosition;
|
yield return self.CenterPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RequiresForceFire { get { return info.RequiresForceFire; } }
|
public bool RequiresForceFire { get { return Info.RequiresForceFire; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return cloak.Cloaked ? info.CloakedTargetTypes : info.TargetTypes;
|
return IsTraitDisabled ? None
|
||||||
|
: (cloak.Cloaked ? info.CloakedTargetTypes : info.TargetTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user