52 lines
1.3 KiB
GDScript
52 lines
1.3 KiB
GDScript
extends StateNode
|
|
|
|
@export var employee : String = ""
|
|
|
|
var target
|
|
var actor
|
|
var in_queue
|
|
var queued_at : GuildQueue
|
|
var next_state : String
|
|
var next_state_args : Array = []
|
|
|
|
|
|
func execute(subject, ...args : Array) -> void:
|
|
actor = subject
|
|
#find the receptionist queue
|
|
var queue = Guild.hall.employees[employee].queue
|
|
#join the queue
|
|
join_queue(queue)
|
|
reposition_queue(queue.length-1)
|
|
|
|
subject.nav_agent.navigation_finished.connect(_on_navigation_finished)
|
|
|
|
func _on_navigation_finished() -> void:
|
|
actor.nav_agent.navigation_finished.disconnect(_on_navigation_finished)
|
|
if !in_queue:
|
|
complete_state()
|
|
|
|
func join_queue(queue : GuildQueue) -> void:
|
|
queue.add_member(actor)
|
|
in_queue = true
|
|
queued_at = queue
|
|
queue.advanced.connect(_on_queue_advanced)
|
|
|
|
func leave_queue() -> void:
|
|
in_queue = false
|
|
queued_at.advanced.disconnect(_on_queue_advanced)
|
|
queued_at = null
|
|
|
|
func reposition_queue(idx : int) -> void:
|
|
var queue = queued_at
|
|
#if zero approach the receptionist with the intent to use her service at navigation complete.
|
|
actor.approach(queue.global_position + idx * queue.direction * 75)
|
|
|
|
func _on_queue_advanced() -> void:
|
|
#find our place within the queue
|
|
var idx : int = queued_at.members.find(actor)
|
|
#We aren't in the queue, time to advance
|
|
if idx < 0:
|
|
leave_queue()
|
|
else:
|
|
reposition_queue(idx)
|