Add skill upgrade system and refactor skill components for enhanced functionality; update resource paths and configurations
This commit is contained in:
@@ -13,6 +13,7 @@ public partial class BrickThrowComponent : Node, ISkill
|
||||
|
||||
private bool _canThrow = true;
|
||||
private Timer _timer;
|
||||
private SkillData _skillData;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -81,13 +82,20 @@ public partial class BrickThrowComponent : Node, ISkill
|
||||
_timer.Start();
|
||||
}
|
||||
|
||||
public void Initialize(Node owner)
|
||||
public void Initialize(Node owner, SkillData data)
|
||||
{
|
||||
PlayerController = owner as PlayerController;
|
||||
_skillData = data;
|
||||
|
||||
if (PlayerController == null)
|
||||
{
|
||||
GD.PushError("BrickThrowComponent: Owner is not a PlayerController.");
|
||||
}
|
||||
|
||||
if (_skillData.Level > 0 && _skillData.Upgrades.Count >= _skillData.Level)
|
||||
{
|
||||
ApplyUpgrade(_skillData.Upgrades[_skillData.Level - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
@@ -99,4 +107,12 @@ public partial class BrickThrowComponent : Node, ISkill
|
||||
{
|
||||
if (ThrowInputBehavior != null) ThrowInputBehavior.ThrowRequested -= ThrowBrick;
|
||||
}
|
||||
|
||||
public void ApplyUpgrade(SkillUpgrade upgrade)
|
||||
{
|
||||
foreach (var property in upgrade.Properties)
|
||||
{
|
||||
Set(property.Key, property.Value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@ using System;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Mr.BrickAdventures.scripts.interfaces;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
@@ -12,6 +13,7 @@ public partial class MagneticSkillComponent : Node, ISkill
|
||||
|
||||
private Array<Node2D> _collectablesToPickUp = [];
|
||||
private Node2D _owner;
|
||||
private SkillData _skillData;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
@@ -70,9 +72,11 @@ public partial class MagneticSkillComponent : Node, ISkill
|
||||
collectable.GlobalPosition += direction.Normalized() * speed;
|
||||
}
|
||||
|
||||
public void Initialize(Node owner)
|
||||
public void Initialize(Node owner, SkillData data)
|
||||
{
|
||||
_owner = owner as Node2D;
|
||||
_skillData = data;
|
||||
|
||||
if (_owner == null)
|
||||
{
|
||||
GD.PushWarning("MagneticSkillComponent: Owner is not a Node2D.");
|
||||
@@ -91,6 +95,11 @@ public partial class MagneticSkillComponent : Node, ISkill
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_skillData.Level > 0 && _skillData.Upgrades.Count >= _skillData.Level)
|
||||
{
|
||||
ApplyUpgrade(_skillData.Upgrades[_skillData.Level - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
@@ -112,4 +121,12 @@ public partial class MagneticSkillComponent : Node, ISkill
|
||||
MagneticArea.BodyEntered -= OnBodyEntered;
|
||||
MagneticArea.AreaEntered -= OnAreaEntered;
|
||||
}
|
||||
|
||||
public void ApplyUpgrade(SkillUpgrade upgrade)
|
||||
{
|
||||
foreach (var property in upgrade.Properties)
|
||||
{
|
||||
Set(property.Key, property.Value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
using Mr.BrickAdventures.scripts.interfaces;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
@@ -28,11 +29,11 @@ public partial class SkillUnlockerComponent : Node
|
||||
{
|
||||
if (_gameManager == null) return false;
|
||||
if (_gameManager.IsSkillUnlocked(skill)) return false;
|
||||
if (!HasEnoughCoins(skill.Cost)) return false;
|
||||
if (!HasEnoughCoins(skill.Upgrades[0].Cost)) return false;
|
||||
|
||||
skill.Level = 1;
|
||||
skill.IsActive = true;
|
||||
_gameManager.RemoveCoins(skill.Cost);
|
||||
_gameManager.RemoveCoins(skill.Upgrades[0].Cost);
|
||||
|
||||
var skillsUnlocked = (Array<SkillData>)_gameManager.CurrentSessionState["skills_unlocked"];
|
||||
skillsUnlocked.Add(skill);
|
||||
@@ -59,11 +60,19 @@ public partial class SkillUnlockerComponent : Node
|
||||
{
|
||||
if (_gameManager == null) return false;
|
||||
if (!_gameManager.IsSkillUnlocked(skill)) return false;
|
||||
if (!HasEnoughCoins(skill.Cost)) return false;
|
||||
if (skill.Level >= skill.MaxLevel) return false;
|
||||
if (!HasEnoughCoins(skill.Upgrades[skill.Level].Cost)) return false;
|
||||
|
||||
_gameManager.RemoveCoins(skill.Cost);
|
||||
_gameManager.RemoveCoins(skill.Upgrades[skill.Level].Cost);
|
||||
skill.Level++;
|
||||
if (SkillManager.ActiveComponents.TryGetValue(skill.Name, out Variant componentVariant))
|
||||
{
|
||||
var component = componentVariant.AsGodotObject();
|
||||
if (component is ISkill skillInstance)
|
||||
{
|
||||
skillInstance.ApplyUpgrade(skill.Upgrades[skill.Level - 1]);
|
||||
}
|
||||
}
|
||||
EmitSignalSkillUnlocked(skill);
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user