Barotrauma Client Doc
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. More...
 
void PurchaseItemSwap (Item itemToRemove, ItemPrefab itemToInstall, bool force=false, Client? client=null)
 Purchases an item swap and handles logic for deducting the credit. More...
 
void CancelItemSwap (Item itemToRemove, bool force=false)
 Cancels the currently pending item swap, or uninstalls the item if there's no swap pending More...
 
void ApplyUpgrades ()
 Applies all our pending upgrades to the submarine. More...
 
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 More...
 
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 More...
 
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 More...
 
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. More...
 
bool CanUpgradeSub ()
 
void Save (XElement? parent)
 
void SetPendingUpgrades (List< PurchasedUpgrade > upgrades)
 Used to sync the pending upgrades list in multiplayer. More...
 

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. More...
 
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. More...
 

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.

Definition at line 55 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.

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

◆ 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

Definition at line 479 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.

◆ 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

Definition at line 385 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.

◆ 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

Definition at line 717 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.

◆ 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.

Definition at line 725 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.

◆ 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.

Definition at line 700 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.

◆ 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  force = false,
Client client = null 
)

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

Definition at line 284 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.

◆ 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.

Definition at line 172 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.

◆ 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

Definition at line 546 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.

◆ 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

Definition at line 825 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.

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.

Definition at line 78 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.

◆ 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.

Definition at line 61 of file BarotraumaShared/SharedSource/GameSession/UpgradeManager.cs.