Merge pull request #12481 from reaperrr/rem-runafterdelay
Remove Game.RunAfterDelay from SwallowActor
This commit is contained in:
65
OpenRA.Mods.Common/Effects/MapNotificationEffect.cs
Normal file
65
OpenRA.Mods.Common/Effects/MapNotificationEffect.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
#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.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Effects
|
||||
{
|
||||
public class MapNotificationEffect : IEffect
|
||||
{
|
||||
readonly RadarPings radarPings;
|
||||
|
||||
readonly WPos pos;
|
||||
readonly Player player;
|
||||
readonly int duration;
|
||||
readonly string category;
|
||||
readonly string notification;
|
||||
readonly bool visible;
|
||||
readonly Color color;
|
||||
|
||||
int remainingDelay;
|
||||
|
||||
public MapNotificationEffect(Player player, string category, string notification, int delay,
|
||||
bool pingVisible, WPos pos, Color pingColor, int pingDuration = 50)
|
||||
{
|
||||
this.player = player;
|
||||
remainingDelay = delay;
|
||||
this.category = category;
|
||||
this.notification = notification;
|
||||
this.pos = pos;
|
||||
duration = pingDuration;
|
||||
visible = pingVisible;
|
||||
color = pingColor;
|
||||
|
||||
radarPings = player.World.WorldActor.TraitOrDefault<RadarPings>();
|
||||
}
|
||||
|
||||
public void Tick(World world)
|
||||
{
|
||||
if (remainingDelay-- > 0)
|
||||
return;
|
||||
|
||||
Game.Sound.PlayNotification(player.World.Map.Rules, player, category, notification, player.Faction.InternalName);
|
||||
|
||||
if (visible && radarPings != null && player == player.World.RenderPlayer)
|
||||
radarPings.Add(() => true, pos, color, duration);
|
||||
|
||||
world.AddFrameEndTask(w => w.Remove(this));
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr) { return SpriteRenderable.None; }
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,7 @@
|
||||
<Compile Include="Effects\RevealShroudEffect.cs" />
|
||||
<Compile Include="Effects\FlashTarget.cs" />
|
||||
<Compile Include="Effects\FloatingText.cs" />
|
||||
<Compile Include="Effects\MapNotificationEffect.cs" />
|
||||
<Compile Include="Effects\PowerdownIndicator.cs" />
|
||||
<Compile Include="Effects\RallyPointIndicator.cs" />
|
||||
<Compile Include="Effects\RepairIndicator.cs" />
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.D2k.Traits;
|
||||
using OpenRA.Traits;
|
||||
@@ -30,7 +31,6 @@ namespace OpenRA.Mods.D2k.Activities
|
||||
readonly Sandworm sandworm;
|
||||
readonly ConditionManager conditionManager;
|
||||
readonly WeaponInfo weapon;
|
||||
readonly RadarPings radarPings;
|
||||
readonly AttackSwallow swallow;
|
||||
readonly IPositionable positionable;
|
||||
|
||||
@@ -47,7 +47,6 @@ namespace OpenRA.Mods.D2k.Activities
|
||||
positionable = self.Trait<Mobile>();
|
||||
swallow = self.Trait<AttackSwallow>();
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>();
|
||||
}
|
||||
|
||||
bool AttackTargets(Actor self, IEnumerable<Actor> targets)
|
||||
@@ -78,19 +77,8 @@ namespace OpenRA.Mods.D2k.Activities
|
||||
var affectedPlayers = targets.Select(x => x.Owner).Distinct().ToList();
|
||||
Game.Sound.Play(SoundType.World, swallow.Info.WormAttackSound, self.CenterPosition);
|
||||
|
||||
Game.RunAfterDelay(1000, () =>
|
||||
{
|
||||
if (!Game.IsCurrentWorld(self.World))
|
||||
return;
|
||||
|
||||
foreach (var player in affectedPlayers)
|
||||
{
|
||||
Game.Sound.PlayNotification(player.World.Map.Rules, player, "Speech", swallow.Info.WormAttackNotification, player.Faction.InternalName);
|
||||
|
||||
if (player == player.World.RenderPlayer)
|
||||
radarPings.Add(() => true, attackPosition, Color.Red, 50);
|
||||
}
|
||||
});
|
||||
foreach (var player in affectedPlayers)
|
||||
self.World.AddFrameEndTask(w => w.Add(new MapNotificationEffect(player, "Speech", swallow.Info.WormAttackNotification, 25, true, attackPosition, Color.Red)));
|
||||
|
||||
foreach (var notify in self.TraitsImplementing<INotifyAttack>())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user