Separate folder for game modes
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class GameMode
|
||||
{
|
||||
public static List<GameModePreset> PresetList = new List<GameModePreset>();
|
||||
|
||||
TimeSpan duration;
|
||||
protected DateTime startTime;
|
||||
protected DateTime endTime;
|
||||
|
||||
//public readonly bool IsSinglePlayer;
|
||||
|
||||
private GUIProgressBar timerBar;
|
||||
|
||||
protected bool isRunning;
|
||||
|
||||
//protected string name;
|
||||
|
||||
protected GameModePreset preset;
|
||||
|
||||
private string endMessage;
|
||||
|
||||
public virtual Quest Quest
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public DateTime StartTime
|
||||
{
|
||||
get { return startTime; }
|
||||
}
|
||||
|
||||
public DateTime EndTime
|
||||
{
|
||||
get { return endTime; }
|
||||
}
|
||||
|
||||
public bool IsRunning
|
||||
{
|
||||
get { return isRunning; }
|
||||
}
|
||||
|
||||
public bool IsSinglePlayer
|
||||
{
|
||||
get { return preset.IsSinglePlayer; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return preset.Name; }
|
||||
}
|
||||
|
||||
public string EndMessage
|
||||
{
|
||||
get { return endMessage; }
|
||||
}
|
||||
|
||||
public GameMode(GameModePreset preset)
|
||||
{
|
||||
this.preset = preset;
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (timerBar != null) timerBar.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public virtual void Start(TimeSpan duration)
|
||||
{
|
||||
startTime = DateTime.Now;
|
||||
if (duration!=TimeSpan.Zero)
|
||||
{
|
||||
endTime = startTime + duration;
|
||||
this.duration = duration;
|
||||
|
||||
timerBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth - 120, 20, 100, 25), Color.Gold, 0.0f, null);
|
||||
}
|
||||
|
||||
endMessage = "The round has ended!";
|
||||
|
||||
isRunning = true;
|
||||
}
|
||||
|
||||
public virtual void Update(float deltaTime)
|
||||
{
|
||||
if (!isRunning) return;
|
||||
|
||||
if (duration != TimeSpan.Zero)
|
||||
{
|
||||
double elapsedTime = (DateTime.Now - startTime).TotalSeconds;
|
||||
timerBar.BarSize = (float)(elapsedTime / duration.TotalSeconds);
|
||||
}
|
||||
//if (DateTime.Now >= endTime)
|
||||
//{
|
||||
// End(endMessage);
|
||||
//}
|
||||
}
|
||||
|
||||
public virtual void End(string endMessage = "")
|
||||
{
|
||||
isRunning = false;
|
||||
|
||||
if (endMessage != "" || this.endMessage == null) this.endMessage = endMessage;
|
||||
|
||||
Game1.GameSession.EndShift(endMessage);
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
new GameModePreset("Single Player", typeof(SinglePlayerMode), true);
|
||||
|
||||
|
||||
var mode = new GameModePreset("SandBox", typeof(GameMode), false);
|
||||
mode.Description = "A game mode with no specific objectives.";
|
||||
|
||||
mode = new GameModePreset("Traitor", typeof(TraitorMode), false);
|
||||
mode.Description = "One of the players is selected as a traitor and given a secret objective. "
|
||||
+ "The rest of the crew will win if they reach the end of the level or kill the traitor "
|
||||
+ "before the objective is completed.";
|
||||
|
||||
mode = new GameModePreset("Quest", typeof(QuestMode), false);
|
||||
mode.Description = "The crew must work together to complete a specific task, such as retrieving "
|
||||
+ "an alien artifact or killing a creature that's terrorizing nearby outposts. The game ends "
|
||||
+ "when the task is completed or everyone in the crew has died.";
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class GameModePreset
|
||||
{
|
||||
public static List<GameModePreset> list = new List<GameModePreset>();
|
||||
|
||||
public ConstructorInfo Constructor;
|
||||
public string Name;
|
||||
public bool IsSinglePlayer;
|
||||
|
||||
public string Description;
|
||||
|
||||
public GameModePreset(string name, Type type, bool isSinglePlayer = false)
|
||||
{
|
||||
this.Name = name;
|
||||
//Constructor = constructor;
|
||||
|
||||
|
||||
Constructor = type.GetConstructor(new Type[] { typeof(GameModePreset) });
|
||||
|
||||
IsSinglePlayer = isSinglePlayer;
|
||||
|
||||
list.Add(this);
|
||||
}
|
||||
|
||||
public GameMode Instantiate()
|
||||
{
|
||||
object[] lobject = new object[] { this };
|
||||
return (GameMode)Constructor.Invoke(lobject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class QuestMode : GameMode
|
||||
{
|
||||
Quest quest;
|
||||
|
||||
public override Quest Quest
|
||||
{
|
||||
get
|
||||
{
|
||||
return quest;
|
||||
}
|
||||
}
|
||||
|
||||
public QuestMode(GameModePreset preset)
|
||||
: base(preset)
|
||||
{
|
||||
Location[] locations = new Location[2];
|
||||
|
||||
Random rand = new Random(Game1.NetLobbyScreen.LevelSeed.GetHashCode());
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
locations[i] = Location.CreateRandom(new Vector2((float)rand.NextDouble() * 10000.0f, (float)rand.NextDouble() * 10000.0f));
|
||||
}
|
||||
quest = Quest.LoadRandom(locations, rand);
|
||||
}
|
||||
|
||||
public override void Start(TimeSpan duration)
|
||||
{
|
||||
base.Start(duration);
|
||||
|
||||
new GUIMessageBox(quest.Name, quest.Description, 400, 400);
|
||||
|
||||
quest.Start(Level.Loaded);
|
||||
}
|
||||
|
||||
public override void End(string endMessage = "")
|
||||
{
|
||||
quest.End();
|
||||
|
||||
base.End(endMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class SinglePlayerMode : GameMode
|
||||
{
|
||||
//private const int StartCharacterAmount = 3;
|
||||
|
||||
public readonly CrewManager CrewManager;
|
||||
//public readonly HireManager hireManager;
|
||||
|
||||
private GUIButton endShiftButton;
|
||||
|
||||
public readonly CargoManager CargoManager;
|
||||
|
||||
public Map Map;
|
||||
|
||||
private bool crewDead;
|
||||
private float endTimer;
|
||||
|
||||
private bool savedOnStart;
|
||||
|
||||
public override Quest Quest
|
||||
{
|
||||
get
|
||||
{
|
||||
return Map.SelectedConnection.Quest;
|
||||
}
|
||||
}
|
||||
|
||||
public int Money
|
||||
{
|
||||
get { return CrewManager.Money; }
|
||||
set { CrewManager.Money = value; }
|
||||
}
|
||||
|
||||
public SinglePlayerMode(GameModePreset preset)
|
||||
: base(preset)
|
||||
{
|
||||
CrewManager = new CrewManager();
|
||||
|
||||
CargoManager = new CargoManager();
|
||||
|
||||
endShiftButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 220, 20, 200, 25), "End shift", Alignment.TopLeft, GUI.style);
|
||||
endShiftButton.OnClicked = EndShift;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
JobPrefab jobPrefab = null;
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
jobPrefab = JobPrefab.List.Find(jp => jp.Name == "Captain");
|
||||
break;
|
||||
case 1:
|
||||
jobPrefab = JobPrefab.List.Find(jp => jp.Name == "Engineer");
|
||||
break;
|
||||
case 2:
|
||||
jobPrefab = JobPrefab.List.Find(jp => jp.Name == "Mechanic");
|
||||
break;
|
||||
}
|
||||
|
||||
CharacterInfo characterInfo =
|
||||
new CharacterInfo(Character.HumanConfigFile, "", Gender.None, jobPrefab);
|
||||
CrewManager.characterInfos.Add(characterInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SinglePlayerMode(XElement element)
|
||||
: this(GameModePreset.list.Find(gm => gm.Name == "Single Player"))
|
||||
{
|
||||
string mapSeed = ToolBox.GetAttributeString(element, "mapseed", "a");
|
||||
|
||||
GenerateMap(mapSeed);
|
||||
|
||||
Map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLower() != "crew") continue;
|
||||
|
||||
CrewManager = new CrewManager(subElement);
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateMap(string seed)
|
||||
{
|
||||
Map = new Map(seed, 500);
|
||||
}
|
||||
|
||||
public override void Start(TimeSpan duration)
|
||||
{
|
||||
CargoManager.CreateItems();
|
||||
|
||||
if (!savedOnStart)
|
||||
{
|
||||
SaveUtil.SaveGame(Game1.GameSession.SaveFile);
|
||||
savedOnStart = true;
|
||||
}
|
||||
|
||||
endTimer = 5.0f;
|
||||
|
||||
CrewManager.StartShift();
|
||||
}
|
||||
|
||||
public bool TryHireCharacter(HireManager hireManager, CharacterInfo characterInfo)
|
||||
{
|
||||
if (CrewManager.Money < characterInfo.Salary) return false;
|
||||
|
||||
hireManager.availableCharacters.Remove(characterInfo);
|
||||
CrewManager.characterInfos.Add(characterInfo);
|
||||
|
||||
CrewManager.Money -= characterInfo.Salary;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public string GetMoney()
|
||||
{
|
||||
return "Money: " + CrewManager.Money;
|
||||
}
|
||||
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
CrewManager.Draw(spriteBatch);
|
||||
|
||||
if (Level.Loaded.AtEndPosition)
|
||||
{
|
||||
endShiftButton.Text = "Enter " + Map.SelectedLocation.Name;
|
||||
endShiftButton.Draw(spriteBatch);
|
||||
}
|
||||
else if (Level.Loaded.AtStartPosition)
|
||||
{
|
||||
endShiftButton.Text = "Enter " + Map.CurrentLocation.Name;
|
||||
endShiftButton.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
//chatBox.Draw(spriteBatch);
|
||||
//textBox.Draw(spriteBatch);
|
||||
|
||||
//timerBar.Draw(spriteBatch);
|
||||
|
||||
//if (Game1.Client == null) endShiftButton.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
base.Update(deltaTime);
|
||||
|
||||
CrewManager.Update(deltaTime);
|
||||
|
||||
endShiftButton.Update(deltaTime);
|
||||
|
||||
if (!crewDead)
|
||||
{
|
||||
if (CrewManager.characters.Find(c => !c.IsDead) == null)
|
||||
{
|
||||
crewDead = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
endTimer -= deltaTime;
|
||||
|
||||
if (endTimer <= 0.0f) End("");
|
||||
}
|
||||
}
|
||||
|
||||
public override void End(string endMessage = "")
|
||||
{
|
||||
|
||||
isRunning = false;
|
||||
|
||||
//if (endMessage != "" || this.endMessage == null) this.endMessage = endMessage;
|
||||
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<Character> casualties = CrewManager.characters.FindAll(c => c.IsDead);
|
||||
|
||||
if (casualties.Count == CrewManager.characters.Count)
|
||||
{
|
||||
sb.Append("Your entire crew has died!");
|
||||
|
||||
var msgBox = new GUIMessageBox("", sb.ToString(), new string[] { "Load game", "Quit" });
|
||||
msgBox.Buttons[0].OnClicked += Game1.GameSession.LoadPrevious;
|
||||
msgBox.Buttons[0].OnClicked += msgBox.Close;
|
||||
msgBox.Buttons[1].OnClicked = Game1.LobbyScreen.QuitToMainMenu;
|
||||
msgBox.Buttons[1].OnClicked += msgBox.Close;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (casualties.Any())
|
||||
{
|
||||
sb.Append("Casualties: \n");
|
||||
foreach (Character c in casualties)
|
||||
{
|
||||
sb.Append(" - " + c.Info.Name + "\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("No casualties!");
|
||||
}
|
||||
|
||||
if (Level.Loaded.AtEndPosition)
|
||||
{
|
||||
Map.MoveToNextLocation();
|
||||
}
|
||||
|
||||
SaveUtil.SaveGame(Game1.GameSession.SaveFile);
|
||||
}
|
||||
|
||||
CrewManager.EndShift();
|
||||
for (int i = Character.CharacterList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Character.CharacterList[i].Remove();
|
||||
}
|
||||
|
||||
Game1.GameSession.EndShift("");
|
||||
|
||||
}
|
||||
|
||||
private bool EndShift(GUIButton button, object obj)
|
||||
{
|
||||
End("");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Save(XElement element)
|
||||
{
|
||||
//element.Add(new XAttribute("day", day));
|
||||
XElement modeElement = new XElement("gamemode");
|
||||
|
||||
modeElement.Add(new XAttribute("currentlocation", Map.CurrentLocationIndex));
|
||||
modeElement.Add(new XAttribute("mapseed", Map.Seed));
|
||||
|
||||
CrewManager.Save(modeElement);
|
||||
|
||||
element.Add(modeElement);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Subsurface.Networking;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class TraitorMode : GameMode
|
||||
{
|
||||
Client traitor;
|
||||
Client target;
|
||||
|
||||
public TraitorMode(GameModePreset preset)
|
||||
: base(preset)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Start(TimeSpan duration)
|
||||
{
|
||||
base.Start(duration);
|
||||
|
||||
traitor = null;
|
||||
target = null;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (Game1.Server == null) return;
|
||||
|
||||
base.Update(deltaTime);
|
||||
|
||||
if (!isRunning) return;
|
||||
|
||||
if (DateTime.Now >= endTime)
|
||||
{
|
||||
string endMessage = traitor.character.Info.Name + " was a traitor! ";
|
||||
endMessage += (traitor.character.Info.Gender == Gender.Male) ? "His" : "Her";
|
||||
endMessage += " task was to assassinate " + target.character.Info.Name + ". The task was unsuccesful.";
|
||||
End(endMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (traitor==null || target ==null)
|
||||
{
|
||||
int clientCount = Game1.Server.connectedClients.Count();
|
||||
if (clientCount < 2) return;
|
||||
|
||||
int traitorIndex = Rand.Int(clientCount, false);
|
||||
traitor = Game1.Server.connectedClients[traitorIndex];
|
||||
|
||||
int targetIndex = 0;
|
||||
while (targetIndex == traitorIndex)
|
||||
{
|
||||
targetIndex = Rand.Int(clientCount, false);
|
||||
}
|
||||
target = Game1.Server.connectedClients[targetIndex];
|
||||
|
||||
|
||||
Game1.Server.NewTraitor(traitor, target);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target.character.IsDead)
|
||||
{
|
||||
string endMessage = traitor.character.Info.Name + " was a traitor! ";
|
||||
endMessage += (traitor.character.Info.Gender == Gender.Male) ? "His" : "Her";
|
||||
endMessage += " task was to assassinate " + target.character.Info.Name + ". The task was succesful.";
|
||||
End(endMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
//class TutorialMode : GameMode
|
||||
//{
|
||||
//}
|
||||
}
|
||||
Reference in New Issue
Block a user