Split INotifyWinStateChanged from INotifyObjectivesUpdated

This commit is contained in:
abcdefg30
2019-03-06 19:07:29 +01:00
committed by reaperrr
parent 6163523334
commit 38b3a4a668
5 changed files with 27 additions and 37 deletions

View File

@@ -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<INotifyOwnerLost>().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) { }
}
}

View File

@@ -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<MissionObjective> objectives = new List<MissionObjective>();
@@ -106,10 +106,8 @@ namespace OpenRA.Mods.Common.Traits
if (objectiveID >= objectives.Count || objectives[objectiveID].State != ObjectiveState.Incomplete)
return;
var inous = player.PlayerActor.TraitsImplementing<INotifyObjectivesUpdated>();
objectives[objectiveID].State = ObjectiveState.Completed;
foreach (var inou in inous)
foreach (var inou in player.PlayerActor.TraitsImplementing<INotifyObjectivesUpdated>())
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<INotifyWinStateChanged>())
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<INotifyObjectivesUpdated>();
objectives[objectiveID].State = ObjectiveState.Failed;
foreach (var inou in inous)
foreach (var inou in player.PlayerActor.TraitsImplementing<INotifyObjectivesUpdated>())
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<INotifyWinStateChanged>())
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<Player, bool> 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")

View File

@@ -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<INotifyOwnerLost>().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) { }
}
}