Remove DelayedAction from WeaponInfo and replace it with the more serialization friendly DelayedImpact

This commit is contained in:
Ori Bar
2016-11-04 01:36:45 +02:00
parent 8cda0dd360
commit fabe799907
3 changed files with 49 additions and 3 deletions

View 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; }
}
}

View File

@@ -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);
}
}
}

View File

@@ -103,6 +103,7 @@
<Compile Include="Download.cs" />
<Compile Include="Effects\AsyncAction.cs" />
<Compile Include="Effects\DelayedAction.cs" />
<Compile Include="Effects\DelayedImpact.cs" />
<Compile Include="Effects\IEffect.cs" />
<Compile Include="Game.cs" />
<Compile Include="GameRules\ActorInfo.cs" />