From 55c3ae212bc820611758192876e215c887c09812 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Tue, 26 Aug 2025 23:48:59 +0200 Subject: [PATCH] Add skill upgrade system and refactor skill components for enhanced functionality; update resource paths and configurations --- resources/skills/brick_throw.tres | 7 +- resources/skills/explosive_brick.tres | 7 +- resources/skills/fire_brick.tres | 7 +- resources/skills/ice_brick.tres | 7 +- resources/skills/magnetic.tres | 12 ++-- .../upgrades/brick_throw/upgrade_1.tres | 12 ++++ .../upgrades/explosive_brick/upgrade_1.tres | 12 ++++ .../skills/upgrades/fire_brick/upgrade_1.tres | 12 ++++ .../skills/upgrades/ice_brick/upgrade_1.tres | 12 ++++ .../skills/upgrades/magnetic/upgrade_1.tres | 12 ++++ scripts/Resources/SkillData.cs | 5 +- scripts/Resources/SkillUpgrade.cs | 12 ++++ scripts/Resources/SkillUpgrade.cs.uid | 1 + scripts/SkillManager.cs | 2 +- scripts/UI/Marketplace.cs | 42 +++++------- scripts/UI/MarketplaceButton.cs | 68 +++++++++++++------ scripts/components/BrickThrowComponent.cs | 18 ++++- scripts/components/MagneticSkillComponent.cs | 19 +++++- scripts/components/SkillUnlockerComponent.cs | 17 +++-- scripts/interfaces/ISkill.cs | 4 +- 20 files changed, 212 insertions(+), 76 deletions(-) create mode 100644 resources/skills/upgrades/brick_throw/upgrade_1.tres create mode 100644 resources/skills/upgrades/explosive_brick/upgrade_1.tres create mode 100644 resources/skills/upgrades/fire_brick/upgrade_1.tres create mode 100644 resources/skills/upgrades/ice_brick/upgrade_1.tres create mode 100644 resources/skills/upgrades/magnetic/upgrade_1.tres create mode 100644 scripts/Resources/SkillUpgrade.cs create mode 100644 scripts/Resources/SkillUpgrade.cs.uid diff --git a/resources/skills/brick_throw.tres b/resources/skills/brick_throw.tres index 0e85383..e88e85d 100644 --- a/resources/skills/brick_throw.tres +++ b/resources/skills/brick_throw.tres @@ -1,17 +1,18 @@ -[gd_resource type="Resource" load_steps=4 format=3 uid="uid://dw5ee2lpeypnb"] +[gd_resource type="Resource" load_steps=6 format=3 uid="uid://dw5ee2lpeypnb"] [ext_resource type="PackedScene" uid="uid://coayig4dxelo2" path="res://objects/player_skills/brick_throw_skill.tscn" id="1_5gnea"] [ext_resource type="Texture2D" uid="uid://dxtdwgg3po0eg" path="res://sprites/brick_power_Skill_icon.png" id="2_yimbq"] +[ext_resource type="Script" uid="uid://dwb0e05pewcsn" path="res://scripts/Resources/SkillUpgrade.cs" id="3_lt17o"] [ext_resource type="Script" uid="uid://d4crrfmbgxnqf" path="res://scripts/Resources/SkillData.cs" id="3_yimbq"] +[ext_resource type="Resource" uid="uid://d0qk7kh47b4pu" path="res://resources/skills/upgrades/brick_throw/upgrade_1.tres" id="4_nhovl"] [resource] script = ExtResource("3_yimbq") Name = "BRICK_POWER" Description = "BRICK_POWER_DESCRIPTION" -Cost = 50 Icon = ExtResource("2_yimbq") IsActive = false Level = 1 -MaxLevel = 3 Type = 1 Node = ExtResource("1_5gnea") +Upgrades = Array[ExtResource("3_lt17o")]([ExtResource("4_nhovl")]) diff --git a/resources/skills/explosive_brick.tres b/resources/skills/explosive_brick.tres index 4ad7936..898d7d2 100644 --- a/resources/skills/explosive_brick.tres +++ b/resources/skills/explosive_brick.tres @@ -1,17 +1,18 @@ -[gd_resource type="Resource" load_steps=4 format=3 uid="uid://cdp8sex36vdq2"] +[gd_resource type="Resource" load_steps=6 format=3 uid="uid://cdp8sex36vdq2"] [ext_resource type="PackedScene" uid="uid://cfses3kn3y8qw" path="res://objects/player_skills/exploding_brick_throw_skill.tscn" id="2_gt8f6"] +[ext_resource type="Script" uid="uid://dwb0e05pewcsn" path="res://scripts/Resources/SkillUpgrade.cs" id="3_txev8"] [ext_resource type="Texture2D" uid="uid://c0xtjfpmkfolk" path="res://sprites/explosive_brick_skill_icon.png" id="3_wkqmb"] +[ext_resource type="Resource" uid="uid://c50advf65oi8c" path="res://resources/skills/upgrades/explosive_brick/upgrade_1.tres" id="4_1x338"] [ext_resource type="Script" uid="uid://d4crrfmbgxnqf" path="res://scripts/Resources/SkillData.cs" id="5_wkqmb"] [resource] script = ExtResource("5_wkqmb") Name = "EXPLOSIVE_BRICK" Description = "EXPLOSIVE_BRICK_DESCRIPTION" -Cost = 180 Icon = ExtResource("3_wkqmb") IsActive = false Level = 0 -MaxLevel = 1 Type = 1 Node = ExtResource("2_gt8f6") +Upgrades = Array[ExtResource("3_txev8")]([ExtResource("4_1x338")]) diff --git a/resources/skills/fire_brick.tres b/resources/skills/fire_brick.tres index 9d74fd6..adb596d 100644 --- a/resources/skills/fire_brick.tres +++ b/resources/skills/fire_brick.tres @@ -1,17 +1,18 @@ -[gd_resource type="Resource" load_steps=4 format=3 uid="uid://cr5lo4h8wm0jc"] +[gd_resource type="Resource" load_steps=6 format=3 uid="uid://cr5lo4h8wm0jc"] [ext_resource type="PackedScene" uid="uid://dfm2you3v5ap4" path="res://objects/player_skills/fire_brick_throw_skill.tscn" id="2_d6y6i"] +[ext_resource type="Script" uid="uid://dwb0e05pewcsn" path="res://scripts/Resources/SkillUpgrade.cs" id="3_1ooyb"] [ext_resource type="Texture2D" uid="uid://cocbnr38qsikt" path="res://sprites/fire_brick_skill_icon.png" id="3_w87qb"] +[ext_resource type="Resource" uid="uid://dmfiqqjmfa7m3" path="res://resources/skills/upgrades/fire_brick/upgrade_1.tres" id="4_aj7vs"] [ext_resource type="Script" uid="uid://d4crrfmbgxnqf" path="res://scripts/Resources/SkillData.cs" id="5_us7vb"] [resource] script = ExtResource("5_us7vb") Name = "FIRE_BRICK" Description = "FIRE_BIRCK_DESCRIPTION" -Cost = 150 Icon = ExtResource("3_w87qb") IsActive = false Level = 0 -MaxLevel = 3 Type = 1 Node = ExtResource("2_d6y6i") +Upgrades = Array[ExtResource("3_1ooyb")]([ExtResource("4_aj7vs")]) diff --git a/resources/skills/ice_brick.tres b/resources/skills/ice_brick.tres index 39907a7..40802a0 100644 --- a/resources/skills/ice_brick.tres +++ b/resources/skills/ice_brick.tres @@ -1,17 +1,18 @@ -[gd_resource type="Resource" load_steps=4 format=3 uid="uid://ceakv6oqob6m7"] +[gd_resource type="Resource" load_steps=6 format=3 uid="uid://ceakv6oqob6m7"] [ext_resource type="PackedScene" uid="uid://dpmmacva7qf8j" path="res://objects/player_skills/ice_brick_throw_skill.tscn" id="2_gm1ka"] [ext_resource type="Texture2D" uid="uid://c1qaxspv8aemf" path="res://sprites/ice_brick_skill_icon.png" id="3_6btth"] +[ext_resource type="Script" uid="uid://dwb0e05pewcsn" path="res://scripts/Resources/SkillUpgrade.cs" id="3_e3cb0"] +[ext_resource type="Resource" uid="uid://myr57ylobqkn" path="res://resources/skills/upgrades/ice_brick/upgrade_1.tres" id="4_3pbub"] [ext_resource type="Script" uid="uid://d4crrfmbgxnqf" path="res://scripts/Resources/SkillData.cs" id="5_57pl3"] [resource] script = ExtResource("5_57pl3") Name = "ICE_BRICK" Description = "ICE_BRICK_DESCRIPTION" -Cost = 180 Icon = ExtResource("3_6btth") IsActive = false Level = 0 -MaxLevel = 3 Type = 1 Node = ExtResource("2_gm1ka") +Upgrades = Array[ExtResource("3_e3cb0")]([ExtResource("4_3pbub")]) diff --git a/resources/skills/magnetic.tres b/resources/skills/magnetic.tres index da13669..1f69f9d 100644 --- a/resources/skills/magnetic.tres +++ b/resources/skills/magnetic.tres @@ -1,22 +1,18 @@ -[gd_resource type="Resource" load_steps=4 format=3 uid="uid://d3bjre2etov1n"] +[gd_resource type="Resource" load_steps=6 format=3 uid="uid://d3bjre2etov1n"] [ext_resource type="Texture2D" uid="uid://cvhoq7aubxlmq" path="res://sprites/ui/magnetic_skill_icon.png" id="1_16qcg"] [ext_resource type="PackedScene" uid="uid://cunyndudjh2he" path="res://objects/player_skills/magnetic_skill.tscn" id="1_er41s"] +[ext_resource type="Script" uid="uid://dwb0e05pewcsn" path="res://scripts/Resources/SkillUpgrade.cs" id="3_0j4wg"] [ext_resource type="Script" uid="uid://d4crrfmbgxnqf" path="res://scripts/Resources/SkillData.cs" id="3_htb6q"] +[ext_resource type="Resource" uid="uid://dte14sxesjm3y" path="res://resources/skills/upgrades/magnetic/upgrade_1.tres" id="4_0hjrs"] [resource] script = ExtResource("3_htb6q") Name = "MAGNETIC" Description = "MAGNETIC_DESCRIPTION" -Config = Dictionary[String, Variant]({ -"magnetic_area": NodePath("MagneticArea"), -"magnetic_move_duration": 1.25, -"root": NodePath(".") -}) -Cost = 70 Icon = ExtResource("1_16qcg") IsActive = false Level = 1 -MaxLevel = 1 Type = 2 Node = ExtResource("1_er41s") +Upgrades = Array[ExtResource("3_0j4wg")]([ExtResource("4_0hjrs")]) diff --git a/resources/skills/upgrades/brick_throw/upgrade_1.tres b/resources/skills/upgrades/brick_throw/upgrade_1.tres new file mode 100644 index 0000000..6a69f6b --- /dev/null +++ b/resources/skills/upgrades/brick_throw/upgrade_1.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="SkillUpgrade" load_steps=2 format=3 uid="uid://d0qk7kh47b4pu"] + +[ext_resource type="Script" uid="uid://dwb0e05pewcsn" path="res://scripts/Resources/SkillUpgrade.cs" id="1_1l84l"] + +[resource] +script = ExtResource("1_1l84l") +Cost = 50 +Description = "Upgrade Description" +Properties = Dictionary[String, Variant]({ +"FireRate": 0.6 +}) +metadata/_custom_type_script = "uid://dwb0e05pewcsn" diff --git a/resources/skills/upgrades/explosive_brick/upgrade_1.tres b/resources/skills/upgrades/explosive_brick/upgrade_1.tres new file mode 100644 index 0000000..cb3cbed --- /dev/null +++ b/resources/skills/upgrades/explosive_brick/upgrade_1.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="SkillUpgrade" load_steps=2 format=3 uid="uid://c50advf65oi8c"] + +[ext_resource type="Script" uid="uid://dwb0e05pewcsn" path="res://scripts/Resources/SkillUpgrade.cs" id="1_0hsac"] + +[resource] +script = ExtResource("1_0hsac") +Cost = 240 +Description = "Upgrade Description" +Properties = Dictionary[String, Variant]({ +"FireRate": 0.6 +}) +metadata/_custom_type_script = "uid://dwb0e05pewcsn" diff --git a/resources/skills/upgrades/fire_brick/upgrade_1.tres b/resources/skills/upgrades/fire_brick/upgrade_1.tres new file mode 100644 index 0000000..afb38ca --- /dev/null +++ b/resources/skills/upgrades/fire_brick/upgrade_1.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="SkillUpgrade" load_steps=2 format=3 uid="uid://dmfiqqjmfa7m3"] + +[ext_resource type="Script" uid="uid://dwb0e05pewcsn" path="res://scripts/Resources/SkillUpgrade.cs" id="1_fyb20"] + +[resource] +script = ExtResource("1_fyb20") +Cost = 150 +Description = "Upgrade Description" +Properties = Dictionary[String, Variant]({ +"FireRate": 0.6 +}) +metadata/_custom_type_script = "uid://dwb0e05pewcsn" diff --git a/resources/skills/upgrades/ice_brick/upgrade_1.tres b/resources/skills/upgrades/ice_brick/upgrade_1.tres new file mode 100644 index 0000000..d7cdd23 --- /dev/null +++ b/resources/skills/upgrades/ice_brick/upgrade_1.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="SkillUpgrade" load_steps=2 format=3 uid="uid://myr57ylobqkn"] + +[ext_resource type="Script" uid="uid://dwb0e05pewcsn" path="res://scripts/Resources/SkillUpgrade.cs" id="1_bfa1e"] + +[resource] +script = ExtResource("1_bfa1e") +Cost = 140 +Description = "Upgrade Description" +Properties = Dictionary[String, Variant]({ +"FireRate": 0.6 +}) +metadata/_custom_type_script = "uid://dwb0e05pewcsn" diff --git a/resources/skills/upgrades/magnetic/upgrade_1.tres b/resources/skills/upgrades/magnetic/upgrade_1.tres new file mode 100644 index 0000000..4574706 --- /dev/null +++ b/resources/skills/upgrades/magnetic/upgrade_1.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="SkillUpgrade" load_steps=2 format=3 uid="uid://dte14sxesjm3y"] + +[ext_resource type="Script" uid="uid://dwb0e05pewcsn" path="res://scripts/Resources/SkillUpgrade.cs" id="1_dkk4n"] + +[resource] +script = ExtResource("1_dkk4n") +Cost = 70 +Description = "Upgrade Description" +Properties = Dictionary[String, Variant]({ +"FireRate": 0.6 +}) +metadata/_custom_type_script = "uid://dwb0e05pewcsn" diff --git a/scripts/Resources/SkillData.cs b/scripts/Resources/SkillData.cs index a1ae78d..8d14269 100644 --- a/scripts/Resources/SkillData.cs +++ b/scripts/Resources/SkillData.cs @@ -8,11 +8,12 @@ public partial class SkillData : Resource { [Export] public string Name { get; set; } = "New Skill"; [Export] public string Description { get; set; } = "New Skill"; - [Export] public int Cost { get; set; } = 0; [Export] public Texture2D Icon { get; set; } [Export] public bool IsActive { get; set; } = false; [Export] public int Level { get; set; } = 1; - [Export] public int MaxLevel { get; set; } = 1; [Export] public SkillType Type { get; set; } = SkillType.Throw; [Export] public PackedScene Node { get; set; } + [Export] public Array Upgrades { get; set; } = []; + + public int MaxLevel => Upgrades.Count; } \ No newline at end of file diff --git a/scripts/Resources/SkillUpgrade.cs b/scripts/Resources/SkillUpgrade.cs new file mode 100644 index 0000000..b3edde9 --- /dev/null +++ b/scripts/Resources/SkillUpgrade.cs @@ -0,0 +1,12 @@ +using Godot; +using Godot.Collections; + +namespace Mr.BrickAdventures.scripts.Resources; + +[GlobalClass] +public partial class SkillUpgrade : Resource +{ + [Export] public int Cost { get; set; } = 50; + [Export(PropertyHint.MultilineText)] public string Description { get; set; } = "Upgrade Description"; + [Export] public Dictionary Properties { get; set; } = new(); +} \ No newline at end of file diff --git a/scripts/Resources/SkillUpgrade.cs.uid b/scripts/Resources/SkillUpgrade.cs.uid new file mode 100644 index 0000000..705bb80 --- /dev/null +++ b/scripts/Resources/SkillUpgrade.cs.uid @@ -0,0 +1 @@ +uid://dwb0e05pewcsn diff --git a/scripts/SkillManager.cs b/scripts/SkillManager.cs index dd3f412..a417d26 100644 --- a/scripts/SkillManager.cs +++ b/scripts/SkillManager.cs @@ -46,7 +46,7 @@ public partial class SkillManager : Node var instance = skillData.Node.Instantiate(); if (instance is ISkill skill) { - skill.Initialize(Owner); + skill.Initialize(Owner, skillData); skill.Activate(); } else diff --git a/scripts/UI/Marketplace.cs b/scripts/UI/Marketplace.cs index 84e6dbd..0d48a55 100644 --- a/scripts/UI/Marketplace.cs +++ b/scripts/UI/Marketplace.cs @@ -35,12 +35,12 @@ public partial class Marketplace : Control var unlockedSkills = _gameManager.GetUnlockedSkills(); foreach (var skill in unlockedSkills) CreateSkillButton(skill); - SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocker; + SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocked; } public override void _ExitTree() { - SkillUnlockerComponent.SkillUnlocked -= OnSkillUnlocker; + SkillUnlockerComponent.SkillUnlocked -= OnSkillUnlocked; } public override void _Input(InputEvent @event) @@ -59,21 +59,24 @@ public partial class Marketplace : Control } } - private string GetButtonText(SkillData skill) + private void OnSkillUnlocked(SkillData skill) { - return $"{Tr(skill.Name)} {skill.Cost}"; - } - - private void OnSkillUnlocker(SkillData skill) - { - if (_skillButtons.Count == 0) CreateSkillButton(skill); + var buttonExists = false; + foreach (var existingButton in _skillButtons) + { + if (existingButton.Name == skill.Name) + { + buttonExists = true; + break; + } + } + + if (!buttonExists) CreateSkillButton(skill); foreach (var btn in _skillButtons) { - if (btn.Data.IsActive) - btn.Activate(); - else - btn.Deactivate(); + if (btn.Data.IsActive) btn.Activate(); + else btn.Deactivate(); } } @@ -93,7 +96,6 @@ public partial class Marketplace : Control private void CreateUpgradeButton(SkillData skill) { var button = MarketplaceButtonScene.Instantiate(); - button.Text = GetButtonText(skill); button.Data = skill; button.Icon = skill.Icon; button.Pressed += () => OnUpgradeButtonPressed(skill); @@ -123,18 +125,6 @@ public partial class Marketplace : Control } } - private void RemoveButton(SkillData skill) - { - foreach (var node in ToUnlockGrid.GetChildren()) - { - var child = (Button)node; - if (child.Text != GetButtonText(skill)) continue; - - child.QueueFree(); - break; - } - } - private void OnSkillButtonPressed(SkillButton button) { SkillUnlockerComponent.SkillManager.ToggleSkillActivation(button.Data); diff --git a/scripts/UI/MarketplaceButton.cs b/scripts/UI/MarketplaceButton.cs index 6bf5c12..da287ca 100644 --- a/scripts/UI/MarketplaceButton.cs +++ b/scripts/UI/MarketplaceButton.cs @@ -18,45 +18,73 @@ public partial class MarketplaceButton : Button public override void _Ready() { _gameManager = GetNode("/root/GameManager"); - - Setup(); var player = _gameManager.Player; - - var skillUnlockerComponent = player?.GetNodeOrNull("SkillUnlockerComponent"); - if (skillUnlockerComponent == null) return; + if (player == null) return; - skillUnlockerComponent.SkillUnlocked += OnSkillUnlock; + _skillUnlockerComponent = player.GetNodeOrNull("SkillUnlockerComponent"); + if (_skillUnlockerComponent != null) + { + _skillUnlockerComponent.SkillUnlocked += OnSkillStateChanged; + } + + UpdateButtonState(); } public override void _ExitTree() { - _skillUnlockerComponent.SkillUnlocked -= OnSkillUnlock; + if (_skillUnlockerComponent != null) + { + _skillUnlockerComponent.SkillUnlocked -= OnSkillStateChanged; + } + } + + private void OnSkillStateChanged(SkillData skill) + { + if (skill.Name == Data.Name) + { + UpdateButtonState(); + } } - private void Setup() + private void UpdateButtonState() { - if (Data == null) return; + if (Data == null || Data.Upgrades.Count == 0) + { + Visible = false; + return; + } + + var isUnlocked = _gameManager.IsSkillUnlocked(Data); + for (var i = 0; i < SkillLevelContainer.GetChildCount(); i++) + { + SkillLevelContainer.GetChild(i).QueueFree(); + } + for (var i = 0; i < Data.MaxLevel; i++) { var icon = new TextureRect() { - Texture = i < Data.Level ? UnlockedSkillIcon : LockedSkillIcon, + Texture = (isUnlocked && i < Data.Level) ? UnlockedSkillIcon : LockedSkillIcon, + ExpandMode = TextureRect.ExpandModeEnum.FitWidthProportional }; SkillLevelContainer.AddChild(icon); } - } - private void OnSkillUnlock(SkillData skill) - { - if (skill.Name != Data.Name) return; - - for (var i = 0; i < Data.MaxLevel; i++) + if (!isUnlocked) { - var icon = SkillLevelContainer.GetChildOrNull(i); - if (icon == null) continue; - icon.Texture = i < Data.Level ? UnlockedSkillIcon : LockedSkillIcon; - Disabled = i >= Data.Level; + Text = $"{Tr(Data.Name)} ({Data.Upgrades[0].Cost})"; + Disabled = false; + } + else if (Data.Level < Data.MaxLevel) + { + Text = $"{Tr(Data.Name)} ({Data.Upgrades[Data.Level].Cost})"; + Disabled = false; + } + else + { + Text = $"{Tr(Data.Name)} (MAX)"; + Disabled = true; } } } \ No newline at end of file diff --git a/scripts/components/BrickThrowComponent.cs b/scripts/components/BrickThrowComponent.cs index 2835048..180c73f 100644 --- a/scripts/components/BrickThrowComponent.cs +++ b/scripts/components/BrickThrowComponent.cs @@ -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); + } + } } \ No newline at end of file diff --git a/scripts/components/MagneticSkillComponent.cs b/scripts/components/MagneticSkillComponent.cs index 520b333..a6068d0 100644 --- a/scripts/components/MagneticSkillComponent.cs +++ b/scripts/components/MagneticSkillComponent.cs @@ -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 _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); + } + } } \ No newline at end of file diff --git a/scripts/components/SkillUnlockerComponent.cs b/scripts/components/SkillUnlockerComponent.cs index 1ffca8d..4bf6a2f 100644 --- a/scripts/components/SkillUnlockerComponent.cs +++ b/scripts/components/SkillUnlockerComponent.cs @@ -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)_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; } diff --git a/scripts/interfaces/ISkill.cs b/scripts/interfaces/ISkill.cs index 20b3643..e676f3c 100644 --- a/scripts/interfaces/ISkill.cs +++ b/scripts/interfaces/ISkill.cs @@ -1,11 +1,13 @@ using Godot; +using Mr.BrickAdventures.scripts.Resources; namespace Mr.BrickAdventures.scripts.interfaces; public interface ISkill { - void Initialize(Node owner); + void Initialize(Node owner, SkillData data); void Activate(); void Deactivate(); + void ApplyUpgrade(SkillUpgrade upgrade); } \ No newline at end of file