Add target flashing for C4. Closes #4659

This commit is contained in:
ScottNZ
2014-07-10 02:51:15 +12:00
parent 8bce37710b
commit 04cd99cd75
3 changed files with 44 additions and 22 deletions

View File

@@ -18,15 +18,13 @@ namespace OpenRA.Effects
{ {
Actor target; Actor target;
Player player; Player player;
int remainingTicks = 4; int remainingTicks;
public FlashTarget(Actor target) public FlashTarget(Actor target, Player asPlayer = null, int ticks = 4)
: this(target, null) { }
public FlashTarget(Actor target, Player asPlayer)
{ {
this.target = target; this.target = target;
player = asPlayer; player = asPlayer;
remainingTicks = ticks;
foreach (var e in target.World.Effects.OfType<FlashTarget>().Where(a => a.target == target).ToArray()) foreach (var e in target.World.Effects.OfType<FlashTarget>().Where(a => a.target == target).ToArray())
target.World.Remove(e); target.World.Remove(e);
} }

View File

@@ -16,13 +16,21 @@ namespace OpenRA.Mods.RA.Activities
{ {
class Demolish : Activity class Demolish : Activity
{ {
Target target; readonly Target target;
int delay; readonly int delay;
readonly int flashes;
readonly int flashesDelay;
readonly int flashInterval;
readonly int flashDuration;
public Demolish(Actor target, int delay) public Demolish(Actor target, int delay, int flashes, int flashesDelay, int flashInterval, int flashDuration)
{ {
this.target = Target.FromActor(target); this.target = Target.FromActor(target);
this.delay = delay; this.delay = delay;
this.flashes = flashes;
this.flashesDelay = flashesDelay;
this.flashInterval = flashInterval;
this.flashDuration = flashDuration;
} }
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
@@ -30,24 +38,31 @@ namespace OpenRA.Mods.RA.Activities
if (IsCanceled || !target.IsValidFor(self)) if (IsCanceled || !target.IsValidFor(self))
return NextActivity; return NextActivity;
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(delay, () => self.World.AddFrameEndTask(w =>
{ {
// Can't demolish an already dead actor for (var f = 0; f < flashes; f++)
if (target.Type != TargetType.Actor) w.Add(new DelayedAction(flashesDelay + f * flashInterval, () =>
return; w.Add(new FlashTarget(target.Actor, ticks: flashDuration))));
// Invulnerable actors can't be demolished w.Add(new DelayedAction(delay, () =>
var modifier = (float)target.Actor.TraitsImplementing<IDamageModifier>() {
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>()) // Can't demolish an already dead actor
.Select(t => t.GetDamageModifier(self, null)).Product(); if (target.Type != TargetType.Actor)
return;
var demolishable = target.Actor.TraitOrDefault<IDemolishable>(); // Invulnerable actors can't be demolished
var modifier = (float)target.Actor.TraitsImplementing<IDamageModifier>()
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>())
.Select(t => t.GetDamageModifier(self, null)).Product();
var demolishable = target.Actor.TraitOrDefault<IDemolishable>();
if (demolishable == null || !demolishable.IsValidTarget(target.Actor, self)) if (demolishable == null || !demolishable.IsValidTarget(target.Actor, self))
return; return;
if (modifier > 0) if (modifier > 0)
demolishable.Demolish(target.Actor, self); demolishable.Demolish(target.Actor, self);
}))); }));
});
return NextActivity; return NextActivity;
} }

View File

@@ -22,6 +22,14 @@ namespace OpenRA.Mods.RA
[Desc("Delay to demolish the target once the C4 is planted." + [Desc("Delay to demolish the target once the C4 is planted." +
"Measured in game ticks. Default is 1.8 seconds.")] "Measured in game ticks. Default is 1.8 seconds.")]
public readonly int C4Delay = 45; public readonly int C4Delay = 45;
[Desc("Number of times to flash the target")]
public readonly int Flashes = 3;
[Desc("Delay before the flashing starts")]
public readonly int FlashesDelay = 4;
[Desc("Interval between each flash")]
public readonly int FlashInterval = 4;
[Desc("Duration of each flash")]
public readonly int FlashDuration = 3;
public object Create(ActorInitializer init) { return new C4Demolition(this); } public object Create(ActorInitializer init) { return new C4Demolition(this); }
} }
@@ -68,7 +76,8 @@ namespace OpenRA.Mods.RA
self.CancelActivity(); self.CancelActivity();
self.SetTargetLine(target, Color.Red); self.SetTargetLine(target, Color.Red);
self.QueueActivity(new Enter(target.Actor, new Demolish(target.Actor, info.C4Delay))); self.QueueActivity(new Enter(target.Actor, new Demolish(
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)