Replace DelayedAction with Tick-based solution in PlaceBuilding
This commit is contained in:
@@ -31,16 +31,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new PlaceBuilding(this); }
|
public object Create(ActorInitializer init) { return new PlaceBuilding(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlaceBuilding : IResolveOrder
|
public class PlaceBuilding : IResolveOrder, ITick
|
||||||
{
|
{
|
||||||
readonly PlaceBuildingInfo info;
|
readonly PlaceBuildingInfo info;
|
||||||
|
bool triggerNotification;
|
||||||
|
int tick;
|
||||||
|
|
||||||
public PlaceBuilding(PlaceBuildingInfo info)
|
public PlaceBuilding(PlaceBuildingInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
void IResolveOrder.ResolveOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
var os = order.OrderString;
|
var os = order.OrderString;
|
||||||
if (os != "PlaceBuilding" &&
|
if (os != "PlaceBuilding" &&
|
||||||
@@ -143,11 +145,26 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (GetNumBuildables(self.Owner) > prevItems)
|
if (GetNumBuildables(self.Owner) > prevItems)
|
||||||
w.Add(new DelayedAction(info.NewOptionsNotificationDelay,
|
triggerNotification = true;
|
||||||
() => Game.Sound.PlayNotification(self.World.Map.Rules, order.Player, "Speech", info.NewOptionsNotification, order.Player.Faction.InternalName)));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ITick.Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (!triggerNotification)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (tick++ >= info.NewOptionsNotificationDelay)
|
||||||
|
PlayNotification(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayNotification(Actor self)
|
||||||
|
{
|
||||||
|
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.NewOptionsNotification, self.Owner.Faction.InternalName);
|
||||||
|
triggerNotification = false;
|
||||||
|
tick = 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int GetNumBuildables(Player p)
|
static int GetNumBuildables(Player p)
|
||||||
{
|
{
|
||||||
// This only matters for local players.
|
// This only matters for local players.
|
||||||
|
|||||||
Reference in New Issue
Block a user