Build 0.18.4.0
This commit is contained in:
+197
-101
@@ -37,7 +37,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (forceMapUI == value) { return; }
|
||||
forceMapUI = value;
|
||||
LastUpdateID++;
|
||||
IncrementLastUpdateIdForFlag(NetFlags.MapAndMissions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,11 +71,43 @@ namespace Barotrauma
|
||||
get { return ForceMapUI || CoroutineManager.IsCoroutineRunning("LevelTransition"); }
|
||||
}
|
||||
|
||||
public static void StartNewCampaign(string savePath, string subPath, string seed, CampaignSettings settings)
|
||||
private bool purchasedHullRepairs, purchasedLostShuttles, purchasedItemRepairs;
|
||||
public override bool PurchasedHullRepairs
|
||||
{
|
||||
get { return purchasedHullRepairs; }
|
||||
set
|
||||
{
|
||||
if (purchasedHullRepairs == value) { return; }
|
||||
purchasedHullRepairs = value;
|
||||
IncrementLastUpdateIdForFlag(NetFlags.Misc);
|
||||
}
|
||||
}
|
||||
public override bool PurchasedLostShuttles
|
||||
{
|
||||
get { return purchasedLostShuttles; }
|
||||
set
|
||||
{
|
||||
if (purchasedLostShuttles == value) { return; }
|
||||
purchasedLostShuttles = value;
|
||||
IncrementLastUpdateIdForFlag(NetFlags.Misc);
|
||||
}
|
||||
}
|
||||
public override bool PurchasedItemRepairs
|
||||
{
|
||||
get { return purchasedItemRepairs; }
|
||||
set
|
||||
{
|
||||
if (purchasedItemRepairs == value) { return; }
|
||||
purchasedItemRepairs = value;
|
||||
IncrementLastUpdateIdForFlag(NetFlags.Misc);
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartNewCampaign(string savePath, string subPath, string seed, CampaignSettings startingSettings)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(savePath)) { return; }
|
||||
|
||||
GameMain.GameSession = new GameSession(new SubmarineInfo(subPath), savePath, GameModePreset.MultiPlayerCampaign, settings, seed);
|
||||
GameMain.GameSession = new GameSession(new SubmarineInfo(subPath), savePath, GameModePreset.MultiPlayerCampaign, startingSettings, seed);
|
||||
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
|
||||
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
|
||||
|
||||
@@ -158,7 +190,7 @@ namespace Barotrauma
|
||||
public override void Start()
|
||||
{
|
||||
base.Start();
|
||||
lastUpdateID++;
|
||||
IncrementAllLastUpdateIds();
|
||||
}
|
||||
|
||||
private static bool IsOwner(Client client) => client != null && client.Connection == GameMain.Server.OwnerConnection;
|
||||
@@ -274,7 +306,7 @@ namespace Barotrauma
|
||||
|
||||
protected override IEnumerable<CoroutineStatus> DoLevelTransition(TransitionType transitionType, LevelData newLevel, Submarine leavingSub, bool mirror, List<TraitorMissionResult> traitorResults)
|
||||
{
|
||||
lastUpdateID++;
|
||||
IncrementAllLastUpdateIds();
|
||||
|
||||
switch (transitionType)
|
||||
{
|
||||
@@ -321,6 +353,7 @@ namespace Barotrauma
|
||||
yield return CoroutineStatus.Running;
|
||||
LeaveUnconnectedSubs(leavingSub);
|
||||
NextLevel = newLevel;
|
||||
GameMain.GameSession.SubmarineInfo = new SubmarineInfo(GameMain.GameSession.Submarine);
|
||||
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
|
||||
}
|
||||
else
|
||||
@@ -329,7 +362,7 @@ namespace Barotrauma
|
||||
GameMain.Server.EndGame(TransitionType.None, wasSaved: false);
|
||||
LoadCampaign(GameMain.GameSession.SavePath);
|
||||
LastSaveID++;
|
||||
LastUpdateID++;
|
||||
IncrementAllLastUpdateIds();
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
@@ -360,14 +393,14 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
partial void InitProjSpecific()
|
||||
{
|
||||
CargoManager.OnItemsInBuyCrateChanged += () => { LastUpdateID++; };
|
||||
CargoManager.OnPurchasedItemsChanged += () => { LastUpdateID++; };
|
||||
CargoManager.OnSoldItemsChanged += () => { LastUpdateID++; };
|
||||
UpgradeManager.OnUpgradesChanged += () => { LastUpdateID++; };
|
||||
Map.OnLocationSelected += (loc, connection) => { LastUpdateID++; };
|
||||
Map.OnMissionsSelected += (loc, mission) => { LastUpdateID++; };
|
||||
Reputation.OnAnyReputationValueChanged += () => { LastUpdateID++; };
|
||||
{
|
||||
CargoManager.OnItemsInBuyCrateChanged += () => { IncrementLastUpdateIdForFlag(NetFlags.ItemsInBuyCrate); };
|
||||
CargoManager.OnPurchasedItemsChanged += () => { IncrementLastUpdateIdForFlag(NetFlags.PurchasedItems); };
|
||||
CargoManager.OnSoldItemsChanged += () => { IncrementLastUpdateIdForFlag(NetFlags.SoldItems); };
|
||||
UpgradeManager.OnUpgradesChanged += () => { IncrementLastUpdateIdForFlag(NetFlags.UpgradeManager); };
|
||||
Map.OnLocationSelected += (loc, connection) => { IncrementLastUpdateIdForFlag(NetFlags.MapAndMissions); };
|
||||
Map.OnMissionsSelected += (loc, mission) => { IncrementLastUpdateIdForFlag(NetFlags.MapAndMissions); };
|
||||
Reputation.OnAnyReputationValueChanged += () => { IncrementLastUpdateIdForFlag(NetFlags.Reputation); };
|
||||
|
||||
//increment save ID so clients know they're lacking the most up-to-date save file
|
||||
LastSaveID++;
|
||||
@@ -388,6 +421,7 @@ namespace Barotrauma
|
||||
discardedCharacters.Add(data);
|
||||
}
|
||||
characterData.Remove(data);
|
||||
IncrementLastUpdateIdForFlag(NetFlags.CharacterInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -402,6 +436,7 @@ namespace Barotrauma
|
||||
characterData.RemoveAll(cd => cd.MatchesClient(client));
|
||||
var data = new CharacterCampaignData(client);
|
||||
characterData.Add(data);
|
||||
IncrementLastUpdateIdForFlag(NetFlags.CharacterInfo);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -413,6 +448,7 @@ namespace Barotrauma
|
||||
var matchingData = GetClientCharacterData(client);
|
||||
if (matchingData != null) { client.CharacterInfo = matchingData.CharacterInfo; }
|
||||
}
|
||||
IncrementLastUpdateIdForFlag(NetFlags.CharacterInfo);
|
||||
}
|
||||
|
||||
public Dictionary<Client, Job> GetAssignedJobs(IEnumerable<Client> connectedClients)
|
||||
@@ -517,127 +553,187 @@ namespace Barotrauma
|
||||
base.End(transitionType);
|
||||
}
|
||||
|
||||
private bool IsFlagRequired(Client c, NetFlags flag)
|
||||
=> !c.LastRecvCampaignUpdate.TryGetValue(flag, out var id) || NetIdUtils.IdMoreRecent(GetLastUpdateIdForFlag(flag), id);
|
||||
|
||||
public void ServerWrite(IWriteMessage msg, Client c)
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(map.Locations.Count < UInt16.MaxValue);
|
||||
|
||||
Reputation reputation = Map?.CurrentLocation?.Reputation;
|
||||
NetFlags requiredFlags = lastUpdateID.Keys.Where(k => IsFlagRequired(c, k)).Aggregate((NetFlags)0, (f1, f2) => f1 | f2);
|
||||
|
||||
msg.Write((UInt16)requiredFlags);
|
||||
|
||||
msg.Write(IsFirstRound);
|
||||
msg.Write(CampaignID);
|
||||
msg.Write(lastUpdateID);
|
||||
msg.Write(lastSaveID);
|
||||
msg.Write(map.Seed);
|
||||
msg.Write(map.CurrentLocationIndex == -1 ? UInt16.MaxValue : (UInt16)map.CurrentLocationIndex);
|
||||
msg.Write(map.SelectedLocationIndex == -1 ? UInt16.MaxValue : (UInt16)map.SelectedLocationIndex);
|
||||
|
||||
var selectedMissionIndices = map.GetSelectedMissionIndices();
|
||||
msg.Write((byte)selectedMissionIndices.Count());
|
||||
foreach (int selectedMissionIndex in selectedMissionIndices)
|
||||
|
||||
if (requiredFlags.HasFlag(NetFlags.Misc))
|
||||
{
|
||||
msg.Write((byte)selectedMissionIndex);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.Misc));
|
||||
msg.Write(PurchasedHullRepairs);
|
||||
msg.Write(PurchasedItemRepairs);
|
||||
msg.Write(PurchasedLostShuttles);
|
||||
}
|
||||
|
||||
var subList = GameMain.NetLobbyScreen.GetSubList();
|
||||
List<int> ownedSubmarineIndices = new List<int>();
|
||||
for (int i = 0; i < subList.Count; i++)
|
||||
if (requiredFlags.HasFlag(NetFlags.MapAndMissions))
|
||||
{
|
||||
if (GameMain.GameSession.OwnedSubmarines.Any(s => s.Name == subList[i].Name))
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.MapAndMissions));
|
||||
msg.Write(ForceMapUI);
|
||||
msg.Write(map.AllowDebugTeleport);
|
||||
msg.Write(map.CurrentLocationIndex == -1 ? UInt16.MaxValue : (UInt16)map.CurrentLocationIndex);
|
||||
msg.Write(map.SelectedLocationIndex == -1 ? UInt16.MaxValue : (UInt16)map.SelectedLocationIndex);
|
||||
|
||||
if (map.CurrentLocation != null)
|
||||
{
|
||||
ownedSubmarineIndices.Add(i);
|
||||
}
|
||||
}
|
||||
msg.Write((ushort)ownedSubmarineIndices.Count);
|
||||
foreach (int index in ownedSubmarineIndices)
|
||||
{
|
||||
msg.Write((ushort)index);
|
||||
}
|
||||
|
||||
msg.Write(map.AllowDebugTeleport);
|
||||
msg.Write(reputation != null);
|
||||
if (reputation != null) { msg.Write(reputation.Value); }
|
||||
|
||||
// hopefully we'll never have more than 128 factions
|
||||
msg.Write((byte)Factions.Count);
|
||||
foreach (Faction faction in Factions)
|
||||
{
|
||||
msg.Write(faction.Prefab.Identifier);
|
||||
msg.Write(faction.Reputation.Value);
|
||||
}
|
||||
|
||||
msg.Write(ForceMapUI);
|
||||
|
||||
msg.Write(PurchasedHullRepairs);
|
||||
msg.Write(PurchasedItemRepairs);
|
||||
msg.Write(PurchasedLostShuttles);
|
||||
|
||||
if (map.CurrentLocation != null)
|
||||
{
|
||||
msg.Write((byte)map.CurrentLocation?.AvailableMissions.Count());
|
||||
foreach (Mission mission in map.CurrentLocation.AvailableMissions)
|
||||
{
|
||||
msg.Write(mission.Prefab.Identifier);
|
||||
if (mission.Locations[0] == mission.Locations[1])
|
||||
msg.Write((byte)map.CurrentLocation.AvailableMissions.Count());
|
||||
foreach (Mission mission in map.CurrentLocation.AvailableMissions)
|
||||
{
|
||||
msg.Write((byte)255);
|
||||
}
|
||||
else
|
||||
{
|
||||
Location missionDestination = mission.Locations[0] == map.CurrentLocation ? mission.Locations[1] : mission.Locations[0];
|
||||
LocationConnection connection = map.CurrentLocation.Connections.Find(c => c.OtherLocation(map.CurrentLocation) == missionDestination);
|
||||
msg.Write((byte)map.CurrentLocation.Connections.IndexOf(connection));
|
||||
msg.Write(mission.Prefab.Identifier);
|
||||
if (mission.Locations[0] == mission.Locations[1])
|
||||
{
|
||||
msg.Write((byte)255);
|
||||
}
|
||||
else
|
||||
{
|
||||
Location missionDestination = mission.Locations[0] == map.CurrentLocation ? mission.Locations[1] : mission.Locations[0];
|
||||
LocationConnection connection = map.CurrentLocation.Connections.Find(c => c.OtherLocation(map.CurrentLocation) == missionDestination);
|
||||
msg.Write((byte)map.CurrentLocation.Connections.IndexOf(connection));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store balance
|
||||
bool hasStores = map.CurrentLocation.Stores != null && map.CurrentLocation.Stores.Any();
|
||||
msg.Write(hasStores);
|
||||
if (hasStores)
|
||||
else
|
||||
{
|
||||
msg.Write((byte)map.CurrentLocation.Stores.Count);
|
||||
foreach (var store in map.CurrentLocation.Stores.Values)
|
||||
msg.Write((byte)0);
|
||||
}
|
||||
|
||||
var selectedMissionIndices = map.GetSelectedMissionIndices();
|
||||
msg.Write((byte)selectedMissionIndices.Count());
|
||||
foreach (int selectedMissionIndex in selectedMissionIndices)
|
||||
{
|
||||
msg.Write((byte)selectedMissionIndex);
|
||||
}
|
||||
|
||||
WriteStores(msg);
|
||||
}
|
||||
|
||||
if (requiredFlags.HasFlag(NetFlags.SubList))
|
||||
{
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.SubList));
|
||||
var subList = GameMain.NetLobbyScreen.GetSubList();
|
||||
List<int> ownedSubmarineIndices = new List<int>();
|
||||
for (int i = 0; i < subList.Count; i++)
|
||||
{
|
||||
if (GameMain.GameSession.OwnedSubmarines.Any(s => s.Name == subList[i].Name))
|
||||
{
|
||||
msg.Write(store.Identifier);
|
||||
msg.Write((UInt16)store.Balance);
|
||||
ownedSubmarineIndices.Add(i);
|
||||
}
|
||||
}
|
||||
msg.Write((ushort)ownedSubmarineIndices.Count);
|
||||
foreach (int index in ownedSubmarineIndices)
|
||||
{
|
||||
msg.Write((ushort)index);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (requiredFlags.HasFlag(NetFlags.UpgradeManager))
|
||||
{
|
||||
msg.Write((byte)0);
|
||||
// Store balance
|
||||
msg.Write(false);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.UpgradeManager));
|
||||
msg.Write((ushort)UpgradeManager.PendingUpgrades.Count);
|
||||
foreach (var (prefab, category, level) in UpgradeManager.PendingUpgrades)
|
||||
{
|
||||
msg.Write(prefab.Identifier);
|
||||
msg.Write(category.Identifier);
|
||||
msg.Write((byte)level);
|
||||
}
|
||||
msg.Write((ushort)UpgradeManager.PurchasedItemSwaps.Count);
|
||||
foreach (var itemSwap in UpgradeManager.PurchasedItemSwaps)
|
||||
{
|
||||
msg.Write(itemSwap.ItemToRemove.ID);
|
||||
msg.Write(itemSwap.ItemToInstall?.Identifier ?? Identifier.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
WriteItems(msg, CargoManager.ItemsInBuyCrate);
|
||||
WriteItems(msg, CargoManager.ItemsInSellFromSubCrate);
|
||||
WriteItems(msg, CargoManager.PurchasedItems);
|
||||
WriteItems(msg, CargoManager.SoldItems);
|
||||
|
||||
msg.Write((ushort)UpgradeManager.PendingUpgrades.Count);
|
||||
foreach (var (prefab, category, level) in UpgradeManager.PendingUpgrades)
|
||||
if (requiredFlags.HasFlag(NetFlags.ItemsInBuyCrate))
|
||||
{
|
||||
msg.Write(prefab.Identifier);
|
||||
msg.Write(category.Identifier);
|
||||
msg.Write((byte)level);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.ItemsInBuyCrate));
|
||||
WriteItems(msg, CargoManager.ItemsInBuyCrate);
|
||||
WriteStores(msg);
|
||||
}
|
||||
|
||||
msg.Write((ushort)UpgradeManager.PurchasedItemSwaps.Count);
|
||||
foreach (var itemSwap in UpgradeManager.PurchasedItemSwaps)
|
||||
if (requiredFlags.HasFlag(NetFlags.ItemsInSellFromSubCrate))
|
||||
{
|
||||
msg.Write(itemSwap.ItemToRemove.ID);
|
||||
msg.Write(itemSwap.ItemToInstall?.Identifier ?? Identifier.Empty);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.ItemsInSellFromSubCrate));
|
||||
WriteItems(msg, CargoManager.ItemsInSellFromSubCrate);
|
||||
WriteStores(msg);
|
||||
}
|
||||
|
||||
var characterData = GetClientCharacterData(c);
|
||||
if (characterData?.CharacterInfo == null)
|
||||
if (requiredFlags.HasFlag(NetFlags.PurchasedItems))
|
||||
{
|
||||
msg.Write(false);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.PurchasedItems));
|
||||
WriteItems(msg, CargoManager.PurchasedItems);
|
||||
WriteStores(msg);
|
||||
|
||||
}
|
||||
else
|
||||
if (requiredFlags.HasFlag(NetFlags.SoldItems))
|
||||
{
|
||||
msg.Write(true);
|
||||
characterData.CharacterInfo.ServerWrite(msg);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.SoldItems));
|
||||
WriteItems(msg, CargoManager.SoldItems);
|
||||
WriteStores(msg);
|
||||
}
|
||||
if (requiredFlags.HasFlag(NetFlags.Reputation))
|
||||
{
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.Reputation));
|
||||
Reputation reputation = Map?.CurrentLocation?.Reputation;
|
||||
msg.Write(reputation != null);
|
||||
if (reputation != null) { msg.Write(reputation.Value); }
|
||||
|
||||
// hopefully we'll never have more than 128 factions
|
||||
msg.Write((byte)Factions.Count);
|
||||
foreach (Faction faction in Factions)
|
||||
{
|
||||
msg.Write(faction.Prefab.Identifier);
|
||||
msg.Write(faction.Reputation.Value);
|
||||
}
|
||||
}
|
||||
if (requiredFlags.HasFlag(NetFlags.CharacterInfo))
|
||||
{
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.CharacterInfo));
|
||||
var characterData = GetClientCharacterData(c);
|
||||
if (characterData?.CharacterInfo == null)
|
||||
{
|
||||
msg.Write(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Write(true);
|
||||
characterData.CharacterInfo.ServerWrite(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteStores(IWriteMessage msg)
|
||||
{
|
||||
if (map.CurrentLocation != null)
|
||||
{
|
||||
// Store balance
|
||||
bool hasStores = map.CurrentLocation.Stores != null && map.CurrentLocation.Stores.Any();
|
||||
msg.Write(hasStores);
|
||||
if (hasStores)
|
||||
{
|
||||
msg.Write((byte)map.CurrentLocation.Stores.Count);
|
||||
foreach (var store in map.CurrentLocation.Stores.Values)
|
||||
{
|
||||
msg.Write(store.Identifier);
|
||||
msg.Write((UInt16)store.Balance);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Write((byte)0);
|
||||
// Store balance
|
||||
msg.Write(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user