From 38b3a4a66869d5df83333f8dc6395d8240be27a6 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Wed, 6 Mar 2019 19:07:29 +0100 Subject: [PATCH] Split INotifyWinStateChanged from INotifyObjectivesUpdated --- .../Scripting/ScriptTriggers.cs | 6 ++--- .../Player/ConquestVictoryConditions.cs | 10 +++---- .../Traits/Player/MissionObjectives.cs | 26 +++++++------------ .../Player/StrategicVictoryConditions.cs | 13 ++++------ OpenRA.Mods.Common/TraitsInterfaces.cs | 9 +++++-- 5 files changed, 27 insertions(+), 37 deletions(-) diff --git a/OpenRA.Mods.Common/Scripting/ScriptTriggers.cs b/OpenRA.Mods.Common/Scripting/ScriptTriggers.cs index 1f5ae72ec0..2fd024ef5b 100644 --- a/OpenRA.Mods.Common/Scripting/ScriptTriggers.cs +++ b/OpenRA.Mods.Common/Scripting/ScriptTriggers.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Scripting public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyOtherProduction, INotifyObjectivesUpdated, INotifyCapture, INotifyInfiltrated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyDiscovered, INotifyActorDisposing, - INotifyPassengerEntered, INotifyPassengerExited, INotifySold + INotifyPassengerEntered, INotifyPassengerExited, INotifySold, INotifyWinStateChanged { readonly World world; readonly Actor self; @@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Scripting OnProducedInternal(self, other); } - void INotifyObjectivesUpdated.OnPlayerWon(Player player) + void INotifyWinStateChanged.OnPlayerWon(Player player) { if (world.Disposing) return; @@ -196,7 +196,7 @@ namespace OpenRA.Mods.Common.Scripting } } - void INotifyObjectivesUpdated.OnPlayerLost(Player player) + void INotifyWinStateChanged.OnPlayerLost(Player player) { if (world.Disposing) return; diff --git a/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs b/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs index d79badf5ae..fd9126f4d7 100644 --- a/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs +++ b/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits public object Create(ActorInitializer init) { return new ConquestVictoryConditions(init.Self, this); } } - public class ConquestVictoryConditions : ITick, INotifyObjectivesUpdated + public class ConquestVictoryConditions : ITick, INotifyWinStateChanged { readonly ConquestVictoryConditionsInfo info; readonly MissionObjectives mo; @@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits mo.MarkCompleted(self.Owner, objectiveID); } - void INotifyObjectivesUpdated.OnPlayerLost(Player player) + void INotifyWinStateChanged.OnPlayerLost(Player player) { foreach (var a in player.World.ActorsWithTrait().Where(a => a.Actor.Owner == player)) a.Trait.OnOwnerLost(a.Actor); @@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits }); } - void INotifyObjectivesUpdated.OnPlayerWon(Player player) + void INotifyWinStateChanged.OnPlayerWon(Player player) { if (info.SuppressNotifications) return; @@ -96,9 +96,5 @@ namespace OpenRA.Mods.Common.Traits Game.Sound.PlayNotification(player.World.Map.Rules, player, "Speech", mo.Info.WinNotification, player.Faction.InternalName); }); } - - void INotifyObjectivesUpdated.OnObjectiveAdded(Player player, int id) { } - void INotifyObjectivesUpdated.OnObjectiveCompleted(Player player, int id) { } - void INotifyObjectivesUpdated.OnObjectiveFailed(Player player, int id) { } } } diff --git a/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs b/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs index 284fc3ddef..c76fc2bfb7 100644 --- a/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs +++ b/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits public object Create(ActorInitializer init) { return new MissionObjectives(init.World, this); } } - public class MissionObjectives : INotifyObjectivesUpdated, ISync, IResolveOrder + public class MissionObjectives : INotifyWinStateChanged, ISync, IResolveOrder { public readonly MissionObjectivesInfo Info; readonly List objectives = new List(); @@ -106,10 +106,8 @@ namespace OpenRA.Mods.Common.Traits if (objectiveID >= objectives.Count || objectives[objectiveID].State != ObjectiveState.Incomplete) return; - var inous = player.PlayerActor.TraitsImplementing(); - objectives[objectiveID].State = ObjectiveState.Completed; - foreach (var inou in inous) + foreach (var inou in player.PlayerActor.TraitsImplementing()) inou.OnObjectiveCompleted(player, objectiveID); if (objectives[objectiveID].Type == ObjectiveType.Primary) @@ -118,8 +116,8 @@ namespace OpenRA.Mods.Common.Traits if (playerWon) { - foreach (var inou in inous) - inou.OnPlayerWon(player); + foreach (var inwc in player.PlayerActor.TraitsImplementing()) + inwc.OnPlayerWon(player); CheckIfGameIsOver(player); } @@ -131,10 +129,8 @@ namespace OpenRA.Mods.Common.Traits if (objectiveID >= objectives.Count || objectives[objectiveID].State == ObjectiveState.Failed) return; - var inous = player.PlayerActor.TraitsImplementing(); - objectives[objectiveID].State = ObjectiveState.Failed; - foreach (var inou in inous) + foreach (var inou in player.PlayerActor.TraitsImplementing()) inou.OnObjectiveFailed(player, objectiveID); if (objectives[objectiveID].Type == ObjectiveType.Primary) @@ -143,8 +139,8 @@ namespace OpenRA.Mods.Common.Traits if (playerLost) { - foreach (var inou in inous) - inou.OnPlayerLost(player); + foreach (var inwc in player.PlayerActor.TraitsImplementing()) + inwc.OnPlayerLost(player); CheckIfGameIsOver(player); } @@ -168,7 +164,7 @@ namespace OpenRA.Mods.Common.Traits }); } - void INotifyObjectivesUpdated.OnPlayerWon(Player player) + void INotifyWinStateChanged.OnPlayerWon(Player player) { var players = player.World.Players.Where(p => !p.NonCombatant); var enemies = players.Where(p => !p.IsAlliedWith(player)); @@ -204,7 +200,7 @@ namespace OpenRA.Mods.Common.Traits CheckIfGameIsOver(player); } - void INotifyObjectivesUpdated.OnPlayerLost(Player player) + void INotifyWinStateChanged.OnPlayerLost(Player player) { var players = player.World.Players.Where(p => !p.NonCombatant); var enemies = players.Where(p => !p.IsAlliedWith(player)); @@ -259,10 +255,6 @@ namespace OpenRA.Mods.Common.Traits public event Action ObjectiveAdded = (player, inhibitAnnouncement) => { player.HasObjectives = true; }; - void INotifyObjectivesUpdated.OnObjectiveAdded(Player player, int id) { } - void INotifyObjectivesUpdated.OnObjectiveCompleted(Player player, int id) { } - void INotifyObjectivesUpdated.OnObjectiveFailed(Player player, int id) { } - public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Surrender") diff --git a/OpenRA.Mods.Common/Traits/Player/StrategicVictoryConditions.cs b/OpenRA.Mods.Common/Traits/Player/StrategicVictoryConditions.cs index f92d461018..d4c2d8d29f 100644 --- a/OpenRA.Mods.Common/Traits/Player/StrategicVictoryConditions.cs +++ b/OpenRA.Mods.Common/Traits/Player/StrategicVictoryConditions.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits public object Create(ActorInitializer init) { return new StrategicVictoryConditions(init.Self, this); } } - public class StrategicVictoryConditions : ITick, ISync, INotifyObjectivesUpdated + public class StrategicVictoryConditions : ITick, ISync, INotifyWinStateChanged { readonly StrategicVictoryConditionsInfo info; @@ -75,7 +75,8 @@ namespace OpenRA.Mods.Common.Traits void ITick.Tick(Actor self) { - if (player.WinState != WinState.Undefined || player.NonCombatant) return; + if (player.WinState != WinState.Undefined || player.NonCombatant) + return; if (objectiveID < 0) objectiveID = mo.Add(player, info.Objective, ObjectiveType.Primary, true); @@ -107,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits } } - void INotifyObjectivesUpdated.OnPlayerLost(Player player) + void INotifyWinStateChanged.OnPlayerLost(Player player) { foreach (var a in player.World.ActorsWithTrait().Where(a => a.Actor.Owner == player)) a.Trait.OnOwnerLost(a.Actor); @@ -123,7 +124,7 @@ namespace OpenRA.Mods.Common.Traits }); } - void INotifyObjectivesUpdated.OnPlayerWon(Player player) + void INotifyWinStateChanged.OnPlayerWon(Player player) { if (info.SuppressNotifications) return; @@ -135,9 +136,5 @@ namespace OpenRA.Mods.Common.Traits Game.Sound.PlayNotification(player.World.Map.Rules, player, "Speech", mo.Info.WinNotification, player.Faction.InternalName); }); } - - void INotifyObjectivesUpdated.OnObjectiveAdded(Player player, int id) { } - void INotifyObjectivesUpdated.OnObjectiveCompleted(Player player, int id) { } - void INotifyObjectivesUpdated.OnObjectiveFailed(Player player, int id) { } } } diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index b14f3919aa..c54d9bc73a 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -436,13 +436,18 @@ namespace OpenRA.Mods.Common.Traits [RequireExplicitImplementation] public interface INotifyObjectivesUpdated { - void OnPlayerWon(Player winner); - void OnPlayerLost(Player loser); void OnObjectiveAdded(Player player, int objectiveID); void OnObjectiveCompleted(Player player, int objectiveID); void OnObjectiveFailed(Player player, int objectiveID); } + [RequireExplicitImplementation] + public interface INotifyWinStateChanged + { + void OnPlayerWon(Player winner); + void OnPlayerLost(Player loser); + } + public interface INotifyCashTransfer { void OnAcceptingCash(Actor self, Actor donor);