//===== rAthena Script ======================================= 
//= Gemstone Trader
//===== By: ================================================== 
//= L0ne_W0lf
//===== Current Version: ===================================== 
//= 1.3
//===== Compatible With: ===================================== 
//= rAthena SVN
//===== Description: ========================================= 
//= [Official Conversion]
//= Trade various colors of gemstones for other color gemstones.
//===== Additional Comments: ================================= 
//= 1.0 Rescripted to Aegis 10.3 standards. [L0ne_W0lf]
//=     Any notes pertaining to the prior trader may be found
//=     in the cities/payon.txt
//= 1.1 Corrected NPC names to fall within proper restrictions. [L0ne_W0lf]
//= 1.2 Updated input with min/max values. [L0ne_W0lf]
//=     Added a checkweight. 
//= 1.3 Fixed checks. [Euphy]
//============================================================ 

payon,173,238,5	script	#pay	754,{
	if (checkweight(1201,1) == 0) {
		mes "Я˷ǳĶ. ΪβһЩֿ?";
		close;
	}
	mes "[]";
	mes "~";
	mes "ͬɫʵ";
	mes "ħʯҵĻ,";
	mes "һϰɲͬɫʵ";
	mes "ħʯ.";
	next;
	switch(select("ɫħʯΪɫħʯ!:ɫħʯΪɫħʯ!:ɫħʯΪɫħʯ!")) {
	case 1: callsub S_TradeGems,717,716;
	case 2: callsub S_TradeGems,716,715;
	case 3: callsub S_TradeGems,715,717;
	}

S_TradeGems:
	if (countitem(getarg(0)) < 2) {
		mes "[]";
		mes "...!";
		mes "ҿЦ?";
		mes "û2ͬɫʵ";
		mes "ħʯĻ,";
		mes "޷жһģ";
		mes "2 "+getitemname(getarg(0))+"!";
		close;
	}
	else {
		set .@gems,countitem(getarg(0))/2;
		mes "[]";
		mes "";
		mes "ܹ " + .@gems + "  " + getitemname(getarg(1)) + ".";
		mes "ϾЩ.";
		mes "+getitemname(getarg(0))+";
		mes "Ҫھͽ?";
		next;
		switch(select("ҪȫʯĶ.:һһ־Ϳ:Ȼ,һ.")) {
		case 1:
			delitem getarg(0),.@gems * 2;
			getitem getarg(1),.@gems;
			break;
		case 2:
			mes "[]";
			mes "һٸ?";
			mes "ֻ벻100ֵ.";
			mes "һ,";
			mes "0.";
			next;
			while(1) {
				input .@input,0,101;
				if (.@input == 0) {
					mes "[]";
					mes "?һһ?";
					mes ".";
					mes "ӦǸı...";
					close;
				}
				else if (.@input > 100) {
					mes "[]";
					mes ",...";
					mes "";
					mes "벻Ҫ100.";
					mes "ס...";
					next;
				}
				else if (.@gems < .@input) {
					// Custom dialogue
					mes "[]";
					mes "...";
					mes "û㹻Ŀʯ.";
					mes "Խн...";
					next;
				}
				else break;
			}
			delitem getarg(0),.@input * 2;
			getitem getarg(1),.@input;
			break;
		case 3:
			mes "[]";
			mes "õ,û.";
			mes "ҪĻʱ.";
			close;
		}
		mes "[]";
		mes "ɸ㶨~";
		mes "ӭ´.";
		mes ",ڿʲô?";
		mes "!";
		mes "ǲʲô?";
		close;
	}
}
