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

shop UpgradeShopAsset
progress CampaignProgress
save Func<bool>

Properties

AnyPurchased

Whether anything is bought (ResetAll() would change anything).

public bool AnyPurchased { get; }

Property Value

bool

Available

Stars left to spend (negative only when an update raised prices of ranks already bought).

public long Available { get; }

Property Value

long

Baseline

Purchases when the shop was opened (or after the last reset).

public UpgradeSnapshot Baseline { get; }

Property Value

UpgradeSnapshot

CanRevert

Whether Revert() would change anything.

public bool CanRevert { get; }

Property Value

bool

EarnedTotal

Stars earned on the map.

public long EarnedTotal { get; }

Property Value

long

Progress

The save slot's progress.

public CampaignProgress Progress { get; }

Property Value

CampaignProgress

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

Func<bool>

SaveFailed

Whether the last save attempt failed.

public bool SaveFailed { get; }

Property Value

bool

Shop

The shop.

public UpgradeShopAsset Shop { get; }

Property Value

UpgradeShopAsset

Spent

Stars spent on the current purchases.

public long Spent { get; }

Property Value

long

State

Current purchases (core state).

public UpgradeSnapshot State { get; }

Property Value

UpgradeSnapshot

TrackCount

Number of tracks.

public int TrackCount { get; }

Property Value

int

Methods

CanPurchase(int, int)

Whether rank rank of track can be bought now.

public bool CanPurchase(int track, int rank)

Parameters

track int
rank int

Returns

bool

Cost(int, int)

Price of rank rank (1-based) of track.

public int Cost(int track, int rank)

Parameters

track int
rank int

Returns

int

GetState(int, int)

What node rank (1-based) of track shows.

public UpgradeRankState GetState(int track, int rank)

Parameters

track int
rank int

Returns

UpgradeRankState

Purchase(int, int)

Buys rank rank of track and saves (false when the rules refuse it).

public bool Purchase(int track, int rank)

Parameters

track int
rank int

Returns

bool

Rank(int)

Purchased rank of track (0 = none).

public int Rank(int track)

Parameters

track int

Returns

int

RankCount(int)

Number of ranks of track track.

public int RankCount(int track)

Parameters

track int

Returns

int

ResetAll()

Clears every purchase (all stars back), makes that the new baseline and saves. No confirmation.

public bool ResetAll()

Returns

bool

Revert()

Returns every track to the purchases of the baseline and saves (false when nothing changed).

public bool Revert()

Returns

bool

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

progress CampaignProgress
shop UpgradeShopAsset

Returns

int

Events

Changed

Raised after every change (purchase, revert, reset).

public event Action Changed

Event Type

Action