56 lines
1.5 KiB
GDScript
56 lines
1.5 KiB
GDScript
extends ActionLeaf
|
|
#执行成功后是否抹除黑板目标数据
|
|
@export var should_erase_target_id:bool=false
|
|
|
|
#用于移动到特定单位的可交互范围内
|
|
func tick(actor:Node,black_board:Blackboard):
|
|
var unit:Unit=actor
|
|
if black_board.has_value("target_unit_id"):
|
|
var target_id:String=black_board.get_value("target_unit_id")
|
|
if Global.get_unit_instance(target_id)==null:
|
|
#移除目标
|
|
black_board.erase_value("target_unit_id")
|
|
return FAILURE
|
|
#获取要移动到的目标实例
|
|
var target_instance:Unit=Global.get_unit_instance(target_id)
|
|
|
|
if not unit.is_unit_instance_in_attack_area(target_instance):
|
|
unit.set_target_pos(target_instance.global_position)
|
|
match unit.get_dir():
|
|
0:
|
|
unit.play_animation("up")
|
|
1:
|
|
unit.play_animation("down")
|
|
2:
|
|
unit.play_animation("left_right")
|
|
3:
|
|
unit.play_animation("left_right")
|
|
return RUNNING
|
|
else:
|
|
unit.stop_move()
|
|
if should_erase_target_id:
|
|
black_board.erase_value("target_unit_id")
|
|
match unit.get_dir():
|
|
0:
|
|
unit.play_animation("up_idle")
|
|
1:
|
|
unit.play_animation("down_idle")
|
|
2:
|
|
unit.play_animation("left_right_idle")
|
|
3:
|
|
unit.play_animation("left_right_idle")
|
|
return SUCCESS
|
|
else:
|
|
black_board.erase_value("target_unit_id")
|
|
match unit.get_dir():
|
|
0:
|
|
unit.play_animation("up_idle")
|
|
1:
|
|
unit.play_animation("down_idle")
|
|
2:
|
|
unit.play_animation("left_right_idle")
|
|
3:
|
|
unit.play_animation("left_right_idle")
|
|
return FAILURE
|
|
|