extends Sprite2D
class_name Encounter
const PERSON = preload("res://Art/person.png")
const PERSON_2 = preload("res://Art/person_2.png")
@export var scene_to_open : PackedScene
@export var number_of_bubbles_max = 5
@export var number_of_bubbles_min = 3

@export var timer_max = 0.5
@export var timer_min = 1.5
@export var spawnpoint : Node2D

var timer = 0
var numebr_of_bubbles = 0
var parent_node : EncounterNode

var is_nazi = false

func _ready() -> void:
	is_nazi = randi_range(0,1) > 0
	reset_bubbles()

func reset_bubbles():
	numebr_of_bubbles = randf_range(number_of_bubbles_min,number_of_bubbles_max)
	if is_nazi:
		texture = PERSON_2
	else:
		texture = PERSON
		

func reduce_bubbles():
	numebr_of_bubbles -= 1
	if numebr_of_bubbles <= 0:	
		modulate = Color.DIM_GRAY
		parent_node.deactive()

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	if numebr_of_bubbles <= 0:
		return
		
	timer -= delta
	if timer <= 0:
		var scene = scene_to_open.instantiate()
		scene.encounter = self
		spawnpoint.add_child(scene)
		timer = randf_range(timer_min,timer_max)
