Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/Events/Missions/CombatMission.cs
2 using System.Collections.Generic;
3 
4 namespace Barotrauma
5 {
6  partial class CombatMission : Mission
7  {
8  private Submarine[] subs;
9 
10  private readonly LocalizedString[] descriptions;
11  private static LocalizedString[] teamNames = { "Team A", "Team B" };
12 
13  public override bool AllowRespawn
14  {
15  get { return false; }
16  }
17 
18  private CharacterTeamType Winner
19  {
20  get
21  {
22  if (GameMain.GameSession?.WinningTeam == null) { return CharacterTeamType.None; }
23  return GameMain.GameSession.WinningTeam.Value;
24  }
25  }
26 
28  {
29  get
30  {
31  if (Winner == CharacterTeamType.None || base.SuccessMessage.IsNullOrEmpty()) { return ""; }
32 
33  //disable success message for now if it hasn't been translated
34  if (!TextManager.ContainsTag("MissionSuccess." + Prefab.TextIdentifier)) { return ""; }
35 
36  var loser = Winner == CharacterTeamType.Team1 ?
37  CharacterTeamType.Team2 :
38  CharacterTeamType.Team1;
39 
40  return base.SuccessMessage
41  .Replace("[loser]", GetTeamName(loser))
42  .Replace("[winner]", GetTeamName(Winner));
43  }
44  }
45 
46  public CombatMission(MissionPrefab prefab, Location[] locations, Submarine sub)
47  : base(prefab, locations, sub)
48  {
49  descriptions = new LocalizedString[]
50  {
51  TextManager.Get("MissionDescriptionNeutral." + prefab.TextIdentifier).Fallback(prefab.ConfigElement.GetAttributeString("descriptionneutral", "")),
52  TextManager.Get("MissionDescription1." + prefab.TextIdentifier).Fallback(prefab.ConfigElement.GetAttributeString("description1", "")),
53  TextManager.Get("MissionDescription2." + prefab.TextIdentifier).Fallback(prefab.ConfigElement.GetAttributeString("description2", ""))
54  };
55 
56  for (int i = 0; i < descriptions.Length; i++)
57  {
58  for (int n = 0; n < 2; n++)
59  {
60  descriptions[i] = descriptions[i].Replace("[location" + (n + 1) + "]", locations[n].DisplayName);
61  }
62  }
63 
64  teamNames = new LocalizedString[]
65  {
66  TextManager.Get("MissionTeam1." + prefab.TextIdentifier).Fallback(prefab.ConfigElement.GetAttributeString("teamname1", "Team A")),
67  TextManager.Get("MissionTeam2." + prefab.TextIdentifier).Fallback(prefab.ConfigElement.GetAttributeString("teamname2", "Team B"))
68  };
69  }
70 
72  {
73  if (teamID == CharacterTeamType.Team1)
74  {
75  return teamNames.Length > 0 ? teamNames[0] : "Team 1";
76  }
77  else if (teamID == CharacterTeamType.Team2)
78  {
79  return teamNames.Length > 1 ? teamNames[1] : "Team 2";
80  }
81 
82  return "Invalid Team";
83  }
84 
85  public bool IsInWinningTeam(Character character)
86  {
87  return character != null &&
88  Winner != CharacterTeamType.None &&
89  Winner == character.TeamID;
90  }
91 
92  protected override void StartMissionSpecific(Level level)
93  {
94  if (GameMain.NetworkMember == null)
95  {
96  DebugConsole.ThrowError("Combat missions cannot be played in the single player mode.");
97  return;
98  }
99 
100  subs = new Submarine[] { Submarine.MainSubs[0], Submarine.MainSubs[1] };
101 
102  subs[0].NeutralizeBallast();
103  subs[0].TeamID = CharacterTeamType.Team1;
104  subs[0].GetConnectedSubs().ForEach(s => s.TeamID = CharacterTeamType.Team1);
105 
106  subs[1].NeutralizeBallast();
107  subs[1].TeamID = CharacterTeamType.Team2;
108  subs[1].GetConnectedSubs().ForEach(s => s.TeamID = CharacterTeamType.Team2);
109  subs[1].SetPosition(subs[1].FindSpawnPos(Level.Loaded.EndPosition));
110  subs[1].FlipX();
111 #if SERVER
112  crews = new List<Character>[] { new List<Character>(), new List<Character>() };
113  roundEndTimer = RoundEndDuration;
114 #endif
115  }
116 
117  protected override bool DetermineCompleted()
118  {
119  return Winner != CharacterTeamType.None;
120  }
121  }
122 }
static LocalizedString GetTeamName(CharacterTeamType teamID)
CombatMission(MissionPrefab prefab, Location[] locations, Submarine sub)
string? GetAttributeString(string key, string? def)
static GameSession?? GameSession
Definition: GameMain.cs:88
static NetworkMember NetworkMember
Definition: GameMain.cs:190
LocalizedString Fallback(LocalizedString fallback, bool useDefaultLanguageIfFound=true)
Use this text instead if the original text cannot be found.
LocalizedString Replace(Identifier find, LocalizedString replace, StringComparison stringComparison=StringComparison.Ordinal)
IEnumerable< Submarine > GetConnectedSubs()
Returns a list of all submarines that are connected to this one via docking ports,...
void FlipX(List< Submarine > parents=null)
void SetPosition(Vector2 position, List< Submarine > checkd=null, bool forceUndockFromStaticSubmarines=true)