警戒系统

master
chendian 1 year ago
parent b771cb38e3
commit 1e33601b90

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

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

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

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

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

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

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://0l8bh5eq104a"
path="res://.godot/imported/headbar_alert_empty.png-3f1e95f05258cc648656ae23fc713fa6.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://resource/ui/hud/headbar_alert_empty.png"
dest_files=["res://.godot/imported/headbar_alert_empty.png-3f1e95f05258cc648656ae23fc713fa6.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

@ -20,7 +20,7 @@
[ext_resource type="Script" path="res://script/manager/input_manager.gd" id="12_vfqm4"]
[ext_resource type="Script" path="res://script/character/status.gd" id="18_nr8sb"]
[ext_resource type="SpriteFrames" uid="uid://2cb8lknel0ih" path="res://resource/animation/character/basic_move.aseprite" id="20_4ni1a"]
[ext_resource type="SpriteFrames" uid="uid://bhsotj76tuovy" path="res://resource/animation/character/hero01_fist_attack.aseprite" id="20_653tf"]
[ext_resource type="SpriteFrames" uid="uid://ce83cuqwgwwi4" path="res://resource/animation/character/hero01_long_attack.aseprite" id="20_8k3m1"]
[ext_resource type="AnimationLibrary" uid="uid://croik07a1qko5" path="res://resource/skill_animation_library/animation_library.tres" id="22_qyapv"]
[ext_resource type="Script" path="res://script/character/skill.gd" id="23_783eu"]
[ext_resource type="Script" path="res://script/character/move.gd" id="25_d520l"]
@ -218,8 +218,9 @@ pixel_size = 0.02
double_sided = false
alpha_cut = 2
texture_filter = 0
sprite_frames = ExtResource("20_653tf")
animation = &"fist_air_attack01"
sprite_frames = ExtResource("20_8k3m1")
animation = &"long_air_attack03"
frame = 8
[node name="Throw" type="AnimatedSprite3D" parent="EditorTool/Character"]
unique_name_in_owner = true

@ -1,9 +1,11 @@
[gd_scene load_steps=5 format=3 uid="uid://dy0u26ba7dle"]
[gd_scene load_steps=7 format=3 uid="uid://dy0u26ba7dle"]
[ext_resource type="Script" path="res://script/ui/hud/headbar.gd" id="1_k0rtd"]
[ext_resource type="Texture2D" uid="uid://cwhu1ec03t3c8" path="res://resource/ui/hud/headbar_hp_empty.png" id="2_g5t31"]
[ext_resource type="Texture2D" uid="uid://b4ly1exl0owck" path="res://resource/ui/hud/headbar_hp.png" id="3_vh1p5"]
[ext_resource type="Texture2D" uid="uid://dqqd56qoquts7" path="res://resource/ui/hud/break_level.png" id="4_wo8oo"]
[ext_resource type="Texture2D" uid="uid://0l8bh5eq104a" path="res://resource/ui/hud/headbar_alert_empty.png" id="5_y2g2r"]
[ext_resource type="Texture2D" uid="uid://b8ejwekki1ubx" path="res://resource/ui/hud/headbar_alert.png" id="6_j2n1r"]
[node name="HeadBar" type="Control"]
layout_mode = 3
@ -14,7 +16,13 @@ offset_right = 256.0
offset_bottom = 88.0
script = ExtResource("1_k0rtd")
[node name="HpBar" type="TextureProgressBar" parent="."]
[node name="BattleInfo" type="Control" parent="."]
unique_name_in_owner = true
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
[node name="HpBar" type="TextureProgressBar" parent="BattleInfo"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 8
@ -22,10 +30,10 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -16.0
offset_top = -2.0
offset_right = 16.0
offset_bottom = 2.0
offset_left = -36.0
offset_top = -22.0
offset_right = -4.0
offset_bottom = -18.0
grow_horizontal = 2
grow_vertical = 2
value = 60.0
@ -36,7 +44,7 @@ texture_under = ExtResource("2_g5t31")
texture_progress = ExtResource("3_vh1p5")
tint_progress = Color(1, 0, 0, 1)
[node name="ShieldBar" type="TextureProgressBar" parent="."]
[node name="ShieldBar" type="TextureProgressBar" parent="BattleInfo"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 8
@ -44,10 +52,10 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -16.0
offset_top = -2.0
offset_right = 16.0
offset_bottom = 2.0
offset_left = -36.0
offset_top = -22.0
offset_right = -4.0
offset_bottom = -18.0
grow_horizontal = 2
grow_vertical = 2
value = 50.0
@ -58,13 +66,35 @@ texture_under = ExtResource("2_g5t31")
texture_progress = ExtResource("3_vh1p5")
tint_progress = Color(0.996078, 0.752941, 0.278431, 1)
[node name="BreakLevel" type="Sprite2D" parent="."]
[node name="BreakLevel" type="Sprite2D" parent="BattleInfo"]
unique_name_in_owner = true
position = Vector2(-21, 0)
texture = ExtResource("4_wo8oo")
hframes = 3
vframes = 3
[node name="AlertBar" type="TextureProgressBar" parent="."]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -8.0
offset_top = -4.0
offset_right = 8.0
offset_bottom = 4.0
grow_horizontal = 2
grow_vertical = 2
value = 60.0
fill_mode = 3
stretch_margin_left = 1
stretch_margin_right = 1
texture_under = ExtResource("5_y2g2r")
texture_progress = ExtResource("6_j2n1r")
tint_progress = Color(0.729412, 0, 0, 1)
[node name="DebugInfo" type="Control" parent="."]
unique_name_in_owner = true
anchors_preset = 0

@ -10,10 +10,13 @@ var has_ai: bool = false
func _process(delta) -> 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:

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

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

@ -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 #受击-地面-轻

@ -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 #恢复速度

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

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

Loading…
Cancel
Save