//===== rAthena Script ======================================= 
//= Refining NPCs
//===== By: ==================================================
//= Syrus22 (1.1) dafide18 (1.4) Skotlex (1.5)
//===== Current Version: =====================================
//= 3.2a
//===== Compatible With: =====================================
//= Any Athena Version
//===== Description: =========================================
//= Refining NPCs and Metal Salesmen.
//===== Additional Comments: =================================
//= 1.0 by A bunch of people!
//=     Syrus22 - Completely redid the script using functions... also
//=     added the option for auto safe refining and multiple refining.
//= 1.1 Negative input bug fixed [Lupus]
//= 1.2 Added additional reparimen in morroc and payon. Added
//=     Christopher the blacksmith in Geffen. Edited some dialogue [kobra_k88]
//= 1.3 New Payon Locations [Darkchild]
//=     Corrected zeny subtraction thx to jpnmania77.[kobra_k88]
//= 1.3a Temporary corrected an exploit. Need to check sources
//=     to fully fix bug [Shinigami]
//=     Fixed repairman prices [shadowlady]
//=     Fixed bug that skips requirements thanks to sir_loon [massdriller]
//=     Fixed itemid error thanks to -Vitamin- [massdriller]
//= 1.4 check again item in refining procedure to avoid
//=     hacker that can change item [dafide18]
//= 1.5 Fixed crashing due to badly used callfunc's [Skotlex]
//=     Lupus, don't rollback this important fix again! >.<
//= 1.5a Corrected an unneeded callfunc, fixed the anti-bot 
//=     exploit ruining the safe refine loop. [Skotlex]
//= 1.5b Fixed Spelling mistakes. [Nexon] 
//= 1.6 Replaced all breaks for ends as per the new script engine [Skotlex]
//= 1.7 Added Einbroch Refiners (Custom names ^^;) and a duplicated BS Shop. [Poki#3]
//= 1.8 Added Lighthalzen Refiners (Custom names again ^^;) [Poki#3]
//= 1.8a Fixed wrong indication thanks to NeoSaro [Lupus]
//= 1.9 Rewrote repairman, removed the Steel from repair cost [DracoRPG]
//= 2.0 Fixed missed equppment presence check. Thx2 Coltaro [Lupus]
//= 2.0a Added weight checks thanks to Neouni [Playtester]
//= 2.0b Fixed the names of Lighthalzen and Einbroch refiners thanks to Maud_Dib [Kargha]
//= 2.1 Removed Duplicates [Silent]
//= 2.2 Changed name from "Emvertacon" to "Emveretarcon". [Samuray22]
//=     Thanks to Barron-Monster.
//= 2.2b Changed name from "Pharacon" to "Phracon". [Samuray22]
//=     Thanks to Barron-Monster.
//= 2.3 Corrected NPC names to fall within proper restrictions. [L0ne_W0lf]
//= 2.4 Updated Refiner function. cleaner, and less dated. [L0ne_w0lf]
//= 2.5 Rather large update to the refiner and merchants. :D [L0ne_W0lf]
//= 2.6 Fixed a few bugs with creating pure stones. [L0ne_W0lf]
//= 2.7 Refiner function accepts additional paramater. [L0ne_W0lf]
//=     0 = No special features; 1 = new refining features
//=     Updated Repairmen and function. No longer shows menu.
//= 2.7a A couple touch-ups to the repairman function. [L0ne_w0lf]
//= 2.8 Changed the nonexistent variable .@matname$ for getitemname(.@material). (bugreport:2340) [Samuray22]
//= 2.8 Added proper Blacksmith Supplier to Einroch. [L0ne_W0lf]
//=     Updated dated features comment to reflect new usage.
//= 2.8a Small bugfix. (bugreport:2418) [Paradox924X]
//= 2.9 Moved Morroc repairman to Morroc Ruins. [L0ne_W0lf]
//= 3.0 Updated several NPC names and locations. [Xantara]
//=     Added WoE map Refiners.
//= 3.1 Added the new refinement & Ore creation NPC's for +11 and above Refinement. [Masao]
//= 3.2 Moved some scripts to Renewal file, other minor changes. [Euphy]
//= 3.2a Added 'disable_items' command. [Euphy]
//============================================================

