Remove DelayedAction from WeaponInfo and replace it with the more serialization friendly DelayedImpact
This commit is contained in:
46
OpenRA.Game/Effects/DelayedImpact.cs
Normal file
46
OpenRA.Game/Effects/DelayedImpact.cs
Normal file
@@ -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<int> damageModifiers;
|
||||||
|
readonly IWarhead wh;
|
||||||
|
|
||||||
|
int delay;
|
||||||
|
|
||||||
|
public DelayedImpact(int delay, IWarhead wh, Target target, Actor firedBy, IEnumerable<int> 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<IRenderable> Render(WorldRenderer wr) { yield break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -159,11 +159,10 @@ namespace OpenRA.GameRules
|
|||||||
{
|
{
|
||||||
var wh = warhead; // force the closure to bind to the current warhead
|
var wh = warhead; // force the closure to bind to the current warhead
|
||||||
|
|
||||||
Action a = () => wh.DoImpact(target, firedBy, damageModifiers);
|
|
||||||
if (wh.Delay > 0)
|
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
|
else
|
||||||
a();
|
wh.DoImpact(target, firedBy, damageModifiers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,7 @@
|
|||||||
<Compile Include="Download.cs" />
|
<Compile Include="Download.cs" />
|
||||||
<Compile Include="Effects\AsyncAction.cs" />
|
<Compile Include="Effects\AsyncAction.cs" />
|
||||||
<Compile Include="Effects\DelayedAction.cs" />
|
<Compile Include="Effects\DelayedAction.cs" />
|
||||||
|
<Compile Include="Effects\DelayedImpact.cs" />
|
||||||
<Compile Include="Effects\IEffect.cs" />
|
<Compile Include="Effects\IEffect.cs" />
|
||||||
<Compile Include="Game.cs" />
|
<Compile Include="Game.cs" />
|
||||||
<Compile Include="GameRules\ActorInfo.cs" />
|
<Compile Include="GameRules\ActorInfo.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user