Refactored CombatMission a bit

This commit is contained in:
Regalis
2016-10-06 16:33:43 +03:00
parent 5e88d91cb8
commit f1762cc6c7
@@ -9,23 +9,27 @@ namespace Barotrauma
{ {
class CombatMission : Mission class CombatMission : Mission
{ {
public Submarine TeamASub = null; private Submarine[] subs;
public List<Character> TeamACrew = new List<Character>(); private List<Character>[] crews;
public Submarine TeamBSub = null;
public List<Character> TeamBCrew = new List<Character>();
int state = 0; private int state = 0;
string winner, loser; private int winner = -1;
public override string SuccessMessage public override string SuccessMessage
{ {
get { return successMessage.Replace("[loser]",loser).Replace("[winner]",winner); } get
{
if (winner == -1) return "";
return successMessage
.Replace("[loser]", Locations[1 - winner]
.Replace("[winner]", Locations[winner]));
}
} }
public CombatMission(XElement element) public CombatMission(XElement element)
: base(element) : base(element)
{ {
} }
public override bool AssignTeamIDs(List<Client> clients, out int hostTeam) public override bool AssignTeamIDs(List<Client> clients, out int hostTeam)
@@ -82,10 +86,12 @@ namespace Barotrauma
Items.Components.Radar.StartMarker = Locations[0]; Items.Components.Radar.StartMarker = Locations[0];
Items.Components.Radar.EndMarker = Locations[1]; Items.Components.Radar.EndMarker = Locations[1];
TeamASub = Submarine.MainSubs[0];
TeamBSub = Submarine.MainSubs[1]; subs = new Submarine[] { Submarine.MainSubs[0], Submarine.MainSubs[1] };
TeamBSub.SetPosition(Level.Loaded.EndPosition - new Vector2(0.0f, 2000.0f)); subs[1].SetPosition(Level.Loaded.EndPosition - new Vector2(0.0f, 2000.0f));
TeamBSub.FlipX(); subs[1].FlipX();
crews = new List<Character>[] { new List<Character>(), new List<Character>() };
foreach (Submarine submarine in Submarine.Loaded) foreach (Submarine submarine in Submarine.Loaded)
{ {
@@ -96,7 +102,7 @@ namespace Barotrauma
public override void Update(float deltaTime) public override void Update(float deltaTime)
{ {
if (TeamACrew.Count == 0 && TeamBCrew.Count == 0) if (crews[0].Count == 0 && crews[1].Count == 0)
{ {
if (GameMain.Server != null) if (GameMain.Server != null)
{ {
@@ -107,57 +113,45 @@ namespace Barotrauma
{ {
if (character.TeamID == 1) if (character.TeamID == 1)
{ {
TeamACrew.Add(character); crews[0].Add(character);
} }
else if (character.TeamID == 2) else if (character.TeamID == 2)
{ {
TeamBCrew.Add(character); crews[1].Add(character);
} }
} }
} }
bool ADead = TeamACrew.All(c => c.IsDead || c.IsUnconscious);
bool BDead = TeamBCrew.All(c => c.IsDead || c.IsUnconscious);
if (BDead && !ADead)
{
TeamBCrew.ForEach(c => { if (!c.IsDead) c.Kill(CauseOfDeath.Damage); }); //make sure nobody in this team can be revived because that would be pretty weird
winner = Locations[0];
loser = Locations[1];
if (state == 0) if (state == 0)
{ {
ShowMessage(1); bool[] teamDead =
state = 1;
}
}
if (ADead && !BDead)
{ {
TeamACrew.ForEach(c => { if (!c.IsDead) c.Kill(CauseOfDeath.Damage); }); //same as above crews[0].All(c => c.IsDead || c.IsUnconscious),
winner = Locations[1]; crews[1].All(c => c.IsDead || c.IsUnconscious)
loser = Locations[0]; };
if (state == 0)
{
ShowMessage(0);
state = 1;
}
}
if ((TeamBSub != null && TeamBSub.AtEndPosition && TeamBCrew.Any(c => c.Submarine == TeamBSub)) || (TeamASub != null && TeamASub.AtEndPosition && TeamBCrew.Any(c => c.Submarine == TeamASub))) for (int i = 0; i < teamDead.Length; i++)
{ {
if (ADead && !BDead) if (!teamDead[i] && teamDead[1-i])
{ {
//team B wins! //make sure nobody in the other team can be revived because that would be pretty weird
GameMain.GameSession.CrewManager.WinningTeam = 2; crews[1-i].ForEach(c => { if (!c.IsDead) c.Kill(CauseOfDeath.Damage); });
if (GameMain.Server!=null) GameMain.Server.EndGame();
}
}
if ((TeamASub != null && TeamASub.AtStartPosition && TeamACrew.Any(c => c.Submarine == TeamASub)) || (TeamBSub != null && TeamBSub.AtStartPosition && TeamACrew.Any(c => c.Submarine == TeamBSub))) winner = i;
ShowMessage(i);
state = 1;
break;
}
}
}
else
{ {
if (BDead && !ADead) if (subs[winner] != null &&
(winner == 0 && subs[winner].AtStartPosition) || (winner == 1 && subs[winner].AtEndPosition) &&
crews[winner].Any(c => !c.IsDead && c.Submarine == subs[winner]))
{ {
//team A wins! GameMain.GameSession.CrewManager.WinningTeam = winner+1;
GameMain.GameSession.CrewManager.WinningTeam = 1;
if (GameMain.Server != null) GameMain.Server.EndGame(); if (GameMain.Server != null) GameMain.Server.EndGame();
} }
} }
@@ -167,41 +161,11 @@ namespace Barotrauma
{ {
if (GameMain.NetworkMember == null) return; if (GameMain.NetworkMember == null) return;
bool ADead = TeamACrew.All(c => c.IsDead || c.IsUnconscious); if (winner > -1)
bool BDead = TeamBCrew.All(c => c.IsDead || c.IsUnconscious);
if (BDead && !ADead)
{ {
winner = Locations[0];
loser = Locations[1];
}
if (ADead && !BDead)
{
winner = Locations[1];
loser = Locations[0];
}
if ((TeamBSub != null && TeamBSub.AtEndPosition) || (TeamASub != null && TeamASub.AtEndPosition))
{
if (ADead && !BDead)
{
//team B wins!
GiveReward(); GiveReward();
completed = true;
}
}
if ((TeamASub != null && TeamASub.AtStartPosition) || (TeamBSub != null && TeamBSub.AtStartPosition))
{
if (BDead && !ADead)
{
//team A wins!
GiveReward();
completed = true; completed = true;
} }
} }
} }
} }
}