Barotrauma Server
Loading...
Searching...
No Matches
Barotrauma.UpgradeManager Class Reference

This class handles all upgrade logic. Storing, applying, checking and validation of upgrades. More...

Public Member Functions

 UpgradeManager (CampaignMode campaign)
 
 UpgradeManager (CampaignMode campaign, XElement element, bool isSingleplayer)
 
int DetermineItemSwapCost (Item item, ItemPrefab? replacement)
 
void PurchaseUpgrade (UpgradePrefab prefab, UpgradeCategory category, bool force=false, Client? client=null)
 Purchases an upgrade and handles logic for deducting the credit.
 
void AddUpgradeExternally (UpgradePrefab prefab, UpgradeCategory category, int level)
 Used for purchasing upgrades from outside the upgrade store. Doesn't deduct the credit, adds the upgrade to the pending list and performs a level sanity check.
 
void PurchaseItemSwap (Item itemToRemove, ItemPrefab itemToInstall, bool isNetworkMessage=false, Client? client=null)
 Purchases an item swap and handles logic for deducting the credit.
 
void CancelItemSwap (Item itemToRemove, bool force=false)
 Cancels the currently pending item swap, or uninstalls the item if there's no swap pending.
 
void ApplyUpgrades ()
 Applies all our pending upgrades to the submarine.
 
void CreateUpgradeErrorMessage (string text, bool isSinglePlayer, Character character)
 
void SanityCheckUpgrades ()
 Validates that upgrade values stored in CampaignMetadata matches the values on the submarine and fixes any inconsistencies. Should be called after every round start right after ApplyUpgrades
 
int GetUpgradeLevel (UpgradePrefab prefab, UpgradeCategory category, SubmarineInfo? info=null)
 Gets the progress that is shown on the store interface. Includes values stored in the metadata and PendingUpgrades, and takes submarine tier and class restrictions into account.
 
int GetRealUpgradeLevel (UpgradePrefab prefab, UpgradeCategory category)
 Gets the level of the upgrade that is stored in the metadata. May be higher than the apparent level on the current sub if the player has switched to a lower-tier sub.
 
int GetRealUpgradeLevelForSub (UpgradePrefab prefab, UpgradeCategory category, SubmarineInfo info)
 Gets the level of the upgrade that is stored in the metadata. Takes into account the limits of the provided submarine.
 
bool CanUpgradeSub ()
 
void Save (XElement? parent)
 
void SetPendingUpgrades (List< PurchasedUpgrade > upgrades)
 Used to sync the pending upgrades list in multiplayer.
 

Static Public Member Functions

static ICollection< ItemGetLinkedItemsToSwap (Item item)
 
static void LogError (string text, Dictionary< string, object?> data, Exception? e=null)
 
static void DebugLog (string msg, Color? color=null)
 

Public Attributes

readonly List< PurchasedUpgrade > PurchasedUpgrades = new List<PurchasedUpgrade>()
 This is used by the client to notify the server which upgrades are yet to be paid for.
 
readonly List< PurchasedUpgrade > PendingUpgrades = new List<PurchasedUpgrade>()
 
readonly List< PurchasedItemSwap > PurchasedItemSwaps = new List<PurchasedItemSwap>()
 
readonly NamedEvent< UpgradeManagerOnUpgradesChanged = new NamedEvent<UpgradeManager>()
 

Static Public Attributes

const bool UpgradeAlsoConnectedSubs = true
 This one toggles whether or not connected submarines get upgraded too. Could probably be removed, I just didn't like magic numbers.
 

Detailed Description

This class handles all upgrade logic. Storing, applying, checking and validation of upgrades.

Upgrades are applied per item basis meaning each item has their own set of slots for upgrades. The store applies upgrades globally to categories of items so the purpose of this class is to keep those individual "upgrade slots" in sync. The target level of an upgrade is stored in the metadata and is what the store displays and modifies while this class will make sure that the upgrades on the items match the values stored in the metadata.

Constructor & Destructor Documentation

◆ UpgradeManager() [1/2]

Barotrauma.UpgradeManager.UpgradeManager ( CampaignMode campaign)

◆ UpgradeManager() [2/2]

Barotrauma.UpgradeManager.UpgradeManager ( CampaignMode campaign,
XElement element,
bool isSingleplayer )

Member Function Documentation

◆ AddUpgradeExternally()

void Barotrauma.UpgradeManager.AddUpgradeExternally ( UpgradePrefab prefab,
UpgradeCategory category,
int level )

Used for purchasing upgrades from outside the upgrade store. Doesn't deduct the credit, adds the upgrade to the pending list and performs a level sanity check.

◆ ApplyUpgrades()

void Barotrauma.UpgradeManager.ApplyUpgrades ( )

Applies all our pending upgrades to the submarine.

