feat: Implement a skill pickup system with a new collectable type, event handling, and dedicated pickup objects.
This commit is contained in:
44
scripts/Events/SkillCollectHandler.cs
Normal file
44
scripts/Events/SkillCollectHandler.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Handles skill collection events and unlocks skills via GameStateStore.
|
||||
/// Skills are immediately activated but only persisted on level complete.
|
||||
/// </summary>
|
||||
public partial class SkillCollectHandler : Node
|
||||
{
|
||||
private SkillManager _skillManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_skillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||
EventBus.Instance.SkillCollected += OnSkillCollected;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (EventBus.Instance != null)
|
||||
{
|
||||
EventBus.Instance.SkillCollected -= OnSkillCollected;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSkillCollected(SkillData skill, Vector2 position)
|
||||
{
|
||||
if (skill == null) return;
|
||||
|
||||
// Unlock in session (will be committed on level complete, lost on death)
|
||||
GameStateStore.Instance?.UnlockSkillInSession(skill);
|
||||
|
||||
// Immediately activate the skill for the player
|
||||
skill.IsActive = true;
|
||||
skill.Level = 1;
|
||||
_skillManager?.AddSkill(skill);
|
||||
|
||||
// Emit skill unlocked event for UI/achievements
|
||||
EventBus.EmitSkillUnlocked(skill.Name, skill.Level);
|
||||
}
|
||||
}
|
||||
1
scripts/Events/SkillCollectHandler.cs.uid
Normal file
1
scripts/Events/SkillCollectHandler.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c1po4hjvqbslm
|
||||
@@ -6,4 +6,9 @@ public partial class CollectableResource : Resource
|
||||
{
|
||||
[Export] public float Amount { get; set; } = 0.0f;
|
||||
[Export] public CollectableType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The skill to unlock when collected. Only used when Type is Skill.
|
||||
/// </summary>
|
||||
[Export] public SkillData Skill { get; set; }
|
||||
}
|
||||
@@ -5,4 +5,5 @@ public enum CollectableType
|
||||
Coin,
|
||||
Kid,
|
||||
Health,
|
||||
Skill,
|
||||
}
|
||||
@@ -64,6 +64,13 @@ public partial class CollectableComponent : Node
|
||||
_floatingTextManager?.ShowMessage("Rescued!", ownerNode.GlobalPosition);
|
||||
EventBus.EmitChildRescued(ownerNode.GlobalPosition);
|
||||
break;
|
||||
case CollectableType.Skill:
|
||||
if (Data.Skill != null)
|
||||
{
|
||||
_floatingTextManager?.ShowMessage($"{Data.Skill.Name} Unlocked!", ownerNode.GlobalPosition);
|
||||
EventBus.EmitSkillCollected(Data.Skill, ownerNode.GlobalPosition);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
EventBus.EmitItemCollected(Data.Type, Data.Amount, ownerNode.GlobalPosition);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user