Moved CrewManager & HireManager to a separate single player GameMode, bleeding decreases health

This commit is contained in:
Regalis
2015-06-16 22:53:02 +03:00
parent d668ad0ede
commit 2ef92c4af0
22 changed files with 656 additions and 283 deletions

View File

@@ -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
{