// ˹ร: Geffen Blacksmith
//============================================================
geffen_in,110,172,0	script	˹ร#1	63,{
	mes "[˹ร]";
	mes "ӭ˹ร̡";
	mes "ﷷйڶõƷ";
	mes "Ҫʲô?";
	next;
	switch(select("Ҫ:ҪεƷ:Ҫ:Ҫԭʯ:ȡ")) {
	case 1:
		mes "[˹ร]";
		mes "赱ȻԽӲĽԽá";
		mes "ӦҲ֪ӲĽ۸Ͼ";
		mes "Լľѡʵġ";
		next;
		switch(select(" - 30,000z:O֮ - 120,000z:ƽ - 300,000z:õ:ȡ")) {
		case 1:
			if (Zeny < 30000) {
				mes "[˹ร]";
				mes "Ҿ۸Ѿ͵ˣΪô͵ļǮҲ";
				close;
			}
			getitem 986,1; // Anvil
			set Zeny,Zeny-30000;
			mes "[˹ร]";
			mes "ѡһǱȽϱ˵һ.";
			close;
		case 2:
			if (Zeny < 120000) {
				mes "[˹ร]";
				mes "Ҿ۸Ѿ͵ˣΪô͵ļǮҲ";
				close;
			}
			getitem 987,1; // Oridecon_Anvil
			set Zeny,Zeny-120000;
			mes "[˹ร]";
			mes "!Ǹмҡһһʺ裬˵?";
			close;
		case 3:
			if (Zeny < 300000) {
				mes "[˹ร]";
				mes "Ҿ۸Ѿ͵ˣΪô͵ļǮҲ";
				close;
			}
			getitem 988,1; // Golden_Anvil
			set Zeny,Zeny-300000;
			mes "[˹ร]";
			mes "һǹ֮еõһ֣裬ԿԳư";
			close;
		case 4:
			mes "[˹ร]";
			mes "ܱǸûбȻƽõ.";
			next;
			mes "[˹ร]";
			mes "˵е'Ringgel'бõ裬ֻһ˵.";
			close;
		case 5:
			mes "[˹ร]";
			mes "κҪĻӭٶȹָ";
			mes "ߡ";
			close;
		}
	case 2:
		mes "[˹ร]";
		mes "ΰȻҪΰĵߡ";
		mes "ڿ˹ร̹ߵĻ";
		mes "һԳΪһΰġ";
		mes "ѡѡһֵ!";
		next;
		switch(select("Яۿ¯ - 150z: - 1,000z:ƽ - 3,000z:֮ - 5,000z:")) {
		case 1:
			mes "[˹ร]";
			mes "õģҪ?";
			mes "׵Ļ밴'0'";
			next;
			while(1) {
				input .@input;
				if (.@input == 0) {
					mes "[˹ร]";
					mes "Ѿߡ";
					close;
				}
				else if ((.@input < 0) || (.@input > 500)) {
					mes "[˹ร]";
					mes "뽫500¡";
					next;
				}
				else {
					break;
				}
			}
			set .@sell,.@input * 150;
			if (Zeny < .@sell) {
				mes "[˹ร]";
				mes "Ҿ۸Ѿ͵ˣΪô͵ļǮҲʡ";
				close;
			}
			if (checkweight(612,.@input) == 0) {
				mes "[˹ร]";
				mes "û취Яôණ!";
				close;
			}
			getitem 612,.@input; // Portable_Furnace
			set Zeny,Zeny-.@sell;
			mes "[˹ร]";
			mes "лĹ٣ӭ´ι!";
			close;
		case 2:
			if (Zeny < 1000) {
				mes "[˹ร]";
				mes "Ҿ۸Ѿ͵ˣΪô͵ļǮҲʡ";
				close;
			}
			getitem 613,1; // Iron_Hammer
			set Zeny,Zeny-1000;
			mes "[˹ร]";
			mes "лĹ٣ӭ´ι!";
			close;
		case 3:
			if (Zeny < 3000) {
				mes "[˹ร]";
				mes "Ҿ۸Ѿ͵ˣΪô͵ļǮҲʡ";
				close;
			}
			getitem 614,1; // Golden_Hammer
			set Zeny,Zeny-3000;
			mes "[˹ร]";
			mes "лĹ٣ӭ´ι!";
			close;
		case 4:
			if (Zeny < 5000) {
				mes "[˹ร]";
				mes "Ҿ۸Ѿ͵ˣΪô͵ļǮҲʡ";
				close;
			}
			getitem 615,1; // Oridecon_Hammer
			set Zeny,Zeny-5000;
			mes "[˹ร]";
			mes "лĹ٣ӭ´ι!";
			close;
		case 5:
			mes "[˹ร]";
			mes "ӭ'˹ร'Ĺ";
			close;
		}
	case 3:
		mes "[˹ร]";
		mes "׼˺ܶĽҪһ?";
		next;
		switch(select("ǿ-һ - 200z:ǿ- - 1000z:ȡ")) {
		case 1:
			mes "[˹ร]";
			mes "Ҫ?㲻κζ'0'";
			next;
			while(1) {
				input .@input;
				if (.@input == 0) {
					mes "[˹ร]";
					mes "ȡ";
					mes "ټ!";
					close;
				}
				else if ((.@input < 0) || (.@input > 500)) {
					mes "[˹ร]";
					mes "ֻܹ500߸";
					next;
				}
				else {
					break;
				}
			}
			set .@sell,.@input * 200;
			if (Zeny < .@sell) {
				mes "[˹ร]";
				mes "Ҿ۸Ѿ͵ˣΪô͵ļǮҲʡ";
				close;
			}
			if (checkweight(1010,.@input) == 0) {
				mes "[˹ร]";
				mes "û취Яôණ!";
				close;
			}
			getitem 1010,.@input; // Phracon
			set Zeny,Zeny-.@sell;
			mes "[˹ร]";
			mes "лĹ٣ӭ´ι!";
			close;
		case 2:
			mes "[˹ร]";
			mes "Ҫ?㲻κζ'0'";
			next;
			while(1) {
				input .@input;
				if (.@input == 0) {
					mes "[˹ร]";
					mes "ȡ";
					mes "ټ!";
					close;
				}
				else if ((.@input < 0) || (.@input > 500)) {
					mes "[˹ร]";
					mes "ֻܹ500߸";
					next;
				}
				else {
					break;
				}
			}
			set .@sell,.@input * 1000;
			if (Zeny < .@sell) {
				mes "[˹ร]";
				mes "Ҿ۸Ѿ͵ˣΪô͵ļǮҲʡ";
				close;
			}
			if (checkweight(1011,.@input) == 0) {
				mes "[˹ร]";
				mes "û취Яôණ!";
				close;
			}
			getitem 1011,.@input; // Emveretarcon
			set Zeny,Zeny-.@sell;
			mes "[˹ร]";
			mes "лĹ٣ӭ´ι!";
			close;
		case 3:
			mes "[˹ร]";
			mes "ӭ'˹ร'Ĺ";
			close;
		}
	case 4:
		mes "[˹ร]";
		mes "ʵĽʯ5֮ԭʯһ֮5ԭʯһһ?";
		next;
		switch(select("֮::ȡ")) {
		case 1:
			if (countitem(756) < 5) {
				mes "[˹ร]";
				mes "Ҹ߹5֮ԭʯһ֮";
				close;
			}
			else {
				delitem 756,5;  //Oridecon_Stone
				getitem 984,1; // Oridecon
				mes "[˹ร]";
				mes "һ֮ӭ´!";
				close;
			}
		case 2:
			if (countitem(757) < 5) {
				mes "[˹ร]";
				mes "Ҹ߹5ԭʯܻһ";
				close;
			}
			else {
				delitem 757,5;  //Elunium_Stone
				getitem 985,1; // Elunium
				mes "[˹ร]";
				mes "һӭ´!";
				close;
			}
		case 3:
			mes "[˹ร]";
			mes "Ҫʱ򣬻ӭʱټ!";
			close;
		}
	case 5:
		mes "[˹ร]";
		mes "ӭ'˹ร'Ĺ";
		close;
	}
}