Upgrades are applied similarly to how items on the submarine are spawned at the start of the round. Upgrades should be applied at the start of the round and after the round ends they are written into the submarine save and saved there. Because of the difficulty of accessing the actual Submarine object from and outpost or when the campaign UI is created we modify levels that are shown on the store interface using campaign metadata.

This method should be called by both the client and the server during level generation. SetUpgradeLevel

See also
GetUpgradeLevel

◆ CancelItemSwap()

void Barotrauma.UpgradeManager.CancelItemSwap ( Item itemToRemove,
bool force = false )

Cancels the currently pending item swap, or uninstalls the item if there's no swap pending.

◆ CanUpgradeSub()

bool Barotrauma.UpgradeManager.CanUpgradeSub ( )

◆ CreateUpgradeErrorMessage()

void Barotrauma.UpgradeManager.CreateUpgradeErrorMessage ( string text,
bool isSinglePlayer,
Character character )

◆ DebugLog()

static void Barotrauma.UpgradeManager.DebugLog ( string msg,
Color? color = null )
static

◆ DetermineItemSwapCost()

int Barotrauma.UpgradeManager.DetermineItemSwapCost ( Item item,
ItemPrefab? replacement )

◆ GetLinkedItemsToSwap()

static ICollection< Item > Barotrauma.UpgradeManager.GetLinkedItemsToSwap ( Item item)
static

◆ GetRealUpgradeLevel()

int Barotrauma.UpgradeManager.GetRealUpgradeLevel ( UpgradePrefab prefab,
UpgradeCategory category )

Gets the level of the upgrade that is stored in the metadata. May be higher than the apparent level on the current sub if the player has switched to a lower-tier sub.

◆ GetRealUpgradeLevelForSub()

int Barotrauma.UpgradeManager.GetRealUpgradeLevelForSub ( UpgradePrefab prefab,
UpgradeCategory category,
SubmarineInfo info )

Gets the level of the upgrade that is stored in the metadata. Takes into account the limits of the provided submarine.

◆ GetUpgradeLevel()

int Barotrauma.UpgradeManager.GetUpgradeLevel ( UpgradePrefab prefab,
UpgradeCategory category,
SubmarineInfo? info = null )

Gets the progress that is shown on the store interface. Includes values stored in the metadata and PendingUpgrades, and takes submarine tier and class restrictions into account.

Parameters
infoSubmarine used to determine the upgrade limit. If not defined, will default to the current sub.

◆ LogError()

static void Barotrauma.UpgradeManager.LogError ( string text,
Dictionary< string, object?> data,
Exception? e = null )
static

◆ PurchaseItemSwap()

void Barotrauma.UpgradeManager.PurchaseItemSwap ( Item itemToRemove,
ItemPrefab itemToInstall,
bool isNetworkMessage = false,
Client? client = null )

Purchases an item swap and handles logic for deducting the credit.

◆ PurchaseUpgrade()

void Barotrauma.UpgradeManager.PurchaseUpgrade ( UpgradePrefab prefab,
UpgradeCategory category,
bool force = false,
Client? client = null )

Purchases an upgrade and handles logic for deducting the credit.

Purchased upgrades are temporarily stored in PendingUpgrades and they are applied after the next round starts similarly how items are spawned in the stowage room after the round starts.

◆ SanityCheckUpgrades()

void Barotrauma.UpgradeManager.SanityCheckUpgrades ( )

Validates that upgrade values stored in CampaignMetadata matches the values on the submarine and fixes any inconsistencies. Should be called after every round start right after ApplyUpgrades

Parameters
submarine

◆ Save()

void Barotrauma.UpgradeManager.Save ( XElement? parent)

◆ SetPendingUpgrades()

void Barotrauma.UpgradeManager.SetPendingUpgrades ( List< PurchasedUpgrade > upgrades)

Used to sync the pending upgrades list in multiplayer.

Parameters
upgrades

Member Data Documentation

◆ OnUpgradesChanged

readonly NamedEvent<UpgradeManager> Barotrauma.UpgradeManager.OnUpgradesChanged = new NamedEvent<UpgradeManager>()

◆ PendingUpgrades

readonly List<PurchasedUpgrade> Barotrauma.UpgradeManager.PendingUpgrades = new List<PurchasedUpgrade>()

◆ PurchasedItemSwaps

readonly List<PurchasedItemSwap> Barotrauma.UpgradeManager.PurchasedItemSwaps = new List<PurchasedItemSwap>()

◆ PurchasedUpgrades

readonly List<PurchasedUpgrade> Barotrauma.UpgradeManager.PurchasedUpgrades = new List<PurchasedUpgrade>()

This is used by the client to notify the server which upgrades are yet to be paid for.

In singleplayer this does nothing.

◆ UpgradeAlsoConnectedSubs

const bool Barotrauma.UpgradeManager.UpgradeAlsoConnectedSubs = true
static

This one toggles whether or not connected submarines get upgraded too. Could probably be removed, I just didn't like magic numbers.


The documentation for this class was generated from the following files: