4 using Microsoft.Xna.Framework;
6 using System.Collections.Generic;
21 ItemsInBuyCrate = 0x10,
22 ItemsInSellFromSubCrate = 0x20,
23 PurchasedItems = 0x80,
29 private readonly Dictionary<NetFlags, UInt16> lastUpdateID;
33 if (!ValidateFlag(flag)) {
return 0; }
34 return lastUpdateID[flag];
38 if (!ValidateFlag(flag)) {
return; }
39 lastUpdateID[flag] = id;
44 if (!ValidateFlag(flag)) {
return; }
45 if (!lastUpdateID.ContainsKey(flag)) { lastUpdateID[flag] = 0; }
52 if (!lastUpdateID.ContainsKey(flag)) { lastUpdateID[flag] = 0; }
57 private static bool ValidateFlag(
NetFlags flag)
59 if (MathHelper.IsPowerOfTwo((
int)flag)) {
return true; }
61 throw new InvalidOperationException($
"\"{flag}\" is not a valid campaign update flag.");
68 private UInt16 lastSaveID;
74 if (
GameMain.Server !=
null && lastSaveID < 1) { lastSaveID++; }
88 private static byte currentCampaignID;
98 lastUpdateID =
new Dictionary<NetFlags, ushort>();
103 lastUpdateID[flag] = 1;
105 lastUpdateID[flag] = 0;
120 campaign.
map =
new Map(campaign, mapSeed);
122 campaign.InitProjSpecific();
129 campaign.Load(element);
130 campaign.InitProjSpecific();
135 partial
void InitProjSpecific();
139 return Path.Combine(Path.GetDirectoryName(savePath), Path.GetFileNameWithoutExtension(savePath) +
"_CharacterData.xml");
150 private void Load(XElement element)
153 PurchasedHullRepairsInLatestSave = element.GetAttributeBool(
"purchasedhullrepairs",
false);
154 PurchasedItemRepairsInLatestSave = element.GetAttributeBool(
"purchaseditemrepairs",
false);
155 CheatsEnabled = element.GetAttributeBool(
"cheatsenabled",
false);
158 DebugConsole.CheatsEnabled =
true;
159 if (!AchievementManager.CheatsEnabled)
161 AchievementManager.CheatsEnabled =
true;
163 new GUIMessageBox(
"Cheats enabled",
"Cheat commands have been enabled on the server. You will not receive achievements until you restart the game.");
165 DebugConsole.NewMessage(
"Cheat commands have been enabled.", Color.Red);
170 foreach (var subElement
in element.Elements())
172 switch (subElement.Name.ToString().ToLowerInvariant())
174 case CampaignSettings.LowerCaseSaveElementName:
175 Settings =
new CampaignSettings(subElement);
177 GameMain.NetworkMember.ServerSettings.CampaignSettings =
Settings;
195 var prevReputations =
Factions.ToDictionary(k => k, v => v.Reputation.Value);
199 if (!MathUtils.NearlyEqual(prevReputations[faction], faction.Reputation.Value))
201 faction.Reputation.OnReputationValueChanged?.Invoke(faction.Reputation);
202 Reputation.OnAnyReputationValueChanged.Invoke(faction.Reputation);
206 case "upgrademanager":
207 case "pendingupgrades":
210 case "bots" when GameMain.NetworkMember !=
null && GameMain.NetworkMember.IsServer:
225 GameMain.GameSession.EventManager.Load(subElement);
227 case Wallet.LowerCaseSaveElementName:
231 case "traitormanager":
232 GameMain.Server?.TraitorManager?.Load(subElement);
234 case "savedexperiencepoints":
235 foreach (XElement savedExp
in subElement.Elements())
237 savedExperiencePoints.Add(
new SavedExperiencePoints(savedExp));
244 int oldMoney = element.GetAttributeInt(
"money", 0);
256 characterData.Clear();
258 if (!File.Exists(characterDataPath))
260 DebugConsole.ThrowError($
"Failed to load the character data for the campaign. Could not find the file \"{characterDataPath}\".");
264 var characterDataDoc = XMLExtensions.TryLoadXml(characterDataPath);
265 if (characterDataDoc?.Root ==
null) {
return; }
266 foreach (var subElement
in characterDataDoc.Root.Elements())
268 characterData.Add(
new CharacterCampaignData(subElement));
278 => s.
Name.Equals(h, StringComparison.OrdinalIgnoreCase));
288 List<SubmarineInfo> campaignSubs =
292 && isSubmarineVisible(s))
295 if (!campaignSubs.Any())
298 campaignSubs.AddRange(availableSubs.Where(isSubmarineVisible));
301 if (!campaignSubs.Any())
310 private static void WriteItems(
IWriteMessage msg, Dictionary<Identifier, List<PurchasedItem>> purchasedItems)
312 msg.
WriteByte((
byte)purchasedItems.Count);
313 foreach (var storeItems
in purchasedItems)
317 foreach (var item
in storeItems.Value)
326 private static Dictionary<Identifier, List<PurchasedItem>> ReadPurchasedItems(
IReadMessage msg,
Client sender)
328 var items =
new Dictionary<Identifier, List<PurchasedItem>>();
330 for (
int i = 0; i < storeCount; i++)
333 items.Add(storeId,
new List<PurchasedItem>());
335 for (
int j = 0; j < itemCount; j++)
343 items[storeId].Add(
new PurchasedItem(itemId, quantity, sender) { DeliverImmediately = deliverImmediately });
349 private static void WriteItems(
IWriteMessage msg, Dictionary<Identifier, List<SoldItem>> soldItems)
352 foreach (var storeItems
in soldItems)
356 foreach (var item
in storeItems.Value)
367 private static Dictionary<Identifier, List<SoldItem>> ReadSoldItems(
IReadMessage msg)
369 var soldItems =
new Dictionary<Identifier, List<SoldItem>>();
371 for (
int i = 0; i < storeCount; i++)
374 soldItems.Add(storeId,
new List<SoldItem>());
376 for (
int j = 0; j < itemCount; j++)
383 soldItems[storeId].Add(
new SoldItem(ItemPrefab.Prefabs[prefabId], itemId, removed, sellerId, (SoldItem.SellOrigin)origin));
UpgradeManager UpgradeManager
void LoadStats(XElement element)
static bool AllowImmediateItemDelivery()
bool PurchasedLostShuttlesInLatestSave
readonly CampaignMetadata CampaignMetadata
CampaignSettings Settings
IReadOnlyList< Faction > Factions
XElement ActiveOrdersElement
readonly CargoManager CargoManager
void LoadPurchasedItems(XElement element)
Stores information about the Character that is needed between rounds in the menu etc....
void AddCharacterElements(XElement element)
static GameSession?? GameSession
static NetLobbyScreen NetLobbyScreen
static NetworkMember NetworkMember
void LoadState(CampaignMode campaign, XElement element, bool showNotifications)
Load the state of an existing map from xml (current state of locations, where the crew is now,...
static Map Load(CampaignMode campaign, XElement element)
Load a previously saved map from an xml element
static string GetCharacterDataSavePath()
static List< SubmarineInfo > GetCampaignSubs()
static string GetCharacterDataSavePath(string savePath)
void IncrementAllLastUpdateIds()
static MultiPlayerCampaign LoadNew(XElement element)
void IncrementLastUpdateIdForFlag(NetFlags flag)
void SetLastUpdateIdForFlag(NetFlags flag, UInt16 id)
static MultiPlayerCampaign StartNew(string mapSeed, CampaignSettings settings)
UInt16 GetLastUpdateIdForFlag(NetFlags flag)
SubmarineInfo SelectedSub
readonly List< SubmarineInfo > ServerSubmarines
bool IsCampaignCompatible
static IEnumerable< SubmarineInfo > SavedSubmarines
This class handles all upgrade logic. Storing, applying, checking and validation of upgrades.
int ReadRangedInteger(int min, int max)
Identifier ReadIdentifier()
void WriteRangedInteger(int val, int min, int max)
void WriteBoolean(bool val)
void WriteUInt16(UInt16 val)
void WriteIdentifier(Identifier val)