v0.11.0.9

This commit is contained in:
Joonas Rikkonen
2020-12-09 16:34:16 +02:00
parent bbf06f0984
commit f433a7ba10
325 changed files with 13947 additions and 3652 deletions
@@ -25,11 +25,12 @@ namespace Barotrauma
subs.ForEach(s => s.Info.InitialSuppliesSpawned = true);
}
foreach (var wreck in Submarine.Loaded)
foreach (var sub in Submarine.Loaded)
{
if (wreck.Info.IsWreck)
if (sub.Info.Type == SubmarineType.Wreck ||
sub.Info.Type == SubmarineType.BeaconStation)
{
Place(wreck.ToEnumerable());
Place(sub.ToEnumerable());
}
}
@@ -204,7 +205,7 @@ namespace Barotrauma
{
SpawnedInOutpost = validContainer.Key.Item.SpawnedInOutpost,
OriginalModuleIndex = validContainer.Key.Item.OriginalModuleIndex,
OriginalContainerID = validContainer.Key.Item.OriginalID
OriginalContainerID = validContainer.Key.Item.ID
};
foreach (WifiComponent wifiComponent in item.GetComponents<WifiComponent>())
{
@@ -217,7 +217,7 @@ namespace Barotrauma
if (containerPrefab == null)
{
DebugConsole.ThrowError("Cargo spawning failed - could not find the item prefab for container \"" + containerPrefab.Name + "\"!");
DebugConsole.ThrowError("Cargo spawning failed - could not find the item prefab for container \"" + pi.ItemPrefab.CargoContainerIdentifier + "\"!");
continue;
}
@@ -25,9 +25,11 @@ namespace Barotrauma
public bool HasBots { get; set; }
public List<Pair<Order, float>> ActiveOrders { get; } = new List<Pair<Order, float>>();
public List<Pair<Order, float?>> ActiveOrders { get; } = new List<Pair<Order, float?>>();
public bool IsSinglePlayer { get; private set; }
public ReadyCheck ActiveReadyCheck;
public CrewManager(bool isSinglePlayer)
{
IsSinglePlayer = isSinglePlayer;
@@ -38,7 +40,7 @@ namespace Barotrauma
partial void InitProjectSpecific();
public bool AddOrder(Order order, float fadeOutTime)
public bool AddOrder(Order order, float? fadeOutTime)
{
if (order.TargetEntity == null)
{
@@ -46,7 +48,10 @@ namespace Barotrauma
return false;
}
Pair<Order, float> existingOrder = ActiveOrders.Find(o => o.First.Prefab == order.Prefab && o.First.TargetEntity == order.TargetEntity);
Pair<Order, float?> existingOrder =
ActiveOrders.Find(o => o.First.Prefab == order.Prefab && o.First.TargetEntity == order.TargetEntity &&
(o.First.TargetType != Order.OrderTargetType.WallSection || o.First.WallSectionIndex == order.WallSectionIndex));
if (existingOrder != null)
{
existingOrder.Second = fadeOutTime;
@@ -54,32 +59,33 @@ namespace Barotrauma
}
else
{
ActiveOrders.Add(new Pair<Order, float>(order, fadeOutTime));
ActiveOrders.Add(new Pair<Order, float?>(order, fadeOutTime));
return true;
}
}
public void RemoveOrder(Order order)
{
ActiveOrders.RemoveAll(o => o.First == order);
}
public void AddCharacterElements(XElement element)
{
foreach (XElement subElement in element.Elements())
foreach (XElement characterElement in element.Elements())
{
if (!subElement.Name.ToString().Equals("character", StringComparison.OrdinalIgnoreCase)) { continue; }
if (!characterElement.Name.ToString().Equals("character", StringComparison.OrdinalIgnoreCase)) { continue; }
CharacterInfo characterInfo = new CharacterInfo(subElement);
CharacterInfo characterInfo = new CharacterInfo(characterElement);
#if CLIENT
if (subElement.GetAttributeBool("lastcontrolled", false)) { characterInfo.LastControlled = true; }
if (characterElement.GetAttributeBool("lastcontrolled", false)) { characterInfo.LastControlled = true; }
#endif
characterInfos.Add(characterInfo);
foreach (XElement invElement in subElement.Elements())
foreach (XElement subElement in characterElement.Elements())
{
if (!invElement.Name.ToString().Equals("inventory", StringComparison.OrdinalIgnoreCase)) { continue; }
characterInfo.InventoryData = invElement;
break;
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "inventory":
characterInfo.InventoryData = subElement;
break;
case "health":
characterInfo.HealthData = subElement;
break;
}
}
}
}
@@ -118,6 +124,12 @@ namespace Barotrauma
AddCharacterToCrewList(character);
AddCurrentOrderIcon(character, character.CurrentOrder, character.CurrentOrderOption);
#endif
var idleObjective = character.AIController?.ObjectiveManager?.GetObjective<AIObjectiveIdle>();
if (idleObjective != null)
{
idleObjective.Behavior = character.Info.Job.Prefab.IdleBehavior;
}
}
public void AddCharacterInfo(CharacterInfo characterInfo)
@@ -175,7 +187,7 @@ namespace Barotrauma
}
if (character.Info.InventoryData != null)
{
character.Info.SpawnInventoryItems(character.Inventory, character.Info.InventoryData);
character.SpawnInventoryItems(character.Inventory, character.Info.InventoryData);
}
else if (!character.Info.StartItemsGiven)
{
@@ -206,14 +218,19 @@ namespace Barotrauma
public void Update(float deltaTime)
{
foreach (Pair<Order, float> order in ActiveOrders)
foreach (Pair<Order, float?> order in ActiveOrders)
{
order.Second -= deltaTime;
if (order.Second.HasValue) { order.Second -= deltaTime; }
}
ActiveOrders.RemoveAll(o => o.Second <= 0.0f);
ActiveOrders.RemoveAll(o => o.Second.HasValue && o.Second <= 0.0f);
UpdateConversations(deltaTime);
UpdateProjectSpecific(deltaTime);
ActiveReadyCheck?.Update(deltaTime);
if (ActiveReadyCheck != null && ActiveReadyCheck.IsFinished)
{
ActiveReadyCheck = null;
}
}
#region Dialog
@@ -146,7 +146,7 @@ namespace Barotrauma
{
for (int i = 0; i < wall.SectionCount; i++)
{
wall.AddDamage(i, -wall.MaxHealth);
wall.SetDamage(i, 0, createNetworkEvent: false);
}
}
}
@@ -181,6 +181,11 @@ namespace Barotrauma
}
}
/// <summary>
/// Automatically cleared after triggering -> no need to unregister
/// </summary>
public event Action BeforeLevelLoading;
public void LoadNewLevel()
{
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient)
@@ -194,6 +199,9 @@ namespace Barotrauma
return;
}
BeforeLevelLoading?.Invoke();
BeforeLevelLoading = null;
if (Level.Loaded == null || Submarine.MainSub == null)
{
LoadInitialLevel();
@@ -504,6 +512,12 @@ namespace Barotrauma
Map.SetLocation(Map.Locations.IndexOf(Map.StartLocation));
Map.SelectLocation(-1);
EndCampaignProjSpecific();
if (CampaignMetadata != null)
{
int loops = CampaignMetadata.GetInt("campaign.endings", 0);
CampaignMetadata.SetValue("campaign.endings", loops + 1);
}
}
protected virtual void EndCampaignProjSpecific() { }
@@ -0,0 +1,11 @@
using System;
namespace Barotrauma
{
class CoOpMode : MissionMode
{
public CoOpMode(GameModePreset preset, MissionPrefab missionPrefab) : base(preset, ValidateMissionPrefab(missionPrefab, MissionPrefab.CoOpMissionClasses)) { }
public CoOpMode(GameModePreset preset, MissionType missionType, string seed) : base(preset, ValidateMissionType(missionType, MissionPrefab.CoOpMissionClasses), seed) { }
}
}
@@ -12,6 +12,7 @@ namespace Barotrauma
public static GameModePreset MultiPlayerCampaign;
public static GameModePreset Tutorial;
public static GameModePreset Mission;
public static GameModePreset PvP;
public static GameModePreset TestMode;
public static GameModePreset Sandbox;
public static GameModePreset DevSandbox;
@@ -51,7 +52,8 @@ namespace Barotrauma
TestMode = new GameModePreset("testmode", typeof(TestGameMode), true);
#endif
Sandbox = new GameModePreset("sandbox", typeof(GameMode), false);
Mission = new GameModePreset("mission", typeof(MissionMode), false);
Mission = new GameModePreset("mission", typeof(CoOpMode), false);
PvP = new GameModePreset("pvp", typeof(PvPMode), false);
MultiPlayerCampaign = new GameModePreset("multiplayercampaign", typeof(MultiPlayerCampaign), false, false);
}
}
@@ -1,6 +1,9 @@
namespace Barotrauma
using System;
using System.Collections.Generic;
namespace Barotrauma
{
partial class MissionMode : GameMode
abstract partial class MissionMode : GameMode
{
private readonly Mission mission;
@@ -25,5 +28,29 @@
Location[] locations = { GameMain.GameSession.StartLocation, GameMain.GameSession.EndLocation };
mission = Mission.LoadRandom(locations, seed, false, missionType);
}
protected static MissionPrefab ValidateMissionPrefab(MissionPrefab missionPrefab, Dictionary<MissionType, Type> missionClasses)
{
if (ValidateMissionType(missionPrefab.Type, missionClasses) != missionPrefab.Type)
{
throw new InvalidOperationException("Cannot start gamemode with mission type " + missionPrefab.Type);
}
return missionPrefab;
}
protected static MissionType ValidateMissionType(MissionType missionType, Dictionary<MissionType, Type> missionClasses)
{
var missionTypes = (MissionType[])Enum.GetValues(typeof(MissionType));
for (int i = 0; i < missionTypes.Length; i++)
{
var type = missionTypes[i];
if (type == MissionType.None || type == MissionType.All) { continue; }
if (!missionClasses.ContainsKey(type))
{
missionType &= ~(type);
}
}
return missionType;
}
}
}
@@ -0,0 +1,11 @@
using System;
namespace Barotrauma
{
class PvPMode : MissionMode
{
public PvPMode(GameModePreset preset, MissionPrefab missionPrefab) : base(preset, ValidateMissionPrefab(missionPrefab, MissionPrefab.PvPMissionClasses)) { }
public PvPMode(GameModePreset preset, MissionType missionType, string seed) : base(preset, ValidateMissionType(missionType, MissionPrefab.PvPMissionClasses), seed) { }
}
}
@@ -160,11 +160,17 @@ namespace Barotrauma
private GameMode InstantiateGameMode(GameModePreset gameModePreset, string seed, MissionPrefab missionPrefab = null, MissionType missionType = MissionType.None)
{
if (gameModePreset.GameModeType == typeof(MissionMode))
if (gameModePreset.GameModeType == typeof(CoOpMode))
{
return missionPrefab != null ?
new MissionMode(gameModePreset, missionPrefab) :
new MissionMode(gameModePreset, missionType, seed ?? ToolBox.RandomSeed(8));
new CoOpMode(gameModePreset, missionPrefab) :
new CoOpMode(gameModePreset, missionType, seed ?? ToolBox.RandomSeed(8));
}
else if (gameModePreset.GameModeType == typeof(PvPMode))
{
return missionPrefab != null ?
new PvPMode(gameModePreset, missionPrefab) :
new PvPMode(gameModePreset, missionType, seed ?? ToolBox.RandomSeed(8));
}
else if (gameModePreset.GameModeType == typeof(MultiPlayerCampaign))
{
@@ -382,7 +388,7 @@ namespace Barotrauma
}
Entity.Spawner = new EntitySpawner();
if (GameMode.Mission != null) { Mission = GameMode.Mission; }
if (GameMode != null) { GameMode.Start(); }
if (GameMode.Mission != null)
@@ -411,6 +417,7 @@ namespace Barotrauma
//the server does this after loading the respawn shuttle
Level?.SpawnNPCs();
Level?.SpawnCorpses();
Level?.PrepareBeaconStation();
AutoItemPlacer.PlaceIfNeeded();
}
if (GameMode is MultiPlayerCampaign mpCampaign)
@@ -0,0 +1,54 @@
#nullable enable
using System;
using System.Collections.Generic;
namespace Barotrauma
{
internal enum ReadyStatus
{
Unanswered,
Yes,
No,
}
internal partial class ReadyCheck
{
private readonly float endTime;
private float time;
public readonly Dictionary<byte, ReadyStatus> Clients;
public bool IsFinished = false;
public ReadyCheck(List<byte> clients, float duration = 30)
{
Clients = new Dictionary<byte, ReadyStatus>();
foreach (byte client in clients)
{
if (Clients.ContainsKey(client)) { continue; }
Clients.Add(client, ReadyStatus.Unanswered);
}
time = duration;
endTime = duration;
#if CLIENT
lastSecond = (int) Math.Ceiling(duration);
#endif
}
partial void EndReadyCheck();
public void Update(float deltaTime)
{
if (time > 0)
{
#if CLIENT
UpdateBar();
#endif
time -= deltaTime;
return;
}
EndReadyCheck();
}
}
}