Merge branch 'master' of https://bitbucket.org/Regalis11/repo
Conflicts: Subsurface/Subsurface.csproj Subsurface_Solution.v12.suo
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
@@ -25,7 +26,7 @@ namespace Subsurface
|
||||
set { money = (int)Math.Max(value, 0.0f); }
|
||||
}
|
||||
|
||||
public CrewManager(GameSession session)
|
||||
public CrewManager()
|
||||
{
|
||||
characters = new List<Character>();
|
||||
characterInfos = new List<CharacterInfo>();
|
||||
@@ -39,19 +40,17 @@ namespace Subsurface
|
||||
money = 10000;
|
||||
}
|
||||
|
||||
private string CreateSaveFile(string mapName)
|
||||
public CrewManager(XElement element)
|
||||
: this()
|
||||
{
|
||||
string path = "Content/Data/Saves/";
|
||||
money = ToolBox.GetAttributeInt(element, "money", 0);
|
||||
|
||||
string name = Path.GetFileNameWithoutExtension(mapName);
|
||||
|
||||
int i = 0;
|
||||
while (File.Exists(path+name + i))
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
i++;
|
||||
}
|
||||
if (subElement.Name.ToString().ToLower()!="character") continue;
|
||||
|
||||
return path + name + i;
|
||||
characterInfos.Add(new CharacterInfo(subElement));
|
||||
}
|
||||
}
|
||||
|
||||
public bool SelectCharacter(object selection)
|
||||
@@ -89,7 +88,7 @@ namespace Subsurface
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(40,0,0,25),
|
||||
name,
|
||||
Color.Transparent, Color.Black,
|
||||
Color.Transparent, Color.White,
|
||||
Alignment.Left,
|
||||
Alignment.Left,
|
||||
frame);
|
||||
@@ -98,6 +97,11 @@ namespace Subsurface
|
||||
new GUIImage(new Rectangle(-10,-10,0,0), character.animController.limbs[0].sprite, Alignment.Left, frame);
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
guiFrame.Update(deltaTime);
|
||||
}
|
||||
|
||||
public void KillCharacter(Character killedCharacter)
|
||||
{
|
||||
GUIComponent characterBlock = listBox.GetChild(killedCharacter) as GUIComponent;
|
||||
@@ -138,5 +142,19 @@ namespace Subsurface
|
||||
{
|
||||
guiFrame.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public void Save(XElement parentElement)
|
||||
{
|
||||
XElement element = new XElement("crew");
|
||||
|
||||
element.Add(new XAttribute("money", money));
|
||||
|
||||
foreach (CharacterInfo ci in characterInfos)
|
||||
{
|
||||
ci.Save(element);
|
||||
}
|
||||
|
||||
parentElement.Add(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Subsurface
|
||||
|
||||
if (endMessage != "" || this.endMessage == null) this.endMessage = endMessage;
|
||||
|
||||
Game1.gameSession.EndShift(null, null);
|
||||
Game1.GameSession.EndShift(null, null);
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
|
||||
@@ -4,6 +4,9 @@ using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
@@ -18,6 +21,8 @@ namespace Subsurface
|
||||
|
||||
public readonly GameMode gameMode;
|
||||
|
||||
private GUIFrame guiRoot;
|
||||
|
||||
private GUIListBox chatBox;
|
||||
private GUITextBox textBox;
|
||||
|
||||
@@ -25,57 +30,85 @@ namespace Subsurface
|
||||
|
||||
private GUIButton endShiftButton;
|
||||
|
||||
string saveFile;
|
||||
private string savePath;
|
||||
|
||||
private Map selectedMap;
|
||||
|
||||
private int day;
|
||||
|
||||
public string SaveFile
|
||||
{
|
||||
get { return saveFile; }
|
||||
}
|
||||
|
||||
public int Day
|
||||
{
|
||||
get { return day; }
|
||||
}
|
||||
|
||||
public GameSession(string selectedMapFile, bool save, TimeSpan gameDuration, GameMode gameMode = null)
|
||||
public GameSession(Map selectedMap, TimeSpan gameDuration, GameMode gameMode = null)
|
||||
{
|
||||
taskManager = new TaskManager(this);
|
||||
crewManager = new CrewManager(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;
|
||||
chatBox = new GUIListBox(new Rectangle(
|
||||
Game1.GraphicsWidth - (int)GUI.style.smallPadding.X - width,
|
||||
Game1.GraphicsHeight - (int)GUI.style.smallPadding.W*2 - 25 - height,
|
||||
width, height),
|
||||
Color.White * 0.5f);
|
||||
if (Game1.Client!=null || Game1.Server!=null)
|
||||
{
|
||||
chatBox = new GUIListBox(new Rectangle(
|
||||
Game1.GraphicsWidth - (int)GUI.style.smallPadding.X - width,
|
||||
Game1.GraphicsHeight - (int)GUI.style.smallPadding.W*2 - 25 - height,
|
||||
width, height),
|
||||
Color.White * 0.5f, guiRoot);
|
||||
|
||||
endShiftButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 240, 20, 100, 25), "End shift", Color.White, Alignment.CenterX, null);
|
||||
endShiftButton.OnClicked = EndShift;
|
||||
textBox = new GUITextBox(
|
||||
new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + (int)GUI.style.smallPadding.W, chatBox.Rect.Width, 25),
|
||||
Color.White * 0.5f, Color.Black, Alignment.Bottom, Alignment.Left, guiRoot);
|
||||
textBox.OnEnter = EnterChatMessage;
|
||||
}
|
||||
|
||||
timerBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth - 120, 20, 100, 25), Color.Gold, 0.0f, null);
|
||||
if (Game1.Client==null)
|
||||
{
|
||||
endShiftButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 240, 20, 100, 25), "End shift", Color.White, Alignment.Left | Alignment.Top, guiRoot);
|
||||
endShiftButton.OnClicked = EndShift;
|
||||
}
|
||||
|
||||
timerBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth - 120, 20, 100, 25), Color.Gold, 0.0f, guiRoot);
|
||||
|
||||
textBox = new GUITextBox(
|
||||
new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + (int)GUI.style.smallPadding.W, chatBox.Rect.Width, 25),
|
||||
Color.White * 0.5f, Color.Black, Alignment.Bottom, Alignment.Left);
|
||||
textBox.OnEnter = EnterChatMessage;
|
||||
|
||||
this.gameMode = gameMode;
|
||||
if (this.gameMode != null) this.gameMode.Start(Game1.netLobbyScreen.GameDuration);
|
||||
if (this.gameMode != null) this.gameMode.Start(Game1.NetLobbyScreen.GameDuration);
|
||||
|
||||
startTime = DateTime.Now;
|
||||
endTime = startTime + gameDuration;
|
||||
endTime = startTime + gameDuration;
|
||||
|
||||
if (!save) return;
|
||||
|
||||
CreateSaveFile(selectedMapFile);
|
||||
|
||||
day = 1;
|
||||
this.selectedMap = selectedMap;
|
||||
|
||||
//if (!save) return;
|
||||
|
||||
//CreateSaveFile(selectedMapFile);
|
||||
|
||||
day = 1;
|
||||
}
|
||||
|
||||
public GameSession(string filePath)
|
||||
: this(null, new TimeSpan(0,0,0,0))
|
||||
{
|
||||
XDocument doc = ToolBox.TryLoadXml(filePath);
|
||||
if (doc == null) return;
|
||||
|
||||
day = ToolBox.GetAttributeInt(doc.Root,"day",1);
|
||||
|
||||
foreach (XElement subElement in doc.Root.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLower()=="crew")
|
||||
{
|
||||
crewManager = new CrewManager(subElement);
|
||||
}
|
||||
}
|
||||
|
||||
savePath = filePath;
|
||||
}
|
||||
|
||||
public bool TryHireCharacter(CharacterInfo characterInfo)
|
||||
@@ -99,32 +132,58 @@ namespace Subsurface
|
||||
{
|
||||
if (crewManager.characterInfos.Count == 0) return;
|
||||
|
||||
if (Map.Loaded!=selectedMap) selectedMap.Load();
|
||||
|
||||
crewManager.StartShift();
|
||||
taskManager.StartShift(scriptedEventCount);
|
||||
}
|
||||
|
||||
public bool EndShift(GUIButton button, object obj)
|
||||
{
|
||||
if (Game1.server!=null)
|
||||
if (Game1.Server!=null)
|
||||
{
|
||||
string endMessage = gameMode.EndMessage;
|
||||
|
||||
Game1.server.EndGame(endMessage);
|
||||
Game1.Server.EndGame(endMessage);
|
||||
|
||||
}
|
||||
else if (Game1.client==null)
|
||||
else if (Game1.Client==null)
|
||||
{
|
||||
if (saveFile == null) return false;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<Character> casualties = crewManager.characters.FindAll(c => c.IsDead);
|
||||
|
||||
Map.Loaded.SaveAs(Path.GetDirectoryName(saveFile) + "/"+ Path.GetFileName(saveFile));
|
||||
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();
|
||||
Game1.LobbyScreen.Select();
|
||||
|
||||
day++;
|
||||
}
|
||||
|
||||
for (int i = Character.characterList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Character.characterList.RemoveAt(i);
|
||||
}
|
||||
|
||||
taskManager.EndShift();
|
||||
|
||||
return true;
|
||||
@@ -132,46 +191,46 @@ namespace Subsurface
|
||||
|
||||
private void CreateSaveFile(string mapName)
|
||||
{
|
||||
string path = "Content/Data/Saves/";
|
||||
//string path = "Content/Data/Saves/";
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
//if (!Directory.Exists(path))
|
||||
//{
|
||||
// Directory.CreateDirectory(path);
|
||||
//}
|
||||
|
||||
string name = Path.GetFileNameWithoutExtension(mapName);
|
||||
string extension = Path.GetExtension(mapName);
|
||||
//string name = Path.GetFileNameWithoutExtension(mapName);
|
||||
//string extension = Path.GetExtension(mapName);
|
||||
|
||||
int i = 0;
|
||||
while (File.Exists(path + name + i + extension))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
//int i = 0;
|
||||
//while (File.Exists(path + name + i + extension))
|
||||
//{
|
||||
// i++;
|
||||
//}
|
||||
|
||||
saveFile = path + name + i+extension;
|
||||
//saveFile = path + name + i+extension;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
File.Copy(mapName, saveFile);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Copying map file ''" + mapName + "'' to ''" + saveFile + "'' failed", e);
|
||||
}
|
||||
//try
|
||||
//{
|
||||
// File.Copy(mapName, saveFile);
|
||||
//}
|
||||
//catch (Exception e)
|
||||
//{
|
||||
// DebugConsole.ThrowError("Copying map file ''" + mapName + "'' to ''" + saveFile + "'' failed", e);
|
||||
//}
|
||||
}
|
||||
|
||||
public bool EnterChatMessage(GUITextBox textBox, string message)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message)) return false;
|
||||
|
||||
if (Game1.server!=null)
|
||||
if (Game1.Server!=null)
|
||||
{
|
||||
Game1.server.SendChatMessage(message);
|
||||
Game1.Server.SendChatMessage(message);
|
||||
}
|
||||
else if (Game1.client!=null)
|
||||
else if (Game1.Client!=null)
|
||||
{
|
||||
Game1.client.SendChatMessage(Game1.client.Name + ": " + message);
|
||||
Game1.Client.SendChatMessage(Game1.Client.Name + ": " + message);
|
||||
}
|
||||
|
||||
textBox.Deselect();
|
||||
@@ -197,8 +256,14 @@ namespace Subsurface
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
taskManager.Update(deltaTime);
|
||||
if (endShiftButton!=null) endShiftButton.Enabled = !taskManager.CriticalTasks;
|
||||
|
||||
textBox.Update(deltaTime);
|
||||
|
||||
guiRoot.Update(deltaTime);
|
||||
crewManager.Update(deltaTime);
|
||||
//endShiftButton.Update(deltaTime);
|
||||
|
||||
//textBox.Update(deltaTime);
|
||||
|
||||
if (gameMode != null) gameMode.Update();
|
||||
|
||||
@@ -222,15 +287,33 @@ namespace Subsurface
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
guiRoot.Draw(spriteBatch);
|
||||
crewManager.Draw(spriteBatch);
|
||||
taskManager.Draw(spriteBatch);
|
||||
|
||||
chatBox.Draw(spriteBatch);
|
||||
textBox.Draw(spriteBatch);
|
||||
//chatBox.Draw(spriteBatch);
|
||||
//textBox.Draw(spriteBatch);
|
||||
|
||||
timerBar.Draw(spriteBatch);
|
||||
//timerBar.Draw(spriteBatch);
|
||||
|
||||
if (Game1.client == null) endShiftButton.Draw(spriteBatch);
|
||||
//if (Game1.Client == null) endShiftButton.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public void Save(string filePath)
|
||||
{
|
||||
XDocument doc = new XDocument(
|
||||
new XElement((XName)"Gamesession"));
|
||||
|
||||
doc.Root.Add(new XAttribute("day", day));
|
||||
|
||||
try
|
||||
{
|
||||
doc.Save(filePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
DebugConsole.ThrowError("Saving gamesession to ''" + filePath + "'' failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,21 +40,21 @@ namespace Subsurface
|
||||
|
||||
if (traitor==null || target ==null)
|
||||
{
|
||||
int clientCount = Game1.server.connectedClients.Count();
|
||||
int clientCount = Game1.Server.connectedClients.Count();
|
||||
if (clientCount < 2) return;
|
||||
|
||||
int traitorIndex = Game1.localRandom.Next(clientCount);
|
||||
traitor = Game1.server.connectedClients[traitorIndex];
|
||||
traitor = Game1.Server.connectedClients[traitorIndex];
|
||||
|
||||
int targetIndex = 0;
|
||||
while (targetIndex==traitorIndex)
|
||||
{
|
||||
targetIndex = Game1.localRandom.Next(clientCount);
|
||||
}
|
||||
target = Game1.server.connectedClients[targetIndex];
|
||||
target = Game1.Server.connectedClients[targetIndex];
|
||||
|
||||
|
||||
Game1.server.NewTraitor(traitor, target);
|
||||
Game1.Server.NewTraitor(traitor, target);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user