// Paul Spanner: Einbroch Blacksmith Supplier
//============================================================
ein_in01,38,29,0	script	Paul Spanner	63,{
	if (checkweight(1201,1) == 0) {
		mes "- Wait a minute !! -";
		mes "- Currently you're carrying -";
		mes "- too many items with you. -";
		mes "- Please try again -";
		mes "- after you loose some weight. -";
		close;
	}
	mes "[Paul Spanner]";
	mes "Welcome, my friend.";
	mes "In my shop, you will find everything that you need in forging.";
	mes "Tell me what you need.";
	next;
	switch(select("Purchase Anvil.:Purchase Forging Items.:Purchase Metal.:Process Ores.:Quit.")) {
	case 1:
		mes "[Paul Spanner]";
		mes "Anvil is the most necessary item for Blacksmiths.";
		mes "Since you will use an Anvil more than once, you'd better buy a nice one.";
		next;
		switch(select("Anvil - 30,000z.:Oridecon Anvil - 120,000z.:Golden Anvil - 300,000z.:I need a better anvil.:Cancel.")) {
		case 1:
			if (zeny < 30000) {
				mes "[Paul Spanner]";
				mes "With that much of money, you cannot even buy a toy anvil!";
				close;
			}
			getitem 986,1; //Anvil
			set zeny,zeny-30000;
			mes "[Paul Spanner]";
			mes "It is the cheapest anvil which has the most basic ability.";
			mes "Thank you for using my shop. If you need anything, just let me know.";
			close;
		case 2:
			if (zeny < 120000) {
				mes "[Paul Spanner]";
				mes "With that much of money, you cannot even buy a toy anvil!";
				close;
			}
			getitem 987,1; //Oridecon_Anvil
			set zeny,zeny-120000;
			mes "[Paul Spanner]";
			mes "Ah, you have an eye for anvil. A Blacksmith needs an anvil at least as good as this.";
			mes "Thank you for using my shop. If you need anything, just let me know.";
			close;
		case 3:
			if (zeny < 300000) {
				mes "[Paul Spanner]";
				mes "With that much of money, you cannot even buy a toy anvil!";
				close;
			}
			getitem 988,1; //Golden_Anvil
			set zeny,zeny-300000;
			mes "[Paul Spanner]";
			mes "I can tell your ambition to become a good Blacksmith just by looking at you to choose this Golden Anvil!";
			mes "This anvil will surely aid you in creating the best weapons.";
			close;
		case 4:
			mes "[Paul Spanner]";
			mes "I am sorry, but I do not sell better anvils than Golden Anvil.";
			mes "Unless you find the legendary anvil of 'Linggell', I don't think that you could find better one than Golden Anvil in any other places.";
			close;
		case 5:
			mes "[Paul Spanner]";
			mes "If you need anything, just let me know.";
			close;
		}
	case 2:
		mes "[Paul Spanner]";
		mes "You need various materials to process ores and to forge weapons.";
		mes "I have everything that you need. Take a look.";
		next;
		switch(select("Mini Furnace - 150z.:Iron Hammer - 1,000z.:Golden Hammer - 3,000z.:Oridecon Hammer - 5,000z.:Cancel.")) {
		case 1:
			set .@item,612;
			set .@item_cost,150;
			set .@item_weight,200;
			mes "[Paul Spanner]";
			mes "You definately need this furnce to process ores!";
			next;
			break;
		case 2:
			set .@item,613;
			set .@item_cost,1000;
			set .@item_weight,200;
			break;
		case 3:
			set .@item,614;
			set .@item_cost,3000;
			set .@item_weight,300;
			break;
		case 4:
			set .@item,615;
			set .@item_cost,5000;
			set .@item_weight,400;
			break;
		case 5:
			mes "[Paul Spanner]";
			mes "If you need anything, just let me know.";
			close;
		}
		mes "[Paul Spanner]";
		mes "So, how many do you need? If you want to cancel the trade, enter '0'.";
		next;
		while(1) {
			input .@input;
			if (.@input == 0) {
				mes "[Paul Spanner]";
				mes "You have canceled the trade. If you need anything, just let me know.";
				close;
			}
			else if ((.@input < 0) || (.@input > 500)) {
				mes "[Paul Spanner]";
				mes "You can only buy 500 or less at a time.";
				next;
			}
			else {
				break;
			}
		}
		set .@sell,.@input * .@item_cost;
		if (zeny < .@sell) {
			mes "[Paul Spanner]";
			mes "You don't have enough money. Sorry, I cannot sell them at a loss.";
			close;
		}
		if (checkweight(.@item,.@input) == 0) {
			mes "[Paul Spanner]";
			mes "Hey, you look pale. Why don't you go lighten your weight first.";
			close;
		}
		set zeny,zeny-.@sell;
		getitem .@item,.@input;
		mes "[Paul Spanner]";
		mes "Thank you for using my shop. If you need anything, just let me know.";
		close;
	case 3:
		mes "[Paul Spanner]";
		mes "I have high quality metal.";
		mes "So, which metal would you like to buy?";
		next;
		switch(select("Phracon - 200z.:Emveretarcon - 1,000z.:Quit.")) {
		case 1:
			set .@item,1010;
			set .@item_price,200;
			break;
		case 2:
			set .@item,1011;
			set .@item_price,1000;
			break;
		case 3:
			mes "[Paul Spanner]";
			mes "If you need anything, just let me know.";
			close;
		}
		mes "[Paul Spanner]";
		mes "So, how many of them do you need? If you want to cancel the trade, enter '0'.";
		next;
		while(1) {
			input .@input;
			if (.@input == 0) {
				mes "[Paul Spanner]";
				mes "The trade has been canceled. If you need anything, just let me know.";
				close;
			}
			else if ((.@input < 0) || (.@input > 500)) {
				mes "[Paul Spanner]";
				mes "You can buy 500 or less at a time.";
				next;
			}
			else {
				break;
			}
		}
		set .@sell,.@input * .@item_price;
		if (zeny < .@sell) {
			mes "[Paul Spanner]";
			mes "You don't have enough money. Sorry, I cannot sell them at a loss.";
			close;
		}
		if (checkweight(.@item,.@input) == 0) {
			mes "[Paul Spanner]";
			mes "Hey, you look pale. Why don't you go lighten your weight first?";
			close;
		}
		getitem .@item,.@input;
		set zeny,zeny-.@sell;
		mes "[Paul Spanner]";
		mes "Thank you for using my shop. If you need anything, just let me know.";
		close;
	case 4:
		mes "[Paul Spanner]";
		mes "I can process Oridecon and Elunium for you.";
		mes "You need 5 ores to process them into one Oridecon or Elunium.";
		mes "So, which one do you want to process?";
		switch(select("Oridecon:Elunium:Quit.")) {
		case 1:
			if (countitem(756) < 5) {
				mes "[Paul Spanner]";
				mes "You need 5 ores to process them into one pure Oridecon.";
				close;
			}
			else {
				delitem 756,5; //Oridecon_Stone
				getitem 984,1; //Oridecon
				mes "[Paul Spanner]";
				mes "There you go. Thank you for using my service.";
				close;
			}
		case 2:
			if (countitem(757) < 5) {
				mes "[Paul Spanner]";
				mes "You need 5 ores to process them into one pure Elunium.";
				close;
			}
			else {
				delitem 757,5; //Elunium_Stone
				getitem 985,1; //Elunium
				mes "[Paul Spanner]";
				mes "There you go. Thank you for using my service.";
				close;
			}
		case 3:
			mes "[Paul Spanner]";
			mes "If you need anything, just let me know.";
			close;
		}
	case 5:
		mes "[Paul Spanner]";
		mes "If you need anything, just let me know.";
		close;
	}
}

