Started moving single player campaign logic to an abstract CampaignMode class to make it reusable in the eventual multiplayer campaign

This commit is contained in:
Joonas Rikkonen
2017-08-28 18:45:08 +03:00
parent 729108c7b9
commit a75fd12020
17 changed files with 202 additions and 189 deletions
@@ -169,7 +169,7 @@ namespace Barotrauma
#if CLIENT
if (GameMain.GameSession != null)
{
SinglePlayerMode mode = GameMain.GameSession.gameMode as SinglePlayerMode;
SinglePlayerCampaign mode = GameMain.GameSession.GameMode as SinglePlayerCampaign;
if (mode != null)
{
Character.Controlled = spawnedCharacter;
@@ -248,12 +248,10 @@ namespace Barotrauma
public void GiveReward()
{
#if CLIENT
var mode = GameMain.GameSession.gameMode as SinglePlayerMode;
var mode = GameMain.GameSession.GameMode as CampaignMode;
if (mode == null) return;
mode.Money += reward;
#endif
}
}
}
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;
namespace Barotrauma
{
abstract class CampaignMode : GameMode
{
public readonly CargoManager CargoManager;
const int InitialMoney = 10000;
protected Map map;
public Map Map
{
get { return map; }
}
public override Mission Mission
{
get
{
return Map.SelectedConnection.Mission;
}
}
private int money;
public int Money
{
get { return money; }
set { money = Math.Max(value, 0); }
}
public CampaignMode(GameModePreset preset, object param)
: base(preset, param)
{
Money = InitialMoney;
CargoManager = new CargoManager();
}
public void GenerateMap(string seed)
{
map = new Map(seed, 1000);
}
protected List<Submarine> GetSubsToLeaveBehind(Submarine leavingSub)
{
//leave subs behind if they're not docked to the leaving sub and not at the same exit
return Submarine.Loaded.FindAll(s =>
s != leavingSub &&
!leavingSub.DockedTo.Contains(s) &&
(s.AtEndPosition != leavingSub.AtEndPosition || s.AtStartPosition != leavingSub.AtStartPosition));
}
public override void End(string endMessage = "")
{
base.End(endMessage);
}
public abstract void Save(XElement element);
}
}
@@ -34,7 +34,7 @@ namespace Barotrauma
public static void Init()
{
#if CLIENT
new GameModePreset("Single Player", typeof(SinglePlayerMode), true);
new GameModePreset("Single Player", typeof(SinglePlayerCampaign), true);
new GameModePreset("Tutorial", typeof(TutorialMode), true);
#endif
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
namespace Barotrauma
{
class MultiplayerCampaign : CampaignMode
{
public MultiplayerCampaign(GameModePreset preset, object param) :
base(preset, param)
{
}
public override void Save(XElement element)
{
throw new NotImplementedException();
}
}
}
@@ -7,9 +7,9 @@ namespace Barotrauma
{
public enum InfoFrameTab { Crew, Mission, ManagePlayers };
public readonly EventManager TaskManager;
public readonly EventManager EventManager;
public readonly GameMode gameMode;
public readonly GameMode GameMode;
//two locations used as the start and end in the MP mode
private Location[] dummyLocations;
@@ -79,14 +79,14 @@ namespace Barotrauma
{
get { return saveFile; }
}
public GameSession(Submarine submarine, string saveFile, GameModePreset gameModePreset = null, string missionType="")
public GameSession(Submarine submarine, string saveFile, GameModePreset gameModePreset = null, string missionType = "")
{
Submarine.MainSub = submarine;
GameMain.GameSession = this;
TaskManager = new EventManager(this);
EventManager = new EventManager(this);
this.saveFile = saveFile;
@@ -97,7 +97,7 @@ namespace Barotrauma
infoButton.OnClicked = ToggleInfoFrame;
#endif
if (gameModePreset != null) gameMode = gameModePreset.Instantiate(missionType);
if (gameModePreset != null) GameMode = gameModePreset.Instantiate(missionType);
this.submarine = submarine;
}
@@ -117,7 +117,7 @@ namespace Barotrauma
{
if (subElement.Name.ToString().ToLowerInvariant() != "gamemode") continue;
gameMode = new SinglePlayerMode(subElement);
GameMode = SinglePlayerCampaign.Load(subElement);
}
#endif
}
@@ -186,18 +186,18 @@ namespace Barotrauma
submarine.SetPosition(submarine.FindSpawnPos(level.StartPosition - new Vector2(0.0f, 2000.0f)));
}
if (gameMode.Mission != null)
if (GameMode.Mission != null)
{
currentMission = gameMode.Mission;
currentMission = GameMode.Mission;
}
if (gameMode!=null) gameMode.Start();
if (GameMode!=null) GameMode.Start();
if (gameMode.Mission != null) Mission.Start(Level.Loaded);
if (GameMode.Mission != null) Mission.Start(Level.Loaded);
TaskManager.StartRound(level);
EventManager.StartRound(level);
if (gameMode != null) gameMode.MsgBox();
if (GameMode != null) GameMode.MsgBox();
Entity.Spawner = new EntitySpawner();
@@ -234,7 +234,7 @@ namespace Barotrauma
}
#endif
TaskManager.EndRound();
EventManager.EndRound();
currentMission = null;
@@ -554,7 +554,7 @@ namespace Barotrauma.Networking
//game already started -> send start message immediately
if (gameStarted)
{
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClient);
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.GameMode.Preset, connectedClient);
}
}
break;
@@ -1131,8 +1131,8 @@ namespace Barotrauma.Networking
GameMain.GameSession = new GameSession(selectedSub, "", selectedMode, Mission.MissionTypes[GameMain.NetLobbyScreen.MissionTypeIndex]);
if (GameMain.GameSession.gameMode.Mission != null &&
GameMain.GameSession.gameMode.Mission.AssignTeamIDs(connectedClients, out hostTeam))
if (GameMain.GameSession.GameMode.Mission != null &&
GameMain.GameSession.GameMode.Mission.AssignTeamIDs(connectedClients, out hostTeam))
{
teamCount = 2;
}
@@ -1149,8 +1149,8 @@ namespace Barotrauma.Networking
GameServer.Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed, ServerLog.MessageType.ServerMessage);
bool missionAllowRespawn =
!(GameMain.GameSession.gameMode is MissionMode) ||
((MissionMode)GameMain.GameSession.gameMode).Mission.AllowRespawn;
!(GameMain.GameSession.GameMode is MissionMode) ||
((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn;
if (AllowRespawn && missionAllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle);
@@ -1261,7 +1261,7 @@ namespace Barotrauma.Networking
}
}
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClients);
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.GameMode.Preset, connectedClients);
yield return CoroutineStatus.Running;
@@ -1308,8 +1308,8 @@ namespace Barotrauma.Networking
msg.Write(selectedMode.Name);
bool missionAllowRespawn =
!(GameMain.GameSession.gameMode is MissionMode) ||
((MissionMode)GameMain.GameSession.gameMode).Mission.AllowRespawn;
!(GameMain.GameSession.GameMode is MissionMode) ||
((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn;
msg.Write(AllowRespawn && missionAllowRespawn);
msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub
@@ -1350,7 +1350,7 @@ namespace Barotrauma.Networking
}
Mission mission = GameMain.GameSession.Mission;
GameMain.GameSession.gameMode.End(endMessage);
GameMain.GameSession.GameMode.End(endMessage);
if (autoRestart)
{