//===== rAthena Script =======================================
//= Advanced Refiner
//===== Description: =========================================
//= [Official Conversion]
//= Refiner that uses Enriched ores to increase upgrade success.
//===== Changelog: ===========================================
//= 1.0 Added Malangdo Refiner "Holink". [Euphy]
//= 1.1 Removed re-roll behavior. [Secret]
//= 1.2 Added db-based material ID [Secret]
//============================================================

// Main NPC :: mal_jerun
//============================================================
malangdo,221,174,6	script	Holink#mal_cash	559,{
	disable_items;
	mes "[Holink]";
	mes "I am the meow~ Blacksmith Holink~";
	mes "Master of refining, Holink~";
	mes "I am the special cat Holink who learned from Morroc~";
	mes "My daughter is so proud of me, Holink~";
	mes "What should Holink~ refine today?";
	next;

	setarray .@indices[1], EQI_HEAD_TOP, EQI_ARMOR, EQI_HAND_L, EQI_HAND_R, EQI_GARMENT, EQI_SHOES, EQI_ACC_L, EQI_ACC_R, EQI_HEAD_MID, EQI_HEAD_LOW;
	for (set .@i,1; .@i<=10; set .@i,.@i+1)
		set .@menu$, .@menu$ + ( getequipisequiped(.@indices[.@i]) ? getequipname(.@indices[.@i]) : F_getpositionname(.@indices[.@i]) +"-[Empty]" ) +":";
	set .@part, .@indices[ select(.@menu$) ];

	if (!getequipisequiped(.@part)) {
		mes "[Holink]";
		switch(.@part) {
		case 1:
			mes "My teacher Aragam said meow~";
			mes "There's no cure for stupidity...";
			break;
		case 2:
			mes "There's nothing to see here, meow!!";
			break;
		case 3:
			mes "Meow? What do you want me to do with this left hand...?";
			break;
		case 4:
			mes "Meow? What do you want me to do with this right hand...?";
			break;
		case 5:
			mes "Meow? You don't have anything on.";
			break;
		case 6:
			mes "Kyang~! Do not mess with my sensitive olfactory, meow~.";
			break;
		case 7:
		case 8:
			mes "Meow? Where is the accessory?";
			break;
		case 9:
		case 10:
			mes "Meow? You talking about the other head parts, meow?~";
			break;
		}
		close;
	}
	if (!getequipisenableref(.@part)) {
		mes "[Holink]";
		mes "Even Aragam can't refine such a thing, meow.";
		close;
	}
	if (getequiprefinerycnt(.@part) >= 10) {
		mes "[Holink]";
		mes "Meow~ Perfect refining. Did Aragam do this, meow?~";
		close;
	}
	mes "[Holink]";
	// TODO: Price is different to Suhnbi of Payon. Intended? [Secret]
	.@material = getequiprefinecost(.@part, REFINE_COST_ENRICHED, REFINE_MATERIAL_ID);
	switch(getequipweaponlv(.@part)) {
	default:
	case 0: // Armor
		set .@price,15000;
		set .@type$,"armor";
		mes "You have chosen an armor, meow~";
		break;
	case 1: // Level 1 Weapon
		set .@price,500;
		set .@type$,"weapon";
		mes "A level 1 weapon...?";
		break;
	case 2: // Level 2 Weapon
		set .@price,2000;
		set .@type$,"weapon";
		mes "Meow, a level 2 weapon...?";
		break;
	case 3: // Level 3 Weapon
		set .@price,20000;
		set .@type$,"weapon";
		mes "Meow Meow~~ A level 3 weapon~~";
		break;
	case 4: // Level 4 Weapon
		set .@price,50000;
		set .@type$,"weapon";
		mes "Me-Meow!... A level 4 weapon...!";
		mes "I've only seen it twice while";
		mes "learning from Aragam... Me-Meow!!";
		break;
	}
	mes "You need ^ff9999"+getitemname(.@material)+"^000000 and ^ff9999"+.@price+"^000000 Zeny for this refine, meow~";
	mes "Want to continue, meow?~";
	next;
	if(select("Yes!!:No!!") == 2) {
		mes "[Holink]";
		mes "Kyack!!";
		mes "You don't belive in refine master Holink, meow?~";
		close;
	}
	if (getequippercentrefinery(.@part, true) < 100) {
		mes "[Holink]";
		mes "Meow!!";
		if (.@type$ == "armor")
			mes "This armor was already refined so many times, meow.";
		else {
			mes "Danger. Danger~";
			mes "This weapon was refined a lot, meow~";
			next;
			mes "[Holink]";
		}
		mes "You might break it if you continue";
		mes "to try refining this item further, meow.";
		next;
		mes "[Holink]";
		mes "Once the "+.@type$+" is broken, you can";
		mes "never use it again, meow. Not to mention... all current";
		mes "^ff0000cards and enchantments will vanish for sure^000000.";
		mes "You still want to try, meow~?";
		next;
		if(select("Yes, I do!!:Forget about it!!") == 2) {
			mes "[Holink]";
			mes "Meow! Wise choice, meow.";
			mes "But!!";
			mes "I am not happy to see you doubting the refine master Holink, meow~";
			close;
		}
	}
	if (countitem(.@material) == 0 || Zeny < .@price) {
		mes "[Holink]";
		mes "You don't have the ingredients.";
		mes "You need ^ff9999"+getitemname(.@material)+"^000000 and ^ff9999"+.@price+"^000000 Zeny, meow~";
		mes "Go get it, meow~";
		close;
	}
	delitem .@material,1;
	set Zeny, Zeny-.@price;
	if (getequippercentrefinery(.@part, true) > rand(100)) {
		successrefitem .@part;
		mes "[Holink]";
		mes "Me~ Me~ Meow! Fun fun refining~";
		next;
		emotion e_kis;
		mes "[Holink]";
		mes "Perfect!! Perfect, meow!!";
		mes "I am the disciple of the refining wizard Aragam~";
		mes "Holink!!";
		mes "Another day of successful refining, meow!!";
		close;
	}
	failedrefitem .@part;
	mes "[Holink]";
	mes "Meo~ Meow~ Kyaaak!!";
	next;
	switch(rand(1,5)) {
		case 1: emotion e_sob; break;
		case 2: emotion e_swt2; break;
		case 3: emotion e_wah; break;
		case 4: emotion e_hmm; break;
		case 5: emotion e_lv2; break;
	}
	mes "[Holink]";
	mes "Meow!! Aaaaakk~~!!!!";
	mes "Kyaaak!! I have failed, meow!!";
	next;
	mes "[Holink]";
	mes "......";
	mes "......";
	mes "All~ Everything~ Broken, meow...";
	next;
	mes "[Holink]";
	mes "Meow.... Master Aragam once said,";
	mes "learn from your failures...";
	mes "Human, this one failure will be the beginning of your success in the future.";
	close;
}
