extends Node3D
class_name VendingMachineRoom

func setup_room(door_id : int):
    var rng := RandomNumberGenerator.new()
    rng.seed = door_id

    Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

    var all_vending_machines = %VendingMachines.get_children() as Array[VendingMachine3d]
    var vending_machine : VendingMachine3d = all_vending_machines[rng.randi()%len(all_vending_machines)]

    var available_artefacts = GameInfo.game_data.progression_data.get_all_artifacts()
    var artefacts = []

    while len(artefacts) < 2:
        var artefact = available_artefacts[rng.randi()%len(available_artefacts)]
        if artefacts.find_custom(
            func (a : Artefact): return a.get_artefact_name() == artefact.get_artefact_name()
        ) == -1:
            artefacts.append(artefact)
    
    vending_machine.artefact_1 = artefacts[0]
    vending_machine.artefact_2 = artefacts[1]
    vending_machine.price = VendingMachineEnergyPrice.new(2)
    vending_machine.state = VendingMachine3d.State.CHOOSE
    vending_machine.used.connect(
        func ():
            GameInfo.game_data.current_region_data.completed_doors.append(door_id)
    )

func _on_exit_clicked():
    %Exit.interactable = false
    SceneManager.change_to_scene(RegionScene.new(GameInfo.game_data.current_region_data))
