//===== eAthena Script =======================================
//= Kafra Express - Stylist Module
//===== By: ==================================================
//= Skotlex
//===== Current Version: =====================================
//= 1.9
//===== Compatible With: =====================================
//= eAthena SVN 3424+
//===== Description: =========================================
//= Part of the Kafra Express Script Package.
//= Offers dying of hair, clothes and hair-style adjusts
//===== Additional Comments: =================================
//= See config.txt for configuration.
//============================================================

-	script	keInit_dye	{
OnInit:	//Load Config
	donpcevent "keConfig::OnLoadDye";
	end;
}

function	script	F_keStylist	{

	function SF_inputpalette;
	function SF_wheelpalette;

	set @jobClass,callfunc("GF_getJobLevel",class);
	set @maxCDye,0;
	
	switch (@jobClass) {
	case 0:
		set @maxCDye, $@kedy_clothJN;
		break;
	case 1:
		set @maxCDye, $@kedy_clothJ1ST;
		break;
	case 2:
		set @maxCDye, $@kedy_clothJ2ND;
		break;
	case 3:	
		set @maxCDye, $@kedy_clothJSN;
		break;
	case 4:
		set @maxCDye, $@kedy_clothJWED;
		break;
	}
	do {
		if ($@kedy_enableHairstyle) {
			set @kmenu, select(
				"- Return",
				"- Change hairstyle (current is "+getlook(1)+"/max is "+$@kedy_styles+")",
				"- Change hairstyle (by wheel)",
				"- Dye hair (current is "+getlook(6)+"/max is "+$@kedy_hair+")",
				"- Dye hair (by wheel)",
				"- Dye clothes (current is "+getlook(7)+"/max is "+@maxCDye+")",
				"- Dye clothes (by wheel)"
			);
		} else {
			set @kmenu, select(
				"- Return",
				"- Dye hair (current is "+getlook(6)+"/max is "+$@kedy_hair+")",
				"- Dye hair (by wheel)",
				"- Dye clothes (current is "+getlook(7)+"/max is "+@maxCDye+")",
				"- Dye clothes (by wheel)"
			);
			if (@kmenu > 1)
				set @kmenu, @kmenu+2;
		}
		switch (@kmenu) {
		case 2:	//Hair Style Input
			SF_inputpalette 1,$@kedy_styles;
			break;
		case 3:	//Hair Style Wheel
			SF_wheelpalette 1,$@kedy_styles;
			break;
		case 4:	//Hair Dye Input
			SF_inputpalette 6,$@kedy_hair;
			break;
		case 5:	//Hair Dye Wheel
			SF_wheelpalette 6,$@kedy_hair;
			break;
		case 6:	//Clothes Input
			SF_inputpalette 7,@maxCDye;
			break;
		case 7:	//Clothes Wheel
			SF_wheelpalette 7,@maxCDye ;
			break;
		}
	} while (@kmenu > 1);
	return;
	
//Subfunction: SF_inputpalette(int part, int maxPalette)
//Sets a palette from the user's request.
function	SF_inputpalette {
	input @pal;
	if (@pal < 0 || @pal > getarg(1)) {
		callfunc "F_keIntro", e_swt2, "Sorry, we do not have that dye available.";
		return;
	}
	setlook getarg(0),@pal;
	emotion e_lv;
}	//SF_ end

//Subfunction: SF_wheelpalette(int part, int maxPalette)
//Sets a palette through browsing.
function	SF_wheelpalette {
	set @loc, getarg(0);
	set @max, getarg(1);
	set @pal, getlook(@loc);
	set @dir, 1;
	do {
		if (@dir > 0)
			set @submenu, select(
				"Next",
				"Previous",
				"Done (current is "+@pal+")"
			);
		else
			set @submenu, select(
				"Previous",
				"Next",
				"Done (current is "+@pal+")"
			);
		switch (@submenu) {
		case 2: //Swap direction
			set @dir, @dir*-1;
		case 1:
			set @pal, @pal+@dir;
			if (@pal < 0)
				set @pal, @max;
			else if (@pal > @max)
				set @pal, 0;
			setlook @loc,@pal;
		}
	} while (@submenu != 3);
	emotion e_lv2;
}	//SF_ end

}
