Demolish as Enter subclass
This commit is contained in:
@@ -8,24 +8,28 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Effects;
|
using OpenRA.Effects;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Activities
|
namespace OpenRA.Mods.RA.Activities
|
||||||
{
|
{
|
||||||
class Demolish : Activity
|
class Demolish : Enter
|
||||||
{
|
{
|
||||||
readonly Target target;
|
readonly Actor target;
|
||||||
|
readonly IEnumerable<IDemolishable> demolishables;
|
||||||
readonly int delay;
|
readonly int delay;
|
||||||
readonly int flashes;
|
readonly int flashes;
|
||||||
readonly int flashesDelay;
|
readonly int flashesDelay;
|
||||||
readonly int flashInterval;
|
readonly int flashInterval;
|
||||||
readonly int flashDuration;
|
readonly int flashDuration;
|
||||||
|
|
||||||
public Demolish(Actor target, int delay, int flashes, int flashesDelay, int flashInterval, int flashDuration)
|
public Demolish(Actor self, Actor target, int delay, int flashes, int flashesDelay, int flashInterval, int flashDuration)
|
||||||
|
: base(self, target)
|
||||||
{
|
{
|
||||||
this.target = Target.FromActor(target);
|
this.target = target;
|
||||||
|
demolishables = target.TraitsImplementing<IDemolishable>();
|
||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
this.flashes = flashes;
|
this.flashes = flashes;
|
||||||
this.flashesDelay = flashesDelay;
|
this.flashesDelay = flashesDelay;
|
||||||
@@ -33,39 +37,35 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
this.flashDuration = flashDuration;
|
this.flashDuration = flashDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
protected override bool CanReserve(Actor self)
|
||||||
{
|
{
|
||||||
if (IsCanceled || !target.IsValidFor(self))
|
return demolishables.Any(i => i.IsValidTarget(target, self));
|
||||||
return NextActivity;
|
}
|
||||||
|
|
||||||
|
protected override void OnInside(Actor self)
|
||||||
|
{
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
|
if (target.IsDead())
|
||||||
|
return;
|
||||||
|
|
||||||
for (var f = 0; f < flashes; f++)
|
for (var f = 0; f < flashes; f++)
|
||||||
w.Add(new DelayedAction(flashesDelay + f * flashInterval, () =>
|
w.Add(new DelayedAction(flashesDelay + f * flashInterval, () =>
|
||||||
w.Add(new FlashTarget(target.Actor, ticks: flashDuration))));
|
w.Add(new FlashTarget(target, ticks: flashDuration))));
|
||||||
|
|
||||||
w.Add(new DelayedAction(delay, () =>
|
w.Add(new DelayedAction(delay, () =>
|
||||||
{
|
{
|
||||||
// Can't demolish an already dead actor
|
if (target.IsDead())
|
||||||
if (target.Type != TargetType.Actor)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var modifiers = target.TraitsImplementing<IDamageModifier>()
|
||||||
|
|
||||||
var demolishable = target.Actor.TraitOrDefault<IDemolishable>();
|
|
||||||
if (demolishable == null || !demolishable.IsValidTarget(target.Actor, self))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var modifiers = target.Actor.TraitsImplementing<IDamageModifier>()
|
|
||||||
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>())
|
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>())
|
||||||
.Select(t => t.GetDamageModifier(self, null));
|
.Select(t => t.GetDamageModifier(self, null));
|
||||||
|
|
||||||
if (Util.ApplyPercentageModifiers(100, modifiers) > 0)
|
if (Util.ApplyPercentageModifiers(100, modifiers) > 0)
|
||||||
demolishable.Demolish(target.Actor, self);
|
demolishables.Do(d => d.Demolish(target, self));
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextActivity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ namespace OpenRA.Mods.RA
|
|||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
|
|
||||||
self.SetTargetLine(target, Color.Red);
|
self.SetTargetLine(target, Color.Red);
|
||||||
self.QueueActivity(new Enter(self, target.Actor, new Demolish(
|
self.QueueActivity(new Demolish(self,
|
||||||
target.Actor, info.C4Delay, info.Flashes, info.FlashesDelay, info.FlashInterval, info.FlashDuration)));
|
target.Actor, info.C4Delay, info.Flashes, info.FlashesDelay, info.FlashInterval, info.FlashDuration));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string VoicePhraseForOrder(Actor self, Order order)
|
public string VoicePhraseForOrder(Actor self, Order order)
|
||||||
|
|||||||
Reference in New Issue
Block a user