|
|
|
|
@ -6,20 +6,33 @@ class_name PlayerAction
|
|
|
|
|
@onready var status: Status = (%Status as Status)
|
|
|
|
|
@onready var combo: Combo = (%Combo as Combo)
|
|
|
|
|
|
|
|
|
|
var is_lock_pressed: bool
|
|
|
|
|
var lock_cd_dict: Dictionary = {}
|
|
|
|
|
var is_lock: bool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _process(delta) -> void:
|
|
|
|
|
var has_target: bool = status.target != 0
|
|
|
|
|
#更新主动锁定目标cd
|
|
|
|
|
for key in lock_cd_dict:
|
|
|
|
|
if lock_cd_dict[key] > 0:
|
|
|
|
|
lock_cd_dict[key] -= delta
|
|
|
|
|
else:
|
|
|
|
|
lock_cd_dict.erase(key)
|
|
|
|
|
if is_lock_pressed == has_target:
|
|
|
|
|
#没有锁定目标 尝试被动锁定
|
|
|
|
|
if not status.target and not is_lock:
|
|
|
|
|
var enemy_list: Array[Character] = Global.character_mgr.get_enemy_list(character.id())
|
|
|
|
|
var pos_player: Vector2 = character.pos2D()
|
|
|
|
|
enemy_list.filter( func(a: Character): return a.pos2D().distance_squared_to(pos_player)<3)
|
|
|
|
|
enemy_list.sort_custom(
|
|
|
|
|
func(a: Character, b: Character):
|
|
|
|
|
return a.pos2D().distance_squared_to(pos_player) < b.pos2D().distance_squared_to(pos_player)
|
|
|
|
|
)
|
|
|
|
|
if enemy_list:
|
|
|
|
|
character.set_target(enemy_list[0].id())
|
|
|
|
|
character.set_is_lock(is_lock)
|
|
|
|
|
#锁定状态有变化 尝试主动锁定
|
|
|
|
|
if status.is_lock == is_lock:
|
|
|
|
|
return
|
|
|
|
|
if is_lock_pressed:
|
|
|
|
|
if is_lock:
|
|
|
|
|
var enemy_list: Array[Character] = Global.character_mgr.get_enemy_list(character.id())
|
|
|
|
|
var pos_player: Vector2 = character.pos2D()
|
|
|
|
|
enemy_list.sort_custom(
|
|
|
|
|
@ -33,8 +46,9 @@ func _process(delta) -> void:
|
|
|
|
|
if enemy_list:
|
|
|
|
|
character.set_target(enemy_list[0].id())
|
|
|
|
|
else:
|
|
|
|
|
lock_cd_dict[character.target()] = 1 #1秒内无法再次锁定
|
|
|
|
|
character.set_target(0)
|
|
|
|
|
if status.target:
|
|
|
|
|
lock_cd_dict[status.target] = 0.5 #0.5秒内无法再次主动锁定
|
|
|
|
|
character.set_is_lock(is_lock)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func check_action(key: String, is_pressed: bool) -> bool:
|
|
|
|
|
@ -60,7 +74,7 @@ func check_action_pressed(key: String) -> bool:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func lock(is_pressed: bool):
|
|
|
|
|
is_lock_pressed = is_pressed
|
|
|
|
|
is_lock = is_pressed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func switch(is_pressed: bool):
|
|
|
|
|
|