// Weapon/Armor Refiners
//============================================================
prt_in,63,60,0	script		85,{
	callfunc "refinemain","",0;
	end;
}
morocc_in,73,38,6	script		99,{
	callfunc "refinemain","",0;
	end;
}
payon,144,173,5	script		88,{
	callfunc "refinemain","",0;
	end;
}
alberta_in,28,58,0	script	׵	85,{
	callfunc "refinemain","׵",0;
	end;
}
yuno_in01,171,21,4	script	˼	88,{
	callfunc "refinemain","˼",0;
	end;
}
ein_in01,24,87,5	script	˹	826,{
	callfunc "refinemain","˹",0;
	end;
}
lhz_in02,282,20,7	script		869,{
	callfunc "refinemain","",0;
	end;
}

//============================================================
//= Main Refiner Function
//============================================================
//= To allow auto safe refining/multiple refining set the
//= second argument to '1' in the function call.
//= If you enable this function, be sure to edit the value of
//= .@safe to the max safe refine in refine_db.txt as well.
//============================================================
function	script	refinemain	{
	disable_items;
	set .@features,getarg(1);
	mes "[" + getarg(0) + "]";
	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)) {
		mes "[" + getarg(0) + "]";
		mes "ҪҪҰ";
		mes "ͷԶε";
		mes "һ㰡?";
		emotion e_an;
		close;
	}
	//Check if the item is refinable...
	if(!getequipisenableref(.@part)) {
		mes "[" + getarg(0) + "]";
		mes "˵Ŀ";
		mes "޷εĿ!";
		close;
	}
	//Check to see if the items is already +10
	if(getequiprefinerycnt(.@part) >= 10) {
		mes "[" + getarg(0) + "]";
		mes "Ѿ";
		mes "ߵȼ";
		mes "ҵ޷ٶ..";
		close;
	}
	set .@refineitemid, getequipid(.@part); // save id of the item
	set .@refinerycnt, getequiprefinerycnt(.@part); //save refinery count
	switch(getequipweaponlv(.@part)){
	case 0: 	//Refine Armor
		set .@price,2000;
		set .@material,985;
		set .@safe,4;
		break;
	case 1: 	//Refine Level 1 Weapon
		set .@price,50;
		set .@material,1010;
		set .@safe,7; 
		break;
	case 2: 	//Refine Level 2 Weapon
		set .@price,200;
		set .@material,1011;
		set .@safe,6; 
		break;
	case 3: 	//Refine Level 3 Weapon
		set .@price,5000;
		set .@material,984;
		set .@safe,5; 
		break;
	case 4: 	//Refine Level 4 Weapon
		set .@price,20000;
		set .@material,984;
		set .@safe,4; 
		break;
	case 5: 	//Refine other stuff?
		set .@price,2000;
		set .@material,985;
		set .@safe,4; 
		break;
	}
	if(.@features != 1) {
		mes "[" + getarg(0) + "]";
		mes "ƷҪ";
		mes "1 ^003366"+getitemname(.@material)+"^000000 ";
		mes " " + .@price + " Zeny.";
		mes "ϣҼ?";
		next;
		if(select("õ:") == 2){
			mes "[" + getarg(0) + "]";
			mes "Ү...";
			mes "Ǻð";
			mes "ӭ´";
			close;
		}
		if(getequippercentrefinery(.@part) < 100) {
			mes "[" + getarg(0) + "]";
			mes "Ҫˣ";
			mes "һս!";
			switch(.@material) {
			case 985:
				mes "Ѿκܶ˵...ҪټεĻܻ!000000!!";
				break;
			default:
				mes "Ҫ𻵵ĻɾͲܼʹ!!ĿƬҲ^ff0000ȫʧ^000000!!";
				mes "ңװҲʧŶȷҪ?";
				break;
			}
			next;
			mes "["+getarg(0)+"]";
			mes "Ҫ˵һ";
			mes "һˣ";	
			mes "Ͳʹ.";
			mes "һѡ";
			mes "^FF0000Զʧȥ^000000 .";
			mes "ȷҪ?";
			next;
			if(select("õ:") == 2){
				mes "[" + getarg(0) + "]";
				mes "ȫͬ...";
				mes "ҿһõľʦʱҲ";
				close;
			}
		}
		if((countitem(.@material) < 1) || (Zeny < .@price)) {
			mes "[" + getarg(0) + "]";
			mes "㿴û";
			mes "㹻ĽǮ  "+getitemname(.@material)+"...";
			mes "ȥһЩ";
			mes "һ";
			close;
		}
		set Zeny,Zeny-.@price;
		delitem .@material,1;
		if(getequipisequiped(.@part) == 0) { // hacker has removed the item (not changed, why?)
			mes "[" + getarg(0) + "]";
			mes "û㹻Ĳ...";
			close;
		}
		if(getequiprefinerycnt(.@part) != .@refinerycnt || getequipid(.@part) != .@refineitemid) { // hacker has changed the item
			mes "[" + getarg(0) + "]";
			emotion e_an;
			mes "һ..";
			mes "ΪǱ?!";
			mes "ȥ,Ȼһҵ..";
			close;
		}
		if(getequippercentrefinery(.@part) <= rand(100)) {
			failedrefitem .@part;
			mes "[" + getarg(0) + "]";
			emotion (!rand(5))?e_cash:e_omg;
			set .@lose,rand(1,3);
			if (.@lose == 1) {
				mes "Ŷ!ҵ";
				mes "";
				mes "ҷǳǸ֪ϰĸ";
				mes "?";
			} else if(.@lose == 2) {
				mes "ȿȿȿȿȿȿ!!!";
				mes "ڶεĳʽˡ";
				mes "ԡԲ";
			} else {
				mes "!";
				mes "ڶεĳʽ";
				mes "ˡ";
				mes "ǳԲ...";
			}
			close;
		}
		mes "["+getarg(0)+"]";
		successrefitem .@part;
		emotion e_heh;
		set .@win,rand(1,3);
		if (.@win == 1) {
			mes "̫!";
			mes "!";
			mes "һ,";
			mes "þûγôʵˣ";
			mes "ǿһҲܸ˰";
		} else if(.@win == 2) {
			mes "ɹ..!";
			mes "ȥ!";
			mes "Ѿˡ";
			mes "þûγôʵ.";
		} else {
			mes "!";
			mes ".";
			mes "ҪҵĹ";
			mes "ȫܴﵽ.";
			mes "ǿһҲܸ˰";
		}
		close;
	}

