From d87d4c9e3fee351bfc67531645f2158ec83c62ea Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 13 Feb 2024 23:12:32 +0100 Subject: [PATCH] Added skill system --- client/enemy/slime/Slime.tscn | 3 ++- client/player/Player.gd | 6 ++++-- client/player/Player.tscn | 21 +++---------------- client/player/animation/AnimationComponent.gd | 17 +++------------ client/player/skills/SkillsComponent.gd | 13 ++++++------ client/{player/skills => skill}/MeleeArea.gd | 2 +- client/skill/Skill.gd | 8 +++++++ client/skill/SkillInstance.gd | 14 +++++++++++++ client/skill/melee_area.tscn | 18 ++++++++++++++++ client/skill/slash/slash.gd | 6 ++++++ client/skill/slash/slash.tres | 13 ++++++++++++ client/skill/slash/slash.tscn | 10 +++++++++ client/skill/spin/spin.gd | 6 ++++++ client/skill/spin/spin.tres | 13 ++++++++++++ client/skill/spin/spin.tscn | 10 +++++++++ 15 files changed, 117 insertions(+), 43 deletions(-) rename client/{player/skills => skill}/MeleeArea.gd (74%) create mode 100644 client/skill/Skill.gd create mode 100644 client/skill/SkillInstance.gd create mode 100644 client/skill/melee_area.tscn create mode 100644 client/skill/slash/slash.gd create mode 100644 client/skill/slash/slash.tres create mode 100644 client/skill/slash/slash.tscn create mode 100644 client/skill/spin/spin.gd create mode 100644 client/skill/spin/spin.tres create mode 100644 client/skill/spin/spin.tscn diff --git a/client/enemy/slime/Slime.tscn b/client/enemy/slime/Slime.tscn index e3ef0aa..11a176e 100644 --- a/client/enemy/slime/Slime.tscn +++ b/client/enemy/slime/Slime.tscn @@ -15,13 +15,14 @@ radius = 0.4 [sub_resource type="Animation" id="Animation_vjs0t"] resource_name = "slime_death" +length = 1.5 tracks/0/type = "scale_3d" tracks/0/imported = false tracks/0/enabled = true tracks/0/path = NodePath("..") tracks/0/interp = 1 tracks/0/loop_wrap = true -tracks/0/keys = PackedFloat32Array(0, 1, 1, 1, 1, 1, 1, 1.1, 0.7, 1.1) +tracks/0/keys = PackedFloat32Array(0, 1, 1, 1, 1, 1.5, 1, 1.1, 0.25, 1.1) [sub_resource type="Animation" id="Animation_qls31"] resource_name = "slime_fall" diff --git a/client/player/Player.gd b/client/player/Player.gd index 6a6ad7f..6937787 100644 --- a/client/player/Player.gd +++ b/client/player/Player.gd @@ -1,17 +1,19 @@ class_name Player extends CharacterBody3D -signal skill_used(slot: int) +signal skill_used(skill: Skill) signal dashed signal jumped signal name_changed(new_name: String) signal direction_changed +@export var skills: Array[Skill] + var id: String var controller: Controller func use_skill(slot: int): - skill_used.emit(slot) + skill_used.emit(skills[slot]) func dash(): dashed.emit() diff --git a/client/player/Player.tscn b/client/player/Player.tscn index 6728fd6..90f8976 100644 --- a/client/player/Player.tscn +++ b/client/player/Player.tscn @@ -3,6 +3,8 @@ [ext_resource type="Script" path="res://player/Player.gd" id="1_8gebs"] [ext_resource type="PackedScene" uid="uid://c8j7t4yg7anb0" path="res://assets/female/Female.blend" id="2_8nah6"] [ext_resource type="PackedScene" uid="uid://2bbycjulf00g" path="res://player/health/HealthComponent.tscn" id="2_np5ag"] +[ext_resource type="Resource" uid="uid://yaq8ui3f6fwa" path="res://skill/slash/slash.tres" id="2_x58e1"] +[ext_resource type="Resource" uid="uid://ba1filjaldakv" path="res://skill/spin/spin.tres" id="3_l76ly"] [ext_resource type="PackedScene" uid="uid://cgqbkj8wbcatv" path="res://assets/hair/PonyTail.blend" id="3_umw6q"] [ext_resource type="FontFile" uid="uid://b7mov13kwi8u8" path="res://assets/font/ubuntu_nf_regular.ttf" id="4_76ehj"] [ext_resource type="Skin" uid="uid://bbqyiue1vj37f" path="res://assets/hoodie/Hoodie_Skin.tres" id="4_b1tg1"] @@ -14,19 +16,16 @@ [ext_resource type="PackedScene" uid="uid://bivxnxwi863o0" path="res://player/animation/AnimationComponent.tscn" id="10_bcaeg"] [ext_resource type="AnimationLibrary" uid="uid://d4n0puibh4hyt" path="res://assets/animations/human.blend" id="11_d0e6r"] [ext_resource type="PackedScene" uid="uid://b8xf4ltqyorjv" path="res://player/skills/SkillsComponent.tscn" id="14_6idcf"] -[ext_resource type="Script" path="res://player/skills/MeleeArea.gd" id="14_g0mpw"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2f50n"] radius = 0.3 height = 1.6 -[sub_resource type="CylinderShape3D" id="CylinderShape3D_4r7eu"] -radius = 1.5 - [node name="Player" type="CharacterBody3D" groups=["player"]] collision_layer = 512 collision_mask = 769 script = ExtResource("1_8gebs") +skills = Array[Resource("res://skill/Skill.gd")]([ExtResource("2_x58e1"), ExtResource("3_l76ly"), null, null]) [node name="Model" type="Node3D" parent="."] @@ -104,19 +103,5 @@ libraries = { [node name="Skills" parent="." instance=ExtResource("14_6idcf")] -[node name="MeleeArea" type="Area3D" parent="."] -unique_name_in_owner = true -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1.8) -collision_layer = 0 -collision_mask = 256 -monitoring = false -monitorable = false -script = ExtResource("14_g0mpw") - -[node name="CylinderShape" type="CollisionShape3D" parent="MeleeArea"] -shape = SubResource("CylinderShape3D_4r7eu") - -[connection signal="body_entered" from="MeleeArea" to="MeleeArea" method="on_body_entered"] - [editable path="Model/Female"] [editable path="Animation"] diff --git a/client/player/animation/AnimationComponent.gd b/client/player/animation/AnimationComponent.gd index a946dd9..1a70e40 100644 --- a/client/player/animation/AnimationComponent.gd +++ b/client/player/animation/AnimationComponent.gd @@ -11,7 +11,6 @@ var skip: int func _ready(): var player := owner as Player player.dashed.connect(dash) - player.skill_used.connect(use_skill) movement = player.find_child("Movement") animation_player = $AnimationPlayer @@ -24,11 +23,6 @@ func _process(_delta): animation_player.play(next_animation) - if animation_player.current_animation == "human/spin": - animation_player.speed_scale = 2.0 - else: - animation_player.speed_scale = 1.0 - func play_movement(): if !movement: play(RESET) @@ -46,19 +40,14 @@ func play_movement(): func dash(): play_with_duration("human/roll", 1.0) -func use_skill(slot: int): - match slot: - 0: - play_with_duration("human/spin", 0.9) - 1: - play_with_duration("human/slash", 1.0) - func play(action_name: StringName): next_animation = action_name -func play_with_duration(action_name: StringName, duration: float): +func play_with_duration(action_name: StringName, duration: float, speed: float = 1.0): next_animation = action_name skip += 1 + animation_player.speed_scale = speed await get_tree().create_timer(duration).timeout + animation_player.speed_scale = 1.0 skip -= 1 diff --git a/client/player/skills/SkillsComponent.gd b/client/player/skills/SkillsComponent.gd index 8fd7594..5a38e74 100644 --- a/client/player/skills/SkillsComponent.gd +++ b/client/player/skills/SkillsComponent.gd @@ -2,15 +2,14 @@ class_name SkillsComponent extends Node var player: Player -var area: Area3D func _ready(): player = owner - area = %MeleeArea player.skill_used.connect(use_skill) -func use_skill(_slot: int): - await get_tree().create_timer(0.7).timeout - area.monitoring = true - await get_tree().create_timer(0.1).timeout - area.monitoring = false +func use_skill(skill: Skill): + if !skill: + return + + var scene := skill.scene.instantiate() + player.add_child(scene) diff --git a/client/player/skills/MeleeArea.gd b/client/skill/MeleeArea.gd similarity index 74% rename from client/player/skills/MeleeArea.gd rename to client/skill/MeleeArea.gd index 95a7cfd..d52e5d5 100644 --- a/client/player/skills/MeleeArea.gd +++ b/client/skill/MeleeArea.gd @@ -4,4 +4,4 @@ func on_body_entered(body: Node3D): var health := body.get_node_or_null("Health") as HealthComponent if health: - health.take_damage(DamageInstance.new(50)) \ No newline at end of file + health.take_damage(DamageInstance.new(100)) \ No newline at end of file diff --git a/client/skill/Skill.gd b/client/skill/Skill.gd new file mode 100644 index 0000000..0d6e81a --- /dev/null +++ b/client/skill/Skill.gd @@ -0,0 +1,8 @@ +class_name Skill +extends Resource + +@export var id: String +@export var name: String +@export var icon: Texture2D +@export var cooldown: float +@export var scene: PackedScene \ No newline at end of file diff --git a/client/skill/SkillInstance.gd b/client/skill/SkillInstance.gd new file mode 100644 index 0000000..7107e86 --- /dev/null +++ b/client/skill/SkillInstance.gd @@ -0,0 +1,14 @@ +class_name SkillInstance +extends Node3D + +func play_animation(animation_name: String, duration: float, speed: float): + var character := get_parent() + var animation := character.get_node("Animation") as AnimationComponent + animation.play_with_duration(animation_name, duration, speed) + +func melee_damage(wait_time: float): + var area := get_node("Area") + await get_tree().create_timer(wait_time).timeout + area.monitoring = true + await get_tree().create_timer(0.1).timeout + area.monitoring = false \ No newline at end of file diff --git a/client/skill/melee_area.tscn b/client/skill/melee_area.tscn new file mode 100644 index 0000000..b62020b --- /dev/null +++ b/client/skill/melee_area.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=3 uid="uid://f1keiecsx5kw"] + +[ext_resource type="Script" path="res://skill/MeleeArea.gd" id="1_qgaoh"] + +[sub_resource type="CylinderShape3D" id="CylinderShape3D_4r7eu"] +radius = 1.5 + +[node name="MeleeArea" type="Area3D"] +collision_layer = 0 +collision_mask = 256 +monitoring = false +monitorable = false +script = ExtResource("1_qgaoh") + +[node name="CylinderShape" type="CollisionShape3D" parent="."] +shape = SubResource("CylinderShape3D_4r7eu") + +[connection signal="body_entered" from="." to="." method="on_body_entered"] diff --git a/client/skill/slash/slash.gd b/client/skill/slash/slash.gd new file mode 100644 index 0000000..53efc5f --- /dev/null +++ b/client/skill/slash/slash.gd @@ -0,0 +1,6 @@ +extends SkillInstance + +func _ready(): + play_animation("human/slash", 0.7, 1.4) + await melee_damage(0.5) + queue_free() \ No newline at end of file diff --git a/client/skill/slash/slash.tres b/client/skill/slash/slash.tres new file mode 100644 index 0000000..ae3a5a2 --- /dev/null +++ b/client/skill/slash/slash.tres @@ -0,0 +1,13 @@ +[gd_resource type="Resource" script_class="Skill" load_steps=3 format=3 uid="uid://yaq8ui3f6fwa"] + +[ext_resource type="Script" path="res://skill/Skill.gd" id="1_268fv"] +[ext_resource type="PackedScene" uid="uid://bhy50ngwxib3i" path="res://skill/slash/slash.tscn" id="1_icaie"] + +[resource] +script = ExtResource("1_268fv") +id = "slash" +name = "Slash" +cooldown = 0.0 +scene = ExtResource("1_icaie") +cast_time = 0.7 +total_time = 1.0 diff --git a/client/skill/slash/slash.tscn b/client/skill/slash/slash.tscn new file mode 100644 index 0000000..7459505 --- /dev/null +++ b/client/skill/slash/slash.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=3 uid="uid://bhy50ngwxib3i"] + +[ext_resource type="Script" path="res://skill/slash/slash.gd" id="1_dbiye"] +[ext_resource type="PackedScene" uid="uid://f1keiecsx5kw" path="res://skill/melee_area.tscn" id="2_q0v6t"] + +[node name="Slash" type="Node3D"] +script = ExtResource("1_dbiye") + +[node name="Area" parent="." instance=ExtResource("2_q0v6t")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1.8) diff --git a/client/skill/spin/spin.gd b/client/skill/spin/spin.gd new file mode 100644 index 0000000..3e06b9e --- /dev/null +++ b/client/skill/spin/spin.gd @@ -0,0 +1,6 @@ +extends SkillInstance + +func _ready(): + play_animation("human/spin", 1.0, 2.0) + await melee_damage(0.5) + queue_free() \ No newline at end of file diff --git a/client/skill/spin/spin.tres b/client/skill/spin/spin.tres new file mode 100644 index 0000000..8ff0222 --- /dev/null +++ b/client/skill/spin/spin.tres @@ -0,0 +1,13 @@ +[gd_resource type="Resource" script_class="Skill" load_steps=3 format=3 uid="uid://ba1filjaldakv"] + +[ext_resource type="PackedScene" uid="uid://bhrlgrleih7d0" path="res://skill/spin/spin.tscn" id="1_1lnya"] +[ext_resource type="Script" path="res://skill/Skill.gd" id="1_n5ckk"] + +[resource] +script = ExtResource("1_n5ckk") +id = "spin" +name = "Spin" +cooldown = 0.0 +scene = ExtResource("1_1lnya") +cast_time = 0.7 +total_time = 1.0 diff --git a/client/skill/spin/spin.tscn b/client/skill/spin/spin.tscn new file mode 100644 index 0000000..eb4daec --- /dev/null +++ b/client/skill/spin/spin.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=3 uid="uid://bhrlgrleih7d0"] + +[ext_resource type="Script" path="res://skill/spin/spin.gd" id="1_p5jmv"] +[ext_resource type="PackedScene" uid="uid://f1keiecsx5kw" path="res://skill/melee_area.tscn" id="2_fjxc1"] + +[node name="Spin" type="Node3D"] +script = ExtResource("1_p5jmv") + +[node name="Area" parent="." instance=ExtResource("2_fjxc1")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1.8)