技能系统

master
chendian 2 years ago
parent fd2f2ce5e5
commit 473c8ec96a

@ -10,8 +10,10 @@ script = ExtResource("1_gik08")
weapon = ExtResource("4_id85o") weapon = ExtResource("4_id85o")
stance_from = 0 stance_from = 0
stance_to = 1 stance_to = 1
action = "light_attack"
name = "" name = ""
skill_animation = ExtResource("2_6nbpq") skill_animation = ExtResource("2_6nbpq")
break_level = 2
has_animation = false has_animation = false
sprite_frams = ExtResource("3_og1bb") sprite_frams = ExtResource("3_og1bb")
animation_name = "long_attack01" animation_name = "long_attack01"

@ -10,8 +10,10 @@ script = ExtResource("1_e0fqi")
weapon = ExtResource("4_novna") weapon = ExtResource("4_novna")
stance_from = 1 stance_from = 1
stance_to = 2 stance_to = 2
action = "light_attack"
name = "" name = ""
skill_animation = ExtResource("2_jrgan") skill_animation = ExtResource("2_jrgan")
has_animation = true break_level = 2
has_animation = false
sprite_frams = ExtResource("3_jidy7") sprite_frams = ExtResource("3_jidy7")
animation_name = "long_attack02" animation_name = "long_attack02"

@ -10,8 +10,10 @@ script = ExtResource("1_uaib7")
weapon = ExtResource("2_8uqiw") weapon = ExtResource("2_8uqiw")
stance_from = 2 stance_from = 2
stance_to = 3 stance_to = 3
action = "light_attack"
name = "" name = ""
skill_animation = ExtResource("2_ugt3f") skill_animation = ExtResource("2_ugt3f")
break_level = 2
has_animation = true has_animation = true
sprite_frams = ExtResource("3_sr2og") sprite_frams = ExtResource("3_sr2og")
animation_name = "long_attack03" animation_name = "long_attack03"

@ -10,8 +10,10 @@ script = ExtResource("1_xsxbs")
weapon = ExtResource("4_plyre") weapon = ExtResource("4_plyre")
stance_from = 3 stance_from = 3
stance_to = 4 stance_to = 4
action = "light_attack"
name = "" name = ""
skill_animation = ExtResource("2_sam6s") skill_animation = ExtResource("2_sam6s")
break_level = 2
has_animation = true has_animation = true
sprite_frams = ExtResource("3_w7h1m") sprite_frams = ExtResource("3_w7h1m")
animation_name = "long_attack04" animation_name = "long_attack04"

@ -0,0 +1,19 @@
[gd_resource type="Resource" script_class="PlayerSkillCfg" load_steps=5 format=3 uid="uid://cyqiiar75vf87"]
[ext_resource type="Script" path="res://script/config/player_skill_cfg.gd" id="1_yamsl"]
[ext_resource type="Animation" uid="uid://cwm116apu63n1" path="res://resource/skill_animation/hero01_long_flash.tres" id="2_bdxlh"]
[ext_resource type="SpriteFrames" uid="uid://0yuryfn6dc2v" path="res://resource/animation/character/hero01_long_skill01.aseprite" id="2_uof6p"]
[ext_resource type="Resource" uid="uid://cy3wwalxeyro0" path="res://config/weapon/long.tres" id="4_xft4c"]
[resource]
script = ExtResource("1_yamsl")
weapon = ExtResource("4_xft4c")
stance_from = 100
stance_to = 0
action = "flash"
name = ""
skill_animation = ExtResource("2_bdxlh")
break_level = 1
has_animation = true
sprite_frams = ExtResource("2_uof6p")
animation_name = "long_flash"

@ -10,8 +10,10 @@ script = ExtResource("1_ud5ph")
weapon = ExtResource("4_3bf64") weapon = ExtResource("4_3bf64")
stance_from = 1 stance_from = 1
stance_to = 2 stance_to = 2
action = "heavy_attack"
name = "" name = ""
skill_animation = ExtResource("2_ewts2") skill_animation = ExtResource("2_ewts2")
break_level = 2
has_animation = true has_animation = true
sprite_frams = ExtResource("3_qwjfl") sprite_frams = ExtResource("3_qwjfl")
animation_name = "long_skill01" animation_name = "long_skill01"

@ -110,6 +110,11 @@ jump={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null)
] ]
} }
flash={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
[rendering] [rendering]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 25 KiB

@ -41,3 +41,15 @@ tracks/2/keys = {
"update": 0, "update": 0,
"values": [0, 1, 2, 3, 4, 5, 6, 7, 8] "values": [0, 1, 2, 3, 4, 5, 6, 7, 8]
} }
tracks/3/type = "value"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("Status:break_level")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(0, 0.5, 0.7),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 1,
"values": [0, 2, 4]
}

