#include "scripts/common.txt"
#include "scripts/BP_common.txt"
#include "scripts/BP_MapCommon.txt"

//Tag IDs
//1000: Start Warp
//1001: Turok Dummy
//1002: Adon Dummy

int charIndex = 0;
int difSelect = DIFFICULTY_HARD;
int adonLockedSound = 0;
bool exiting;
bool touchedChoose = false;
kActor @turok;
kActor @adon;
//------------------------------------------------------------------------------------------------------------------------
// Start Map
//------------------------------------------------------------------------------------------------------------------------
$script 0
{
	@turok = World.GetActorByTID(1001);
	@adon = World.GetActorByTID(1002);
	charIndex = GetPlayerCharacter();
	switch (charIndex)
	{
		case PLAYER_CHAR_TUROK:
		{
			turok.RunFxEvent("CharSelection");
			adon.RunFxEvent("ClearFx");
			break;
		}
		case PLAYER_CHAR_ADON:
		{
			turok.RunFxEvent("ClearFx");
			adon.RunFxEvent("CharSelection");
			break;
		}
	}
	
	Game.CallDelayedMapScript(1, instigator, 0);
	//PlayLoop.ChangeMap("levels/01.map");
}

//------------------------------------------------------------------------------------------------------------------------
void OnSelectDifEasy()
{
	PlayCharSound("sounds/shaders/adon_taunt_01.ksnd");
	difSelect = DIFFICULTY_EASY;
}
//------------------------------------------------------------------------------------------------------------------------
void OnSelectDifNormal()
{
	PlayCharSound("sounds/shaders/adon_dif1.ksnd");
	difSelect = DIFFICULTY_NORMAL;
}
//------------------------------------------------------------------------------------------------------------------------
void OnSelectDifHard()
{
	PlayCharSound("sounds/shaders/adon_dif2.ksnd");
	difSelect = DIFFICULTY_HARD;
}
//------------------------------------------------------------------------------------------------------------------------
void OnSelectDifHardcore()
{
	PlayCharSound("sounds/shaders/adon_dif3.ksnd");
	difSelect = DIFFICULTY_HARDCORE;
}
//------------------------------------------------------------------------------------------------------------------------
void OnSelectConfirmCharacter()
{
	Game.PlaySound("sounds/shaders/generic_216.ksnd");
	SetPlayerCharacter(charIndex);
}
//------------------------------------------------------------------------------------------------------------------------
void OnSelectBackToCharSelect()
{
	Game.PlaySound("sounds/shaders/generic_216.ksnd");
}
//------------------------------------------------------------------------------------------------------------------------
void OnSelectConfirmDifficulty()
{
	SetStarted(true);
	Game.PlaySound("sounds/shaders/generic_216.ksnd");
	SetStartDifficulty(difSelect);
	GameVariables.SetValue("g_difficulty", "" + difSelect);
	PlayLoop.ChangeMap("levels/01.map");
	exiting = true;
}
//------------------------------------------------------------------------------------------------------------------------
bool OnSelectTurok()
{
	PlayCharSound("sounds/shaders/turok_i_am.ksnd");
	charIndex = PLAYER_CHAR_TUROK;
	return true;
}
//------------------------------------------------------------------------------------------------------------------------
bool OnSelectAdon()
{
	if (HasUnlockCharacter(PLAYER_CHAR_ADON) || IsCheatOn(CHEAT_ADON))
	{
		//select
		charIndex = PLAYER_CHAR_ADON;
		PlayCharSound("sounds/shaders/adon_select.ksnd");
		return true;
	}
	else
	{	
		//can't select
		PrintLinesReverse(array<kStr> = { "", "", "", "", "" + AdonFeathers + " " + Game.GetLocalizedText(LTKey(26)) }, 120);
				//PrintLinesReverse(array<kStr> = { "", "", LTKey(26) }, 120);
		adonLockedSound++;
		if (adonLockedSound > 4)
			adonLockedSound = 1;
		switch (adonLockedSound)
		{
			case 1:
			{
				PlayCharSound("sounds/shaders/adon_eheheh.ksnd");
				break;
			}
			case 2:
			{
				PlayCharSound("sounds/shaders/adon_death2.ksnd");
				break;
			}
			case 3:
			{
				PlayCharSound("sounds/shaders/adon_death3.ksnd");
				break;
			}
			case 4:
			{
				PlayCharSound("sounds/shaders/adon_death4.ksnd");
				break;
			}
		}
		return false;
	}
}
//------------------------------------------------------------------------------------------------------------------------
void PlayCharSound(const kStr &in path)
{
	Player.Actor().StopSound();
	Player.Actor().PlaySound(path);
}
//------------------------------------------------------------------------------------------------------------------------
void OnSelectBackToMainMenu()
{
	Game.PlaySound("sounds/shaders/generic_216.ksnd");
	Game.Restart();
	exiting = true;
}
//------------------------------------------------------------------------------------------------------------------------
// Update Map
//------------------------------------------------------------------------------------------------------------------------
$script 1
{
	if (exiting)
	{
		return;
	}
	
	$restart;
}
//------------------------------------------------------------------------------------------------------------------------
// Entered Sector - Choose your difficulty
//------------------------------------------------------------------------------------------------------------------------
$script 2
{
	if (touchedChoose)
		return;
	touchedChoose = true;
	Game.PrintHelp(LTKey(35));
	delay(0.5f);
	Game.PrintHelp(LTKey(35));
	delay(0.5f);
	Game.PrintHelp(LTKey(35));
	delay(0.5f);
	Game.PrintHelp(LTKey(35));
	delay(0.5f);
	Game.PrintHelp(LTKey(35));
}
//------------------------------------------------------------------------------------------------------------------------
// Entered Sector - Easy
//------------------------------------------------------------------------------------------------------------------------
$script 3
{
    // if ((instigator.Flags() & AF_ENTEREDAREAEVENT) != 0)
        // return;
	Game.PrintHelp(LTKey(36));
}
//------------------------------------------------------------------------------------------------------------------------
// Entered Sector - Easy Confirm
//------------------------------------------------------------------------------------------------------------------------
$script 4
{
    if (exiting)
        return;
	
	difSelect = DIFFICULTY_EASY;
	OnSelectConfirmDifficulty();
}
//------------------------------------------------------------------------------------------------------------------------
// Entered Sector - Normal
//------------------------------------------------------------------------------------------------------------------------
$script 5
{
    // if ((instigator.Flags() & AF_ENTEREDAREAEVENT) != 0)
        // return;
	Game.PrintHelp(LTKey(37));
}
//------------------------------------------------------------------------------------------------------------------------
// Entered Sector - Normal Confirm
//------------------------------------------------------------------------------------------------------------------------
$script 6
{
    if (exiting)
        return;
	
	difSelect = DIFFICULTY_NORMAL;
	OnSelectConfirmDifficulty();
}
//------------------------------------------------------------------------------------------------------------------------
// Entered Sector - Hard
//------------------------------------------------------------------------------------------------------------------------
$script 7
{
    // if ((instigator.Flags() & AF_ENTEREDAREAEVENT) != 0)
        // return;
	Game.PrintHelp(LTKey(38));
}
//------------------------------------------------------------------------------------------------------------------------
// Entered Sector - Hard Confirm
//------------------------------------------------------------------------------------------------------------------------
$script 8
{
    if (exiting)
        return;
	
	difSelect = DIFFICULTY_HARD;
	OnSelectConfirmDifficulty();
}
//------------------------------------------------------------------------------------------------------------------------
// Entered Sector - Hardcore
//------------------------------------------------------------------------------------------------------------------------
$script 9
{
    // if ((instigator.Flags() & AF_ENTEREDAREAEVENT) != 0)
        // return;
	Game.PrintHelp(LTKey(39));
}
//------------------------------------------------------------------------------------------------------------------------
// Entered Sector - Hardcore Confirm
//------------------------------------------------------------------------------------------------------------------------
$script 10
{
    if (exiting || !Player.Actor().OnGround())
        return;
	
	difSelect = DIFFICULTY_HARDCORE;
	OnSelectConfirmDifficulty();
}
//------------------------------------------------------------------------------------------------------------------------
// Entered Sector - Turok Char Select
//------------------------------------------------------------------------------------------------------------------------
$script 11
{
    if ((instigator.Flags() & AF_ENTEREDAREAEVENT) != 0)
        return;
	
	if (charIndex == PLAYER_CHAR_TUROK)
	{
		PlayCharSound("sounds/shaders/turok_i_am.ksnd");
		return;
	}

	if (OnSelectTurok())
	{
		SetPlayerCharacter(charIndex);
		
		turok.RunFxEvent("CharSelection");
		adon.RunFxEvent("ClearFx");
	}
}
//------------------------------------------------------------------------------------------------------------------------
// Entered Sector - Adon Char Select
//------------------------------------------------------------------------------------------------------------------------
$script 12
{
    if ((instigator.Flags() & AF_ENTEREDAREAEVENT) != 0)
        return;
	
	if (charIndex == PLAYER_CHAR_ADON)
	{
		PlayCharSound("sounds/shaders/adon_select.ksnd");
		return;
	}

	if (OnSelectAdon())
	{
		SetPlayerCharacter(charIndex);
		turok.RunFxEvent("ClearFx");
		adon.RunFxEvent("CharSelection");
	}
}
//------------------------------------------------------------------------------------------------------------------------
