Merge pull request #5904 from ScottNZ/c4-flashtarget
Add target flashing for C4.
This commit is contained in:
@@ -18,15 +18,13 @@ namespace OpenRA.Effects
|
||||
{
|
||||
Actor target;
|
||||
Player player;
|
||||
int remainingTicks = 4;
|
||||
int remainingTicks;
|
||||
|
||||
public FlashTarget(Actor target)
|
||||
: this(target, null) { }
|
||||
|
||||
public FlashTarget(Actor target, Player asPlayer)
|
||||
public FlashTarget(Actor target, Player asPlayer = null, int ticks = 4)
|
||||
{
|
||||
this.target = target;
|
||||
player = asPlayer;
|
||||
remainingTicks = ticks;
|
||||
foreach (var e in target.World.Effects.OfType<FlashTarget>().Where(a => a.target == target).ToArray())
|
||||
target.World.Remove(e);
|
||||
}
|
||||
|
||||
@@ -16,13 +16,21 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Demolish : Activity
|
||||
{
|
||||
Target target;
|
||||
int delay;
|
||||
readonly Target target;
|
||||
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.delay = delay;
|
||||
this.flashes = flashes;
|
||||
this.flashesDelay = flashesDelay;
|
||||
this.flashInterval = flashInterval;
|
||||
this.flashDuration = flashDuration;
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
@@ -30,24 +38,31 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (IsCanceled || !target.IsValidFor(self))
|
||||
return NextActivity;
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(delay, () =>
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
// Can't demolish an already dead actor
|
||||
if (target.Type != TargetType.Actor)
|
||||
return;
|
||||
for (var f = 0; f < flashes; f++)
|
||||
w.Add(new DelayedAction(flashesDelay + f * flashInterval, () =>
|
||||
w.Add(new FlashTarget(target.Actor, ticks: flashDuration))));
|
||||
|
||||
// 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();
|
||||
w.Add(new DelayedAction(delay, () =>
|
||||
{
|
||||
// Can't demolish an already dead actor
|
||||
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))
|
||||
return;
|
||||
return;
|
||||
|
||||
if (modifier > 0)
|
||||
demolishable.Demolish(target.Actor, self);
|
||||
})));
|
||||
if (modifier > 0)
|
||||
demolishable.Demolish(target.Actor, self);
|
||||
}));
|
||||
});
|
||||
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,14 @@ namespace OpenRA.Mods.RA
|
||||
[Desc("Delay to demolish the target once the C4 is planted." +
|
||||
"Measured in game ticks. Default is 1.8 seconds.")]
|
||||
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); }
|
||||
}
|
||||
@@ -68,7 +76,8 @@ namespace OpenRA.Mods.RA
|
||||
self.CancelActivity();
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user