// New Refining Functions ========================
	if(getequiprefinerycnt(.@part) < .@safe) {
		mes "[" + getarg(0) + "]";
		mes "ѡֱӶұȫֵҪұĴ... Ҷû......";
		next;
		set .@menu2,select("ұȫֵ.","ұֵָ.","Ҹı...");
	} else
		set .@menu2,2;
	switch(.@menu2){
	case 1: 
		set .@refinecnt,.@safe - getequiprefinerycnt(.@part);
		break;
	case 2:
		next;
		mes "[" + getarg(0) + "]";
		mes "ôҪҰұٴ?";
		next;
		input .@refinecnt;
		set .@refinecheck,.@refinecnt + getequiprefinerycnt(.@part);
		if (.@refinecnt < 1 || .@refinecheck > 10) {
			mes "[" + getarg(0) + "]";
			mes "ҲپƷ.";
			close;
		}
		if(.@refinecheck > .@safe) {
			set .@refinecheck,.@refinecheck - .@safe;
			mes "[" + getarg(0) + "]";
			mes "ôҪʼұ  + @refinecheck +  Σ⽫ֵ. װпܻỵ... Ҫұ?";
			next;
			if(select("õ...","...") == 2){
				mes "[" + getarg(0) + "]";
				mes "˵Ŷ...";
				close;
			}
		}
		break;
	case 3:
		next;
		mes "[" + getarg(0) + "]";
		mes "˵Ŷ...";
		close;
	}
	set .@fullprice,.@price * .@refinecnt;
	mes "[" + getarg(0) + "]";
	mes "ܹҪ" + .@refinecnt + " " + getitemname(.@material) + " Լ " + .@fullprice + " Zeny... Ҫұ?";
	next;
	if(select("õ","...") == 2){
		mes "[" + getarg(0) + "]";
		mes "˵Ŷ...";
		close;
	}
	if(countitem(.@material) < .@refinecnt || Zeny < .@fullprice) {
		mes "[" + getarg(0) + "]";
		mes "ЩӵеƷ?ȻܿϧĲϲ㣬ҲʵڰĪ˵ҸҲӦõҪջ!";
		close;
	}
	set Zeny,Zeny - .@fullprice;
	delitem .@material,.@refinecnt;
	while(.@refinecnt){
		if (getequipisequiped(.@part) == 0) {
			mes "[" + getarg(0) + "]";
			mes "Բ,ϲҲܰ.....";
			close;
		}
		if (getequipid(.@part) != .@refineitemid || (.@menu2 == 1 && getequippercentrefinery(.@part) < 100)) {
			mes "[" + getarg(0) + "]";
			mes "ҪЦ,ΪǱ !! !?!";
			mes "ȥ...";
			mes "Ȼһҵ..!!!";
			close;
		} 
		mes ", !!!";
		if(.@menu2 == 2 && getequippercentrefinery(.@part) <= rand(100)) {
			failedrefitem .@part;
			emotion e_omg;
			mes "[" + getarg(0) + "]";
			mes "ȿȿȿȿȿȿ!!! ڶεĹ...";
			set .@refinecnt,.@refinecnt - 1;
			if(.@refinecnt == 0) close;
			mes "ʣµǮͲ...";
			getitem .@material,.@refinecnt;
			set .@fullprice,.@refinecnt * .@price;
			set Zeny,Zeny + .@fullprice;
			close;
		}
		successrefitem .@part;
		emotion e_no1;
		set .@refinecnt,.@refinecnt - 1;
		next;
	}
	mes "[" + getarg(0) + "]";
	mes "еĶˣӭ´.";
	close;		
}

