Skip to main content

PlayerProgressionManager

A class in Root.Township, the global namespace.

Per-player component that holds experience, levels and unlocked skill slots for each progression path, and saves them in the player save. Reach it through Player.ProgressionManager; experience is only granted on the server.

Constructors​

MemberWhat it is
PlayerProgressionManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

11 private and internal fields
MemberWhat it is
private bool canBuyMoreSkillsFalse once the owned skill count reaches the global MaxBoughtSkills limit (when that limit is set).
private int currentlyOwnedSkillsCountNumber of skill slots the player owns. Counts towards the max bought skills limit.
private Stat experienceBoostStatThe character's experience boost stat. GainExperience multiplies gained experience by its value.
private static ToggleBool experiencePopupxppopup console toggle that shows a floating text popup when a player gains experience.
private static Logger loggerNLog logger for this class.
private ProfessionSkill sendingSkillSkill whose message is being sent, held while skillMessage serializes.
private Dictionary<uint, int> skillLevelSkill hash to level: how many owned or practiced slots grant that skill. 0 or missing means locked.
private MethodSync skillMessageMethod sync that carries a skill's custom message (SendMessage, SendMessageToPlayer).
private MethodSyncStruct<bool> syncLevelUpEffectMethod sync for the level-up effect.
private MethodSync syncPracticedFullMethod sync that sends all practiced slots to a player (SyncPracticedToPlayer).
private MethodSyncClass<PlayerProgressionManager.PracticeTuple> syncSlotPracticeMethod sync the server uses to tell clients a single slot was practiced.

Properties​

MemberWhat it is
Dictionary<ProgressionPath, PathExperience> PathExperiences { get; }Experience state per progression path. Entries are created on first use.
SkillOrb PracticingOrb { get; private set; }The skill orb currently being practised, or null.

Events​

MemberWhat it is
event SkillOrbDelegate OnPracticingChangedRaised when practising of a skill orb starts or stops.
event Action<bool> OnSlotPracticedRaised by MarkSlotPracticed with whether the slot was newly practised.
event Action<Player, ProgressionPath> UpdatedFreePointsRaised when free points on a path change.

Methods​

MemberWhat it is
void EndPractice()Stops practising the current skill orb and locks the skill again if practice was the only thing unlocking it.
IEnumerable<string> ExperienceLog() (iterator)One text line per path with level, free points and experience, for debug output.
static void GainExperience(IPlayer targetPlayer, ProgressionPath path, float experience)Server: static. Adds experience to a player's path, scaled by their experience boost stat. Does nothing for disabled paths or amounts of zero or less.
static bool GainExperience(IPlayer targetPlayer, ProgressionPath path, int experience)Server: static. Adds experience to a player's path, scaled by their experience boost stat. Does nothing for disabled paths or amounts of zero or less.
static void GainSharedExperience(Player mainPlayer, Player supportPlayer, ProgressionPath path, float experience)Server: static. Splits experience between a main and a supporting player using the shared multipliers from ProgressionSettings.
int GetFreePoints(ProgressionPath path)Unspent skill points the player has on a path.
int GetLevel(ProfessionSkill skill)For a ProfessionSkill, how many times it is unlocked (0 when not). For a path, the player's current level.
uint GetLevel(ProgressionPath path)For a ProfessionSkill, how many times it is unlocked (0 when not). For a path, the player's current level.
IEnumerable<ProgressionPath> GetPaths() (iterator)Yields each path once per slot unlocked on it.
float GetPercentageToNextLevel(ProgressionPath path)Current experience on a path as a fraction of what the current level needs.
IEnumerable<ProgressionSlot> GetSlots() (iterator)Every skill tree slot the player has unlocked, across all paths.
SkillStatus IsSlotAvailable(ProgressionSlot slot)The SkillStatus of a slot for this player (owned, allowed, can't buy, and testing variants while it is being practised).
bool IsSlotPracticed(ProgressionSlot slot)Whether the slot has been practised. Always true unless the server setting CanOnlyBuySkillsAfterPracticing is on.
void LoadFrom(PlayerSave save)Reads path experience and practised slots from a PlayerSave.
void LockSlot(ProgressionSlot slot)Removes an unlocked slot and lowers the skill's level, letting the player buy skills again if they were at the cap.
bool MarkSlotPracticed(ProgressionPath path, uint slotHash)Marks a slot as practised and raises OnSlotPracticed. On the server it also syncs that to clients.
void PracticeSlot(SkillOrb orb)Starts practising a skill orb at a shrine. The skill is unlocked for the player while they practise it.
void SaveTo(PlayerSave save)Writes path experience and practised slots into a PlayerSave.
void SendMessage(ProfessionSkill skill, params IPlayer[] except)Sends a skill's network message to everyone in the player's chunks, except the listed players.
void SendMessageToPlayer(ProfessionSkill skill, Player player)Sends a skill's network message to one player.
bool SkillUnlocked(ProfessionSkill skill)True when the player has the skill at any level, including while practising it.
void SyncPracticedToPlayer(Player player)Sends all practised slots to one player; called when that player connects.
void UnlockSlot(ProgressionSlot slot, bool isConsumingPoints = true, bool isFromLoad = false)Unlocks a slot, spending points unless told not to. Refuses (and logs) when dependencies are missing, except when loading.
void UpdateCounts()Rebuilds the owned skill count and skill levels from the unlocked slots.
13 private and internal methods
MemberWhat it is
private void Awake()Hooks Initialize to the player's initialization finishing.
private void CharacterDied(DamageData killingBlow)Server: takes the configured fraction of unspent experience from every path when the character dies.
private PathExperience CreatePathExperience(ProgressionPath path)Makes a new PathExperience for a path, wired to the level-up and free-points callbacks.
private void Initialize(NetworkEntity entity)Creates the method syncs. On the server, also hooks RegisterStat to the player getting a character.
private void NetworkLevelUpEffect(IPlayer player, Stream stream, bool isLevelCap)Method sync handler: plays the level-up effect on receivers, with a flag for hitting the level cap.
private void NetworkSkillMessage(IPlayer connectionPlayer, Stream stream)Method sync handler: writes or reads the sending skill's hash, then lets that skill serialize its own message.
private void OnLeveledUp(bool isLevelCap)Plays the level-up effect on non-headless builds. The server also sends it to nearby clients.
private void OnUpdatedPoints(ProgressionPath path)Raises UpdatedFreePoints for a path when its free points change.
private void RegisterStat(PlayerCharacter playerCharacter)Server: finds the character's experience boost stat, and hooks CharacterDied if the server takes experience on death.
private void SaveSerialize(Stream stream)Reads or writes every path's experience and practiced slots, for player saves.
private void SerializeAllPracticedSlots(Stream stream)Reads or writes each path's practiced slots. Used for saves and the full practice sync.
private void SyncPracticedFull(IPlayer player, Stream stream)Method sync handler that sends all practiced slots. Refuses incoming data on the server.
private void SyncSlotPracticed(IPlayer player, Stream stream, PlayerProgressionManager.PracticeTuple arguments)Method sync handler for one practiced slot. Clients mark the slot practiced when it arrives.

Used in​

Members of other types that take, return or hold a PlayerProgressionManager: