Class UpgradeShopSession
- Namespace
- TDMaker.Unity.Campaign
- Assembly
- TDMaker.Unity.dll
One visit of the star-upgrade shop over a save slot. Every rule comes from the core UpgradeShopRules:
only the next rank of a track can be bought and only with enough stars (Available = EarnedTotal − Spent); opening the
session copies the purchases as the revert baseline; Revert() returns to that baseline (not one step back);
ResetAll() clears every purchase and makes the cleared state the new baseline. Each change is written into the
slot's ProfileData (ranks per track key and stars spent) and saved at once through Save.
public sealed class UpgradeShopSession
- Inheritance
-
UpgradeShopSession
- Inherited Members
Constructors
UpgradeShopSession(UpgradeShopAsset, CampaignProgress, Func<bool>)
Opens the shop over progress: reads its purchases and copies them as the revert baseline.
public UpgradeShopSession(UpgradeShopAsset shop, CampaignProgress progress, Func<bool> save = null)
Parameters
shopUpgradeShopAssetprogressCampaignProgresssaveFunc<bool>
Properties
AnyPurchased
Whether anything is bought (ResetAll() would change anything).
public bool AnyPurchased { get; }
Property Value
Available
Stars left to spend (negative only when an update raised prices of ranks already bought).
public long Available { get; }
Property Value
Baseline
Purchases when the shop was opened (or after the last reset).
public UpgradeSnapshot Baseline { get; }
Property Value
CanRevert
Whether Revert() would change anything.
public bool CanRevert { get; }
Property Value
EarnedTotal
Stars earned on the map.
public long EarnedTotal { get; }
Property Value
Progress
The save slot's progress.
public CampaignProgress Progress { get; }
Property Value
Save
Writes the slot after a purchase, a revert or a reset (returns false when the write failed). The default saves through CampaignSession when the progress belongs to its open slot (and does nothing for a progress outside any slot).
public Func<bool> Save { get; set; }
Property Value
SaveFailed
Whether the last save attempt failed.
public bool SaveFailed { get; }
Property Value
Shop
The shop.
public UpgradeShopAsset Shop { get; }
Property Value
Spent
Stars spent on the current purchases.
public long Spent { get; }
Property Value
State
Current purchases (core state).
public UpgradeSnapshot State { get; }
Property Value
TrackCount
Number of tracks.
public int TrackCount { get; }
Property Value
Methods
CanPurchase(int, int)
Whether rank rank of track can be bought now.
public bool CanPurchase(int track, int rank)
Parameters
Returns
Cost(int, int)
Price of rank rank (1-based) of track.
public int Cost(int track, int rank)
Parameters
Returns
GetState(int, int)
What node rank (1-based) of track shows.
public UpgradeRankState GetState(int track, int rank)
Parameters
Returns
Purchase(int, int)
Buys rank rank of track and saves (false when the rules refuse it).
public bool Purchase(int track, int rank)
Parameters
Returns
Rank(int)
Purchased rank of track (0 = none).
public int Rank(int track)
Parameters
trackint
Returns
RankCount(int)
Number of ranks of track track.
public int RankCount(int track)
Parameters
trackint
Returns
ResetAll()
Clears every purchase (all stars back), makes that the new baseline and saves. No confirmation.
public bool ResetAll()
Returns
Revert()
Returns every track to the purchases of the baseline and saves (false when nothing changed).
public bool Revert()
Returns
UnspentBadge(CampaignProgress, UpgradeShopAsset)
Stars the world map announces as unspent: min(EarnedTotal, FullShopCost) − Spent, never below zero (stars beyond the
full shop price are not announced; this is a display limit, not a cap on earning).
public static int UnspentBadge(CampaignProgress progress, UpgradeShopAsset shop)
Parameters
progressCampaignProgressshopUpgradeShopAsset
Returns
Events
Changed
Raised after every change (purchase, revert, reset).
public event Action Changed