Search and destroy mission
Featuring ugly code
This commit is contained in:
@@ -8,9 +8,8 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class CargoMission : Mission
|
||||
class CargoMission : Mission, SinglePlayerMission
|
||||
{
|
||||
|
||||
private XElement itemConfig;
|
||||
|
||||
private List<Item> items;
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
using System;
|
||||
using Barotrauma;
|
||||
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class CombatMission : Mission
|
||||
{
|
||||
public Submarine TeamASub = null;
|
||||
public List<Character> TeamACrew = new List<Character>();
|
||||
public Submarine TeamBSub = null;
|
||||
public List<Character> TeamBCrew = new List<Character>();
|
||||
|
||||
int state = 0;
|
||||
string winner; string loser;
|
||||
|
||||
public override string SuccessMessage
|
||||
{
|
||||
get { return successMessage.Replace("[loser]",loser).Replace("[winner]",winner); }
|
||||
}
|
||||
|
||||
public CombatMission(XElement element)
|
||||
: base(element)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool AssignClientIDs(List<Client> clients)
|
||||
{
|
||||
List<Client> randList = new List<Client>(clients);
|
||||
for (int i = 0; i < randList.Count; i++)
|
||||
{
|
||||
Client a = randList[i];
|
||||
int oi = Rand.Range(0, randList.Count - 1);
|
||||
Client b = randList[oi];
|
||||
randList[i] = b;
|
||||
randList[oi] = a;
|
||||
}
|
||||
int halfPlayers = randList.Count / 2;
|
||||
for (int i = 0; i < randList.Count; i++)
|
||||
{
|
||||
if (i < halfPlayers)
|
||||
{
|
||||
randList[i].TeamID = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
randList[i].TeamID = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Start(Level level)
|
||||
{
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.AllowRespawn = false;
|
||||
}
|
||||
|
||||
Items.Components.Radar.StartMarker = Locations[0];
|
||||
Items.Components.Radar.EndMarker = Locations[1];
|
||||
TeamASub = Submarine.MainSubs[0];
|
||||
TeamBSub = Submarine.MainSubs[1];
|
||||
TeamBSub.SetPosition(Level.Loaded.EndPosition - new Vector2(0.0f, 2000.0f));
|
||||
|
||||
for (int i = 0; i < Character.CharacterList.Count; i++)
|
||||
{
|
||||
if (Character.CharacterList[i].TeamID==0)
|
||||
{
|
||||
TeamACrew.Add(Character.CharacterList[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
TeamBCrew.Add(Character.CharacterList[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (TeamACrew.Count == 0 && TeamBCrew.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < Character.CharacterList.Count; i++)
|
||||
{
|
||||
if (Character.CharacterList[i].TeamID == 0)
|
||||
{
|
||||
TeamACrew.Add(Character.CharacterList[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
TeamBCrew.Add(Character.CharacterList[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.AllowRespawn = false;
|
||||
}
|
||||
|
||||
bool ADead = true;
|
||||
foreach (Character c in TeamACrew)
|
||||
{
|
||||
if (!c.IsDead)
|
||||
{
|
||||
ADead = false; break;
|
||||
}
|
||||
}
|
||||
bool BDead = true;
|
||||
foreach (Character c in TeamBCrew)
|
||||
{
|
||||
if (!c.IsDead)
|
||||
{
|
||||
BDead = false; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (BDead && !ADead)
|
||||
{
|
||||
winner = Locations[0];
|
||||
loser = Locations[1];
|
||||
if (state==0)
|
||||
{
|
||||
ShowMessage(1);
|
||||
state = 1;
|
||||
}
|
||||
}
|
||||
if (ADead && !BDead)
|
||||
{
|
||||
winner = Locations[1];
|
||||
loser = Locations[0];
|
||||
if (state == 0)
|
||||
{
|
||||
ShowMessage(0);
|
||||
state = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((TeamBSub != null && TeamBSub.AtEndPosition) || (TeamASub != null && TeamASub.AtEndPosition))
|
||||
{
|
||||
if (ADead && !BDead)
|
||||
{
|
||||
//team B wins!
|
||||
if (GameMain.Server!=null) GameMain.Server.EndGame();
|
||||
}
|
||||
}
|
||||
|
||||
if ((TeamASub != null && TeamASub.AtStartPosition) || (TeamBSub != null && TeamBSub.AtStartPosition))
|
||||
{
|
||||
if (BDead && !ADead)
|
||||
{
|
||||
//team A wins!
|
||||
if (GameMain.Server != null) GameMain.Server.EndGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void End()
|
||||
{
|
||||
bool ADead = true;
|
||||
foreach (Character c in TeamACrew)
|
||||
{
|
||||
if (!c.IsDead && !c.IsUnconscious)
|
||||
{
|
||||
ADead = false; break;
|
||||
}
|
||||
}
|
||||
bool BDead = true;
|
||||
foreach (Character c in TeamBCrew)
|
||||
{
|
||||
if (!c.IsDead && !c.IsUnconscious)
|
||||
{
|
||||
BDead = false; break;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
completed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((TeamASub != null && TeamASub.AtStartPosition) || (TeamBSub != null && TeamBSub.AtStartPosition))
|
||||
{
|
||||
if (BDead && !ADead)
|
||||
{
|
||||
//team A wins!
|
||||
GiveReward();
|
||||
|
||||
completed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ namespace Barotrauma
|
||||
|
||||
private int reward;
|
||||
|
||||
protected string[] Locations = new string[2];
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
@@ -57,7 +59,7 @@ namespace Barotrauma
|
||||
get { return Vector2.Zero; }
|
||||
}
|
||||
|
||||
public string SuccessMessage
|
||||
virtual public string SuccessMessage
|
||||
{
|
||||
get { return successMessage; }
|
||||
}
|
||||
@@ -111,7 +113,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public static Mission LoadRandom(Location[] locations, MTRandom rand, string missionType = "")
|
||||
public static Mission LoadRandom(Location[] locations, MTRandom rand, string missionType = "", bool isSinglePlayer = false)
|
||||
{
|
||||
missionType = missionType.ToLowerInvariant();
|
||||
|
||||
@@ -182,22 +184,29 @@ namespace Barotrauma
|
||||
DebugConsole.ThrowError("Error in " + configFile + "! Could not find a mission class of the type \"" + type + "\".");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isSinglePlayer && t.GetInterface("Barotrauma.SinglePlayerMission")==null) continue;
|
||||
|
||||
ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement) });
|
||||
|
||||
object instance = constructor.Invoke(new object[] { element });
|
||||
|
||||
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<mission.messages.Count;m++)
|
||||
{
|
||||
mission.messages[m] = mission.messages[m].Replace("[location" + (n + 1) + "]", locations[n].Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return mission;
|
||||
}
|
||||
|
||||
@@ -212,6 +221,8 @@ namespace Barotrauma
|
||||
|
||||
public virtual void Update(float deltaTime) { }
|
||||
|
||||
public virtual bool AssignClientIDs(List<Networking.Client> clients) { return false; }
|
||||
|
||||
public void ShowMessage(int index)
|
||||
{
|
||||
if (index >= headers.Count && index >= messages.Count) return;
|
||||
@@ -242,4 +253,9 @@ namespace Barotrauma
|
||||
mode.Money += reward;
|
||||
}
|
||||
}
|
||||
|
||||
interface SinglePlayerMission
|
||||
{
|
||||
//all valid single player missions should inherit this
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class MonsterMission : Mission
|
||||
class MonsterMission : Mission, SinglePlayerMission
|
||||
{
|
||||
private string monsterFile;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class SalvageMission : Mission
|
||||
class SalvageMission : Mission, SinglePlayerMission
|
||||
{
|
||||
private ItemPrefab itemPrefab;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user