//////////////////////////////////////////////////
//	Author: Drammel								//
//	Date: 7/14/2009								//
//	Name: gui_tob_switch						//
//	Description: Turns the martial adept menus  //
//  on and off when the player switches between //
//  characters.									//
//////////////////////////////////////////////////

#include "bot9s_inc_constants"

void CloseScreens(object oPC, int bPC)
{
	object oMartialAdept = GetControlledCharacter(oPC);
	string sToB;
	object oParty, oToB;
	int nCrusader, nSaint, nSwordsage, nWarblade;

	oParty = GetFirstFactionMember(oPC, FALSE);

	while (GetIsObjectValid(oParty))
	{
	//	SendMessageToPC(oMartialAdept, GetName(oParty));
		sToB = GetFirstName(oParty) + "tob";
		oToB = GetObjectByTag(sToB);
		nCrusader = GetLevelByClass(CLASS_TYPE_CRUSADER, oPC);
		nSaint = GetLevelByClass(CLASS_TYPE_SAINT, oPC);
		nSwordsage = GetLevelByClass(CLASS_TYPE_SWORDSAGE, oPC);
		nWarblade = GetLevelByClass(CLASS_TYPE_WARBLADE, oPC);

	//	if (nCrusader == 0)
	//	{
			CloseGUIScreen(oParty, "SCREEN_MARTIAL_MENU_CR");
			CloseGUIScreen(oParty, "SCREEN_QUICK_STRIKE_CR");
			SetLocalInt(oToB, "IsQStrikeActive_CR", 0);
	//	}
	
	//	if (nSaint == 0)
	//	{
			CloseGUIScreen(oParty, "SCREEN_MARTIAL_MENU_SA");
			CloseGUIScreen(oParty, "SCREEN_QUICK_STRIKE_SA");
			SetLocalInt(oToB, "IsQStrikeActive_SA", 0);
	//	}
	
	//	if (nSwordsage == 0)
	//	{
			CloseGUIScreen(oParty, "SCREEN_MARTIAL_MENU_SS");
			CloseGUIScreen(oParty, "SCREEN_QUICK_STRIKE_SS");
	//		CloseGUIScreen(oParty, "SCREEN_MANEUVERS_KNOWN_SS");
	//		CloseGUIScreen(oParty, "SCREEN_MANUEVERS_READIED_SS");
			SetLocalInt(oToB, "IsQStrikeActive_SS", 0);
	//	}
	
//		if (nWarblade == 0)
	//	{
			CloseGUIScreen(oParty, "SCREEN_MARTIAL_MENU_WB");
			CloseGUIScreen(oParty, "SCREEN_QUICK_STRIKE_WB");
			SetLocalInt(oToB, "IsQStrikeActive_WB", 0);
	//	}
	
	//	if (GetHasFeat(!FEAT_MARTIAL_STUDY, oPC))
	//	{
			CloseGUIScreen(oParty, "SCREEN_MARTIAL_MENU");
			CloseGUIScreen(oParty, "SCREEN_QUICK_STRIKE");
		//	CloseGUIScreen(oParty, "SCREEN_MANEUVERS_KNOWN");
		//	CloseGUIScreen(oParty, "SCREEN_MANUEVERS_READIED");
			SetLocalInt(oToB, "IsQStrikeActive___", 0);
	//	}
	
		CloseGUIScreen(oParty, "SCREEN_SWIFT_ACTION");

		oParty = GetNextFactionMember(oPC);
	}
}

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

	int nCrusader = GetLevelByClass(CLASS_TYPE_CRUSADER, oPC);
	int nSaint = GetLevelByClass(CLASS_TYPE_SAINT, oPC);
	int nSwordsage = GetLevelByClass(CLASS_TYPE_SWORDSAGE, oPC);
	int nWarblade = GetLevelByClass(CLASS_TYPE_WARBLADE, oPC);

	if ((nCrusader > 0) && (GetLocalInt(oToB, "Unfettered") == 0))
	{
		DisplayGuiScreen(oPC, "SCREEN_MARTIAL_MENU_CR", FALSE, "martial_menu_cr.xml");
	}

	if ((nSaint > 0) && (GetLocalInt(oToB, "SublimeWay") == 0))
	{
		DisplayGuiScreen(oPC, "SCREEN_MARTIAL_MENU_SA", FALSE, "martial_menu_sa.xml");
	}

	if ((nSwordsage > 0) && (GetLocalInt(oToB, "DesertWind") == 0))
	{
		DisplayGuiScreen(oPC, "SCREEN_MARTIAL_MENU_SS", FALSE, "martial_menu_ss.xml");
	}

	if ((nWarblade > 0) && (GetLocalInt(oToB, "SupernalClarity") == 0))
	{
		DisplayGuiScreen(oPC, "SCREEN_MARTIAL_MENU_WB", FALSE, "martial_menu_wb.xml");
	}

	if ((GetHasFeat(FEAT_MARTIAL_STUDY, oPC)) && (GetLocalInt(oToB, "UmbralAwn") == 0))
	{
		DisplayGuiScreen(oPC, "SCREEN_MARTIAL_MENU", FALSE, "martial_menu.xml");
	}

	if (GetHasFeat(FEAT_MARTIAL_ADEPT, oPC))
	{
		DisplayGuiScreen(oPC, "SCREEN_SWIFT_ACTION", FALSE, "swift_action.xml");
	}
}

