Grant condition to units closest to the crate
This commit is contained in:
committed by
Matthias Mailänder
parent
cfc026a1ac
commit
a4821b51a2
@@ -13,7 +13,7 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Grants a condition on the collector.")]
|
[Desc("Grants a condition to the collector and nearby units.")]
|
||||||
public class GrantExternalConditionCrateActionInfo : CrateActionInfo
|
public class GrantExternalConditionCrateActionInfo : CrateActionInfo
|
||||||
{
|
{
|
||||||
[FieldLoader.Require]
|
[FieldLoader.Require]
|
||||||
@@ -60,20 +60,22 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public override void Activate(Actor collector)
|
public override void Activate(Actor collector)
|
||||||
{
|
{
|
||||||
|
if (collector.IsInWorld && !collector.IsDead)
|
||||||
|
GrantCondition(collector);
|
||||||
|
|
||||||
var actorsInRange = self.World.FindActorsInCircle(self.CenterPosition, info.Range)
|
var actorsInRange = self.World.FindActorsInCircle(self.CenterPosition, info.Range)
|
||||||
.Where(a => a != self && a != collector && a.Owner == collector.Owner && AcceptsCondition(a));
|
.Where(a => a != self && a != collector && a.IsInWorld && !a.IsDead && a.Owner == collector.Owner && AcceptsCondition(a))
|
||||||
|
.OrderBy(a => (a.CenterPosition - self.CenterPosition).LengthSquared);
|
||||||
|
|
||||||
if (info.MaxExtraCollectors > -1)
|
foreach (var a in info.MaxExtraCollectors > -1 ? actorsInRange.Take(info.MaxExtraCollectors) : actorsInRange)
|
||||||
actorsInRange = actorsInRange.Take(info.MaxExtraCollectors);
|
GrantCondition(a);
|
||||||
|
|
||||||
collector.World.AddFrameEndTask(w =>
|
base.Activate(collector);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GrantCondition(Actor actor)
|
||||||
{
|
{
|
||||||
foreach (var a in actorsInRange.Append(collector))
|
var externals = actor.TraitsImplementing<ExternalCondition>()
|
||||||
{
|
|
||||||
if (!a.IsInWorld || a.IsDead)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var externals = a.TraitsImplementing<ExternalCondition>()
|
|
||||||
.Where(t => t.Info.Condition == info.Condition);
|
.Where(t => t.Info.Condition == info.Condition);
|
||||||
|
|
||||||
ExternalCondition external = null;
|
ExternalCondition external = null;
|
||||||
@@ -86,12 +88,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
external.GrantCondition(a, self, info.Duration);
|
external.GrantCondition(actor, self, info.Duration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
base.Activate(collector);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user