Vast improvements and a working finite state machine, working on new guild member registration.

This commit is contained in:
2025-07-24 08:41:19 -04:00
parent 90151369de
commit dc30d1b15c
100 changed files with 1987 additions and 194 deletions

View File

@@ -0,0 +1,6 @@
extends StateNode
func execute(subject, ...args : Array) -> void:
if !subject.busy:
subject.queue.try_advance()
complete_state()

View File

@@ -0,0 +1 @@
uid://csicx3fpxv7xt

1
fsm/nodes/leave.gd Normal file
View File

@@ -0,0 +1 @@
extends StateNode

1
fsm/nodes/leave.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://b0ewnwcibhu21

51
fsm/nodes/queue.gd Normal file
View File

@@ -0,0 +1,51 @@
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)

1
fsm/nodes/queue.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://y85swbbk8kbd

17
fsm/nodes/state_node.gd Normal file
View File

@@ -0,0 +1,17 @@
class_name StateNode extends Node
var state_machine : StateMachine = null
signal completed(state : StateNode)
func enter() -> void:
pass
func exit() -> void:
pass
func execute(subject, ...args : Array) -> void:
pass
func complete_state() -> void:
completed.emit(self)

View File

@@ -0,0 +1 @@
uid://c27ctn874rdns

13
fsm/nodes/test.gd Normal file
View File

@@ -0,0 +1,13 @@
extends StateNode
@export var message : String = ""
var target
func execute(subject, ...args : Array) -> void:
subject.approach(Game.player.global_position)
subject.nav_agent.navigation_finished.connect(_on_navigation_finished)
target = subject
func _on_navigation_finished() -> void:
target.nav_agent.navigation_finished.disconnect(_on_navigation_finished)
complete_state()

1
fsm/nodes/test.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://e8we6nmaob1k

34
fsm/nodes/wait.gd Normal file
View File

@@ -0,0 +1,34 @@
extends StateNode
@export var wait_duration : float = 1
var wait_remaining : float = 0
var next_state : String
var next_state_args : Array = []
var actor
func exit() -> void:
actor.show_speech_bubble("")
func _process(delta: float) -> void:
if wait_remaining > 0:
wait_remaining -= delta
if wait_remaining <= 0:
wait_remaining = 0
complete_state()
func execute(subject, ...args : Array) -> void:
wait_remaining = wait_duration
actor = subject
if len(args) > 0 and args[0] != "":
subject.show_speech_bubble(args[0])
if len(args) > 1 and args[1] != "":
next_state = args[1]
else:
next_state = ""
if len(args) > 2 and args[2] != "":
next_state_args = args[2]
else:
next_state_args = []

1
fsm/nodes/wait.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://dl3b5aywu1hf6