require "Dialogs"

Arena.ResizeImmediate(565, 130)
Player.sprite.alpha = 0
timer = 0

Shards = {}

function Update()
	DialogUpdate()
	if (Encounter["Animation"] != "Death 1" and Encounter["Animation"] != "Death 2") or Encounter["Going"] then
		timer = timer + 1
	end
	if timer == 10 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			Bubble("[noskip][font:papyrus][voice:papyrus]Yo . . .", "rightwide", 520.5, 315, 40, 90, 1)
		elseif GetAlMightyGlobal("Idioma") == "Russian" then
			Bubble("[noskip][font:papyrus][voice:papyrus]Я . . .", "rightwide", 520.5, 315, 40, 90, 1)
		else
			Bubble("[noskip][font:papyrus][voice:papyrus]I . . .", "rightwide", 520.5, 315, 40, 90, 1)
		end
	elseif timer == 40 then
		Audio.PlaySound("slice")
		Slice = CreateSprite("UI/Battle/spr_slice_o_1", "Top")
		Slice.MoveTo(320, 360)
	elseif timer == 46 then
		Slice.Set("UI/Battle/spr_slice_o_2")
	elseif timer == 52 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 58 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 64 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 70 then
		Slice.alpha = 0
		Encounter["Animation"] = "Death 2"
		Encounter["vel"] = 0
		Bubble("", "", 0, 0, 0, 0, 1)
		timer = 71
	elseif timer == 72 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Todavía creo en\nti![w:10000000000] ", "rightwide", 520.5, 265, 40, 90, 1)
		elseif GetAlMightyGlobal("Idioma") == "Russian" then
			Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Я всё ещё\nверю в тебя![w:10000000000] ", "rightwide", 520.5, 265, 40, 90, 1)
		else
			Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]I still believe\nin you![w:10000000000] ", "rightwide", 520.5, 265, 40, 90, 1)
		end
	elseif timer == 132 then
		Audio.PlaySound("slice")
		Slice.Set("UI/Battle/spr_slice_o_1")
		Slice.MoveTo(365, 280)
		Slice.alpha = 1
	elseif timer == 138 then
		Slice.Set("UI/Battle/spr_slice_o_2")
	elseif timer == 144 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 150 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 156 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 162 then
		Slice.alpha = 0
		Encounter["Animation"] = "Death 3"
		Encounter["vel"] = 0
		Bubble("", "", 0, 0, 0, 0, 1)
		for i=1,4 do
			local shard = CreateSprite("Soul Shards/1", "Top")
			shard.SetAnimation({"Soul Shards/1", "Soul Shards/2", "Soul Shards/3", "Soul Shards/4"}, 0.08)
			table.insert(Shards, {Sprite = shard, X = math.random(-20, 20), Y = math.random(30), Pos = {X = 372, Y = 278}})
		end
	elseif timer == 192 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			Bubble("[noskip][font:papyrus][voice:papyrus][waittall:1.5]Todavía . . .[w:10000000000] ", "rightwide", 520.5, 265, 40, 90, 1)
		elseif GetAlMightyGlobal("Idioma") == "Russian" then
			Bubble("[noskip][font:papyrus][voice:papyrus][waittall:1.5]Я всё ещё. . .[w:10000000000] ", "rightwide", 520.5, 265, 40, 90, 1)
		else
			Bubble("[noskip][font:papyrus][voice:papyrus][waittall:1.5]I still . . .[w:10000000000] ", "rightwide", 520.5, 265, 40, 90, 1)
		end
	elseif timer == 222 then
		Audio.PlaySound("slice")
		Slice.Set("UI/Battle/spr_slice_o_1")
		Slice.alpha = 1
	elseif timer == 228 then
		Slice.Set("UI/Battle/spr_slice_o_2")
	elseif timer == 234 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 240 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 246 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 252 then
		Slice.alpha = 0
		Encounter["Animation"] = "Death 4"
		Encounter["vel"] = 0
		Bubble("", "", 0, 0, 0, 0, 1)
		for i=1,7 do
			local shard = CreateSprite("Soul Shards/1", "Top")
			shard.SetAnimation({"Soul Shards/1", "Soul Shards/2", "Soul Shards/3", "Soul Shards/4"}, 0.08)
			table.insert(Shards, {Sprite = shard, X = math.random(-20, 20), Y = math.random(30), Pos = {X = 372, Y = 278}})
		end
	elseif timer == 267 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			Bubble("[noskip][font:papyrus][voice:papyrus][waittall:2]Yo . . .[w:10000000000] ", "rightwide", 520.5, 265, 40, 90, 1)
		elseif GetAlMightyGlobal("Idioma") == "Russian" then
			Bubble("[noskip][font:papyrus][voice:papyrus][waittall:2]Я . . .[w:10000000000] ", "rightwide", 520.5, 265, 40, 90, 1)
		else
			Bubble("[noskip][font:papyrus][voice:papyrus][waittall:2]I . . .[w:10000000000] ", "rightwide", 520.5, 265, 40, 90, 1)
		end
		Audio.PlaySound("slice")
		Slice.Set("UI/Battle/spr_slice_o_1")
		Slice.alpha = 1
	elseif timer == 273 then
		Slice.Set("UI/Battle/spr_slice_o_2")
	elseif timer == 279 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 285 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 291 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 297 then
		Slice.alpha = 0
		Encounter["Animation"] = "Death 5"
		Encounter["vel"] = 0
		Bubble("", "", 0, 0, 0, 0, 1)
		for i=1,10 do
			local shard = CreateSprite("Soul Shards/1", "Top")
			shard.SetAnimation({"Soul Shards/1", "Soul Shards/2", "Soul Shards/3", "Soul Shards/4"}, 0.08)
			table.insert(Shards, {Sprite = shard, X = math.random(-20, 20), Y = math.random(30), Pos = {X = 372, Y = 278}})
		end
	elseif timer == 312 then
		Audio.PlaySound("slice")
		Slice.Set("UI/Battle/spr_slice_o_1")
		Slice.alpha = 1
	elseif timer == 318 then
		Slice.Set("UI/Battle/spr_slice_o_2")
	elseif timer == 324 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 330 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 336 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 342 then
		Slice.alpha = 0
		Encounter["Animation"] = "Death 6"
		Encounter["vel"] = 0
		Encounter.Call("SetCustomHP", {210, 20, 191, Player.hp, true})
	elseif timer > 660 then
		if not Black then
			Black = CreateSprite("Pixel","Top")
			Black.color = {0,0,0}
			Black.MoveTo(320, 240)
			Black.Scale(640, 480)
			Black.alpha = 0
		else
			Black.alpha = Black.alpha + 0.02
			if Black.alpha >= 1 then
				Slice.Remove()
				Black.Remove()
				for i=1,#Shards do
					local Datos = Shards[i - tableaux]
					Datos.Sprite.Remove()
					table.remove(Shards, i - tableaux)
					tableaux = tableaux + 1
				end
				tableaux = 0
				Encounter["nextwaves"] = {"Overworld/Genocide"}
				State("DEFENDING")
			end
		end
	end
	for i=1,#Shards do
		local Datos = Shards[i - tableaux]
		if not Datos.Timer then
			Datos.Timer = 0
		end
		Datos.Timer = Datos.Timer + 1
		Datos.Pos.X = Datos.Pos.X + Datos.X/10
		Datos.Pos.Y = Datos.Pos.Y + Datos.Y/10
		Datos.Sprite.MoveTo(Datos.Pos.X, Datos.Pos.Y)
		Datos.Y = Datos.Y - 1
		if Datos.Timer > 40 then
			Datos.Sprite.alpha = Datos.Sprite.alpha - 0.05
		end
		if Datos.Sprite.alpha <= 0 then
			Datos.Sprite.Remove()
			table.remove(Shards, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
end