class_name cCharacter
extends Node

# --- Parameters ---
@export_range(0, 20) var ai_level := 10

@export var min_interval := 8
@export var max_interval := 12
@export var reset_after_climax := true
@export var character_name := "template"

# --- Constants ---
const MAX_STATE := 6
const DEBUG := true

# --- Runtime ---
var current_room: int = -1
var move_timer := 0.0
var stunted: bool = false

func move_to(room_id: int):
	if current_room != -1:
		Global.rooms[current_room].remove_enemy(self)

	current_room = room_id
	Global.rooms[current_room].add_enemy(self)

func _init():
	_ready()

func _ready() -> void:
	randomize()
	_set_next_interval()

# Pick the next random movement interval (3–5 sec)
func _set_next_interval() -> void:
	move_timer = randf_range(min_interval, max_interval)

# Rolls to see if the character may move
func try_move(delta: float) -> bool:
	move_timer -= delta
	if move_timer > 0.0:
		return false

	# Interval completed → immediately pick the next one
	_set_next_interval()

	# Roll 1–20 like OG FNAF
	var roll := randi_range(1, 20)

	if DEBUG:
		print(character_name, " | AI:", ai_level, " | Roll:", roll)

	return roll <= ai_level

func _process(delta: float) -> void:
	if try_move(delta):
		if(stunted):
			stunted = false
			return
