锁定优化

master
chendian 1 year ago
parent 271eb69a39
commit 5614893442

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1021 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://dx2vp753yvh4y" uid="uid://dx2vp753yvh4y"
path="res://.godot/imported/lock.png-32166d0b031590623c7496bf56c8f4a7.ctex" path="res://.godot/imported/lock.png-e2a5c1eddc1a695c4c501a4c652e0820.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://render/texture/decal/lock.png" source_file="res://resource/ui/hud/lock.png"
dest_files=["res://.godot/imported/lock.png-32166d0b031590623c7496bf56c8f4a7.ctex"] dest_files=["res://.godot/imported/lock.png-e2a5c1eddc1a695c4c501a4c652e0820.ctex"]
[params] [params]

@ -11,7 +11,7 @@
[ext_resource type="Texture2D" uid="uid://0f3lam5c3k0y" path="res://resource/ui/hud/player_status_hp.png" id="5_b0cyb"] [ext_resource type="Texture2D" uid="uid://0f3lam5c3k0y" path="res://resource/ui/hud/player_status_hp.png" id="5_b0cyb"]
[ext_resource type="Script" path="res://script/ui/hud/lock_item.gd" id="5_usy8x"] [ext_resource type="Script" path="res://script/ui/hud/lock_item.gd" id="5_usy8x"]
[ext_resource type="Texture2D" uid="uid://g4b4cjfdaxsx" path="res://resource/ui/hud/player_status_mp_sub_empty.png" id="6_fqaaa"] [ext_resource type="Texture2D" uid="uid://g4b4cjfdaxsx" path="res://resource/ui/hud/player_status_mp_sub_empty.png" id="6_fqaaa"]
[ext_resource type="Texture2D" uid="uid://dx2vp753yvh4y" path="res://render/texture/decal/lock.png" id="6_hmslt"] [ext_resource type="Texture2D" uid="uid://dx2vp753yvh4y" path="res://resource/ui/hud/lock.png" id="6_hmslt"]
[ext_resource type="Script" path="res://script/ui/hud/weapon_item.gd" id="7_3g1k3"] [ext_resource type="Script" path="res://script/ui/hud/weapon_item.gd" id="7_3g1k3"]
[ext_resource type="Texture2D" uid="uid://bvuv86ujfaqfx" path="res://resource/ui/hud/player_status_mp_sub.png" id="7_wiq06"] [ext_resource type="Texture2D" uid="uid://bvuv86ujfaqfx" path="res://resource/ui/hud/player_status_mp_sub.png" id="7_wiq06"]
[ext_resource type="Texture2D" uid="uid://bp7cve5pxkvv0" path="res://resource/ui/hud/boss_status_hp_empty.png" id="9_3sg6t"] [ext_resource type="Texture2D" uid="uid://bp7cve5pxkvv0" path="res://resource/ui/hud/boss_status_hp_empty.png" id="9_3sg6t"]
@ -218,6 +218,7 @@ script = ExtResource("5_usy8x")
[node name="Lock" type="Sprite2D" parent="HudPage/LockItem"] [node name="Lock" type="Sprite2D" parent="HudPage/LockItem"]
texture = ExtResource("6_hmslt") texture = ExtResource("6_hmslt")
hframes = 2
[node name="AnimationPlayer" type="AnimationPlayer" parent="HudPage/LockItem"] [node name="AnimationPlayer" type="AnimationPlayer" parent="HudPage/LockItem"]
libraries = { libraries = {

@ -193,6 +193,10 @@ func set_target(target: int):
set_status("target", target) set_status("target", target)
func set_is_lock(value: bool):
set_status("is_lock", value)
func cast_particle(resource: Resource, is_attach: bool, offset: Vector3 = Vector3.ZERO, scale: Vector3 = Vector3.ONE): func cast_particle(resource: Resource, is_attach: bool, offset: Vector3 = Vector3.ZERO, scale: Vector3 = Vector3.ONE):
effect.cast_particle(resource, is_attach, offset, scale) effect.cast_particle(resource, is_attach, offset, scale)

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

@ -57,7 +57,7 @@ func get_switch_action(action_name: String)->String:
return action_name return action_name
if not status.is_switch: if not status.is_switch:
return action_name return action_name
if status.target: if status.is_lock:
return "lock_%s" % action_name return "lock_%s" % action_name
else: else:
return "free_%s" % action_name return "free_%s" % action_name
@ -68,7 +68,7 @@ func get_skill_action(action_name: String)->String:
return action_name return action_name
var index: int = skill_action_list.find(action_name) var index: int = skill_action_list.find(action_name)
action_name = switch_action_list[index] action_name = switch_action_list[index]
if status.target: if status.is_lock:
return "lock_%s" % action_name return "lock_%s" % action_name
else: else:
return "free_%s"% action_name return "free_%s"% action_name

@ -46,9 +46,11 @@ func cast_skill_by_name(name: String, cast_dir: Vector2):
func cast_skill(cfg: SkillCfg, cast_dir: Vector2, action_key: String = "") -> bool: func cast_skill(cfg: SkillCfg, cast_dir: Vector2, action_key: String = "") -> bool:
if cast_dir.length() == 0: var is_no_dir: bool = cast_dir.length() == 0
if is_no_dir:
cast_dir = Vector2.RIGHT if status.is_right else Vector2.LEFT cast_dir = Vector2.RIGHT if status.is_right else Vector2.LEFT
if !cfg.free_lock and status.target: var is_cast_to_target: bool = status.target and (status.is_lock or is_no_dir)
if !cfg.free_lock and is_cast_to_target:
var target: Character = Global.character_mgr.get_character(status.target) var target: Character = Global.character_mgr.get_character(status.target)
if target: if target:
cast_dir = character.pos2D().direction_to(target.pos2D()).normalized() cast_dir = character.pos2D().direction_to(target.pos2D()).normalized()

@ -22,6 +22,7 @@ class_name Status
@export var mp_sub_max: float #次级mp最大值 @export var mp_sub_max: float #次级mp最大值
@export var is_dead: bool #是否死亡 @export var is_dead: bool #是否死亡
@export var target: int #目标角色 @export var target: int #目标角色
@export var is_lock: bool #是否主动锁定
@export var throw_target: int #投技目标 @export var throw_target: int #投技目标
@export var break_level_def: int #硬直抗性等级 @export var break_level_def: int #硬直抗性等级
@export_category("表现状态") @export_category("表现状态")

@ -1,6 +1,7 @@
extends Control extends Control
@onready var animation: AnimationPlayer = $AnimationPlayer as AnimationPlayer @onready var animation: AnimationPlayer = $AnimationPlayer as AnimationPlayer
@onready var lock: Sprite2D = $Lock as Sprite2D
@onready var camera: CameraManager = Global.camera_mgr @onready var camera: CameraManager = Global.camera_mgr
var target: Character var target: Character
@ -19,3 +20,7 @@ func _process(delta):
func on_target_changed(target_id: int): func on_target_changed(target_id: int):
target = Global.character_mgr.get_character(target_id) target = Global.character_mgr.get_character(target_id)
visible = target != null visible = target != null
func on_is_lock_changed(is_lock: bool):
lock.frame = 0 if is_lock else 1

Loading…
Cancel
Save