'''
Attempts to simulate human-esc responses.

green	- good at subtraction
red		- good at multiplication
blue	- good at addition
'''

extends Node

var currently_executing:bool = false
var faster_operand:String = ""
var wait_time:int
var is_correct:bool
var last_executed_player:int

var clock:int = 0
		
func _physics_process(_delta: float) -> void:
	if GLOBALVARS.selected_player != 0:
		if not currently_executing and GLOBALVARS.selected_player != last_executed_player:
			if GLOBALVARS.selected_player == 1:
				faster_operand = "-"
			elif GLOBALVARS.selected_player == 2:
				faster_operand = "*"
			elif GLOBALVARS.selected_player == 3:
				faster_operand = "+"
				
			if GLOBALVARS.current_operand == faster_operand:
				wait_time = randi_range(45,120)
				is_correct = true if randf() > 0.05 else false
			else:
				wait_time = randi_range(60,350)
				is_correct = true if randf() > 0.15 else false
			currently_executing = true
			last_executed_player = GLOBALVARS.selected_player
			
		elif clock > wait_time and currently_executing:
			if %ANSWER.text == "":
				%ANSWER.text = str(GLOBALVARS.current_solution) if is_correct else str(GLOBALVARS.current_solution+(1 if randf() > .5 else -1))
			elif clock > wait_time + 30:
				%ANSWER.emit_signal("text_submitted",%ANSWER.text)
				currently_executing = false
				clock = 0
			else:
				clock+=1
		else:
			clock+=1
	else:
		last_executed_player = 0
