Class CampaignProgress
- Namespace
- TDMaker.Unity.Campaign
- Assembly
- TDMaker.Unity.dll
Campaign rules over one save slot's ProfileData. A level is locked until its record exists; records are created when the unlock rule holds (Refresh()), and an opened level never locks again. A victory is first recorded as a pending clear (RecordVictory(string, int), at the end of the battle) and merged into the map once by ApplyPending() (on map entry): best stars keep the maximum, re-wins never grant stars twice, the first win raises FirstCleared, and the next levels open. Several victories before a merge keep the best rating, and a later defeat does not discard it. Earned stars = sum of best stars of the levels that count; available = earned − spent.
public sealed class CampaignProgress
- Inheritance
-
CampaignProgress
- Inherited Members
Constructors
CampaignProgress(CampaignAsset, ProfileData)
Wraps data (null starts a new profile).
public CampaignProgress(CampaignAsset campaign, ProfileData data = null)
Parameters
campaignCampaignAssetdataProfileData
Properties
AvailableStars
Stars left to spend (earned − spent, never below 0).
public int AvailableStars { get; }
Property Value
Campaign
The campaign.
public CampaignAsset Campaign { get; }
Property Value
Data
The slot data this progress reads and changes (save it through the store).
public ProfileData Data { get; }
Property Value
EarnedStars
Stars earned on the map: best stars of every campaign level that counts toward the total.
public int EarnedStars { get; }
Property Value
HasPending
Whether victories wait to be merged into the map.
public bool HasPending { get; }
Property Value
ProjectedStars
Stars the slot will have once the pending victories are merged (for slot previews): each level counts the higher of its record and its pending rating, never both, capped by MaxStars.
public int ProjectedStars { get; }
Property Value
SpentStars
Stars spent on permanent upgrades.
public int SpentStars { get; set; }
Property Value
Methods
ApplyPending()
Merges the pending victories into the map once and clears them: best stars keep the maximum, the first win completes the level (and raises FirstCleared), then every level whose rule now holds opens. Pending clears of unknown or still locked levels are dropped. Calling it again without new victories changes nothing. Save the slot afterwards.
public CampaignMapUpdate ApplyPending()
Returns
EnterMap()
Map entry in one call: merges pending victories and opens levels whose rules hold (ApplyPending() runs Refresh() itself). Save the slot afterwards when HasChanges is true.
public CampaignMapUpdate EnterMap()
Returns
GetBestStars(int)
Best stars of level index.
public int GetBestStars(int index)
Parameters
indexint
Returns
GetBestStars(string)
Best stars applied to the map for key (0 when never won).
public int GetBestStars(string key)
Parameters
keystring
Returns
GetState(int)
Map state of level index.
public CampaignLevelState GetState(int index)
Parameters
indexint
Returns
GetState(string)
Map state of the level with key (Locked for unknown keys).
public CampaignLevelState GetState(string key)
Parameters
keystring
Returns
GetUpgradeRank(string)
Purchased rank of a permanent upgrade track.
public int GetUpgradeRank(string track)
Parameters
trackstring
Returns
IsPlayable(int)
Whether level index can be played (open or completed).
public bool IsPlayable(int index)
Parameters
indexint
Returns
IsUnlockSatisfied(int)
Whether level index's unlock rule and star gate hold right now.
public bool IsUnlockSatisfied(int index)
Parameters
indexint
Returns
RecordResult(string, bool, int)
Records the outcome of a battle on key. A victory becomes a pending clear (several victories keep the best
rating); a defeat changes nothing. The map merges pending clears with ApplyPending(). Save the slot afterwards.
Returns false for unknown keys and defeats.
public bool RecordResult(string key, bool won, int stars)
Parameters
Returns
RecordVictory(string, int)
Records a victory with stars (see RecordResult(string, bool, int)).
public bool RecordVictory(string key, int stars)
Parameters
Returns
Refresh()
Opens every level whose rule holds (also the first levels of a new profile, and follow-up levels an older save missed). Never locks anything. Returns the keys opened by this call.
public List<string> Refresh()
Returns
SetUpgradeRank(string, int)
Sets the purchased rank of a permanent upgrade track (the shop checks prices and order).
public void SetUpgradeRank(string track, int rank)
Parameters
Events
FirstCleared
Raised by ApplyPending() when a level is won for the first time (key, stars).
public event Action<string, int> FirstCleared
Event Type
LevelOpened
Raised when a level opens (key).
public event Action<string> LevelOpened