using Godot; using Mr.BrickAdventures.scripts.interfaces; using Mr.BrickAdventures.scripts.Resources; namespace Mr.BrickAdventures.scripts.components; /// /// Base class for all skill components, to reduce boilerplate. /// public abstract partial class SkillComponentBase : Node, ISkill { protected PlayerController Player { get; private set; } protected SkillData Data { get; private set; } /// /// How far this skill is upgraded, as owned by the Playthrough. Never read from /// — see . /// protected int Level { get; private set; } = 1; public virtual void Initialize(Node owner, SkillData data, int level) { Player = owner as PlayerController; Data = data; Level = level; if (Player == null) { GD.PrintErr($"{GetType().Name} must be a child of a PlayerController."); } } /// /// Applies the upgrade matching the level this skill was initialised at, if the authored table /// goes that far. /// /// /// Lives here because three components had this guard copy-pasted and one of them — the brick /// armor — was missing it, indexing Upgrades[Level - 1] unchecked. /// protected void ApplyCurrentUpgrade() { if (Data == null || Level < 1 || Data.Upgrades.Count < Level) return; ApplyUpgrade(Data.Upgrades[Level - 1]); } public abstract void Activate(); public abstract void Deactivate(); public virtual void ApplyUpgrade(SkillUpgrade upgrade) { } }