@ -0,0 +1,43 @@
[gd_resource type="Animation" load_steps=2 format=3 uid="uid://cwm116apu63n1"]
[ext_resource type="SpriteFrames" uid="uid://0yuryfn6dc2v" path="res://resource/animation/character/hero01_long_skill01.aseprite" id="2_3eu5o"]
[resource]
resource_name = "hero01_long_flash"
length = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("View:sprite_frames")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [ExtResource("2_3eu5o")]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("View:animation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": ["long_flash"]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("View:frame")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 0,
"values": [0, 1, 2, 3, 4]
}

@ -1,15 +1,13 @@
[gd_scene load_steps=5 format=3 uid="uid://b85fy0wfgr4gs"] [gd_scene load_steps=4 format=3 uid="uid://b85fy0wfgr4gs"]
[ext_resource type="PackedScene" uid="uid://vnkcr04hevna" path="res://scene/character/character.tscn" id="1_bny0p"] [ext_resource type="PackedScene" uid="uid://vnkcr04hevna" path="res://scene/character/character.tscn" id="1_bny0p"]
[ext_resource type="Script" path="res://script/character/player/input.gd" id="2_qkra8"] [ext_resource type="Script" path="res://script/character/player/input.gd" id="2_qkra8"]
[ext_resource type="Resource" uid="uid://b6x3jdiqtum6" path="res://config/player_skill/hero01_long_attack01.tres" id="3_n2lf8"]
[ext_resource type="Script" path="res://script/character/player/combo.gd" id="4_jsefx"] [ext_resource type="Script" path="res://script/character/player/combo.gd" id="4_jsefx"]
[node name="Character" instance=ExtResource("1_bny0p")] [node name="Character" instance=ExtResource("1_bny0p")]
[node name="Input" type="Node3D" parent="." index="5"] [node name="Input" type="Node3D" parent="." index="5"]
script = ExtResource("2_qkra8") script = ExtResource("2_qkra8")
test_skill_cfg = ExtResource("3_n2lf8")
[node name="Combo" type="Node3D" parent="." index="6"] [node name="Combo" type="Node3D" parent="." index="6"]
unique_name_in_owner = true unique_name_in_owner = true

@ -9,4 +9,4 @@ enum EStance {
None = 99, None = 99,
Any = 100, Any = 100,
} }
enum EBreakLevel {None, Cancel, Combo, Jump, Walk} #不可打断 取消技打断 连招打断 跳跃打断 行走打断 enum EBreakLevel {None, Cancel, Jump, Combo, Walk} #不可打断 取消技打断 跳跃打断 连招打断 行走打断

@ -4,3 +4,5 @@ extends Node3D
const pixel_size : float = 0.01 const pixel_size : float = 0.01
const sprite_scale : float = 1.414 const sprite_scale : float = 1.414
#技能系统
const input_alive_time : float = 0.2

@ -18,3 +18,13 @@ func refresh_animation_lib():
animation_library.add_animation(animation_name,animation) animation_library.add_animation(animation_name,animation)
animation_library.animation_added.emit(animation_name) animation_library.animation_added.emit(animation_name)
func get_all_player_skill():
var ret = []
var dir_path = "res://config/player_skill"
var dir = DirAccess.open(dir_path)
for file in dir.get_files():
var path = dir_path + "/" + file
var res = load(path)
if res is PlayerSkillCfg:
ret.append(res)
return ret

