From 7f82f539a2e2b8a265f5e86eb480bb9cf0504b96 Mon Sep 17 00:00:00 2001 From: Zaid Alsaigh Date: Sun, 6 Oct 2024 01:25:59 -0400 Subject: [PATCH 1/4] Create defend component, animation TBD --- src/components/defend_component.gd | 20 ++++++++++++++++++++ src/components/defend_component.tscn | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100644 src/components/defend_component.gd create mode 100644 src/components/defend_component.tscn diff --git a/src/components/defend_component.gd b/src/components/defend_component.gd new file mode 100644 index 0000000..875a37b --- /dev/null +++ b/src/components/defend_component.gd @@ -0,0 +1,20 @@ +extends Node + +@export var defence = 10 + +@export_category("Animation") +@export var animation : AnimationPlayer + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +func generate_mitigated_attack(incoming_attack : Attack) -> Attack: + # Placeholder calculation + return Attack.create( + incoming_attack.name, + incoming_attack.description, + incoming_attack.damage - defence, + incoming_attack.accuracy + ) diff --git a/src/components/defend_component.tscn b/src/components/defend_component.tscn new file mode 100644 index 0000000..27baae1 --- /dev/null +++ b/src/components/defend_component.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://b18463a7xv7jr"] + +[ext_resource type="Script" path="res://src/components/defend_component.gd" id="1_xsk6h"] + +[node name="DefendComponent" type="Node"] +script = ExtResource("1_xsk6h") From e8a2d643145720f7b192989eda3143905fe126a2 Mon Sep 17 00:00:00 2001 From: Zaid Alsaigh Date: Sun, 6 Oct 2024 01:26:31 -0400 Subject: [PATCH 2/4] Add defendcomponent to player --- player.tscn | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/player.tscn b/player.tscn index 134cfec..13d7b1b 100644 --- a/player.tscn +++ b/player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=3 uid="uid://cf3emyoet5j64"] +[gd_scene load_steps=11 format=3 uid="uid://cf3emyoet5j64"] [ext_resource type="Script" path="res://player.gd" id="1_ft17v"] [ext_resource type="SpriteFrames" uid="uid://b06a3lft4r7qs" path="res://player_overworld.tres" id="2_3mhg4"] @@ -8,6 +8,7 @@ [ext_resource type="Script" path="res://resources/attack_rsc.gd" id="6_bcgn8"] [ext_resource type="Resource" uid="uid://cs60ixhmh86wm" path="res://resources/attacks/normal_attack.tres" id="6_i87wm"] [ext_resource type="Resource" uid="uid://hodugild11n5" path="res://resources/attacks/slash_attack.tres" id="7_u0ent"] +[ext_resource type="PackedScene" uid="uid://b18463a7xv7jr" path="res://src/components/defend_component.tscn" id="9_uluyt"] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_8s1xf"] height = 38.0 @@ -32,3 +33,5 @@ zoom = Vector2(3, 3) [node name="AttackComponent" parent="." instance=ExtResource("5_xlubi")] attacks = Array[ExtResource("6_bcgn8")]([ExtResource("6_i87wm"), ExtResource("7_u0ent")]) + +[node name="DefendComponent" parent="." instance=ExtResource("9_uluyt")] From 29e1113ff1bdf11df048791cf79325423ff2c610 Mon Sep 17 00:00:00 2001 From: Zaid Alsaigh Date: Mon, 18 Nov 2024 01:51:35 -0500 Subject: [PATCH 3/4] Squashed commit of the following: commit 33a5f1f8989f4fbd2b4066ea282471275f42ae88 Merge: 1429f9d 255c0ef Author: zalsaigh <60819371+zalsaigh@users.noreply.github.com> Date: Mon Nov 18 01:48:12 2024 -0500 Merge pull request #5 from zalsaigh/feature/attack-component Attack component commit 255c0efedfdbf2f7568169fe1dd52c60da3b281b Merge: 0808ec7 1429f9d Author: zalsaigh <60819371+zalsaigh@users.noreply.github.com> Date: Mon Nov 18 01:48:02 2024 -0500 Merge branch 'main' into feature/attack-component commit 0808ec7d8e02bc5b3f86b02c44f0a7ba8b3419a2 Author: Zaid Alsaigh Date: Mon Nov 18 01:45:28 2024 -0500 Update attack_rsc.gd commit 58972d9f029a31f8a84e576a191c2910112c25b7 Author: Zaid Alsaigh Date: Mon Nov 18 01:44:15 2024 -0500 Update variable names back commit 581b0a340395156b63aa4bd7c7486e8af1ebec6a Author: Zaid Alsaigh Date: Mon Nov 18 01:32:02 2024 -0500 Update constructor and class variables of attack_rsc.gd commit 3803fee8ce93270277df123d3579762ccf35afe6 Author: Zaid Alsaigh Date: Sun Nov 17 19:38:40 2024 -0500 Squashed commit of the following: commit 1429f9d25b4874dff60bd5b7754522d38bd897db Merge: d233d4d d7de065 Author: zalsaigh <60819371+zalsaigh@users.noreply.github.com> Date: Sun Nov 17 13:36:04 2024 -0500 Merge pull request #8 from zalsaigh/start-combat Start combat + Combat Manager as Autoload (singleton) commit d233d4d6c8fc5af29a5e2459c9fa979c33f97b5b Author: Michael Le <43327291+LeMichael88@users.noreply.github.com> Date: Sat Nov 16 13:44:59 2024 -0500 Implement Spell Component (#2) * Files that godot automatically generated or edited * Implement spell component, spell class, and sample spells * Update combat gui to test spells component PoC * Address comments commit d7de0656c90e32adcc40a2d4e6f7952852220c17 Author: Ada Vu Date: Thu Nov 14 14:09:08 2024 -0800 Combat Manager as Autoload (singleton) added groups(or tags) to enemies as "enemy" get all enemies in a scene using group switch from overworld to combat scene commit 1429f9d25b4874dff60bd5b7754522d38bd897db Merge: d233d4d d7de065 Author: zalsaigh <60819371+zalsaigh@users.noreply.github.com> Date: Sun Nov 17 13:36:04 2024 -0500 Merge pull request #8 from zalsaigh/start-combat Start combat + Combat Manager as Autoload (singleton) commit d233d4d6c8fc5af29a5e2459c9fa979c33f97b5b Author: Michael Le <43327291+LeMichael88@users.noreply.github.com> Date: Sat Nov 16 13:44:59 2024 -0500 Implement Spell Component (#2) * Files that godot automatically generated or edited * Implement spell component, spell class, and sample spells * Update combat gui to test spells component PoC * Address comments commit d7de0656c90e32adcc40a2d4e6f7952852220c17 Author: Ada Vu Date: Thu Nov 14 14:09:08 2024 -0800 Combat Manager as Autoload (singleton) added groups(or tags) to enemies as "enemy" get all enemies in a scene using group switch from overworld to combat scene commit 2e5121ae0316dd5472fac3c4d4826da3091670a5 Merge: 38f411e ed1b4b7 Author: Zaid Alsaigh Date: Wed Oct 16 22:14:11 2024 -0400 Merge branch 'main' into feature/attack-component --- PlayerSprite.gd | 16 ++++++ art/combat/health_bars/h1.blend.import | 51 +++++++++++++++++++ .../health_bars/h_background.blend.import | 51 +++++++++++++++++++ combat_gui.gd | 24 +++++++++ combat_gui.tscn | 16 +++++- combat_manager.gd | 4 +- enemy.gd | 3 +- project.godot | 4 ++ resources/attack_rsc.gd | 14 ++--- second_scene.gd | 4 +- second_scene.tscn | 2 +- spell.gd | 29 +++++++++++ spells/grass_whip.tres | 12 +++++ spells/spell_database.gd | 4 ++ spells/spell_database.tres | 10 ++++ spells/starlight.gd | 5 ++ spells/starlight.tres | 12 +++++ spells_component.gd | 35 +++++++++++++ spells_component.tscn | 6 +++ 19 files changed, 285 insertions(+), 17 deletions(-) create mode 100644 art/combat/health_bars/h1.blend.import create mode 100644 art/combat/health_bars/h_background.blend.import create mode 100644 spell.gd create mode 100644 spells/grass_whip.tres create mode 100644 spells/spell_database.gd create mode 100644 spells/spell_database.tres create mode 100644 spells/starlight.gd create mode 100644 spells/starlight.tres create mode 100644 spells_component.gd create mode 100644 spells_component.tscn diff --git a/PlayerSprite.gd b/PlayerSprite.gd index 03b9f9d..9012bb6 100644 --- a/PlayerSprite.gd +++ b/PlayerSprite.gd @@ -1,11 +1,27 @@ extends AnimatedSprite2D +var timer # Called when the node enters the scene tree for the first time. func _ready(): play("idle") + timer = $AnimationTimer # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): pass + + +# Shows the unit's character casting animation +func _on_combat_gui_spell_animation(duration: int) -> void: + # Start one-shot timer with a wait time dependent on spell + timer.wait_time = duration + + # Start the animation and timer + play("casting") + timer.start() + + +func _on_animation_timer_timeout() -> void: + play("idle") diff --git a/art/combat/health_bars/h1.blend.import b/art/combat/health_bars/h1.blend.import new file mode 100644 index 0000000..5c806a9 --- /dev/null +++ b/art/combat/health_bars/h1.blend.import @@ -0,0 +1,51 @@ +[remap] + +importer="scene" +importer_version=1 +type="PackedScene" +uid="uid://x5mynlh3spd6" +path="res://.godot/imported/h1.blend-b32bd9746d9f550c17e6c22d6f01b780.scn" + +[deps] + +source_file="res://art/combat/health_bars/h1.blend" +dest_files=["res://.godot/imported/h1.blend-b32bd9746d9f550c17e6c22d6f01b780.scn"] + +[params] + +nodes/root_type="" +nodes/root_name="" +nodes/apply_root_scale=true +nodes/root_scale=1.0 +nodes/import_as_skeleton_bones=false +meshes/ensure_tangents=true +meshes/generate_lods=true +meshes/create_shadow_meshes=true +meshes/light_baking=1 +meshes/lightmap_texel_size=0.2 +meshes/force_disable_compression=false +skins/use_named_skins=true +animation/import=true +animation/fps=30 +animation/trimming=false +animation/remove_immutable_tracks=true +animation/import_rest_as_RESET=false +import_script/path="" +_subresources={} +blender/nodes/visible=0 +blender/nodes/active_collection_only=false +blender/nodes/punctual_lights=true +blender/nodes/cameras=true +blender/nodes/custom_properties=true +blender/nodes/modifiers=1 +blender/meshes/colors=false +blender/meshes/uvs=true +blender/meshes/normals=true +blender/meshes/tangents=true +blender/meshes/skins=2 +blender/meshes/export_bones_deforming_mesh_only=false +blender/materials/unpack_enabled=true +blender/materials/export_materials=1 +blender/animation/limit_playback=true +blender/animation/always_sample=true +blender/animation/group_tracks=true diff --git a/art/combat/health_bars/h_background.blend.import b/art/combat/health_bars/h_background.blend.import new file mode 100644 index 0000000..49ba65d --- /dev/null +++ b/art/combat/health_bars/h_background.blend.import @@ -0,0 +1,51 @@ +[remap] + +importer="scene" +importer_version=1 +type="PackedScene" +uid="uid://dqnk6pticepam" +path="res://.godot/imported/h_background.blend-d2443c144680577969a71feb5fb1622f.scn" + +[deps] + +source_file="res://art/combat/health_bars/h_background.blend" +dest_files=["res://.godot/imported/h_background.blend-d2443c144680577969a71feb5fb1622f.scn"] + +[params] + +nodes/root_type="" +nodes/root_name="" +nodes/apply_root_scale=true +nodes/root_scale=1.0 +nodes/import_as_skeleton_bones=false +meshes/ensure_tangents=true +meshes/generate_lods=true +meshes/create_shadow_meshes=true +meshes/light_baking=1 +meshes/lightmap_texel_size=0.2 +meshes/force_disable_compression=false +skins/use_named_skins=true +animation/import=true +animation/fps=30 +animation/trimming=false +animation/remove_immutable_tracks=true +animation/import_rest_as_RESET=false +import_script/path="" +_subresources={} +blender/nodes/visible=0 +blender/nodes/active_collection_only=false +blender/nodes/punctual_lights=true +blender/nodes/cameras=true +blender/nodes/custom_properties=true +blender/nodes/modifiers=1 +blender/meshes/colors=false +blender/meshes/uvs=true +blender/meshes/normals=true +blender/meshes/tangents=true +blender/meshes/skins=2 +blender/meshes/export_bones_deforming_mesh_only=false +blender/materials/unpack_enabled=true +blender/materials/export_materials=1 +blender/animation/limit_playback=true +blender/animation/always_sample=true +blender/animation/group_tracks=true diff --git a/combat_gui.gd b/combat_gui.gd index 3d3252c..f744079 100644 --- a/combat_gui.gd +++ b/combat_gui.gd @@ -1,5 +1,10 @@ extends Control +signal spell_animation(duration: int) + +# TODO: remove this later, just used to test cycling through spells +var curr_spell: int + # Called when the node enters the scene tree for the first time. func _ready(): @@ -11,5 +16,24 @@ func _process(delta): pass + func _on_attack_button_pressed(): pass # Replace with function body. + + +# Called when Spells button is pressed (used to test the spells component) +func _on_spells_button_pressed() -> void: + print("Clicked Spell Button") + + # TODO: get a specific unit's spell component instead of hardcoding player + var spells_component = $PlayerContainer/SpellsComponent + if spells_component.is_in_group("has_spells"): + # Get the next spell (for debugging purposes) + var spell_index = curr_spell % spells_component.spells.size() + curr_spell += 1 + + # Cast this spell + var spell = spells_component.get_spell(spell_index) + if spell: + spell_animation.emit(spell.animation_time) + spell._cast() diff --git a/combat_gui.tscn b/combat_gui.tscn index ec19a34..5eda390 100644 --- a/combat_gui.tscn +++ b/combat_gui.tscn @@ -7,6 +7,7 @@ [ext_resource type="Texture2D" uid="uid://cx31yayiwhamx" path="res://art/combat/health_bars/green_bar.png" id="4_s3jjx"] [ext_resource type="FontFile" uid="uid://ddqgixpjigtib" path="res://fonts/NESCyrillic.ttf" id="7_0tnrd"] [ext_resource type="SpriteFrames" uid="uid://b615m8ddqw36u" path="res://player_combat.tres" id="8_hq5nd"] +[ext_resource type="PackedScene" uid="uid://dprvni6fde6dc" path="res://spells_component.tscn" id="9_a5vcp"] [ext_resource type="Script" path="res://PlayerSprite.gd" id="9_w2uuc"] [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_rf5w2"] @@ -106,14 +107,19 @@ offset_bottom = 141.0 grow_vertical = 2 [node name="PlayerSprite" type="AnimatedSprite2D" parent="PlayerContainer"] -position = Vector2(-61, 110) +position = Vector2(252, 42) scale = Vector2(5, 5) sprite_frames = ExtResource("8_hq5nd") -animation = &"walk_right" +animation = &"idle" +frame_progress = 0.935869 +flip_h = true script = ExtResource("9_w2uuc") [node name="AnimationPlayer" type="AnimationPlayer" parent="PlayerContainer/PlayerSprite"] +[node name="AnimationTimer" type="Timer" parent="PlayerContainer/PlayerSprite"] +one_shot = true + [node name="HealthBarControl" type="Control" parent="PlayerContainer"] layout_mode = 2 @@ -145,6 +151,8 @@ theme_override_fonts/font = ExtResource("7_0tnrd") theme_override_font_sizes/font_size = 32 text = "15/24" +[node name="SpellsComponent" parent="PlayerContainer" instance=ExtResource("9_a5vcp")] + [node name="ActionsPanel" type="Panel" parent="."] layout_mode = 1 anchors_preset = 12 @@ -194,6 +202,7 @@ size_flags_horizontal = 3 theme_override_fonts/font = ExtResource("7_0tnrd") theme_override_font_sizes/font_size = 32 theme_override_styles/normal = SubResource("StyleBoxFlat_ewjaf") +action_mode = 0 text = "Spells " @@ -207,3 +216,6 @@ text = "Steal " [connection signal="pressed" from="ActionsPanel/MarginContainer/ActionsContainer/AttackButton" to="." method="_on_attack_button_pressed"] +[connection signal="spell_animation" from="." to="PlayerContainer/PlayerSprite" method="_on_combat_gui_spell_animation"] +[connection signal="timeout" from="PlayerContainer/PlayerSprite/AnimationTimer" to="PlayerContainer/PlayerSprite" method="_on_animation_timer_timeout"] +[connection signal="pressed" from="ActionsPanel/MarginContainer/ActionsContainer/SpellsButton" to="." method="_on_spells_button_pressed"] diff --git a/combat_manager.gd b/combat_manager.gd index 6df8ff6..f11226b 100644 --- a/combat_manager.gd +++ b/combat_manager.gd @@ -2,7 +2,9 @@ extends Node @export var combatHUDScene : PackedScene -func start_combat_scene(party : Array[CharacterBody2D], enemies : Array[Area2D]): +func start_combat_scene(party : Array[CharacterBody2D], enemies : Array[Area2D], path): + combatHUDScene = load(path) + if not combatHUDScene: print("No combat scene selected! Please select one in the editor.") return diff --git a/enemy.gd b/enemy.gd index b0dba41..ffc0a39 100644 --- a/enemy.gd +++ b/enemy.gd @@ -3,8 +3,7 @@ extends Area2D # Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. - + add_to_group("enemy") # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): diff --git a/project.godot b/project.godot index 0e7048a..226d06e 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,10 @@ run/main_scene="res://first_scene.tscn" config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://icon.svg" +[autoload] + +CombatManager="*res://combat_manager.gd" + [filesystem] import/blender/enabled=false diff --git a/resources/attack_rsc.gd b/resources/attack_rsc.gd index 3485be2..39c3a02 100644 --- a/resources/attack_rsc.gd +++ b/resources/attack_rsc.gd @@ -8,12 +8,8 @@ class_name Attack extends Resource @export_category("Sounds") @export var attack_execution_sounds : Array[AudioStream] = [] # multiple to loop through - - -static func create(p_name="Sample Attack", p_description="Sample Description", p_damage=10, p_accuracy=50) -> Attack: - var instance = Attack.new() - instance.name = p_name - instance.description = p_description - instance.damage = p_damage - instance.accuracy = clamp(p_accuracy, 0, 100) / 100 # percentage division for use in further maths - return instance +func _init(p_name: String, p_description: String, p_damage=10, p_accuracy=50): + name = p_name + description = p_description + damage = p_damage + accuracy = clamp(p_accuracy, 0, 100) / 100 # percentage division for use in further maths diff --git a/second_scene.gd b/second_scene.gd index a4cfdcf..201ddb7 100644 --- a/second_scene.gd +++ b/second_scene.gd @@ -18,5 +18,5 @@ func _process(delta): func _on_enemy_body_entered(body: PhysicsBody2D): - #combat_system.start_combat_scene() - pass + var enemy = get_tree().get_nodes_in_group("enemy") + CombatManager.start_combat_scene([player, player], [enemy], "res://combat_gui.tscn") diff --git a/second_scene.tscn b/second_scene.tscn index 7ab0cfd..a571188 100644 --- a/second_scene.tscn +++ b/second_scene.tscn @@ -13,7 +13,7 @@ layer_2/tile_data = PackedInt32Array(-327685, 458752, 2, -262149, 458752, 2, -19 [node name="Player" parent="." instance=ExtResource("2_jttwt")] -[node name="Enemy" parent="." instance=ExtResource("3_msafq")] +[node name="Enemy" parent="." groups=["enemy"] instance=ExtResource("3_msafq")] position = Vector2(1048, 307) [connection signal="body_entered" from="Enemy" to="." method="_on_enemy_body_entered"] diff --git a/spell.gd b/spell.gd new file mode 100644 index 0000000..bfb0730 --- /dev/null +++ b/spell.gd @@ -0,0 +1,29 @@ +extends Resource +class_name Spell + +enum ElementType { + NEUTRAL, + STAR, + NATURE, + MOON, + CHAOS, +} + +# General Spell Attributes +@export var spell_name: String +@export var description: String +@export var animation_time: float +@export var element: ElementType + +@export var damage: float +@export var heal: float + + +# Default cast function +""" +TODO: Pass in targets and modify their health component accordingly + Use a map in case some spells are multi target with different effects? +""" +func _cast() -> void: + print("Casting spell: ", spell_name) + print("Damaged target by ", damage, " damage!") diff --git a/spells/grass_whip.tres b/spells/grass_whip.tres new file mode 100644 index 0000000..e8d718d --- /dev/null +++ b/spells/grass_whip.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="Spell" load_steps=2 format=3 uid="uid://bhidthvpqenlc"] + +[ext_resource type="Script" path="res://spell.gd" id="1_1mtfi"] + +[resource] +script = ExtResource("1_1mtfi") +spell_name = "Grass Whip" +description = "Throw grass at enemy" +animation_time = 1.5 +element = 2 +damage = 10.0 +heal = 0.0 diff --git a/spells/spell_database.gd b/spells/spell_database.gd new file mode 100644 index 0000000..fc087eb --- /dev/null +++ b/spells/spell_database.gd @@ -0,0 +1,4 @@ +extends Resource +class_name SpellDatabase + +@export var spell_database: Array[Spell] diff --git a/spells/spell_database.tres b/spells/spell_database.tres new file mode 100644 index 0000000..b7e5aee --- /dev/null +++ b/spells/spell_database.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=5 format=3 uid="uid://dwtsb7cb6wt6d"] + +[ext_resource type="Script" path="res://spells/spell_database.gd" id="1_sfgwt"] +[ext_resource type="Script" path="res://spell.gd" id="2_lrf77"] +[ext_resource type="Resource" uid="uid://bhidthvpqenlc" path="res://spells/grass_whip.tres" id="3_ykmwl"] +[ext_resource type="Resource" uid="uid://cc65m1tmobhat" path="res://spells/starlight.tres" id="4_gd5w5"] + +[resource] +script = ExtResource("1_sfgwt") +spell_database = Array[ExtResource("2_lrf77")]([ExtResource("3_ykmwl"), ExtResource("4_gd5w5")]) diff --git a/spells/starlight.gd b/spells/starlight.gd new file mode 100644 index 0000000..fe497ca --- /dev/null +++ b/spells/starlight.gd @@ -0,0 +1,5 @@ +extends Spell + +func _cast() -> void: + print("Casting spell: ", spell_name, " which is a different spell!") + print("Healed target by ", heal, " health!") diff --git a/spells/starlight.tres b/spells/starlight.tres new file mode 100644 index 0000000..dec4790 --- /dev/null +++ b/spells/starlight.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cc65m1tmobhat"] + +[ext_resource type="Script" path="res://spells/starlight.gd" id="1_1mang"] + +[resource] +script = ExtResource("1_1mang") +spell_name = "Starlight" +description = "Flash enemy with starlight" +animation_time = 3.0 +element = 1 +damage = 0.0 +heal = 10.0 diff --git a/spells_component.gd b/spells_component.gd new file mode 100644 index 0000000..e09a7b3 --- /dev/null +++ b/spells_component.gd @@ -0,0 +1,35 @@ +extends Node2D + +# Current unit's spells +@export var MAX_SPELLS = 4 +var spells : Array[Spell] + +# Array prepopulated with a list of all possible spells +var spell_database = load("res://spells/spell_database.tres") + + +func _ready() -> void: + # TODO: remove this, used for adding test data + for i in range(2): + add_spell(spell_database.spell_database[i]) + + +# Add a new spell resource to the unit's list of spells +func add_spell(spell: Spell): + assert(spells.size() != MAX_SPELLS) + + spells.append(spell) + + +# Remove spell from unit's list of spells specified by an index +func remove_spell(spell_index: int): + assert(spell_index < spells.size()) + + spells.remove_at(spell_index) + + +# Get the spell resource specified by an index in the unit's spell list +func get_spell(spell_index: int) -> Spell: + assert(spell_index < spells.size()) + + return spells[spell_index] diff --git a/spells_component.tscn b/spells_component.tscn new file mode 100644 index 0000000..3fdd8ea --- /dev/null +++ b/spells_component.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://dprvni6fde6dc"] + +[ext_resource type="Script" path="res://spells_component.gd" id="1_xm8yn"] + +[node name="SpellsComponent" type="Node2D" groups=["has_spells"]] +script = ExtResource("1_xm8yn") From c92d1c3038e52a2fae64ee3d4f542a3c14a9cc0c Mon Sep 17 00:00:00 2001 From: Zaid Alsaigh Date: Sat, 14 Dec 2024 12:54:36 -0500 Subject: [PATCH 4/4] Update defend_component.gd --- src/components/defend_component.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/defend_component.gd b/src/components/defend_component.gd index 875a37b..28cf7e6 100644 --- a/src/components/defend_component.gd +++ b/src/components/defend_component.gd @@ -12,7 +12,7 @@ func _ready(): func generate_mitigated_attack(incoming_attack : Attack) -> Attack: # Placeholder calculation - return Attack.create( + return Attack.new( incoming_attack.name, incoming_attack.description, incoming_attack.damage - defence,