///////////////////////////////////////////////
// Author: Drammel							 //
// Date: 1/7/2009						  	 //
// Title: gui_launch_bot9s					 //
// Description: Launch the Martial Adept Menu//
///////////////////////////////////////////////

#include "bot9s_inc_misc"

void main(string sClass)
{
	object oOrigin = OBJECT_SELF;
	object oPC = GetControlledCharacter(oOrigin);
	string sScreenKnown;
	string sScreenReadied;

	string sToB = GetFirstName(oPC) + "tob";
	object oToB = GetObjectByTag(sToB);

	if (sClass == "___")
	{
		sScreenKnown = "SCREEN_MANEUVERS_KNOWN";
	}
	else  sScreenKnown = "SCREEN_MANEUVERS_KNOWN" + sClass;

	if (sClass == "___")
	{
		sScreenReadied = "SCREEN_MANEUVERS_READIED";
	}
	else sScreenReadied = "SCREEN_MANEUVERS_READIED" + sClass;

	string sKnown;
	string sReadied;

	if (sClass == "_CR")
	{
		sKnown = "maneuvers_known_cr.xml";
	}
	else if (sClass == "_SA")
	{
		sKnown = "maneuvers_known_sa.xml";
	}
	else if (sClass == "_SS")
	{
		sKnown = "maneuvers_known_ss.xml";
	}
	else if (sClass == "_WB")
	{
		sKnown = "maneuvers_known_wb.xml";
	}
	else sKnown = "maneuvers_known.xml";
	
	if (sClass == "_CR")
	{
		sReadied = "maneuvers_readied_cr.xml";
	}
	else if (sClass == "_SA")
	{
		sReadied = "maneuvers_readied_sa.xml";
	}
	else if (sClass == "_SS")
	{
		sReadied = "maneuvers_readied_ss.xml";
	}
	else if (sClass == "_WB")
	{
		sReadied = "maneuvers_readied_wb.xml";
	}
	else sReadied = "maneuvers_readied.xml";

	int nAdaptive = GetLocalInt(oToB, "AdaptiveStyle");

	if ((GetIsObjectValid(oToB)) && (GetLocalInt(oToB, "Encounter") != 0) && (GetHasFeat(FEAT_ADAPTIVE_STYLE, oPC)) && (nAdaptive == 0) && (GetLocalInt(oToB, "Is9SMenuActive" + sClass) == 0))
	{
		SetLocalString(oToB, "AS_Class", sClass);
		SetLocalString(oToB, "AS_Known", sKnown);
		SetLocalString(oToB, "AS_Readied", sReadied);
		SetLocalString(oToB, "AS_ScreenKnown", sScreenKnown);
		SetLocalString(oToB, "AS_ScreenReadied", sScreenReadied);

		if (sClass == "_CR")
		{
			SetLocalInt(oToB, "AS_HaltCrCycle", 1); // Red Light on the Crusader's recovery method.
			SetLocalInt(oToB, "RedCrusader", 1);
			SetLocalInt(oToB, "EncounterR1", 0);
		}

		ActionUseFeat(FEAT_ADAPTIVE_STYLE, oPC);
	}
	else if ((sClass == "_CR") && (CheckRedCrusader()) && (GetLocalInt(oToB, "Is9SMenuActive" + sClass) == 1) && (nAdaptive == 1))
	{
		SetLocalInt(oToB, "Is9SMenuActive" + sClass, 0);
		SetLocalInt(oToB, "RedCrusader", 0);
		SetLocalInt(oToB, "CR_ForcedClose", 0);
		CloseGUIScreen(oPC, sScreenKnown);
		CloseGUIScreen(oPC, sScreenReadied);
		SetLocalInt(oToB, "CrusaderActive", 0);
		SetLocalInt(oPC, "CrusaderActive", 0);
		SetLocalInt(oToB, "AdaptiveStyle", 0);
		SetLocalInt(oToB, "DisableQuickstrike", 0);
		SetLocalInt(oToB, "AS_HaltCrCycle", 0); // Green Light on the Crusader's recovery method.
		DelayCommand(0.1f, ExecuteScript("cr_recovery", oPC));
	}
	else if ((sClass != "_CR") && (GetLocalInt(oToB, "Is9SMenuActive" + sClass) == 1) && (nAdaptive == 1))
	{
		SetLocalInt(oToB, "Is9SMenuActive" + sClass, 0);	
		CloseGUIScreen(oPC, sScreenKnown);
		CloseGUIScreen(oPC, sScreenReadied);
		SetLocalInt(oToB, "AdaptiveStyle", 0);
		SetLocalInt(oToB, "DisableQuickstrike", 0);

		string sScreen;

		if (sClass == "___")
		{
			sScreen = "SCREEN_QUICK_STRIKE";
		}
		else sScreen = "SCREEN_QUICK_STRIKE" + sClass;

		RecoverAllManeuvers(sScreen);
	}
	else if ((GetLocalInt(oToB, "Is9SMenuActive_CR") == 1) && (GetLocalInt(oToB, "Encounter") != 0) && (!CheckRedCrusader()))
	{
		int nReadiedTotal = GetLocalInt(oToB, "ReadiedTotal_CR");

		SendMessageToPC(oPC, "<color=red>You must ready a total of " + IntToString(nReadiedTotal) + " maneuvers before you can close the menu.</color>");
	}
	else if (GetIsObjectValid(oToB) && (GetLocalInt(oToB, "Encounter") != 0))
	{
		SendMessageToPC(oPC, "<color=red>You cannot change maneuvers while in combat.</color>");
	}
	else if (GetIsObjectValid(oToB))
	{
		if (GetLocalInt(oToB, "Is9SMenuActive" + sClass) == 0)
		{
			SetLocalInt(oToB, "Is9SMenuActive" + sClass, 1);
			DisplayGuiScreen(oPC, sScreenReadied, FALSE, sReadied);
			DisplayGuiScreen(oPC, sScreenKnown, FALSE, sKnown);

			if (sClass == "_CR")
			{
				SetLocalInt(oToB, "RedCrusader", 1);
			}
		}
		else if ((sClass == "_CR") && (!CheckRedCrusader()))
		{
			int nReadiedTotal = GetLocalInt(oToB, "ReadiedTotal_CR");

			SendMessageToPC(oPC, "<color=red>You must ready a total of " + IntToString(nReadiedTotal) + " maneuvers before you can close the menu.</color>");
		}
		else
		{
			CloseGUIScreen(oPC, sScreenReadied);
			CloseGUIScreen(oPC, sScreenKnown);
			SetLocalInt(oToB, "Is9SMenuActive" + sClass, 0);

			if (sClass == "_CR")
			{
				SetLocalInt(oToB, "RedCrusader", 0);
				SetLocalInt(oToB, "CR_ForcedClose", 0);
			}
		}
	}
	else SendMessageToPC(oPC, "<color=red>You must activate the training feat for your class before you can open the Martial Adept Menu.</color>");
}