Implement DetectCloakedMultiplier.
This commit is contained in:
committed by
reaperrr
parent
d36973138c
commit
3e39ada304
@@ -197,9 +197,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!Cloaked || self.Owner.IsAlliedWith(viewer))
|
||||
return true;
|
||||
|
||||
return self.World.ActorsWithTrait<DetectCloaked>().Any(a => !a.Trait.IsTraitDisabled && a.Actor.Owner.IsAlliedWith(viewer)
|
||||
return self.World.ActorsWithTrait<DetectCloaked>().Any(a => a.Actor.Owner.IsAlliedWith(viewer)
|
||||
&& Info.CloakTypes.Overlaps(a.Trait.Info.CloakTypes)
|
||||
&& (self.CenterPosition - a.Actor.CenterPosition).LengthSquared <= a.Trait.Info.Range.LengthSquared);
|
||||
&& (self.CenterPosition - a.Actor.CenterPosition).LengthSquared <= a.Trait.Range.LengthSquared);
|
||||
}
|
||||
|
||||
Color IRadarColorModifier.RadarColorOverride(Actor self, Color color)
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
@@ -24,9 +26,29 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public override object Create(ActorInitializer init) { return new DetectCloaked(this); }
|
||||
}
|
||||
|
||||
public class DetectCloaked : ConditionalTrait<DetectCloakedInfo>
|
||||
public class DetectCloaked : ConditionalTrait<DetectCloakedInfo>, INotifyCreated
|
||||
{
|
||||
IDetectCloakedModifier[] rangeModifiers;
|
||||
|
||||
public DetectCloaked(DetectCloakedInfo info)
|
||||
: base(info) { }
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
rangeModifiers = self.TraitsImplementing<IDetectCloakedModifier>().ToArray();
|
||||
}
|
||||
|
||||
public WDist Range
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return WDist.Zero;
|
||||
|
||||
var detectCloakedModifier = rangeModifiers.Select(x => x.GetDetectCloakedModifier());
|
||||
var range = Util.ApplyPercentageModifiers(Info.Range.Length, detectCloakedModifier);
|
||||
return new WDist(range);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Modifies the cloak detection range of this actor.")]
|
||||
public class DetectCloakedMultiplierInfo : ConditionalTraitInfo
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
[Desc("Percentage modifier to apply.")]
|
||||
public readonly int Modifier = 100;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new DetectCloakedMultiplier(this); }
|
||||
}
|
||||
|
||||
public class DetectCloakedMultiplier : ConditionalTrait<DetectCloakedMultiplierInfo>, IDetectCloakedModifier
|
||||
{
|
||||
public DetectCloakedMultiplier(DetectCloakedMultiplierInfo info)
|
||||
: base(info) { }
|
||||
|
||||
int IDetectCloakedModifier.GetDetectCloakedModifier()
|
||||
{
|
||||
return IsTraitDisabled ? 100 : Info.Modifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,8 +51,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
yield break;
|
||||
|
||||
var range = self.TraitsImplementing<DetectCloaked>()
|
||||
.Where(a => !a.IsTraitDisabled)
|
||||
.Select(a => a.Info.Range)
|
||||
.Select(a => a.Range)
|
||||
.Append(WDist.Zero).Max();
|
||||
|
||||
if (range == WDist.Zero)
|
||||
|
||||
@@ -388,6 +388,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[RequireExplicitImplementation]
|
||||
public interface IRevealsShroudModifier { int GetRevealsShroudModifier(); }
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface IDetectCloakedModifier { int GetDetectCloakedModifier(); }
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface ICustomMovementLayer
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user