Initial project sync
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
class_name EnemyActionDriver
|
||||
extends Node
|
||||
|
||||
const AIIntentScript := preload("res://scenes/components/ai_intent.gd")
|
||||
|
||||
@export var action_controller_path: NodePath
|
||||
|
||||
@onready var action_controller: Node = get_node_or_null(action_controller_path)
|
||||
|
||||
|
||||
func start_action(action_id: StringName) -> void:
|
||||
if action_controller == null or not action_controller.has_method("submit_ai_intent"):
|
||||
return
|
||||
if not _owner_allows_action(action_id):
|
||||
return
|
||||
var intent: RefCounted = AIIntentScript.create(action_id, float(Time.get_ticks_msec()))
|
||||
action_controller.call("submit_ai_intent", intent)
|
||||
|
||||
|
||||
func handle_chart_event(event: Resource) -> void:
|
||||
if event == null:
|
||||
return
|
||||
var action_id := StringName(str(event.get("action_id")))
|
||||
if action_id.is_empty() and event.get("payload") is Dictionary:
|
||||
action_id = StringName(str(event.get("payload").get("action_id", &"")))
|
||||
if action_id.is_empty():
|
||||
return
|
||||
if not _owner_allows_action(action_id):
|
||||
return
|
||||
if action_controller != null and int(action_controller.get("phase")) != 0 and action_controller.has_method("cancel_current"):
|
||||
action_controller.call("cancel_current", &"chart_override")
|
||||
start_action(action_id)
|
||||
|
||||
|
||||
func _owner_allows_action(action_id: StringName) -> bool:
|
||||
var actor := get_parent()
|
||||
if actor != null and actor.has_method("can_start_enemy_action"):
|
||||
return bool(actor.call("can_start_enemy_action", action_id))
|
||||
return true
|
||||
Reference in New Issue
Block a user