void SwitchCharacters()
{
	object oPC = OBJECT_SELF;  //Despite who the player controls OBJECT_SELF is the person that opened the GUI.
	object oMartialAdept = GetControlledCharacter(oPC);

/*	object oLast;
	string sLastToB;

	oLast = GetLocalObject(oPC, "bot9s_lastPC");

	if (oLast == OBJECT_INVALID)
	{
		oLast = OBJECT_SELF;
		sLastToB = GetFirstName(oPC) + "tob";
	}
	else sLastToB = GetFirstName(oLast) + "tob";

	object oLastToB = GetObjectByTag(sLastToB);

	SendMessageToPC(oMartialAdept, "oPC is " + GetName(oPC));
	SendMessageToPC(oMartialAdept, "oMartialAdpet is " + GetName(oMartialAdept));
	SendMessageToPC(oMartialAdept, "oLast is " + GetName(oLast));

	int nLastCrusader = GetLevelByClass(CLASS_TYPE_CRUSADER, oLast);
	int nLastSaint = GetLevelByClass(CLASS_TYPE_SAINT, oLast);
	int nLastSwordsage = GetLevelByClass(CLASS_TYPE_SWORDSAGE, oLast);
	int nLastWarblade = GetLevelByClass(CLASS_TYPE_WARBLADE, oLast);

	CloseGUIScreen(oLast, "SCREEN_SWIFT_ACTION");
	SetLocalInt(oLastToB, "AdaptiveStyle", 0);

	if (nLastCrusader > 0)
	{
		CloseGUIScreen(oLast, "SCREEN_MARTIAL_MENU_CR");
		//AssignCommand(oPC, CloseGUIScreen(oPC, "SCREEN_MANEUVERS_KNOWN_CR"));
		//Absolutely will not run from this file for some reason.  
		//The script that turns it off has been rerouted through 
		//launch_martial_menu.
		//AssignCommand(oPC, CloseGUIScreen(oPC, "SCREEN_MANUEVERS_READIED_CR"));
		CloseGUIScreen(oLast, "SCREEN_QUICK_STRIKE_CR");
		SetLocalInt(oLastToB, "IsQStrikeActive_CR", 0);
	}

	if (nLastSaint > 0)
	{
		CloseGUIScreen(oLast, "SCREEN_MARTIAL_MENU_SA");
		CloseGUIScreen(oLast, "SCREEN_QUICK_STRIKE_SA");
		SetLocalInt(oLastToB, "IsQStrikeActive_SA", 0);
	}

	if (nLastSwordsage > 0)
	{
		CloseGUIScreen(oLast, "SCREEN_MARTIAL_MENU_SS");
		CloseGUIScreen(oLast, "SCREEN_QUICK_STRIKE_SS");
		SetLocalInt(oLastToB, "IsQStrikeActive_SS", 0);
	}

	if (nLastWarblade > 0)
	{
		CloseGUIScreen(oLast, "SCREEN_MARTIAL_MENU_WB");
		CloseGUIScreen(oLast, "SCREEN_QUICK_STRIKE_WB");
		SetLocalInt(oLastToB, "IsQStrikeActive_WB", 0);
	}

	if (GetHasFeat(FEAT_MARTIAL_STUDY, oLast))
	{
		CloseGUIScreen(oLast, "SCREEN_MARTIAL_MENU");
		CloseGUIScreen(oLast, "SCREEN_QUICK_STRIKE");
		SetLocalInt(oLastToB, "IsQStrikeActive___", 0);
	}

	string sMAToB = GetFirstName(oMartialAdept) + "tob";
	object oMAToB = GetObjectByTag(sMAToB);

	int nMACrusader = GetLevelByClass(CLASS_TYPE_CRUSADER, oMartialAdept);
	int nMASaint = GetLevelByClass(CLASS_TYPE_SAINT, oMartialAdept);
	int nMASwordsage = GetLevelByClass(CLASS_TYPE_SWORDSAGE, oMartialAdept);
	int nMAWarblade = GetLevelByClass(CLASS_TYPE_WARBLADE, oMartialAdept);

	CloseGUIScreen(oLast, "SCREEN_MARTIAL_MENU_CR");
	CloseGUIScreen(oLast, "SCREEN_MARTIAL_MENU_SA");
	CloseGUIScreen(oLast, "SCREEN_MARTIAL_MENU_SS");
	CloseGUIScreen(oLast, "SCREEN_MARTIAL_MENU_WB");
	CloseGUIScreen(oLast, "SCREEN_MARTIAL_MENU");
	CloseGUIScreen(oLast, "SCREEN_SWIFT_ACTION");

	if ((nMACrusader > 0) && (GetLocalInt(oMAToB, "Unfettered") == 0))
	{
		DisplayGuiScreen(oMartialAdept, "SCREEN_MARTIAL_MENU_CR", FALSE, "martial_menu_cr.xml");	
	}

	if ((nMASaint > 0) && (GetLocalInt(oMAToB, "SublimeWay") == 0))
	{
		DisplayGuiScreen(oMartialAdept, "SCREEN_MARTIAL_MENU_SA", FALSE, "martial_menu_sa.xml");
	}

	if ((nMASwordsage > 0) && (GetLocalInt(oMAToB, "DesertWind") == 0))
	{
		DisplayGuiScreen(oMartialAdept, "SCREEN_MARTIAL_MENU_SS", FALSE, "martial_menu_ss.xml");
	}

	if ((nMAWarblade > 0) && (GetLocalInt(oMAToB, "SupernalClarity") == 0))
	{
		DisplayGuiScreen(oMartialAdept, "SCREEN_MARTIAL_MENU_WB", FALSE, "martial_menu_wb.xml");
	}

	if ((GetHasFeat(FEAT_MARTIAL_STUDY, oMartialAdept)) && (GetLocalInt(oMAToB, "UmbralAwn") == 0))
	{
		DisplayGuiScreen(oMartialAdept, "SCREEN_MARTIAL_MENU", FALSE, "martial_menu.xml");
	}

	if (GetHasFeat(FEAT_MARTIAL_ADEPT, oMartialAdept))
	{
		DisplayGuiScreen(oMartialAdept, "SCREEN_SWIFT_ACTION", FALSE, "swift_action.xml");
	}

	SetLocalObject(oPC, "bot9s_lastPC", oMartialAdept);*/
//	CloseScreens(oPC, TRUE);
	CloseScreens(oPC, FALSE);
	DelayCommand(0.05f, OpenScreens(oMartialAdept));
}

void main()
{
	DelayCommand(0.05f, SwitchCharacters());
}