Refactored CombatMission a bit
This commit is contained in:
@@ -9,26 +9,30 @@ 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)
|
||||||
{
|
{
|
||||||
List<Client> randList = new List<Client>(clients);
|
List<Client> randList = new List<Client>(clients);
|
||||||
for (int i = 0; i < randList.Count; i++)
|
for (int i = 0; i < randList.Count; i++)
|
||||||
@@ -51,11 +55,11 @@ namespace Barotrauma
|
|||||||
randList[i].TeamID = 2;
|
randList[i].TeamID = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (halfPlayers*2==randList.Count)
|
if (halfPlayers * 2 == randList.Count)
|
||||||
{
|
{
|
||||||
hostTeam = Rand.Range(1, 2);
|
hostTeam = Rand.Range(1, 2);
|
||||||
}
|
}
|
||||||
else if (halfPlayers*2<randList.Count)
|
else if (halfPlayers * 2 < randList.Count)
|
||||||
{
|
{
|
||||||
hostTeam = 1;
|
hostTeam = 1;
|
||||||
}
|
}
|
||||||
@@ -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);
|
if (state == 0)
|
||||||
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
|
bool[] teamDead =
|
||||||
winner = Locations[0];
|
|
||||||
loser = Locations[1];
|
|
||||||
if (state==0)
|
|
||||||
{
|
{
|
||||||
ShowMessage(1);
|
crews[0].All(c => c.IsDead || c.IsUnconscious),
|
||||||
state = 1;
|
crews[1].All(c => c.IsDead || c.IsUnconscious)
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < teamDead.Length; i++)
|
||||||
|
{
|
||||||
|
if (!teamDead[i] && teamDead[1-i])
|
||||||
|
{
|
||||||
|
//make sure nobody in the other team can be revived because that would be pretty weird
|
||||||
|
crews[1-i].ForEach(c => { if (!c.IsDead) c.Kill(CauseOfDeath.Damage); });
|
||||||
|
|
||||||
|
winner = i;
|
||||||
|
|
||||||
|
ShowMessage(i);
|
||||||
|
state = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ADead && !BDead)
|
else
|
||||||
{
|
{
|
||||||
TeamACrew.ForEach(c => { if (!c.IsDead) c.Kill(CauseOfDeath.Damage); }); //same as above
|
if (subs[winner] != null &&
|
||||||
winner = Locations[1];
|
(winner == 0 && subs[winner].AtStartPosition) || (winner == 1 && subs[winner].AtEndPosition) &&
|
||||||
loser = Locations[0];
|
crews[winner].Any(c => !c.IsDead && c.Submarine == subs[winner]))
|
||||||
if (state == 0)
|
|
||||||
{
|
{
|
||||||
ShowMessage(0);
|
GameMain.GameSession.CrewManager.WinningTeam = winner+1;
|
||||||
state = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((TeamBSub != null && TeamBSub.AtEndPosition && TeamBCrew.Any(c => c.Submarine == TeamBSub)) || (TeamASub != null && TeamASub.AtEndPosition && TeamBCrew.Any(c => c.Submarine == TeamASub)))
|
|
||||||
{
|
|
||||||
if (ADead && !BDead)
|
|
||||||
{
|
|
||||||
//team B wins!
|
|
||||||
GameMain.GameSession.CrewManager.WinningTeam = 2;
|
|
||||||
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)))
|
|
||||||
{
|
|
||||||
if (BDead && !ADead)
|
|
||||||
{
|
|
||||||
//team A wins!
|
|
||||||
GameMain.GameSession.CrewManager.WinningTeam = 1;
|
|
||||||
if (GameMain.Server != null) GameMain.Server.EndGame();
|
if (GameMain.Server != null) GameMain.Server.EndGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,42 +159,12 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public override void End()
|
public override void End()
|
||||||
{
|
{
|
||||||
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];
|
GiveReward();
|
||||||
loser = Locations[1];
|
completed = true;
|
||||||
}
|
|
||||||
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();
|
|
||||||
|
|
||||||
completed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((TeamASub != null && TeamASub.AtStartPosition) || (TeamBSub != null && TeamBSub.AtStartPosition))
|
|
||||||
{
|
|
||||||
if (BDead && !ADead)
|
|
||||||
{
|
|
||||||
//team A wins!
|
|
||||||
GiveReward();
|
|
||||||
|
|
||||||
completed = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user