Moved CrewManager & HireManager to a separate single player GameMode, bleeding decreases health
This commit is contained in:
@@ -77,16 +77,16 @@ namespace Subsurface
|
||||
characterInfos.Add(character.info);
|
||||
}
|
||||
|
||||
GUIFrame frame = new GUIFrame(new Rectangle(0,0,0,40), Color.Transparent, listBox);
|
||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, listBox);
|
||||
frame.UserData = character;
|
||||
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||
frame.HoverColor = Color.LightGray * 0.5f;
|
||||
frame.SelectedColor = Color.Gold * 0.5f;
|
||||
|
||||
string name = character.info.name.Replace(' ','\n');
|
||||
string name = character.info.name.Replace(' ', '\n');
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(40,0,0,25),
|
||||
new Rectangle(40, 0, 0, 25),
|
||||
name,
|
||||
Color.Transparent, Color.White,
|
||||
Alignment.Left,
|
||||
@@ -94,7 +94,7 @@ namespace Subsurface
|
||||
frame);
|
||||
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
||||
|
||||
new GUIImage(new Rectangle(-10,-10,0,0), character.animController.limbs[0].sprite, Alignment.Left, frame);
|
||||
new GUIImage(new Rectangle(-10, -10, 0, 0), character.animController.limbs[0].sprite, Alignment.Left, frame);
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
@@ -106,7 +106,11 @@ namespace Subsurface
|
||||
{
|
||||
GUIComponent characterBlock = listBox.GetChild(killedCharacter) as GUIComponent;
|
||||
if (characterBlock != null) characterBlock.Color = Color.DarkRed * 0.5f;
|
||||
|
||||
|
||||
if (characters.Find(c => !c.IsDead)==null)
|
||||
{
|
||||
Game1.GameSession.EndShift(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void StartShift()
|
||||
|
||||
@@ -1,19 +1,53 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class GameModePreset
|
||||
{
|
||||
public static List<GameModePreset> list = new List<GameModePreset>();
|
||||
|
||||
public ConstructorInfo Constructor;
|
||||
public string Name;
|
||||
public bool IsSinglePlayer;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
class GameMode
|
||||
{
|
||||
public static List<GameMode> list = new List<GameMode>();
|
||||
public static List<GameModePreset> presetList = new List<GameModePreset>();
|
||||
|
||||
//TimeSpan duration;
|
||||
protected DateTime startTime;
|
||||
protected DateTime endTime;
|
||||
|
||||
//public readonly bool IsSinglePlayer;
|
||||
|
||||
protected bool isRunning;
|
||||
|
||||
protected string name;
|
||||
//protected string name;
|
||||
|
||||
protected GameModePreset preset;
|
||||
|
||||
private string endMessage;
|
||||
|
||||
@@ -32,9 +66,14 @@ namespace Subsurface
|
||||
get { return isRunning; }
|
||||
}
|
||||
|
||||
public bool IsSinglePlayer
|
||||
{
|
||||
get { return preset.IsSinglePlayer; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
get { return preset.Name; }
|
||||
}
|
||||
|
||||
public string EndMessage
|
||||
@@ -42,13 +81,16 @@ namespace Subsurface
|
||||
get { return endMessage; }
|
||||
}
|
||||
|
||||
public GameMode(string name)
|
||||
public GameMode(GameModePreset preset)
|
||||
{
|
||||
this.name = name;
|
||||
this.preset = preset;
|
||||
|
||||
list.Add(this);
|
||||
//list.Add(this);
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch)
|
||||
{ }
|
||||
|
||||
public virtual void Start(TimeSpan duration)
|
||||
{
|
||||
startTime = DateTime.Now;
|
||||
@@ -59,7 +101,7 @@ namespace Subsurface
|
||||
isRunning = true;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
public virtual void Update(float deltaTime)
|
||||
{
|
||||
if (!isRunning) return;
|
||||
|
||||
@@ -69,7 +111,7 @@ namespace Subsurface
|
||||
}
|
||||
}
|
||||
|
||||
public void End(string endMessage = "")
|
||||
public virtual void End(string endMessage = "")
|
||||
{
|
||||
isRunning = false;
|
||||
|
||||
@@ -80,8 +122,14 @@ namespace Subsurface
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
new GameMode("Sandbox");
|
||||
new TraitorMode("Traitor");
|
||||
new GameModePreset("Single Player", typeof(SinglePlayerMode), true);
|
||||
new GameModePreset("SandBox", typeof(GameMode), false);
|
||||
new GameModePreset("Traitor", typeof(TraitorMode), false);
|
||||
|
||||
|
||||
//new SinglePlayerMode("Single Player", true);
|
||||
//new GameMode("Sandbox");
|
||||
//new TraitorMode("Traitor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ namespace Subsurface
|
||||
class GameSession
|
||||
{
|
||||
public readonly TaskManager taskManager;
|
||||
public readonly CrewManager crewManager;
|
||||
public readonly HireManager hireManager;
|
||||
|
||||
|
||||
protected DateTime startTime;
|
||||
protected DateTime endTime;
|
||||
@@ -34,23 +33,20 @@ namespace Subsurface
|
||||
|
||||
private Map selectedMap;
|
||||
|
||||
private int day;
|
||||
|
||||
|
||||
public int Day
|
||||
public GameSession(Map selectedMap, TimeSpan gameDuration, GameModePreset gameModePreset)
|
||||
:this(selectedMap, gameDuration, gameModePreset.Instantiate())
|
||||
{
|
||||
get { return day; }
|
||||
|
||||
}
|
||||
|
||||
public GameSession(Map selectedMap, TimeSpan gameDuration, GameMode gameMode = null)
|
||||
{
|
||||
taskManager = new TaskManager(this);
|
||||
crewManager = new CrewManager();
|
||||
hireManager = new HireManager();
|
||||
|
||||
savePath = SaveUtil.CreateSavePath(SaveUtil.SaveFolder);
|
||||
|
||||
hireManager.GenerateCharacters("Content/Characters/Human/human.xml", 10);
|
||||
|
||||
guiRoot = new GUIFrame(new Rectangle(0,0,Game1.GraphicsWidth,Game1.GraphicsWidth), Color.Transparent);
|
||||
|
||||
int width = 350, height = 100;
|
||||
@@ -75,10 +71,12 @@ namespace Subsurface
|
||||
}
|
||||
|
||||
timerBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth - 120, 20, 100, 25), Color.Gold, 0.0f, guiRoot);
|
||||
|
||||
|
||||
|
||||
this.gameMode = gameMode;
|
||||
if (this.gameMode != null) this.gameMode.Start(Game1.NetLobbyScreen.GameDuration);
|
||||
//if (gameMode != null && !gameMode.IsSinglePlayer)
|
||||
//{
|
||||
// gameMode.Start(Game1.NetLobbyScreen.GameDuration);
|
||||
//}
|
||||
|
||||
startTime = DateTime.Now;
|
||||
endTime = startTime + gameDuration;
|
||||
@@ -88,53 +86,38 @@ namespace Subsurface
|
||||
//if (!save) return;
|
||||
|
||||
//CreateSaveFile(selectedMapFile);
|
||||
|
||||
day = 1;
|
||||
|
||||
}
|
||||
|
||||
public GameSession(string filePath)
|
||||
: this(null, new TimeSpan(0,0,0,0))
|
||||
public GameSession(Map selectedMap, string savePath, string filePath)
|
||||
: this(selectedMap, new TimeSpan(0,0,0,0))
|
||||
{
|
||||
XDocument doc = ToolBox.TryLoadXml(filePath);
|
||||
if (doc == null) return;
|
||||
|
||||
day = ToolBox.GetAttributeInt(doc.Root,"day",1);
|
||||
//gameMode = GameModePreset.list.Find(gm => gm.Name == "Single Player").Instantiate();
|
||||
|
||||
//day = ToolBox.GetAttributeInt(doc.Root,"day",1);
|
||||
|
||||
foreach (XElement subElement in doc.Root.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLower()=="crew")
|
||||
{
|
||||
crewManager = new CrewManager(subElement);
|
||||
}
|
||||
if (subElement.Name.ToString().ToLower() != "gamemode") continue;
|
||||
|
||||
gameMode = new SinglePlayerMode(subElement);
|
||||
}
|
||||
|
||||
savePath = filePath;
|
||||
}
|
||||
|
||||
public bool TryHireCharacter(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);
|
||||
this.savePath = savePath;
|
||||
}
|
||||
|
||||
public void StartShift(int scriptedEventCount = 1)
|
||||
{
|
||||
if (crewManager.characterInfos.Count == 0) return;
|
||||
//if (crewManager.characterInfos.Count == 0) return;
|
||||
|
||||
if (Map.Loaded!=selectedMap) selectedMap.Load();
|
||||
|
||||
crewManager.StartShift();
|
||||
gameMode.Start(TimeSpan.Zero);
|
||||
|
||||
//crewManager.StartShift();
|
||||
taskManager.StartShift(scriptedEventCount);
|
||||
}
|
||||
|
||||
@@ -148,76 +131,30 @@ namespace Subsurface
|
||||
|
||||
}
|
||||
else if (Game1.Client==null)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<Character> casualties = crewManager.characters.FindAll(c => c.IsDead);
|
||||
|
||||
if (casualties.Any())
|
||||
{
|
||||
sb.Append("Casualties: \n");
|
||||
foreach (Character c in casualties)
|
||||
{
|
||||
sb.Append(" - " + c.info.name + "\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("No casualties!");
|
||||
}
|
||||
|
||||
new GUIMessageBox("Day #" + day + " is over!\n", sb.ToString());
|
||||
|
||||
|
||||
//if (saveFile == null) return false;
|
||||
|
||||
//Map.Loaded.SaveAs(saveFile);
|
||||
|
||||
crewManager.EndShift();
|
||||
|
||||
{
|
||||
Game1.LobbyScreen.Select();
|
||||
|
||||
day++;
|
||||
}
|
||||
|
||||
for (int i = Character.characterList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Character.characterList.RemoveAt(i);
|
||||
SaveUtil.SaveGame(savePath);
|
||||
}
|
||||
|
||||
taskManager.EndShift();
|
||||
gameMode.End();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CreateSaveFile(string mapName)
|
||||
|
||||
public void KillCharacter(Character character)
|
||||
{
|
||||
//string path = "Content/Data/Saves/";
|
||||
SinglePlayerMode singlePlayerMode = gameMode as SinglePlayerMode;
|
||||
if (singlePlayerMode == null) return;
|
||||
singlePlayerMode.crewManager.KillCharacter(character);
|
||||
}
|
||||
|
||||
//if (!Directory.Exists(path))
|
||||
//{
|
||||
// Directory.CreateDirectory(path);
|
||||
//}
|
||||
|
||||
//string name = Path.GetFileNameWithoutExtension(mapName);
|
||||
//string extension = Path.GetExtension(mapName);
|
||||
|
||||
//int i = 0;
|
||||
//while (File.Exists(path + name + i + extension))
|
||||
//{
|
||||
// i++;
|
||||
//}
|
||||
|
||||
//saveFile = path + name + i+extension;
|
||||
|
||||
|
||||
//try
|
||||
//{
|
||||
// File.Copy(mapName, saveFile);
|
||||
//}
|
||||
//catch (Exception e)
|
||||
//{
|
||||
// DebugConsole.ThrowError("Copying map file ''" + mapName + "'' to ''" + saveFile + "'' failed", e);
|
||||
//}
|
||||
public bool LoadPrevious(GUIButton button, object obj)
|
||||
{
|
||||
SaveUtil.LoadGame(savePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool EnterChatMessage(GUITextBox textBox, string message)
|
||||
@@ -237,7 +174,7 @@ namespace Subsurface
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void NewChatMessage(string text, Color color)
|
||||
{
|
||||
GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, 0, 20), text,
|
||||
@@ -252,20 +189,20 @@ namespace Subsurface
|
||||
chatBox.RemoveChild(chatBox.children.First());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
taskManager.Update(deltaTime);
|
||||
if (endShiftButton!=null) endShiftButton.Enabled = !taskManager.CriticalTasks;
|
||||
|
||||
//if (endShiftButton!=null) endShiftButton.Enabled = !taskManager.CriticalTasks;
|
||||
endShiftButton.Enabled = true;
|
||||
|
||||
guiRoot.Update(deltaTime);
|
||||
crewManager.Update(deltaTime);
|
||||
|
||||
//endShiftButton.Update(deltaTime);
|
||||
|
||||
//textBox.Update(deltaTime);
|
||||
|
||||
if (gameMode != null) gameMode.Update();
|
||||
if (gameMode != null) gameMode.Update(deltaTime);
|
||||
|
||||
double duration = (endTime - startTime).TotalSeconds;
|
||||
double elapsedTime = (DateTime.Now-startTime).TotalSeconds;
|
||||
@@ -288,9 +225,11 @@ namespace Subsurface
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
guiRoot.Draw(spriteBatch);
|
||||
crewManager.Draw(spriteBatch);
|
||||
//crewManager.Draw(spriteBatch);
|
||||
taskManager.Draw(spriteBatch);
|
||||
|
||||
gameMode.Draw(spriteBatch);
|
||||
|
||||
//chatBox.Draw(spriteBatch);
|
||||
//textBox.Draw(spriteBatch);
|
||||
|
||||
@@ -304,7 +243,11 @@ namespace Subsurface
|
||||
XDocument doc = new XDocument(
|
||||
new XElement((XName)"Gamesession"));
|
||||
|
||||
doc.Root.Add(new XAttribute("day", day));
|
||||
((SinglePlayerMode)gameMode).Save(doc.Root);
|
||||
|
||||
//doc.Root.Add(new XAttribute("day", day));
|
||||
|
||||
//crewManager.Save(doc.Root);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
155
Subsurface/GameSession/SinglePlayerMode.cs
Normal file
155
Subsurface/GameSession/SinglePlayerMode.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
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
|
||||
{
|
||||
public readonly CrewManager crewManager;
|
||||
public readonly HireManager hireManager;
|
||||
|
||||
private int day;
|
||||
|
||||
public int Day
|
||||
{
|
||||
get { return day; }
|
||||
}
|
||||
|
||||
bool crewDead;
|
||||
private float endTimer;
|
||||
|
||||
public SinglePlayerMode(GameModePreset preset)
|
||||
: base(preset)
|
||||
{
|
||||
crewManager = new CrewManager();
|
||||
hireManager = new HireManager();
|
||||
|
||||
hireManager.GenerateCharacters("Content/Characters/Human/human.xml", 10);
|
||||
|
||||
day = 1;
|
||||
}
|
||||
|
||||
public SinglePlayerMode(XElement element)
|
||||
: this(GameModePreset.list.Find(gm => gm.Name == "Single Player"))
|
||||
{
|
||||
day = ToolBox.GetAttributeInt(element,"day",1);
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLower() != "crew") continue;
|
||||
|
||||
crewManager = new CrewManager(subElement);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Start(TimeSpan duration)
|
||||
{
|
||||
endTimer = 5.0f;
|
||||
|
||||
crewManager.StartShift();
|
||||
}
|
||||
|
||||
public bool TryHireCharacter(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)
|
||||
{
|
||||
crewManager.Draw(spriteBatch);
|
||||
|
||||
//chatBox.Draw(spriteBatch);
|
||||
//textBox.Draw(spriteBatch);
|
||||
|
||||
//timerBar.Draw(spriteBatch);
|
||||
|
||||
//if (Game1.Client == null) endShiftButton.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
crewManager.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 = "")
|
||||
{
|
||||
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("GG", 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!");
|
||||
}
|
||||
|
||||
new GUIMessageBox("Day #" + day + " is over!\n", sb.ToString());
|
||||
|
||||
day++;
|
||||
}
|
||||
|
||||
crewManager.EndShift();
|
||||
for (int i = Character.characterList.Count-1; i>=0; i--)
|
||||
{
|
||||
Character.characterList.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(XElement element)
|
||||
{
|
||||
element.Add(new XAttribute("day", day));
|
||||
|
||||
crewManager.Save(element);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@ namespace Subsurface
|
||||
Client traitor;
|
||||
Client target;
|
||||
|
||||
public TraitorMode(string name)
|
||||
: base(name)
|
||||
public TraitorMode(GameModePreset preset)
|
||||
: base(preset)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -23,9 +23,8 @@ namespace Subsurface
|
||||
target = null;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
|
||||
if (!isRunning) return;
|
||||
|
||||
if (DateTime.Now >= endTime)
|
||||
|
||||
Reference in New Issue
Block a user