Added MP campaign setup to the dedicated server & some console commands for managing the campaign
This commit is contained in:
@@ -9,15 +9,6 @@ namespace Barotrauma
|
|||||||
private GUIButton infoButton;
|
private GUIButton infoButton;
|
||||||
private GUIFrame infoFrame;
|
private GUIFrame infoFrame;
|
||||||
|
|
||||||
public Map Map
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
CampaignMode mode = (GameMode as CampaignMode);
|
|
||||||
return (mode == null) ? null : mode.Map;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private RoundSummary roundSummary;
|
private RoundSummary roundSummary;
|
||||||
public RoundSummary RoundSummary
|
public RoundSummary RoundSummary
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,15 +63,18 @@ namespace Barotrauma
|
|||||||
"Are you sure you want to choose a shuttle as your vessel?",
|
"Are you sure you want to choose a shuttle as your vessel?",
|
||||||
new string[] { "Yes", "No" });
|
new string[] { "Yes", "No" });
|
||||||
|
|
||||||
msgBox.Buttons[0].OnClicked = (button, obj) => { StartNewGame?.Invoke(selectedSub, saveNameBox.Text, seedBox.Text); return true; };
|
string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
|
||||||
|
msgBox.Buttons[0].OnClicked = (button, obj) => { StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text); return true; };
|
||||||
msgBox.Buttons[0].OnClicked += msgBox.Close;
|
msgBox.Buttons[0].OnClicked += msgBox.Close;
|
||||||
|
|
||||||
msgBox.Buttons[1].OnClicked = msgBox.Close;
|
msgBox.Buttons[1].OnClicked = msgBox.Close;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
|
{
|
||||||
StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
|
string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
|
||||||
|
StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -66,7 +66,6 @@
|
|||||||
<Compile Include="Source\Characters\Character.cs" />
|
<Compile Include="Source\Characters\Character.cs" />
|
||||||
<Compile Include="Source\DebugConsole.cs" />
|
<Compile Include="Source\DebugConsole.cs" />
|
||||||
<Compile Include="Source\GameMain.cs" />
|
<Compile Include="Source\GameMain.cs" />
|
||||||
<Compile Include="Source\GameSession\GameSession.cs" />
|
|
||||||
<Compile Include="Source\GameSettings.cs" />
|
<Compile Include="Source\GameSettings.cs" />
|
||||||
<Compile Include="Source\Items\Components\ItemComponent.cs" />
|
<Compile Include="Source\Items\Components\ItemComponent.cs" />
|
||||||
<Compile Include="Source\Items\Components\ItemLabel.cs" />
|
<Compile Include="Source\Items\Components\ItemLabel.cs" />
|
||||||
@@ -123,6 +122,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Source\GameSession\" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="..\BarotraumaShared\BarotraumaShared.projitems" Label="Shared" />
|
<Import Project="..\BarotraumaShared\BarotraumaShared.projitems" Label="Shared" />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|||||||
@@ -72,11 +72,27 @@ namespace Barotrauma
|
|||||||
int index = -1;
|
int index = -1;
|
||||||
if (int.TryParse(string.Join(" ", args), out index))
|
if (int.TryParse(string.Join(" ", args), out index))
|
||||||
{
|
{
|
||||||
GameMain.NetLobbyScreen.SelectedModeIndex = index;
|
if (index > 0 && index < GameMain.NetLobbyScreen.GameModes.Length &&
|
||||||
|
GameMain.NetLobbyScreen.GameModes[index].Name == "Campaign")
|
||||||
|
{
|
||||||
|
MultiplayerCampaign.StartCampaignSetup();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GameMain.NetLobbyScreen.SelectedModeIndex = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GameMain.NetLobbyScreen.SelectedModeName = string.Join(" ", args);
|
string modeName = string.Join(" ", args);
|
||||||
|
if (modeName.ToLowerInvariant() == "campaign")
|
||||||
|
{
|
||||||
|
MultiplayerCampaign.StartCampaignSetup();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GameMain.NetLobbyScreen.SelectedModeName = modeName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
NewMessage("Set gamemode to " + GameMain.NetLobbyScreen.SelectedModeName, Color.Cyan);
|
NewMessage("Set gamemode to " + GameMain.NetLobbyScreen.SelectedModeName, Color.Cyan);
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace Barotrauma
|
|
||||||
{
|
|
||||||
partial class GameSession
|
|
||||||
{
|
|
||||||
public const Map Map = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -21,26 +21,31 @@ namespace Barotrauma
|
|||||||
set { selectedShuttle = value; lastUpdateID++; }
|
set { selectedShuttle = value; lastUpdateID++; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private GameModePreset[] GameModes;
|
private GameModePreset[] gameModes;
|
||||||
|
public GameModePreset[] GameModes
|
||||||
|
{
|
||||||
|
get { return gameModes; }
|
||||||
|
}
|
||||||
|
|
||||||
private int selectedModeIndex;
|
private int selectedModeIndex;
|
||||||
public int SelectedModeIndex
|
public int SelectedModeIndex
|
||||||
{
|
{
|
||||||
get { return selectedModeIndex; }
|
get { return selectedModeIndex; }
|
||||||
set {
|
set
|
||||||
|
{
|
||||||
lastUpdateID++;
|
lastUpdateID++;
|
||||||
selectedModeIndex = Math.Max(0, Math.Min(GameModes.Count()-1, value));
|
selectedModeIndex = MathHelper.Clamp(value, 0, gameModes.Length - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SelectedModeName
|
public string SelectedModeName
|
||||||
{
|
{
|
||||||
get { return GameModes[SelectedModeIndex].Name; }
|
get { return gameModes[SelectedModeIndex].Name; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
for (int i = 0; i < GameModes.Count(); i++)
|
for (int i = 0; i < gameModes.Count(); i++)
|
||||||
{
|
{
|
||||||
if (GameModes[i].Name.ToLower() == value.ToLower())
|
if (gameModes[i].Name.ToLower() == value.ToLower())
|
||||||
{
|
{
|
||||||
SelectedModeIndex = i;
|
SelectedModeIndex = i;
|
||||||
break;
|
break;
|
||||||
@@ -51,7 +56,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public GameModePreset SelectedMode
|
public GameModePreset SelectedMode
|
||||||
{
|
{
|
||||||
get { return GameModes[SelectedModeIndex]; }
|
get { return gameModes[SelectedModeIndex]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ServerMessageText;
|
public string ServerMessageText;
|
||||||
@@ -117,12 +122,7 @@ namespace Barotrauma
|
|||||||
DebugConsole.NewMessage("Selected sub: " + SelectedSub.Name, Color.White);
|
DebugConsole.NewMessage("Selected sub: " + SelectedSub.Name, Color.White);
|
||||||
DebugConsole.NewMessage("Selected shuttle: " + SelectedShuttle.Name, Color.White);
|
DebugConsole.NewMessage("Selected shuttle: " + SelectedShuttle.Name, Color.White);
|
||||||
|
|
||||||
GameModes = GameModePreset.list.ToArray();
|
gameModes = GameModePreset.list.ToArray();
|
||||||
}
|
|
||||||
|
|
||||||
public override void Select()
|
|
||||||
{
|
|
||||||
base.Select();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Submarine> subs;
|
private List<Submarine> subs;
|
||||||
@@ -152,5 +152,19 @@ namespace Barotrauma
|
|||||||
get { return true; }
|
get { return true; }
|
||||||
set { /* do nothing */ }
|
set { /* do nothing */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ToggleCampaignMode(bool enabled)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < GameModes.Length; i++)
|
||||||
|
{
|
||||||
|
if ((GameModes[i].Name == "Campaign") == enabled)
|
||||||
|
{
|
||||||
|
selectedModeIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastUpdateID++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public static List<ColoredText> Messages = new List<ColoredText>();
|
public static List<ColoredText> Messages = new List<ColoredText>();
|
||||||
|
|
||||||
private delegate void QuestionCallback(string answer);
|
public delegate void QuestionCallback(string answer);
|
||||||
private static QuestionCallback activeQuestionCallback;
|
private static QuestionCallback activeQuestionCallback;
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
private static GUIComponent activeQuestionText;
|
private static GUIComponent activeQuestionText;
|
||||||
@@ -634,6 +634,65 @@ namespace Barotrauma
|
|||||||
var character = FindMatchingCharacter(argsRight, false);
|
var character = FindMatchingCharacter(argsRight, false);
|
||||||
GameMain.Server.SetClientCharacter(client, character);
|
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
|
#if DEBUG
|
||||||
commands.Add(new Command("spamevents", "A debug command that immediately creates entity events for all items, characters and structures.", (string[] args) =>
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ShowQuestionPrompt(string question, QuestionCallback onAnswered)
|
public static void ShowQuestionPrompt(string question, QuestionCallback onAnswered)
|
||||||
{
|
{
|
||||||
NewMessage(" >>" + question, Color.Cyan);
|
NewMessage(" >>" + question, Color.Cyan);
|
||||||
activeQuestionCallback += onAnswered;
|
activeQuestionCallback += onAnswered;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Microsoft.Xna.Framework;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
@@ -58,5 +59,33 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract void Save(XElement element);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,53 @@ namespace Barotrauma
|
|||||||
return true;
|
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
|
#endif
|
||||||
|
|
||||||
private void SetDelegates()
|
private void SetDelegates()
|
||||||
|
|||||||
@@ -40,6 +40,15 @@ namespace Barotrauma
|
|||||||
get { return level; }
|
get { return level; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map Map
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
CampaignMode mode = (GameMode as CampaignMode);
|
||||||
|
return (mode == null) ? null : mode.Map;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Location StartLocation
|
public Location StartLocation
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|||||||
@@ -397,6 +397,19 @@ namespace Barotrauma
|
|||||||
OnLocationSelected?.Invoke(selectedLocation, selectedConnection);
|
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)
|
public void Save(XElement element)
|
||||||
{
|
{
|
||||||
XElement mapElement = new XElement("map");
|
XElement mapElement = new XElement("map");
|
||||||
|
|||||||
Reference in New Issue
Block a user