Barotrauma Client
|
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< Item > | GetLinkedItemsToSwap (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< UpgradeManager > | OnUpgradesChanged = 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. | |
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.
Barotrauma.UpgradeManager.UpgradeManager | ( | CampaignMode | campaign | ) |
Barotrauma.UpgradeManager.UpgradeManager | ( | CampaignMode | campaign, |
XElement | element, | ||
bool | isSingleplayer ) |
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.
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
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.
bool Barotrauma.UpgradeManager.CanUpgradeSub | ( | ) |
void Barotrauma.UpgradeManager.CreateUpgradeErrorMessage | ( | string | text, |
bool | isSinglePlayer, | ||
Character | character ) |
|
static |
int Barotrauma.UpgradeManager.DetermineItemSwapCost | ( | Item | item, |
ItemPrefab? | replacement ) |
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.
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.
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.
info | Submarine used to determine the upgrade limit. If not defined, will default to the current sub. |
|
static |
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.
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.
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
submarine |
void Barotrauma.UpgradeManager.Save | ( | XElement? | parent | ) |
void Barotrauma.UpgradeManager.SetPendingUpgrades | ( | List< PurchasedUpgrade > | upgrades | ) |
Used to sync the pending upgrades list in multiplayer.
upgrades |
readonly NamedEvent<UpgradeManager> Barotrauma.UpgradeManager.OnUpgradesChanged = new NamedEvent<UpgradeManager>() |
readonly List<PurchasedUpgrade> Barotrauma.UpgradeManager.PendingUpgrades = new List<PurchasedUpgrade>() |
readonly List<PurchasedItemSwap> Barotrauma.UpgradeManager.PurchasedItemSwaps = new List<PurchasedItemSwap>() |
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.
|
static |
This one toggles whether or not connected submarines get upgraded too. Could probably be removed, I just didn't like magic numbers.