extends RefCounted
## Awakening merged into the ULT (Boss 2026-10-09) - QA screenshots (main.gd _take_shot: --shotawult=<op>[:s], awaited
## right before the picture; use with --lang=th --shotsize=1920x1080):
##   pad      - a Lv 45 Defend&Counter before the Awakening Trial: the pad without the AWAKEN button, a padlock badge on ULT
##   card     - the same + the ULT's how-to-unlock card (right-click on the ULT): the lock card text
##   ult[:s]  - the trial done, the ULT cast beside a monster: the awakened ULT moment, s seconds after the cast (0.9)

const SelfTest = preload("res://scripts/selftest.gd")
const JobSlots = preload("res://scripts/server/job_slots.gd")


static func _frames(main: Node, n: int) -> void:
	for i in n:
		await main.get_tree().process_frame


static func _hero(main: Node, trial: bool) -> void:
	var c = PlayerState.ch
	c.class_pick = true
	JobSlots.pick_class(c, "defend_counter")
	c.base_lv = 45
	for s in c.job_slots:
		if s is Dictionary:
			s["base_lv"] = 45
	c.skills["dc_ult"] = 1
	c.skill_cd = {}
	if trial and not ("awaken_trial" in c.quests.done):
		c.quests.done.append("awaken_trial")
	if not trial:
		c.quests.done.erase("awaken_trial")
	c.hp = c.max_hp()
	c.changed.emit()
	PlayerState.changed.emit()
	await _frames(main, 20)


static func run(main: Node, spec: String) -> void:
	var p := spec.split(":")
	GameData.config["awaken_free_test"] = false
	for m in main.mobs():
		m.data = m.data.duplicate(true)
		m.data["aggressive"] = false
	var pad = main.hud.get_meta("ui3_pad") if main.hud.has_meta("ui3_pad") else null
	match p[0]:
		"pad":
			await _hero(main, false)
			await _frames(main, 30)
		"card":
			await _hero(main, false)
			if pad:
				var rc := InputEventMouseButton.new()
				rc.button_index = MOUSE_BUTTON_RIGHT
				rc.pressed = true
				pad._ult_input(rc)
			await _frames(main, 40)
		"ult":
			await _hero(main, true)
			var mob = SelfTest.dummy(main, "pit_foreman", main.me().global_position + Vector3(2.0, 0, 0.5))
			mob.data["aggressive"] = false
			await _frames(main, 20)
			if main.player:
				main.player.manual_control()
				main.player.use_skill("dc_ult")
			var wait := float(p[1]) if p.size() > 1 else 0.9
			await main.get_tree().create_timer(wait).timeout
	print("AWULT shot ", spec, " awakened=", load("res://scripts/server/awaken.gd").active(PlayerState.ch), " pad_awaken_visible=", pad.awaken.visible if pad else null)
