extends RefCounted
## Screenshots of the painted 2D gacha (main.gd --shotgacha=<mode>[:<seconds>], test mode, nothing saved):
##   well          the Starwell page            well10:<s> / well1:<s>   a x10 / x1 pull, <s> s into the reveal
##   asura         the Asura summon page        asura10:<s> / asura1:<s> an Asura x10 / x1 summon, <s> s in
##   splash        a x1 pull forced to a Mythic and held on its splash
## The hero gets shards / tickets for the pull; the result is whatever the server rolls (except "splash").

const Mounts = preload("res://scripts/server/mounts.gd")
const Asura = preload("res://scripts/server/asura.gd")


static func run(main, arg: String) -> void:
	var parts := arg.split(":")
	var mode := parts[0]
	var at := float(parts[1]) if parts.size() > 1 else 2.5
	var c = PlayerState.ch
	main.hud.visible = true
	for i in 20:
		await main.get_tree().process_frame
	if mode.begins_with("well") or mode == "splash":
		Mounts.ensure(c)["shards"] = 5000
		var w = main.hud.mount_ui.well
		w.open()
		for i in 20:
			await main.get_tree().process_frame
		if mode == "splash":
			w.play_reveal([{"id": "aurelion", "rarity": "mythic", "new": true, "stars": 1}], "mythic")
			at = maxf(at, 3.2)
		elif mode != "well":
			w._pull(10 if mode == "well10" else 1)
	elif mode.begins_with("asura"):
		Asura.ensure(c)["tickets"] = 50
		var ui = main.hud.get_meta("asura_ui") if main.hud.has_meta("asura_ui") else null
		if ui == null:
			print("GACHA SHOT no asura ui")
			return
		ui.open("summon")
		for i in 20:
			await main.get_tree().process_frame
		if mode != "asura":
			ui._pull(10 if mode == "asura10" else 1)
	else:
		print("GACHA SHOT unknown mode ", mode)
		return
	for i in int(at * 60.0):
		await main.get_tree().process_frame
