You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
GDScript
58 lines
1.4 KiB
GDScript
extends Area3D
|
|
class_name BattleAttackArea
|
|
|
|
@onready var battle: Battle = (%Battle as Battle)
|
|
@onready var collision: CollisionShape3D = (%BattleAttackAreaCollision as CollisionShape3D)
|
|
|
|
var is_active: bool
|
|
var alive_time: float
|
|
var attack_info: Struct.AttackInfo
|
|
var attack_id_set: Dictionary = {}
|
|
|
|
|
|
func _ready():
|
|
body_entered.connect(on_body_entered)
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
if is_active:
|
|
alive_time -= delta
|
|
if alive_time <= 0:
|
|
set_active(false)
|
|
|
|
|
|
func refresh_attack_area(attack_info_new: Struct.AttackInfo) -> void:
|
|
attack_info = attack_info_new
|
|
var offset_xz: Vector2 = attack_info.attack_dir * attack_info.attack_box.offset.x
|
|
var offset_y: float = attack_info.attack_box.offset.y
|
|
var offset: Vector3 = Vector3(offset_xz.x, offset_y, offset_xz.y)
|
|
var shape: Shape3D = attack_info.attack_box.shape
|
|
collision.position = offset
|
|
collision.shape = shape
|
|
|
|
attack_id_set.clear()
|
|
alive_time = Setting.animation_frame_rate
|
|
set_active(false)
|
|
set_active(true)
|
|
|
|
|
|
func on_body_entered(body: Node3D):
|
|
call_deferred("on_body_entereddeferred", body)
|
|
|
|
|
|
func on_body_entereddeferred(body: Node3D):
|
|
if body is Character:
|
|
if not attack_id_set.has(body.id):
|
|
battle.on_attack_character(body, attack_info)
|
|
attack_id_set[body.id] = true
|
|
|
|
|
|
func set_active(value: bool) -> void:
|
|
if value:
|
|
alive_time = Setting.animation_frame_rate
|
|
else:
|
|
alive_time = 0
|
|
|
|
is_active = value
|
|
collision.disabled = not value
|