//===== 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 Morocc~";
	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 EQI_HEAD_TOP:
			mes "My teacher Aragam said meow~";
			mes "There's no cure for stupidity...";
			break;
		case EQI_ARMOR:
			mes "There's nothing to see here, meow!!";
			break;
		case EQI_HAND_L:
			mes "Meow? What do you want me to do with this left hand...?";
			break;
		case EQI_HAND_R:
			mes "Meow? What do you want me to do with this right hand...?";
			break;
		case EQI_GARMENT:
			mes "Meow? You don't have anything on.";
			break;
		case EQI_SHOES:
			mes "Kyang~! Do not mess with my sensitive olfactory, meow~.";
			break;
		case EQI_ACC_L:
		case EQI_ACC_R:
			mes "Meow? Where is the accessory?";
			break;
		case EQI_HEAD_MID:
		case EQI_HEAD_LOW:
			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]";
	.@refineitemid = getequipid(.@part); // save id of the item
	.@itemtype = getiteminfo( .@refineitemid, ITEMINFO_TYPE );
	.@refinerycnt = getequiprefinerycnt(.@part); //save refinery count
	setarray .@card[0], getequipcardid(.@part,0), getequipcardid(.@part,1), getequipcardid(.@part,2), getequipcardid(.@part,3);
// Holink has different hardcoded prices
//	.@price = getequiprefinecost(.@part, REFINE_COST_NORMAL, REFINE_ZENY_COST);
	.@material = getequiprefinecost(.@part, REFINE_COST_NORMAL, REFINE_MATERIAL_ID);

	if( .@itemtype == IT_ARMOR ){
		.@equip_lv = getequiparmorlv( .@part );
		.@type$ = "armor";
		mes "You have chosen an armor, meow~";

		switch(.@equip_lv) {
			case 1:
				.@price = 15000;
				break;
			default:
				// TODO:
				close;
		}
	}else if( .@itemtype == IT_WEAPON ){
		.@equip_lv = getequipweaponlv( .@part );
		.@type$ = "weapon";

		switch( .@equip_lv ){
			case 1: // Level 1 Weapon
				.@price = 500;
				mes "A level 1 weapon...?";
				break;
			case 2: // Level 2 Weapon
				.@price = 2000;
				mes "Meow, a level 2 weapon...?";
				break;
			case 3: // Level 3 Weapon
				.@price = 20000;
				mes "Meow Meow~~ A level 3 weapon~~";
				break;
			case 4: // Level 4 Weapon
				.@price = 50000;
				mes "Me-Meow!... A level 4 weapon...!";
				mes "I've only seen it twice while";
				mes "learning from Aragam... Me-Meow!!";
				break;
			default:
				// TODO:
				close;
		}
	}else{
		// TODO:
		close;
	}

	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 believe 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;

	// anti-hack
	if (callfunc("F_IsEquipIDHack", .@part, .@refineitemid) || callfunc("F_IsEquipCardHack", .@part, .@card[0], .@card[1], .@card[2], .@card[3]) ||
		callfunc("F_IsEquipRefineHack", .@part, .@refinerycnt)) {
		mes "[Holink]";
		emotion ET_FRET;
		mes "Wait a second...";
		mes "Do you think I'm stupid?!";
		mes "You switched the item while I wasn't looking! Get out of here!";
		close;
	}

	if (getequippercentrefinery(.@part, true) > rand(100)) {
		successrefitem .@part;
		mes "[Holink]";
		mes "Me~ Me~ Meow! Fun fun refining~";
		next;
		emotion ET_CHUP;
		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 ET_CRY; break;
		case 2: emotion ET_PROFUSELY_SWEAT; break;
		case 3: emotion ET_KEK; break;
		case 4: emotion ET_SCRATCH; break;
		case 5: emotion ET_BIGTHROB; 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;
}
