Merge pull request #11162 from reaperrr/fix-11159
Enable Targetable to handle multiple Cloak traits
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
@@ -29,24 +30,25 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public class Targetable : UpgradableTrait<TargetableInfo>, ITargetable, INotifyCreated
|
public class Targetable : UpgradableTrait<TargetableInfo>, ITargetable, INotifyCreated
|
||||||
{
|
{
|
||||||
protected static readonly string[] None = new string[] { };
|
protected static readonly string[] None = new string[] { };
|
||||||
protected Cloak cloak;
|
protected Cloak[] cloaks;
|
||||||
|
|
||||||
public Targetable(Actor self, TargetableInfo info)
|
public Targetable(Actor self, TargetableInfo info)
|
||||||
: base(info) { }
|
: base(info) { }
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
{
|
{
|
||||||
cloak = self.TraitOrDefault<Cloak>();
|
cloaks = self.TraitsImplementing<Cloak>().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool TargetableBy(Actor self, Actor viewer)
|
public virtual bool TargetableBy(Actor self, Actor viewer)
|
||||||
{
|
{
|
||||||
if (IsTraitDisabled)
|
if (IsTraitDisabled)
|
||||||
return false;
|
return false;
|
||||||
if (cloak == null || (!viewer.IsDead && viewer.Info.HasTraitInfo<IgnoresCloakInfo>()))
|
|
||||||
|
if (!cloaks.Any() || (!viewer.IsDead && viewer.Info.HasTraitInfo<IgnoresCloakInfo>()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return cloak.IsVisible(self, viewer.Owner);
|
return cloaks.All(c => c.IsTraitDisabled || c.IsVisible(self, viewer.Owner));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual HashSet<string> TargetTypes { get { return Info.TargetTypes; } }
|
public virtual HashSet<string> TargetTypes { get { return Info.TargetTypes; } }
|
||||||
|
|||||||
Reference in New Issue
Block a user