// Material Salesmen
//============================================================
prt_in,56,68,5	script	Խ	86,{
	callfunc "phramain","Խ";
	end;
}
payon,145,178,3	script	ɵ	88,{
	callfunc "phramain","ɵ";
	end;
}
morocc_in,63,32,6	script	ɳ	99,{
	callfunc "phramain","ɳ";
	end;
}
alberta_in,13,71,3	script	˹	86,{
	callfunc "phramain","˹";
	end;
}
yuno_in01,171,27,4	script		88,{
	callfunc "phramain","";
	end;
}
ein_in01,15,87,3	script	˹	86,{
	callfunc "phramain","˹";
	end;
}
lhz_in02,278,24,3	script	տ	86,{
	callfunc "phramain","տ";
	end;
}

// Material Salesmen Functions
//============================================================
function	script	phramain	{
	if (checkweight(1201,1) == 0) {
		mes "- һ!! -";
		mes "- Я -";
		mes "- ̫Ĳ. -";
		mes "- һЩ -";
		mes "- . -";
		close;
	}
	mes "[" + getarg(0) + "]";
	mes "ǸƷʱҪĽ";
	mes "ĿǰĶжεȼ1^007777ǿý-ǿһ^000000Լұȼ2^007777ǿý-ǿ^000000";
	next;
	switch(select("ǿ-һ - 200 :ǿ- - 1000 :ѯ")) {
	case 1:
		set .@material,1010;
		set .@price,200;
		break;
	case 2:
		set .@material,1011;
		set .@price,1000;
		break;
	case 3:
		mes "[" + getarg(0) + "]";
		mes "ϣ";
		mes "ҪһЩߵȼô֪֮Ǻҵ...";
		close;
	}
	mes "[" + getarg(0) + "]";
	mes "Ҫ?";
	mes "㲻빺, '0.'";
	next;
	while(1) {
		input .@input;
		if (.@input == 0) {
			mes "[" + getarg(0) + "]";
			mes "ν";
			mes "Ѿ.";
			close;
		}
		else if (.@input < 0 || .@input > 500) {
			mes "[" + getarg(0) + "]";
			mes "õ";
			mes "㲻һι.";
			mes "500,";
			mes "֪.";
			next;
		}
		else {
			break;
		}
	}
	set .@sell,.@input * .@price;
	if (Zeny < .@sell) {
		mes "[" + getarg(0) + "]";
		mes "ԲŶ";
		mes "ڵĽҲ";
		mes "ɲʵġ";
		mes ""+ .@input +" of them.";
		close;
	}
	if (checkweight(.@material,.@input) == 0) {
		mes "[" + getarg(0) + "]";
		mes "Ǹ!";
		mes "ĸ״̬޷ôණ";
		close;
	}
	getitem .@material,.@input;
	set Zeny,Zeny-.@sell;
	mes "[" + getarg(0) + "]";
	mes "!";
	mes "ǳл";
	mes "Ĺ.";
	close;
}

