refactor: Consolidate skill component logic into SkillComponentBase and update manager access to singletons.
This commit is contained in:
@@ -7,41 +7,33 @@ using Mr.BrickAdventures.scripts.Resources;
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class BrickShieldSkillComponent : Node, ISkill
|
||||
public partial class BrickShieldSkillComponent : SkillComponentBase
|
||||
{
|
||||
[Export] public PackedScene ShieldScene { get; set; }
|
||||
|
||||
private PlayerController _player;
|
||||
private Node2D _shieldInstance;
|
||||
private SkillData _skillData;
|
||||
private GameManager _gameManager;
|
||||
private SkillManager _skillManager;
|
||||
private HealthComponent _shieldHealth;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||
_skillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||
_gameManager = GameManager.Instance;
|
||||
_skillManager = SkillManager.Instance;
|
||||
}
|
||||
|
||||
public void Initialize(Node owner, SkillData data)
|
||||
public override void Activate()
|
||||
{
|
||||
_player = owner as PlayerController;
|
||||
_skillData = data;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
if (_player == null || ShieldScene == null || _shieldInstance != null) return;
|
||||
if (Player == null || ShieldScene == null || _shieldInstance != null) return;
|
||||
|
||||
_shieldInstance = ShieldScene.Instantiate<Node2D>();
|
||||
_player.AddChild(_shieldInstance);
|
||||
Player.AddChild(_shieldInstance);
|
||||
_shieldInstance.Position = Vector2.Zero;
|
||||
_shieldInstance.TreeExiting += OnShieldDestroyed;
|
||||
_shieldHealth = _shieldInstance.GetNode<HealthComponent>("HealthComponent");
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
public override void Deactivate()
|
||||
{
|
||||
if (_shieldInstance != null && IsInstanceValid(_shieldInstance))
|
||||
{
|
||||
@@ -51,7 +43,7 @@ public partial class BrickShieldSkillComponent : Node, ISkill
|
||||
_shieldInstance = null;
|
||||
}
|
||||
|
||||
public void ApplyUpgrade(SkillUpgrade upgrade)
|
||||
public override void ApplyUpgrade(SkillUpgrade upgrade)
|
||||
{
|
||||
upgrade.Properties.TryGetValue("shield_health", out var newHealth);
|
||||
if (_shieldHealth != null)
|
||||
@@ -63,10 +55,10 @@ public partial class BrickShieldSkillComponent : Node, ISkill
|
||||
|
||||
private void OnShieldDestroyed()
|
||||
{
|
||||
if (_gameManager != null && _skillData != null && _skillManager != null)
|
||||
if (_gameManager != null && Data != null && _skillManager != null)
|
||||
{
|
||||
_gameManager.RemoveSkill(_skillData.Name);
|
||||
_skillManager.RemoveSkill(_skillData.Name);
|
||||
_gameManager.RemoveSkill(Data.Name);
|
||||
_skillManager.RemoveSkill(Data.Name);
|
||||
}
|
||||
_shieldInstance = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user