Added skill system

This commit is contained in:
Eduard Urbach 2024-02-13 23:12:32 +01:00
parent cf155d9aab
commit d87d4c9e3f
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
15 changed files with 117 additions and 43 deletions

View File

@ -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"

View File

@ -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()

View File

@ -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"]

View File

@ -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

View File

@ -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)

View File

@ -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))
health.take_damage(DamageInstance.new(100))

8
client/skill/Skill.gd Normal file
View File

@ -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

View File

@ -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

View File

@ -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"]

View File

@ -0,0 +1,6 @@
extends SkillInstance
func _ready():
play_animation("human/slash", 0.7, 1.4)
await melee_damage(0.5)
queue_free()

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1,6 @@
extends SkillInstance
func _ready():
play_animation("human/spin", 1.0, 2.0)
await melee_damage(0.5)
queue_free()

View File

@ -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

View File

@ -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)