89 lines
2.0 KiB
GDScript
89 lines
2.0 KiB
GDScript
extends Node3D
|
|
|
|
class_name Actor
|
|
|
|
enum ACTOR_STATE {INACTIVE, ACTIVE, IDLE}
|
|
|
|
var actor_state = null: set = state_change
|
|
|
|
const red = preload("res://tiles/base_tile/red.tres")
|
|
|
|
var target = null
|
|
var next_step = null
|
|
|
|
var temp_speed = 4
|
|
var time = 0
|
|
|
|
var current_tile = null: set = change_current_tile
|
|
var current_room = null
|
|
|
|
var lookup_actor_to_task = []
|
|
var current_task: Dictionary
|
|
|
|
|
|
@onready var task_creator: TaskCreator = $TaskCreator
|
|
|
|
signal current_tile_request
|
|
|
|
func state_change(state):
|
|
actor_state = state
|
|
match state:
|
|
ACTOR_STATE.ACTIVE:
|
|
$SelfMesh.set_material_override(red)
|
|
ACTOR_STATE.IDLE:
|
|
if lookup_actor_to_task:
|
|
current_task = lookup_actor_to_task[0]
|
|
else:
|
|
var target = Vector3i(randi_range(1, 32), 0, randi_range(1, 32))
|
|
$SelfMesh.set_material_override(null)
|
|
task_creator.create_task(
|
|
self,
|
|
self,
|
|
target,
|
|
)
|
|
|
|
#func task_check():
|
|
#if lookup_actor_to_task:
|
|
#current_task = lookup_actor_to_task[0]
|
|
#next_step = current_task.location
|
|
#actor_state = ACTOR_STATE.ACTIVE
|
|
|
|
func _process(delta: float) -> void:
|
|
#var velocity = Vector3.ZERO
|
|
|
|
match actor_state:
|
|
ACTOR_STATE.ACTIVE:
|
|
get_current_tile()
|
|
|
|
if next_step:
|
|
if self.position.distance_to(next_step) > 1:
|
|
#velocity = self.position.direction_to(next_step) * temp_speed
|
|
position = lerp(Vector3(next_step), self.position, 0.995)
|
|
else:
|
|
var completed_task = lookup_actor_to_task.pop_front()
|
|
current_task = {}
|
|
task_creator.complete_task(self, completed_task)
|
|
actor_state = ACTOR_STATE.IDLE
|
|
|
|
ACTOR_STATE.IDLE:
|
|
if lookup_actor_to_task:
|
|
current_task = lookup_actor_to_task[0]
|
|
next_step = current_task.location
|
|
actor_state = ACTOR_STATE.ACTIVE
|
|
pass
|
|
|
|
func get_current_tile():
|
|
emit_signal("current_tile_request", self)
|
|
|
|
func change_current_tile(new_tile):
|
|
if current_tile != new_tile:
|
|
current_tile = new_tile
|
|
get_room()
|
|
prints(current_tile, current_room)
|
|
|
|
func get_room():
|
|
if current_tile.lookup_tile_to_room:
|
|
current_room = current_tile.lookup_tile_to_room[0]
|
|
else:
|
|
current_room = null
|