Added MP campaign setup to the dedicated server & some console commands for managing the campaign

This commit is contained in:
Joonas Rikkonen
2017-09-17 20:03:18 +03:00
parent 9114ae658f
commit e26600d088
11 changed files with 218 additions and 42 deletions
@@ -50,7 +50,7 @@ namespace Barotrauma
public static List<ColoredText> Messages = new List<ColoredText>();
private delegate void QuestionCallback(string answer);
public delegate void QuestionCallback(string answer);
private static QuestionCallback activeQuestionCallback;
#if CLIENT
private static GUIComponent activeQuestionText;
@@ -634,6 +634,65 @@ namespace Barotrauma
var character = FindMatchingCharacter(argsRight, false);
GameMain.Server.SetClientCharacter(client, character);
}));
commands.Add(new Command("campaigninfo|campaignstatus", "campaigninfo: Display information about the state of the currently active campaign.", (string[] args) =>
{
var campaign = GameMain.GameSession?.GameMode as CampaignMode;
if (campaign == null)
{
ThrowError("No campaign active!");
return;
}
campaign.LogState();
}));
commands.Add(new Command("campaigndestination|setcampaigndestination", "campaigndestination [index]: Set the location to head towards in the currently active campaign.", (string[] args) =>
{
var campaign = GameMain.GameSession?.GameMode as CampaignMode;
if (campaign == null)
{
ThrowError("No campaign active!");
return;
}
if (args.Length == 0)
{
int i = 0;
foreach (LocationConnection connection in campaign.Map.CurrentLocation.Connections)
{
NewMessage(" " + i + ". " + connection.OtherLocation(campaign.Map.CurrentLocation).Name, Color.White);
i++;
}
ShowQuestionPrompt("Select a destination (0 - " + (campaign.Map.CurrentLocation.Connections.Count - 1) + "):", (string selectedDestination) =>
{
int destinationIndex = -1;
if (!int.TryParse(selectedDestination, out destinationIndex)) return;
if (destinationIndex < 0 || destinationIndex >= campaign.Map.CurrentLocation.Connections.Count)
{
NewMessage("Index out of bounds!", Color.Red);
return;
}
Location location = campaign.Map.CurrentLocation.Connections[destinationIndex].OtherLocation(campaign.Map.CurrentLocation);
campaign.Map.SelectLocation(location);
NewMessage(location.Name+" selected.", Color.White);
});
}
else
{
int destinationIndex = -1;
if (!int.TryParse(args[0], out destinationIndex)) return;
if (destinationIndex < 0 || destinationIndex >= campaign.Map.CurrentLocation.Connections.Count)
{
NewMessage("Index out of bounds!", Color.Red);
return;
}
Location location = campaign.Map.CurrentLocation.Connections[destinationIndex].OtherLocation(campaign.Map.CurrentLocation);
campaign.Map.SelectLocation(location);
NewMessage(location.Name + " selected.", Color.White);
}
}));
#if DEBUG
commands.Add(new Command("spamevents", "A debug command that immediately creates entity events for all items, characters and structures.", (string[] args) =>
{
@@ -875,7 +934,7 @@ namespace Barotrauma
#endif
}
private static void ShowQuestionPrompt(string question, QuestionCallback onAnswered)
public static void ShowQuestionPrompt(string question, QuestionCallback onAnswered)
{
NewMessage(" >>" + question, Color.Cyan);
activeQuestionCallback += onAnswered;
@@ -1,4 +1,5 @@
using System;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
@@ -58,5 +59,33 @@ namespace Barotrauma
}
public abstract void Save(XElement element);
public void LogState()
{
DebugConsole.NewMessage("********* CAMPAIGN STATUS *********", Color.White);
DebugConsole.NewMessage(" Money: " + Money, Color.White);
DebugConsole.NewMessage(" Current location: " + map.CurrentLocation.Name, Color.White);
DebugConsole.NewMessage(" Available destinations: ", Color.White);
for (int i = 0; i < map.CurrentLocation.Connections.Count; i++)
{
Location destination = map.CurrentLocation.Connections[i].OtherLocation(map.CurrentLocation);
if (destination == map.SelectedLocation)
{
DebugConsole.NewMessage(" " + i + ". " + destination.Name + " [SELECTED]", Color.White);
}
else
{
DebugConsole.NewMessage(" " + i + ". " + destination.Name, Color.White);
}
}
if (map.SelectedConnection?.Mission != null)
{
DebugConsole.NewMessage(" Selected mission: " + map.SelectedConnection.Mission.Name, Color.White);
DebugConsole.NewMessage("\n" + map.SelectedConnection.Mission.Description, Color.White);
}
}
}
}
@@ -75,7 +75,7 @@ namespace Barotrauma
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
campaign.LastSaveID++;
campaign.LastSaveID++;
};
campaignSetupUI.LoadGame = (string fileName) =>
@@ -104,6 +104,53 @@ namespace Barotrauma
return true;
};
}
#elif SERVER
public static void StartCampaignSetup()
{
DebugConsole.NewMessage("********* CAMPAIGN SETUP *********", Color.White);
DebugConsole.ShowQuestionPrompt("Do you want to start a new campaign? Y/N", (string arg) =>
{
if (arg.ToLowerInvariant() == "y" || arg.ToLowerInvariant() == "yes")
{
DebugConsole.ShowQuestionPrompt("Enter a save name for the campaign:", (string saveName) =>
{
if (string.IsNullOrWhiteSpace(saveName)) return;
string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, saveName);
GameMain.GameSession = new GameSession(new Submarine(GameMain.NetLobbyScreen.SelectedSub.FilePath, ""), savePath, GameModePreset.list.Find(g => g.Name == "Campaign"));
var campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode);
campaign.GenerateMap(GameMain.NetLobbyScreen.LevelSeed);
campaign.SetDelegates();
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
campaign.LastSaveID++;
DebugConsole.NewMessage("Campaign started!", Color.Cyan);
});
}
else
{
string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer);
DebugConsole.NewMessage("Saved campaigns:", Color.White);
for (int i = 0; i < saveFiles.Length; i++)
{
DebugConsole.NewMessage(" " + i + ". " + saveFiles[i], Color.White);
}
DebugConsole.ShowQuestionPrompt("Select a save file to load (0 - " + (saveFiles.Length - 1) + "):", (string selectedSave) =>
{
int saveIndex = -1;
if (!int.TryParse(selectedSave, out saveIndex)) return;
SaveUtil.LoadGame(saveFiles[saveIndex]);
((MultiplayerCampaign)GameMain.GameSession.GameMode).LastSaveID++;
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
DebugConsole.NewMessage("Campaign loaded!", Color.Cyan);
});
}
});
}
#endif
private void SetDelegates()
@@ -39,7 +39,16 @@ namespace Barotrauma
{
get { return level; }
}
public Map Map
{
get
{
CampaignMode mode = (GameMode as CampaignMode);
return (mode == null) ? null : mode.Map;
}
}
public Location StartLocation
{
get
@@ -397,6 +397,19 @@ namespace Barotrauma
OnLocationSelected?.Invoke(selectedLocation, selectedConnection);
}
public void SelectLocation(Location location)
{
if (!locations.Contains(location))
{
DebugConsole.ThrowError("Failed to select a location. "+location.Name+" not found in the map.");
return;
}
selectedLocation = location;
selectedConnection = connections.Find(c => c.Locations.Contains(currentLocation) && c.Locations.Contains(selectedLocation));
OnLocationSelected?.Invoke(selectedLocation, selectedConnection);
}
public void Save(XElement element)
{
XElement mapElement = new XElement("map");