diff --git a/OpenRA.Game/Effects/DelayedImpact.cs b/OpenRA.Game/Effects/DelayedImpact.cs new file mode 100644 index 0000000000..9f6b6d007f --- /dev/null +++ b/OpenRA.Game/Effects/DelayedImpact.cs @@ -0,0 +1,46 @@ +#region Copyright & License Information +/* + * Copyright 2007-2016 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using OpenRA.Graphics; +using OpenRA.Traits; + +namespace OpenRA.Effects +{ + public class DelayedImpact : IEffect + { + readonly Target target; + readonly Actor firedBy; + readonly IEnumerable damageModifiers; + readonly IWarhead wh; + + int delay; + + public DelayedImpact(int delay, IWarhead wh, Target target, Actor firedBy, IEnumerable damageModifiers) + { + this.wh = wh; + this.delay = delay; + + this.target = target; + this.firedBy = firedBy; + this.damageModifiers = damageModifiers; + } + + public void Tick(World world) + { + if (--delay <= 0) + world.AddFrameEndTask(w => { w.Remove(this); wh.DoImpact(target, firedBy, damageModifiers); }); + } + + public IEnumerable Render(WorldRenderer wr) { yield break; } + } +} \ No newline at end of file diff --git a/OpenRA.Game/GameRules/WeaponInfo.cs b/OpenRA.Game/GameRules/WeaponInfo.cs index 973ee5b574..c506161b40 100644 --- a/OpenRA.Game/GameRules/WeaponInfo.cs +++ b/OpenRA.Game/GameRules/WeaponInfo.cs @@ -159,11 +159,10 @@ namespace OpenRA.GameRules { var wh = warhead; // force the closure to bind to the current warhead - Action a = () => wh.DoImpact(target, firedBy, damageModifiers); if (wh.Delay > 0) - firedBy.World.AddFrameEndTask(w => w.Add(new DelayedAction(wh.Delay, a))); + firedBy.World.AddFrameEndTask(w => w.Add(new DelayedImpact(wh.Delay, wh, target, firedBy, damageModifiers))); else - a(); + wh.DoImpact(target, firedBy, damageModifiers); } } } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index e243084f06..d7b00aae34 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -103,6 +103,7 @@ +