SkillManager
Manages the skill tree (DAG), skill points and the injection of passive modifiers. Accessible via engine.skills.
import { SkillManager } from 'catalyst-engine';Conceptual guide: Skill tree.
Constructor
new SkillManager(statManager: StatManager, eventBus: EngineEventBus)Receives by dependency injection the StatManager (to inject the passive modifiers) and the EngineEventBus (to emit STAT_CHANGED). Instantiated automatically by the CatalystEngine.
Properties
| Property | Type | Description |
|---|---|---|
skillPoints (getter) | number | Available skill points. |
Methods
loadSkillTree()
loadSkillTree(config: ISkillNode[]): voidLoads the tree nodes. Each node is cloned with currentLevel forced to 0.
engine.skills.loadSkillTree(skillTreeJson);addSkillPoints()
addSkillPoints(points: number): voidAdds spendable skill points. The facade automatically adds 2 of them for each level gained.
getSkill()
getSkill(skillId: string): ISkillNode | undefinedReturns the skill node, or undefined if it does not exist.
upgradeSkill()
upgradeSkill(skillId: string, playerLevel: number): ISkillUnlockResultAttempts to upgrade the skill by one level. It runs the checks in order and returns an ISkillUnlockResult. On success: it deducts the points, increments currentLevel, injects/updates the passive modifiers (for PASSIVE skills) and emits STAT_CHANGED.
Failure reason | Cause |
|---|---|
NOT_FOUND | skill does not exist |
MAX_LEVEL | already at maximum level |
NO_POINTS | not enough points |
LOW_LEVEL | player level too low |
MISSING_PREREQUISITES | prerequisite not unlocked |
const res = engine.skills.upgradeSkill('brute_force', engine.exp.currentLevel);
if (!res.success) console.log(res.reason);exportState()
exportState(): { unspentPoints: number; unlockedSkills: Record<string, number> }Exports unspent points and unlocked skills (id → level), including only those with currentLevel > 0. Used by save().
importState()
importState(state: { unspentPoints: number; unlockedSkills: Record<string, number> }): voidRestores skill points and levels, first resetting the entire tree, and re-injects the passive modifiers into the stats. Used by load().