// Ori/Elu Refiners
//============================================================
prt_in,63,69,3	script		84,{
	callfunc "orimain","";
	end;
}
payon,137,178,5	script	Ľ	88,{
	callfunc "orimain","Ľ";
	end;
}
morocc_in,72,32,6	script	Ƕ	99,{
	callfunc "orimain","Ƕ";
	end;
}
alberta_in,21,63,5	script	ŵ	84,{
	callfunc "orimain","ŵ";
	end;
}
yuno_in01,164,27,4	script		88,{
	callfunc "orimain","";
	end;
}
ein_in01,18,82,6	script		84,{
	callfunc "orimain","";
	end;
}
lhz_in02,281,24,5	script	³	84,{
	callfunc "orimain","³";
	end;
}

// Ori/Elu Functions
//============================================================
function	script	orimain	{
	if (checkweight(1201,1) == 0) {
		mes "- һЩ!! -";
		mes "- Я -";
		mes "- ̫ණ. -";
		mes "- һЩ-";
		mes "- . -";
		close;
	}
	mes "[" + getarg(0) + "]";
	mes "ֻҪ㽫^FF0000֮ԭʯ^000000";
	mes "^FF0000ԭʯ^000000ң";
	mes "ϾͿΪ֮Լ";
	mes "Ҫ5ԭʯ";
	mes "Ҳа취.";
	next;
	switch(select("::ѯǿʯ")) {
	case 1:
		if (countitem(756) > 4) {
			delitem 756,5;  //Oridecon_Stone
			getitem 984,1; // Oridecon
			mes "[" + getarg(0) + "]";
			mes "Ҫ֮.";
			mes "ӭ";
			mes "´.";
			close;
		}
		else {
			mes "[" + getarg(0) + "]";
			mes "...氮Ц";
			mes "ҲǸ˵Ҫû5֮ԭʯĻ޷֮?";
			close;
		}
	case 2:
		if (countitem(757) > 4) {
			delitem 757,5;  //Elunium_Stone
			getitem 985,1; // Elunium
			mes "[" + getarg(0) + "]";
			mes "Ҫ";
			mes "ӭ";
			mes "´";
			close;
		}
		else {
			mes "[" + getarg(0) + "]";
			mes "...氮Ц";
			mes "ҲǸ˵Ҫû5ԭʯĻ޷";
			close;
		}
	case 3:
		mes "[" + getarg(0) + "]";
		mes "νʯ...";
		mes "ұѾ˶ʮ꣬ܶĴ˵...";
		mes "ûʵʼ!";
		next;
		mes "[" + getarg(0) + "]";
		mes "˵ӵˮء𡢷ԡ";
		next;
		mes "[" + getarg(0) + "]";
		mes "˵ڶұʱʱĻ...ӵʱĳǿ";
		next;
		mes "[" + getarg(0) + "]";
		mes "..˵һӵмߵĶұ";
		close;
	}
}

