diff --git a/Subsurface/Content/Missions.xml b/Subsurface/Content/Missions.xml index df09fdc82..6a615bd06 100644 --- a/Subsurface/Content/Missions.xml +++ b/Subsurface/Content/Missions.xml @@ -177,13 +177,22 @@ - - + + + \ No newline at end of file diff --git a/Subsurface/Source/Events/Missions/CargoMission.cs b/Subsurface/Source/Events/Missions/CargoMission.cs index 4185fa3f1..a0b8a5629 100644 --- a/Subsurface/Source/Events/Missions/CargoMission.cs +++ b/Subsurface/Source/Events/Missions/CargoMission.cs @@ -16,8 +16,8 @@ namespace Barotrauma private int requiredDeliveryAmount; - public CargoMission(XElement element) - : base(element) + public CargoMission(XElement element, Location[] locations) + : base(element, locations) { itemConfig = element.Element("Items"); diff --git a/Subsurface/Source/Events/Missions/CombatMission.cs b/Subsurface/Source/Events/Missions/CombatMission.cs index 6fccfe6b3..188f10c3f 100644 --- a/Subsurface/Source/Events/Missions/CombatMission.cs +++ b/Subsurface/Source/Events/Missions/CombatMission.cs @@ -15,6 +15,26 @@ namespace Barotrauma private int state = 0; private int winner = -1; + private string[] descriptions; + + private static string[] teamNames; + + public override string Description + { + get + { + if (GameMain.NetworkMember==null || GameMain.NetworkMember.Character==null) + { + //non-team-specific description + return descriptions[0]; + } + + //team specific + return descriptions[GameMain.NetworkMember.Character.TeamID]; + } + } + + public override string SuccessMessage { get @@ -22,14 +42,47 @@ namespace Barotrauma if (winner == -1) return ""; return successMessage - .Replace("[loser]", Locations[1 - winner] - .Replace("[winner]", Locations[winner])); + .Replace("[loser]", teamNames[1 - winner]) + .Replace("[winner]", teamNames[winner]); } } - public CombatMission(XElement element) - : base(element) + public CombatMission(XElement element, Location[] locations) + : base(element, locations) { + descriptions = new string[] + { + ToolBox.GetAttributeString(element, "descriptionneutral", ""), + ToolBox.GetAttributeString(element, "description1", ""), + ToolBox.GetAttributeString(element, "description2", "") + }; + + for (int i = 0; i < descriptions.Length; i++ ) + { + for (int n = 0; n < 2;n++ ) + { + descriptions[i] = descriptions[i].Replace("[location" + (n + 1) + "]", Locations[n]); + } + } + + teamNames = new string[] + { + ToolBox.GetAttributeString(element, "teamname1", "Team A"), + ToolBox.GetAttributeString(element, "teamname2", "Team B") + }; + } + + public static string GetTeamName(int teamID) + { + //team IDs start from 1, while teamName array starts from 0 + teamID--; + + if (teamID < 0 || teamID >= teamNames.Length) + { + return "Team " + teamID; + } + + return teamNames[teamID]; } public override bool AssignTeamIDs(List clients, out int hostTeam) @@ -111,6 +164,15 @@ namespace Barotrauma foreach (Character character in Character.CharacterList) { + if (GameMain.NetworkMember != null && character == GameMain.NetworkMember.Character) + { + //ugly hack to switch the text in the mission popup to the team-specific description + if (GUIMessageBox.MessageBoxes.Count > 0 && GUIMessageBox.MessageBoxes.Peek().UserData as string == "missionstartmessage") + { + (GUIMessageBox.MessageBoxes.Peek() as GUIMessageBox).Text = Description; + } + } + if (character.TeamID == 1) { crews[0].Add(character); @@ -122,14 +184,14 @@ namespace Barotrauma } } + bool[] teamDead = + { + crews[0].All(c => c.IsDead || c.IsUnconscious), + crews[1].All(c => c.IsDead || c.IsUnconscious) + }; + if (state == 0) { - bool[] teamDead = - { - crews[0].All(c => c.IsDead || c.IsUnconscious), - crews[1].All(c => c.IsDead || c.IsUnconscious) - }; - for (int i = 0; i < teamDead.Length; i++) { if (!teamDead[i] && teamDead[1-i]) @@ -155,6 +217,11 @@ namespace Barotrauma if (GameMain.Server != null) GameMain.Server.EndGame(); } } + + if (teamDead[0] && teamDead[1]) + { + if (GameMain.Server != null) GameMain.Server.EndGame(); + } } public override void End() diff --git a/Subsurface/Source/Events/Missions/Mission.cs b/Subsurface/Source/Events/Missions/Mission.cs index 991c2d5d8..8263dfc87 100644 --- a/Subsurface/Source/Events/Missions/Mission.cs +++ b/Subsurface/Source/Events/Missions/Mission.cs @@ -34,7 +34,7 @@ namespace Barotrauma get { return name; } } - public string Description + public virtual string Description { get { return description; } } @@ -88,7 +88,7 @@ namespace Barotrauma } } - public Mission(XElement element) + public Mission(XElement element, Location[] locations) { name = ToolBox.GetAttributeString(element, "name", ""); @@ -111,6 +111,21 @@ namespace Barotrauma headers.Add(ToolBox.GetAttributeString(subElement, "header", "")); messages.Add(ToolBox.GetAttributeString(subElement, "text", "")); } + + + for (int n = 0; n < 2; n++) + { + Locations[n] = locations[n].Name; + description = description.Replace("[location" + (n + 1) + "]", locations[n].Name); + + successMessage = successMessage.Replace("[location" + (n + 1) + "]", locations[n].Name); + failureMessage = failureMessage.Replace("[location" + (n + 1) + "]", locations[n].Name); + + for (int m = 0; m < messages.Count; m++) + { + messages[m] = messages[m].Replace("[location" + (n + 1) + "]", locations[n].Name); + } + } } public static Mission LoadRandom(Location[] locations, MTRandom rand, string missionType = "", bool isSinglePlayer = false) @@ -192,25 +207,11 @@ namespace Barotrauma continue; } - ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement) }); + ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement), typeof(Location[]) }); - object instance = constructor.Invoke(new object[] { element }); + object instance = constructor.Invoke(new object[] { element, locations }); Mission mission = (Mission)instance; - - for (int n = 0; n<2; n++) - { - mission.Locations[n] = locations[n].Name; - mission.description = mission.description.Replace("[location"+(n+1)+"]", locations[n].Name); - - mission.successMessage = mission.successMessage.Replace("[location" + (n + 1) + "]", locations[n].Name); - mission.failureMessage = mission.failureMessage.Replace("[location" + (n + 1) + "]", locations[n].Name); - - for (int m=0;m 1) { - new GUITextBlock(new Rectangle(0,y-20,100,20),"Team "+teamIDs[i], GUI.Style, crewFrame); + new GUITextBlock(new Rectangle(0, y - 20, 100, 20), CombatMission.GetTeamName(teamIDs[i]), GUI.Style, crewFrame); } GUIListBox crewList = new GUIListBox(new Rectangle(0, y, 280, listBoxHeight), Color.White * 0.7f, GUI.Style, crewFrame); diff --git a/Subsurface/Source/GameSession/GameModes/MissionMode.cs b/Subsurface/Source/GameSession/GameModes/MissionMode.cs index 8e9111f5c..243e6af89 100644 --- a/Subsurface/Source/GameSession/GameModes/MissionMode.cs +++ b/Subsurface/Source/GameSession/GameModes/MissionMode.cs @@ -35,7 +35,8 @@ namespace Barotrauma if (mission == null) return; - new GUIMessageBox(mission.Name, mission.Description, 400, 400); + var missionMsg = new GUIMessageBox(mission.Name, mission.Description, 400, 400); + missionMsg.UserData = "missionstartmessage"; Networking.GameServer.Log("Mission: " + mission.Name, Color.Cyan); Networking.GameServer.Log(mission.Description, Color.Cyan);