Split INotifyWinStateChanged from INotifyObjectivesUpdated
This commit is contained in:
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
|
|
||||||
public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyOtherProduction,
|
public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyOtherProduction,
|
||||||
INotifyObjectivesUpdated, INotifyCapture, INotifyInfiltrated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyDiscovered, INotifyActorDisposing,
|
INotifyObjectivesUpdated, INotifyCapture, INotifyInfiltrated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyDiscovered, INotifyActorDisposing,
|
||||||
INotifyPassengerEntered, INotifyPassengerExited, INotifySold
|
INotifyPassengerEntered, INotifyPassengerExited, INotifySold, INotifyWinStateChanged
|
||||||
{
|
{
|
||||||
readonly World world;
|
readonly World world;
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
@@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
OnProducedInternal(self, other);
|
OnProducedInternal(self, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyObjectivesUpdated.OnPlayerWon(Player player)
|
void INotifyWinStateChanged.OnPlayerWon(Player player)
|
||||||
{
|
{
|
||||||
if (world.Disposing)
|
if (world.Disposing)
|
||||||
return;
|
return;
|
||||||
@@ -196,7 +196,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyObjectivesUpdated.OnPlayerLost(Player player)
|
void INotifyWinStateChanged.OnPlayerLost(Player player)
|
||||||
{
|
{
|
||||||
if (world.Disposing)
|
if (world.Disposing)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new ConquestVictoryConditions(init.Self, this); }
|
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 ConquestVictoryConditionsInfo info;
|
||||||
readonly MissionObjectives mo;
|
readonly MissionObjectives mo;
|
||||||
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
mo.MarkCompleted(self.Owner, objectiveID);
|
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))
|
foreach (var a in player.World.ActorsWithTrait<INotifyOwnerLost>().Where(a => a.Actor.Owner == player))
|
||||||
a.Trait.OnOwnerLost(a.Actor);
|
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)
|
if (info.SuppressNotifications)
|
||||||
return;
|
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);
|
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) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new MissionObjectives(init.World, this); }
|
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;
|
public readonly MissionObjectivesInfo Info;
|
||||||
readonly List<MissionObjective> objectives = new List<MissionObjective>();
|
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)
|
if (objectiveID >= objectives.Count || objectives[objectiveID].State != ObjectiveState.Incomplete)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var inous = player.PlayerActor.TraitsImplementing<INotifyObjectivesUpdated>();
|
|
||||||
|
|
||||||
objectives[objectiveID].State = ObjectiveState.Completed;
|
objectives[objectiveID].State = ObjectiveState.Completed;
|
||||||
foreach (var inou in inous)
|
foreach (var inou in player.PlayerActor.TraitsImplementing<INotifyObjectivesUpdated>())
|
||||||
inou.OnObjectiveCompleted(player, objectiveID);
|
inou.OnObjectiveCompleted(player, objectiveID);
|
||||||
|
|
||||||
if (objectives[objectiveID].Type == ObjectiveType.Primary)
|
if (objectives[objectiveID].Type == ObjectiveType.Primary)
|
||||||
@@ -118,8 +116,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
if (playerWon)
|
if (playerWon)
|
||||||
{
|
{
|
||||||
foreach (var inou in inous)
|
foreach (var inwc in player.PlayerActor.TraitsImplementing<INotifyWinStateChanged>())
|
||||||
inou.OnPlayerWon(player);
|
inwc.OnPlayerWon(player);
|
||||||
|
|
||||||
CheckIfGameIsOver(player);
|
CheckIfGameIsOver(player);
|
||||||
}
|
}
|
||||||
@@ -131,10 +129,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (objectiveID >= objectives.Count || objectives[objectiveID].State == ObjectiveState.Failed)
|
if (objectiveID >= objectives.Count || objectives[objectiveID].State == ObjectiveState.Failed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var inous = player.PlayerActor.TraitsImplementing<INotifyObjectivesUpdated>();
|
|
||||||
|
|
||||||
objectives[objectiveID].State = ObjectiveState.Failed;
|
objectives[objectiveID].State = ObjectiveState.Failed;
|
||||||
foreach (var inou in inous)
|
foreach (var inou in player.PlayerActor.TraitsImplementing<INotifyObjectivesUpdated>())
|
||||||
inou.OnObjectiveFailed(player, objectiveID);
|
inou.OnObjectiveFailed(player, objectiveID);
|
||||||
|
|
||||||
if (objectives[objectiveID].Type == ObjectiveType.Primary)
|
if (objectives[objectiveID].Type == ObjectiveType.Primary)
|
||||||
@@ -143,8 +139,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
if (playerLost)
|
if (playerLost)
|
||||||
{
|
{
|
||||||
foreach (var inou in inous)
|
foreach (var inwc in player.PlayerActor.TraitsImplementing<INotifyWinStateChanged>())
|
||||||
inou.OnPlayerLost(player);
|
inwc.OnPlayerLost(player);
|
||||||
|
|
||||||
CheckIfGameIsOver(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 players = player.World.Players.Where(p => !p.NonCombatant);
|
||||||
var enemies = players.Where(p => !p.IsAlliedWith(player));
|
var enemies = players.Where(p => !p.IsAlliedWith(player));
|
||||||
@@ -204,7 +200,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
CheckIfGameIsOver(player);
|
CheckIfGameIsOver(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyObjectivesUpdated.OnPlayerLost(Player player)
|
void INotifyWinStateChanged.OnPlayerLost(Player player)
|
||||||
{
|
{
|
||||||
var players = player.World.Players.Where(p => !p.NonCombatant);
|
var players = player.World.Players.Where(p => !p.NonCombatant);
|
||||||
var enemies = players.Where(p => !p.IsAlliedWith(player));
|
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; };
|
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)
|
public void ResolveOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
if (order.OrderString == "Surrender")
|
if (order.OrderString == "Surrender")
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new StrategicVictoryConditions(init.Self, this); }
|
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;
|
readonly StrategicVictoryConditionsInfo info;
|
||||||
|
|
||||||
@@ -75,7 +75,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void ITick.Tick(Actor self)
|
void ITick.Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (player.WinState != WinState.Undefined || player.NonCombatant) return;
|
if (player.WinState != WinState.Undefined || player.NonCombatant)
|
||||||
|
return;
|
||||||
|
|
||||||
if (objectiveID < 0)
|
if (objectiveID < 0)
|
||||||
objectiveID = mo.Add(player, info.Objective, ObjectiveType.Primary, true);
|
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))
|
foreach (var a in player.World.ActorsWithTrait<INotifyOwnerLost>().Where(a => a.Actor.Owner == player))
|
||||||
a.Trait.OnOwnerLost(a.Actor);
|
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)
|
if (info.SuppressNotifications)
|
||||||
return;
|
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);
|
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) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -436,13 +436,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
public interface INotifyObjectivesUpdated
|
public interface INotifyObjectivesUpdated
|
||||||
{
|
{
|
||||||
void OnPlayerWon(Player winner);
|
|
||||||
void OnPlayerLost(Player loser);
|
|
||||||
void OnObjectiveAdded(Player player, int objectiveID);
|
void OnObjectiveAdded(Player player, int objectiveID);
|
||||||
void OnObjectiveCompleted(Player player, int objectiveID);
|
void OnObjectiveCompleted(Player player, int objectiveID);
|
||||||
void OnObjectiveFailed(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
|
public interface INotifyCashTransfer
|
||||||
{
|
{
|
||||||
void OnAcceptingCash(Actor self, Actor donor);
|
void OnAcceptingCash(Actor self, Actor donor);
|
||||||
|
|||||||
Reference in New Issue
Block a user