atomic pair - purchasing couples them, so neither moves alone. SkillData.Level is gone. It was an [Export] on a cached Resource: one instance per process, so the level never persisted, leaked between save slots, and made "unowned" indistinguishable from "level 1". Level now comes from the Playthrough and is passed to ISkill.Initialize. SkillManager reconciles from SkillSetChanged instead of being told by each caller. The old shape was "record it, then tell SkillManager" as two calls at four sites; AddSkill's early return when no player is registered left the skill owned but inert. Reconciliation also tracks the level each component was built at, so an upgrade rebuilds it rather than being patched in from outside. SkillUnlockerComponent collapses to one TryBuy - unlock and upgrade were two methods each doing affordability, debit, level mutation and manager notification in order. The guard three components copy-pasted around Upgrades[Level - 1] - and which BrickArmor omitted - now lives once in SkillComponentBase. Hud reads coins from CoinsChanged instead of rebuilding translated strings every frame. Lives still polls; it moves with the death path.
63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using Godot;
|
|
using Mr.BrickAdventures;
|
|
using Mr.BrickAdventures.Autoloads;
|
|
using Mr.BrickAdventures.scripts.interfaces;
|
|
using Mr.BrickAdventures.scripts.Resources;
|
|
|
|
namespace Mr.BrickAdventures.scripts.components;
|
|
|
|
[GlobalClass]
|
|
public partial class BrickShieldSkillComponent : SkillComponentBase
|
|
{
|
|
[Export] public PackedScene ShieldScene { get; set; }
|
|
|
|
private Node2D _shieldInstance;
|
|
private SkillManager _skillManager;
|
|
private HealthComponent _shieldHealth;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_skillManager = SkillManager.Instance;
|
|
}
|
|
|
|
public override void Activate()
|
|
{
|
|
if (Player == null || ShieldScene == null || _shieldInstance != null) return;
|
|
|
|
_shieldInstance = ShieldScene.Instantiate<Node2D>();
|
|
Player.AddChild(_shieldInstance);
|
|
_shieldInstance.Position = Vector2.Zero;
|
|
_shieldInstance.TreeExiting += OnShieldDestroyed;
|
|
_shieldHealth = _shieldInstance.GetNode<HealthComponent>("HealthComponent");
|
|
}
|
|
|
|
public override void Deactivate()
|
|
{
|
|
if (_shieldInstance != null && IsInstanceValid(_shieldInstance))
|
|
{
|
|
_shieldInstance.TreeExiting -= OnShieldDestroyed;
|
|
_shieldInstance.QueueFree();
|
|
}
|
|
_shieldInstance = null;
|
|
}
|
|
|
|
public override void ApplyUpgrade(SkillUpgrade upgrade)
|
|
{
|
|
upgrade.Properties.TryGetValue("shield_health", out var newHealth);
|
|
if (_shieldHealth != null)
|
|
{
|
|
_shieldHealth.Health = (float)newHealth;
|
|
_shieldHealth.MaxHealth = (float)newHealth;
|
|
}
|
|
}
|
|
|
|
private void OnShieldDestroyed()
|
|
{
|
|
if (Data != null && _skillManager != null)
|
|
{
|
|
// Revoking is enough: SkillManager reconciles the live component away from SkillSetChanged.
|
|
ProgressionRoot.Instance?.RevokeSkill(Progression.SkillId.Of(Data.Name));
|
|
}
|
|
_shieldInstance = null;
|
|
}
|
|
} |