// Equipment Repairmen
//============================================================
alberta_in,31,65,4	script	#alb	86,{
	callfunc "repairmain","";
	end;
}

moc_ruins,107,94,4	script	#moc	99,{
	callfunc "repairmain","";
	end;
}

payon,143,165,4	script	#pay	88,{
	callfunc "repairmain","";
	end;
}

prt_in,63,54,2	script	#prt	86,{
	callfunc "repairmain","";
	end;
}

yuno_in01,175,28,3	script	#juno	86,{
	callfunc "repairmain","";
	end;
}

geffen_in,34,166,3	script	#gef	99,{
	callfunc "repairmain","";
	end;
}

aldeba_in,38,60,3	script	#alde	86,{
	callfunc "repairmain","";
	end;
}

lhz_in02,284,14,3	script	.#lhz	86,{
	callfunc "repairmain","";
	end;
}

prt_gld,139,117,4	script	#prt_gld	86,{
	callfunc "repairmain","";
	end;
}

gef_fild13,263,117,4	script	#gef_fild	86,{
	callfunc "repairmain","";
	end;
}

pay_gld,295,183,4	script	#pay_gld	86,{
	callfunc "repairmain","";
	end;
}

alde_gld,220,152,4	script	#alde_gld	86,{
	callfunc "repairmain","";
	end;
}

aru_gld,189,336,4	script	#aru_gld	86,{
	callfunc "repairmain","";
	end;
}

sch_gld,340,80,7	script	#sch_gld	86,{
	callfunc "repairmain","";
	end;
}

// Equipment Repair Function
//============================================================
function	script	repairmain	{
	set .@repairprice,5000;
	mes "["+getarg(0)+"]";
	mes "!";
	mes "?";
	mes "ҿ԰װ!";
	next;
	switch(select("...ж...:Ŀǰû")) {
	case 1:
		set .@checkitem,1;
		while (1) {
			if (getbrokenid(.@checkitem) == 0) {
				break;
			}
			set .@checkitem,.@checkitem+1;
		}
		set .@checkitem,.@checkitem-1;
		if (!.@checkitem) {
			mes "["+getarg(0)+"]";
			mes "!";
			mes "϶ǳƷ!ûһŶ";
			next;
			mes "["+getarg(0)+"]";
			mes "ÿ˶ҾͻҪʧҵ!";
			close;
		}
		mes "["+getarg(0)+"]";
		mes "...";
		mes "ҿ...";
		mes "Ʒ,";
		mes "" + .@checkitem + " are damaged.";
		mes "?";
		next;
		set .@totalcost,.@repairprice*.@checkitem;
		mes "["+getarg(0)+"]";
		mes "һҪ " + .@repairprice + " Zeny. ȫ𻵵ƷҪ " + .@totalcost + " Zeny! ?";
		next;
		switch(select("Yes:No")) {
		case 1:
			if (Zeny < .@totalcost) {
				mes "["+getarg(0)+"]";
				mes "..";
				mes "ĽǮ.";
				close;
			}
			set .@checkitem2,1;
			while (1) {
				if (getbrokenid(.@checkitem2) == 0) {
					break;
				}
				set .@checkitem2,.@checkitem2+1;
			}
			set .@checkitem2,.@checkitem2-1;
			if (.@checkitem == .@checkitem2) {
				set zeny,zeny-.@totalcost;
				while (.@checkitem) {
					repair(.@checkitem);
					set .@checkitem,.@checkitem-1;
				}
				mes "["+getarg(0)+"]";
				mes "Ok! ޺ˡ";
				close;
			}
			else {
				mes "["+getarg(0)+"]";
				mes "㲢ûκλĶҪ...";
				close;
			}
		case 2:
			mes "["+getarg(0)+"]";
			mes "ҿ԰װ";
			close;
		}
	case 2:
		mes "["+getarg(0)+"]";
		mes "Ŷ...";
		mes "û";
		mes "Ҫ";
		mes "ûκζ";
		mes "Ҫ.";
		close;
	}
}
