//===== rAthena Script =======================================
//= Advanced Refiner
//===== By: ==================================================
//= L0ne_W0lf
//===== Current Version: =====================================
//= 1.4b
//===== Compatible With: =====================================
//= rAthena SVN
//===== Description: =========================================
//= [Official Conversion]
//= Refiner that uses Enriched ores to increase upgrade success.
//= After a conversation with Doddler, it's been established that
//= the advanced refiner works similar the the "Bubble Gum" item.
//= The success percentage is not "increased" however, if it fails
//= You get a second try. This tries twice at the same time,
//= effectively giving you a re-roll on your attempt.
//= - Dialog is only partly official to iRO.
//= - Uses the iRO position for this NPC.
//===== Additional Comments: =================================
//= 1.0 First Version. [L0ne_W0lf]
//= 1.1 Fixed a weird carriage return. o_o [L0ne_W0lf]
//= 1.2 Optimizing refine method [Zephyrus]
//= 1.3 Typo fixes [Yommy]
//= 1.4 Removed unnecessary dialogs [Zephyrus]
//= 1.4a Added 'disable_items' command. [Euphy]
//= 1.4b Fixed coordinates. [Euphy]
//============================================================

payon,157,146,6	script	#cash_payon::LXRefiner	85,{
	disable_items;
	mes "[]";
	mes "רŶߵ";
	mes "ҿΪװרеƷ";
	mes "ҪװרеһƷ?";
	next;
	setarray .@position$[1], "ͷ","","","","","Ь","װƷ1","װƷ2","ͷ","ͷ";
	set .@menu$,"";
	for( set .@i,1; .@i <= 10; set .@i,.@i+1 )
	{
		if( getequipisequiped(.@i) )
			set .@menu$, .@menu$ + .@position$[.@i] + "-" + "[" + getequipname(.@i) + "]";

		set .@menu$, .@menu$ + ":";
	}
	set .@part,select(.@menu$);

	if( !getequipisequiped(.@part) )
		close;

	if( !getequipisenableref(.@part) )
	{
		mes "[]";
		mes "˵Ŀ޷εĿ!...";
		close;
	}
	if( getequiprefinerycnt(.@part) >= 10 )
	{
		mes "[]";
		mes "Ѿε10ˣҵ޷ٶ..";
		close;
	}

	// Make sure you have the neccessary items and Zeny to refine your items
	// Determines chance of failure and verifies that you want to continue.
	switch( getequipweaponlv(.@part) )
	{
		case 1: callsub S_RefineValidate,1,7620,50,.@part; break;
		case 2: callsub S_RefineValidate,2,7620,200,.@part; break;
		case 3: callsub S_RefineValidate,3,7620,5000,.@part; break;
		case 4: callsub S_RefineValidate,4,7620,20000,.@part; break;
		default: callsub S_RefineValidate,0,7619,2000,.@part; break;
	}

	if( getequippercentrefinery(.@part) > rand(100) || getequippercentrefinery(.@part) > rand(100) )
	{
		mes "[]";
		mes "! ! !";
		SuccessRefItem .@part;
		next;
		Emotion e_no1;
		mes "[]";
		mes "ȥ! Ѿˡ";
		mes "þûγôʵˣǿһҲܸ˰!";
		close;
	}
	mes "[]";
	mes "! ! !";
	FailedRefItem .@part;
	next;
	if (rand(5) == 1){
		Emotion e_cash;
	} else {
		Emotion e_omg;
	}
	mes "[]";
	mes "ȿȿȿȿȿȿ!!!!";
	next;
	mes "[]";
	mes "...ȿ...";
	mes "...";
	mes "ڶεĳˡ";
	mes "......͸߹!";
	close;

S_RefineValidate:
	mes "[]";
	if (getarg(0))
		mes "Ҫȼ" + getarg(0) + "!";
	mes "ҪεĻҪ ^ff9999" + getitemname(getarg(1)) + "^000000";
	mes "Լ " + getarg(2) + " Zeny.";
	mes "Ҫ?";
	next;
	if( select("ǵ:Ҫ") == 1 )
	{
		if( getequippercentrefinery(getarg(3)) < 100 )
		{
			mes "[]";
			mes "!!";
			mes "Ѿκܶ˵...";
			mes "ҪټεĻܻ!";
			next;
			mes "Ҫ𻵵ĻɾͲܼʹ!!";
			mes "ĿƬ";
			mes "^ff0000ȫʧ!!^000000";
			mes "˵߱ʧ!!";
			mes "ȷҪ?";
			next;
			if( select(":") == 2 )
			{
				mes "[]";
				mes "ܺá";
				mes "̫Ķ𻵣Ҳű仵ġ";
				close;
			}
		}
		if( countitem(getarg(1)) > 0 && Zeny > getarg(2) )
		{
			delitem getarg(1), 1;
			set Zeny, Zeny - getarg(2);
			return;
		}
		mes "[]";
		mes "㿴û㹻ĽǮ "+getitemname(getarg(1))+"...";
		mes "ȥһЩһ";
		close;
	}
	mes "[]";
	mes "Ű... ûбҪھ;~";
	mes "~~";
	close;
}

morocc,183,94,4	duplicate(LXRefiner)	#cash_morocc	85