extends Node2D
class_name Wave

@export var title: String
@export_multiline var description: String
@export var duration: float = 20.0
@export var power_level: float = 1.0

@export_group("Encounters")
var UFO1: PackedScene = preload("res://scene/entity/ufo_1.tscn")
var UFO2: PackedScene = preload("res://scene/entity/ufo_2.tscn")
var UFO2B: PackedScene = preload("res://scene/entity/ufo_2_big.tscn")
var UFO3: PackedScene = preload("res://scene/entity/ufo_3.tscn")
var UFO4: PackedScene = preload("res://scene/entity/ufo_4.tscn")
var UFO5: PackedScene = preload("res://scene/entity/ufo_ast.tscn")
@export var witchUFO: int
@export var fork: int
@export var forkB: int
@export var star: int
@export var boss: int
@export var ast: int

@onready var mob_target = $"../../UFOs"
var index = 0
var timer: Timer = Timer.new()

func _ready():
    timer.set_wait_time(0.5)
    timer.set_one_shot(true)
    add_child(timer)

func insert(mob: PackedScene, count: int):
    for i in range(0, count):
        var new_mob = mob.instantiate()
        new_mob.set_position(get_global_position() + Vector2(index * 800, 0))
        index += 1
        index %= 5
        mob_target.add_child(new_mob)
        timer.start()
        await timer.timeout

func activate():
    insert(UFO1, witchUFO)
    insert(UFO2, fork)
    insert(UFO2B, forkB)
    insert(UFO3, star)
    insert(UFO4, boss)
    insert(UFO5, ast)

func get_log_data_per_mob(val: int, tstr: String, target: String) -> String:
    if val > 0:
        target += "[indent]" + str(val) + "x " + tstr + "[/indent]\n" 
    return target

func get_log_data():
    var l = ""
    l = get_log_data_per_mob(witchUFO, "U.W.O.", l)
    l = get_log_data_per_mob(fork, "Farm ship", l)
    l = get_log_data_per_mob(forkB, "Shipfork", l)
    l = get_log_data_per_mob(star, "Morning star", l)
    l = get_log_data_per_mob(boss, "Comically large U.W.O.", l)
    l = get_log_data_per_mob(ast, "Asteroid", l)
    return l