@ -1,13 +1,96 @@
extends Node3D extends Node3D
class_name Combo
var skill_map = {} #stance -> skill @onready var status = (%Status as Status)
@onready var skill = (%Skill as Skill)
@onready var move = (%Move as Move)
class InputData:
var action:String
var alive_time:float
var skill_map = {} #input -> skill[]
var input_list = [] #指令缓存 var input_list = [] #指令缓存
# Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
pass # Replace with function body. for player_skill_res in Util.get_all_player_skill():
var player_skill = player_skill_res as PlayerSkillCfg
add_skill(player_skill.action,player_skill_res)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
pass update_input_alive(delta)
update_break()
update_move()
func update_input_alive(delta):
var input_list_new = []
for input in input_list:
input.alive_time -= delta
if input.alive_time > 0:
input_list_new.append(input)
input_list = input_list_new
func update_break():
for break_level_name in Enum.EBreakLevel:
var break_level = Enum.EBreakLevel[break_level_name]
if break_level <= status.break_level:
match break_level:
Enum.EBreakLevel.None: pass
Enum.EBreakLevel.Cancel: update_break_cancel()
Enum.EBreakLevel.Jump: update_break_jump()
Enum.EBreakLevel.Combo: update_break_combo()
Enum.EBreakLevel.Walk: update_break_walk()
func update_break_cancel():
update_break_by_level(Enum.EBreakLevel.Cancel)
func update_break_jump():
var index = input_list.find("jump")
if index == -1:
return
refresh_input(index)
skill.cancel_skill()
move.jump()
func update_break_combo():
update_break_by_level(Enum.EBreakLevel.Combo)
func update_break_walk():
if status.input_dir.length() > 0:
refresh_input(len(input_list))
skill.cancel_skill()
func update_break_by_level(break_level:Enum.EBreakLevel):
for i in range(0,len(input_list)):
var input = input_list[i]
var skillCfgList = []
if input.action in skill_map:
skillCfgList.append_array(skill_map[input.action])
if "any" in skill_map:
skillCfgList.append_array(skill_map["any"])
for skillCfg in skillCfgList:
if skillCfg.break_level == break_level:
skill.cast_skill(skillCfg,status.input_dir)
refresh_input(i)
func refresh_input(index:int):
if index >= len(input_list)-1:
input_list = []
else:
input_list = input_list.slice(index+1)
func update_move():
if status.is_free_control:
status.move_dir = status.input_dir
func add_input_action(action:String):
var new_input = InputData.new()
new_input.action = action
new_input.alive_time = Setting.input_alive_time
input_list.append(new_input)
func add_skill(action:String,skillCfg:SkillCfg):
if not action in skill_map:
skill_map[action] = []
skill_map[action].append(skillCfg)

@ -1,9 +1,7 @@
extends Node extends Node
@export var test_skill_cfg:SkillCfg
@onready var status = (%Status as Status) @onready var status = (%Status as Status)
@onready var skill = (%Skill as Skill) @onready var combo = (%Combo as Combo)
@onready var move = (%Move as Move)
func _ready(): func _ready():
SignalManager.connect("input_action_pressed",on_input_action_pressed) SignalManager.connect("input_action_pressed",on_input_action_pressed)
@ -11,15 +9,10 @@ func _ready():
SignalManager.connect("input_action_move",on_input_action_move) SignalManager.connect("input_action_move",on_input_action_move)
func on_input_action_pressed(event:InputEvent): func on_input_action_pressed(event:InputEvent):
if event.is_action("attack_light"): combo.add_input_action(event.as_text())
skill.cast_skill(test_skill_cfg,Vector2(1,1))
elif event.is_action("jump"):
move.jump()
func on_input_action_released(event:InputEvent): func on_input_action_released(event:InputEvent):
pass pass
func on_input_action_move(input_dir): func on_input_action_move(input_dir):
if !status.is_free_control: status.input_dir = input_dir
return
status.move_dir = input_dir

@ -12,9 +12,14 @@ func _process(delta):
func cast_skill(cfg:SkillCfg,cast_dir:Vector2): func cast_skill(cfg:SkillCfg,cast_dir:Vector2):
status.is_free_control = false status.is_free_control = false
status.is_skill_running = true
status.skill_dir = cast_dir
play("animation_library/%s"%Util.get_resource_name(cfg)) play("animation_library/%s"%Util.get_resource_name(cfg))
func _on_animation_finished(_anim_name): func cancel_skill():
view.reset() view.reset()
status.is_free_control = true status.is_free_control = true
status.is_skill_running = false
func _on_animation_finished(_anim_name):
cancel_skill()

@ -25,6 +25,11 @@ class_name Status
@export var is_jumped : bool #是否已跳跃 @export var is_jumped : bool #是否已跳跃
@export_category("技能状态") @export_category("技能状态")
@export var is_skill_running : bool #技能是否正在释放
@export_category("玩家输入状态")
@export var input_dir : Vector2 #指令方向
@export var skill_dir : Vector2 #技能释放方向
@export var stance : Enum.EStance #技能姿态 @export var stance : Enum.EStance #技能姿态
@export var break_level : Enum.EBreakLevel #打断等级 @export var break_level : Enum.EBreakLevel #打断等级

@ -6,3 +6,4 @@ class_name PlayerSkillCfg
@export var weapon : WeaponCfg @export var weapon : WeaponCfg
@export var stance_from : Enum.EStance @export var stance_from : Enum.EStance
@export var stance_to : Enum.EStance @export var stance_to : Enum.EStance
@export_enum("light_attack","heavy_attack","flash") var action : String = "light_attack"

@ -5,6 +5,7 @@ class_name SkillCfg
@export var name : String @export var name : String
@export var skill_animation : Animation @export var skill_animation : Animation
@export var break_level : Enum.EBreakLevel = Enum.EBreakLevel.Combo
var _has_animation : bool var _has_animation : bool
@export var has_animation : bool : @export var has_animation : bool :

Loading…
Cancel
Save