From 1e33601b905ba83a18dcdc6676aa3a616fbb56a1 Mon Sep 17 00:00:00 2001 From: chendian <-> Date: Mon, 23 Sep 2024 04:38:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AD=A6=E6=88=92=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/beehave/nodes/beehave_tree.gd | 4 +- config/character/monster01.tres | 4 +- config/character/monster02.tres | 4 +- config/character/monster03.tres | 4 +- config/character_ai/normal.tres | 10 ++++ .../hero01_long_air_attack03.tres | 4 +- .../hero01_long_air_attack03.tres | 3 +- resource/ui/hud/headbar_alert.png | Bin 0 -> 147 bytes resource/ui/hud/headbar_alert.png.import | 34 +++++++++++ resource/ui/hud/headbar_alert_empty.png | Bin 0 -> 160 bytes .../ui/hud/headbar_alert_empty.png.import | 34 +++++++++++ scene/launcher.tscn | 7 ++- scene/ui/item/headbar.tscn | 54 ++++++++++++++---- script/character/ai/ai.gd | 47 ++++++++++++++- script/character/battle.gd | 3 + script/character/character.gd | 12 +++- script/character/status.gd | 3 + script/config/ai_cfg.gd | 9 +++ script/config/character_cfg.gd | 1 + script/ui/hud/headbar.gd | 15 +++++ 20 files changed, 225 insertions(+), 27 deletions(-) create mode 100644 config/character_ai/normal.tres create mode 100644 resource/ui/hud/headbar_alert.png create mode 100644 resource/ui/hud/headbar_alert.png.import create mode 100644 resource/ui/hud/headbar_alert_empty.png create mode 100644 resource/ui/hud/headbar_alert_empty.png.import create mode 100644 script/config/ai_cfg.gd diff --git a/addons/beehave/nodes/beehave_tree.gd b/addons/beehave/nodes/beehave_tree.gd index 409cc76..ad5efd5 100644 --- a/addons/beehave/nodes/beehave_tree.gd +++ b/addons/beehave/nodes/beehave_tree.gd @@ -69,7 +69,7 @@ var _process_time_metric_name : String var _process_time_metric_value : float = 0.0 var _can_send_message: bool = false -func _ready() -> void: +func init() -> void: if Engine.is_editor_hint(): return @@ -100,7 +100,7 @@ func _ready() -> void: BeehaveDebuggerMessages.register_tree(_get_debugger_data(self)) -func _physics_process(delta: float) -> void: +func process(delta: float) -> void: if Engine.is_editor_hint(): return diff --git a/config/character/monster01.tres b/config/character/monster01.tres index c8c56b3..64f29b5 100644 --- a/config/character/monster01.tres +++ b/config/character/monster01.tres @@ -1,6 +1,7 @@ -[gd_resource type="Resource" script_class="CharacterCfg" load_steps=7 format=3 uid="uid://b1gf2jimihmc7"] +[gd_resource type="Resource" script_class="CharacterCfg" load_steps=8 format=3 uid="uid://b1gf2jimihmc7"] [ext_resource type="Script" path="res://script/config/character_cfg.gd" id="1_4orbu"] +[ext_resource type="Resource" uid="uid://b26gc616anvo1" path="res://config/character_ai/normal.tres" id="1_jvsh2"] [ext_resource type="Resource" uid="uid://dkjv5kj8mgy8v" path="res://config/character_move/slow.tres" id="1_vaqv0"] [ext_resource type="Resource" uid="uid://dpajmgrlaytah" path="res://config/character_mp/normal.tres" id="2_pl54c"] [ext_resource type="SpriteFrames" uid="uid://dkljs5h8gj5l" path="res://resource/animation/character/monster01_move.aseprite" id="2_su3hg"] @@ -18,6 +19,7 @@ move = ExtResource("1_vaqv0") shield = ExtResource("4_ei6r7") stun = ExtResource("6_25uqm") mp = ExtResource("2_pl54c") +ai = ExtResource("1_jvsh2") hp_max = 20.0 attack = 10.0 sub_character_auto_create = false diff --git a/config/character/monster02.tres b/config/character/monster02.tres index 84eb275..89cbebb 100644 --- a/config/character/monster02.tres +++ b/config/character/monster02.tres @@ -1,6 +1,7 @@ -[gd_resource type="Resource" script_class="CharacterCfg" load_steps=7 format=3 uid="uid://dmfh54jffhx28"] +[gd_resource type="Resource" script_class="CharacterCfg" load_steps=8 format=3 uid="uid://dmfh54jffhx28"] [ext_resource type="Resource" uid="uid://dkjv5kj8mgy8v" path="res://config/character_move/slow.tres" id="1_tsstu"] +[ext_resource type="Resource" uid="uid://b26gc616anvo1" path="res://config/character_ai/normal.tres" id="1_vfyb7"] [ext_resource type="Script" path="res://script/config/character_cfg.gd" id="1_wkjce"] [ext_resource type="Resource" uid="uid://dpajmgrlaytah" path="res://config/character_mp/normal.tres" id="2_gly3h"] [ext_resource type="SpriteFrames" uid="uid://crdd52skym3ir" path="res://resource/animation/character/monster02_move.aseprite" id="2_h60bf"] @@ -18,6 +19,7 @@ move = ExtResource("1_tsstu") shield = ExtResource("4_uyg17") stun = ExtResource("6_vlmkd") mp = ExtResource("2_gly3h") +ai = ExtResource("1_vfyb7") hp_max = 50.0 attack = 10.0 sub_character_auto_create = false diff --git a/config/character/monster03.tres b/config/character/monster03.tres index c0e8050..5d4851b 100644 --- a/config/character/monster03.tres +++ b/config/character/monster03.tres @@ -1,5 +1,6 @@ -[gd_resource type="Resource" script_class="CharacterCfg" load_steps=7 format=3 uid="uid://c4v710n3f6pb3"] +[gd_resource type="Resource" script_class="CharacterCfg" load_steps=8 format=3 uid="uid://c4v710n3f6pb3"] +[ext_resource type="Resource" uid="uid://b26gc616anvo1" path="res://config/character_ai/normal.tres" id="1_lr20m"] [ext_resource type="Resource" uid="uid://dx54fjf5t0uu8" path="res://config/character_move/normal.tres" id="1_ol2gy"] [ext_resource type="Resource" uid="uid://dpajmgrlaytah" path="res://config/character_mp/normal.tres" id="2_kkpsf"] [ext_resource type="Script" path="res://script/config/character_cfg.gd" id="3_0gem5"] @@ -18,6 +19,7 @@ move = ExtResource("1_ol2gy") shield = ExtResource("4_3daai") stun = ExtResource("6_ar00t") mp = ExtResource("2_kkpsf") +ai = ExtResource("1_lr20m") hp_max = 100.0 attack = 10.0 sub_character_auto_create = false diff --git a/config/character_ai/normal.tres b/config/character_ai/normal.tres new file mode 100644 index 0000000..7f13d37 --- /dev/null +++ b/config/character_ai/normal.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" script_class="AICfg" load_steps=2 format=3 uid="uid://b26gc616anvo1"] + +[ext_resource type="Script" path="res://script/config/ai_cfg.gd" id="1_jkdaq"] + +[resource] +script = ExtResource("1_jkdaq") +is_auto_alert = false +alert_range = 5.0 +alert_max = 10.0 +alert_speed = 4.0 diff --git a/config/skill_player_weapon/hero01_long_air_attack03.tres b/config/skill_player_weapon/hero01_long_air_attack03.tres index 71b33b3..6d547f8 100644 --- a/config/skill_player_weapon/hero01_long_air_attack03.tres +++ b/config/skill_player_weapon/hero01_long_air_attack03.tres @@ -1,7 +1,8 @@ -[gd_resource type="Resource" script_class="SkillWeaponCfg" load_steps=5 format=3 uid="uid://b705py5rht5i3"] +[gd_resource type="Resource" script_class="SkillWeaponCfg" load_steps=6 format=3 uid="uid://b705py5rht5i3"] [ext_resource type="Resource" uid="uid://bv4uoey1liqoq" path="res://config/attack/sharp_heavy_hit_blow.tres" id="1_5rgpl"] [ext_resource type="Script" path="res://script/config/skill_weapon_cfg.gd" id="2_0x7hh"] +[ext_resource type="Resource" uid="uid://bqejjllfy03h3" path="res://config/attack_box/box_normal.tres" id="2_rpr7r"] [ext_resource type="Animation" uid="uid://bh5s2t3cbobpp" path="res://resource/skill_animation/hero01_long_air_attack03.tres" id="3_1erk8"] [ext_resource type="Resource" uid="uid://cy3wwalxeyro0" path="res://config/weapon/long.tres" id="5_u3vas"] @@ -15,6 +16,7 @@ range = 0.0 free_lock = false ignore_push = false attack1 = ExtResource("1_5rgpl") +attack1_box = ExtResource("2_rpr7r") stance_from = 12 stance_to = 10 break_level = 3 diff --git a/resource/skill_animation/hero01_long_air_attack03.tres b/resource/skill_animation/hero01_long_air_attack03.tres index 439ad6a..5ff9e93 100644 --- a/resource/skill_animation/hero01_long_air_attack03.tres +++ b/resource/skill_animation/hero01_long_air_attack03.tres @@ -5,6 +5,7 @@ [resource] resource_name = "hero01_long_air_attack03" length = 0.9 +step = 0.1 tracks/0/type = "value" tracks/0/imported = false tracks/0/enabled = true @@ -36,7 +37,7 @@ tracks/2/path = NodePath("Status:break_level") tracks/2/interp = 1 tracks/2/loop_wrap = true tracks/2/keys = { -"times": PackedFloat32Array(0, 0.3, 0.5), +"times": PackedFloat32Array(0, 0.5, 0.7), "transitions": PackedFloat32Array(1, 1, 1), "update": 1, "values": [0, 3, 4] diff --git a/resource/ui/hud/headbar_alert.png b/resource/ui/hud/headbar_alert.png new file mode 100644 index 0000000000000000000000000000000000000000..e2a090525e64f6023850a275750558c666a72f47 GIT binary patch literal 147 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~c!3HEhl+{lMQjEnx?oJHr&dIz4a(q2q978lF zuAS(~b-;j!*;Mua|4mgKnu-&5J3LQGIbGo>DQ@N8qgTe~DWM4fbMrG# literal 0 HcmV?d00001 diff --git a/resource/ui/hud/headbar_alert.png.import b/resource/ui/hud/headbar_alert.png.import new file mode 100644 index 0000000..ae83a28 --- /dev/null +++ b/resource/ui/hud/headbar_alert.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b8ejwekki1ubx" +path="res://.godot/imported/headbar_alert.png-e46709cab95ebc3974aa4c78a5b256f2.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://resource/ui/hud/headbar_alert.png" +dest_files=["res://.godot/imported/headbar_alert.png-e46709cab95ebc3974aa4c78a5b256f2.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=0 +compress/normal_map=2 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=false +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 diff --git a/resource/ui/hud/headbar_alert_empty.png b/resource/ui/hud/headbar_alert_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..acc834edf706c11ffebf5e8e9cc34e182173e5b7 GIT binary patch literal 160 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~c!3HEhl+{lMQjEnx?oJHr&dIz4a-uw4978lF zPMvs=_kaNhbG4}PCU5l@dO9!nDFu27eVr#}##C(L5wx5+ void: - if is_init: - if has_ai: on_process(delta) - return + if not is_init: + init() + else: + process(delta) + +func init() -> void: if not status.cfg: return is_init = true @@ -24,6 +27,44 @@ func _process(delta) -> void: add_child(ai) has_ai = true on_init() + ai.init() + + +func process(delta) -> void: + if has_ai and status.ai_is_alert: + on_process(delta) + ai.process(delta) + else: + if status.cfg.ai: + stroll() + var player: Character = Global.character_mgr.get_player() + var dir: Vector2 = player.pos2D() - character.pos2D() + var dist: float = dir.length() + var can_see: bool = character.get_face_dir().angle_to(dir) < PI/2 + var alert_range: float = status.cfg.ai.alert_range if can_see else status.cfg.ai.alert_range_back + var alert_speed: float = status.cfg.ai.alert_speed if can_see else status.cfg.ai.alert_speed_back + if dist < alert_range: + status.ai_alert += alert_speed * delta + status.emit_status("ai_alert") + if status.ai_alert >= status.ai_alert_max: + status.ai_is_alert = true + status.ai_alert = 0 + status.emit_status("ai_is_alert") + status.emit_status("ai_alert") + else: + status.ai_alert -= status.cfg.ai.alert_recover * delta + if status.ai_alert < 0: + status.ai_alert = 0 + status.emit_status("ai_alert") + else: + status.ai_is_alert = true + status.emit_status("ai_is_alert") + + +func stroll() -> void: + #todo 闲逛 + character.move_stop() + pass func on_init() -> void: diff --git a/script/character/battle.gd b/script/character/battle.gd index d8ef702..673d9fb 100644 --- a/script/character/battle.gd +++ b/script/character/battle.gd @@ -177,6 +177,9 @@ func add_attack(from: int, to: int, dir: Vector2, attack: AttackCfg) -> HitResul character_from.add_mp_sub(damage * cfg_from.mp.add_rate_attack, true) character_to.add_mp_sub(damage * cfg_to.mp.add_rate_hit, true) + #受击结束警戒 + character_to.set_status("ai_is_alert", true) + #投技检测 if is_break_skill and attack.is_throw_check and not character_to.get_status("is_be_throw") and status.throw_target == 0: character_to.set_status("is_be_throw", true) diff --git a/script/character/character.gd b/script/character/character.gd index cfe9ef0..bb29fb2 100644 --- a/script/character/character.gd +++ b/script/character/character.gd @@ -28,13 +28,16 @@ func init(id: int, cfg: CharacterCfg, team: Enum.ETeam, owner_id: int): func init_after(): var cfg: CharacterCfg = status.cfg as CharacterCfg set_status("hp_max", cfg.hp_max) + set_status("hp", cfg.hp_max) set_status("shield_max", cfg.shield.shield_max) set_status("stun_max", cfg.stun.stun_max) set_status("mp_max", cfg.mp.mp_max) set_status("mp_sub_max", cfg.mp.mp_sub_max) - set_status("hp", cfg.hp_max) set_shield(cfg.shield.shield_max) add_mp_sub(0, true) + if cfg.ai: + set_status("ai_alert_max", cfg.ai.alert_max) + set_status("ai_is_alert", false) func set_body_scale(cfg: CharacterCfg) -> void: @@ -60,7 +63,7 @@ func set_body_scale(cfg: CharacterCfg) -> void: pushbox.scale = body_scale status.basic_offset = Vector3(0, center_height, randf()*0.001) status.ui_offset = Vector3(0, height*1.25, 0) - status.ui_center_offset = Vector3(0, center_height, 0) + status.ui_center_offset = Vector3(0, half_height, 0) status.radius = width status.height = height effect.set_body_scale(body_scale) @@ -134,6 +137,11 @@ func move_stop(): set_status("move_dir", Vector2.ZERO) move.stop() +func get_face_dir() -> Vector2: + if status.move_dir == Vector2.ZERO: + return Vector2.RIGHT if is_right() else Vector2.LEFT + return status.move_dir + func add_buff(buff_name: String, duration: float, ignore_pause: bool = false): buff.add_buff(buff_name, duration, ignore_pause) diff --git a/script/character/status.gd b/script/character/status.gd index 2e8aa9b..eff2223 100644 --- a/script/character/status.gd +++ b/script/character/status.gd @@ -91,6 +91,9 @@ var charging_level: int #蓄力等级 #ai状态 var ai_role: int #ai角色 var ai_skill_order: Array[SkillOrder] = [] #ai技能指令 +var ai_alert_max: float #警戒值最大值 +var ai_alert: float #警戒值 +var ai_is_alert: bool #是否已激活 #动画触发器 var trigger_jump: bool #跳跃 var trigger_hit: bool #受击-地面-轻 diff --git a/script/config/ai_cfg.gd b/script/config/ai_cfg.gd new file mode 100644 index 0000000..5d5e405 --- /dev/null +++ b/script/config/ai_cfg.gd @@ -0,0 +1,9 @@ +extends Cfg +class_name AICfg + +@export var alert_max: float = 10 #最大警戒值 +@export var alert_range: float = 5 #触发距离 +@export var alert_speed: float = 4 #触发速度 +@export var alert_range_back: float = 2 #背面触发距离 +@export var alert_speed_back: float = 2 #背面触发速度 +@export var alert_recover: float = 2 #恢复速度 diff --git a/script/config/character_cfg.gd b/script/config/character_cfg.gd index 20db8cb..5d45b69 100644 --- a/script/config/character_cfg.gd +++ b/script/config/character_cfg.gd @@ -13,6 +13,7 @@ class_name CharacterCfg @export var shield: ShieldCfg @export var stun: StunCfg @export var mp: MpCfg +@export var ai: AICfg #战斗信息 @export var hp_max: float @export var attack: float diff --git a/script/ui/hud/headbar.gd b/script/ui/hud/headbar.gd index 5fdcdba..d284017 100644 --- a/script/ui/hud/headbar.gd +++ b/script/ui/hud/headbar.gd @@ -2,9 +2,11 @@ extends Control class_name Headbar @onready var hit_text_scene: PackedScene = preload("res://scene/ui/item/hit_text.tscn") +@onready var battle_info: Control = (%BattleInfo as Control) @onready var hp_bar: TextureProgressBar = (%HpBar as TextureProgressBar) @onready var shield_bar: TextureProgressBar = (%ShieldBar as TextureProgressBar) @onready var break_level: Sprite2D = (%BreakLevel as Sprite2D) +@onready var alert_bar: TextureProgressBar = (%AlertBar as TextureProgressBar) #debug info @onready var stun_bar: TextureProgressBar = (%StunBar as TextureProgressBar) @onready var mp_bar: TextureProgressBar = (%MpBar as TextureProgressBar) @@ -54,6 +56,19 @@ func on_break_level_def_changed(value): break_level.frame = clamp(value + 4, 0, 8) +func on_ai_is_alert_changed(value): + alert_bar.visible = not value + battle_info.visible = value + + +func on_ai_alert_max_changed(value): + alert_bar.max_value = value + + +func on_ai_alert_changed(value): + alert_bar.value = value + + func on_stun_changed(value): stun_bar.value = value