//===== rAthena Script =======================================
//= Upgrade Weapon Enchants
//===== By: ==================================================
//= Skorm
//===== Current Version: =====================================
//= 1.1
//===== Compatible With: =====================================
//= rAthena Project
//===== Description: =========================================
//= [Official Conversion]
//= Adds enchantments to Upgrade weapons.
//===== Additional Comments: =================================
//= 1.0 First version.
//= 1.1 Standardizing, grammar and bug fixes. [Euphy]
//============================================================

// Main NPC :: 201105_luk_enc
//============================================================
prt_in,28,73,3	script	Devil Enchant Master#prq	63,{
	disable_items;
	if (checkweight(1201,1) == 0) {
		mes "You are carrying too many items, please reduce it and come back again!";
		close;
	}
	if (MaxWeight - Weight < 10000) {
		mes "You are over the weight limit, please reduce it and come back again!";
		close;
	}
	mes "[Devil Enchant Master]";
	mes "Yes?";
	mes "You are looking for me?";
	next;
	switch(select("This is the first time seeing you!:I heard that you are the best!:Please initialize the enchant.")) {
	case 1:
		mes "[Devil Enchant Master]";
		mes "Ha ha ha~ Of course, I am not the kind of person that simply deals with people.";
		next;
		mes "[Devil Enchant Master]";
		mes "Including you! Even if you offer me plenty of money, I will not simply enchant for you!!";
		next;
		mes "[Devil Enchant Master]";
		mes "Have you seen my title? Very few people have this title for a reason!";
		next;
		mes "[Devil Enchant Master]";
		mes "I will only enchant if you bring an ^0000ffEnchant Book^000000 along!";
		next;
		mes "[Devil Enchant Master]";
		mes "Else, I will not enchant for you....";
		close;
	case 2:
		if (!countitem(6484)) {
			mes "[Devil Enchant Master]";
			mes "Are you listening to me? I will only do for you if you bring the Enchant Book!";
			close;
		}
		set .@select,1;
		break;
	case 3:
		mes "[Devil Enchant Master]";
		if (Zeny < 100000) {
			mes "Initializing will cost 100,000 zeny. It seems you do not have enough zeny...";
			close;
		}
		mes "Initializing will cost 100,000 zeny and confirming whether the weapon is enchanted!";
		next;
		if (select("Let me think about it.:Initialize it now!") == 1) {
			mes "[Devil Enchant Master]";
			mes "Come back after you have confirmed!";
			close;
		}
		set .@select,2;
		break;
	}
	set .@part, EQI_HAND_R;

	mes "[Devil Enchant Master]";
	if (!getequipisequiped(.@part)) {
		mes "Are you trying to remove the enchanted equipment?";
		close;
	}
	setarray .@equip_card[0], getequipcardid(.@part,0), getequipcardid(.@part,1), getequipcardid(.@part,2), getequipcardid(.@part,3);
	if (!getequipisequiped(.@part)) {
		mes "It is dangerous to remove equipment during enchant process!";
		close;
	}
	set .@equip_id, getequipid(.@part);
	set .@item$, "|1292|1394|1491|1585|2015|13071|13115|16019|18112|21000|";
	if (!compare(.@item$,"|"+.@equip_id+"|")) {
		mes "I don't want to touch your equipment now!";
		close;
	}

	if (.@select == 1) {
		if (!countitem(6484)) {
			mes "Are you listening to me? I will only do for you if you bring the Enchant Book!";
			close;
		}
		mes "Which type of effect do you want to enchant?";
		next;
		switch(select("Let me think about it.:Physical Series:Magical Series")) {
		case 1:
			mes "[Devil Enchant Master]";
			mes "Come back again after you change your mind!";
			close;
		case 2:
			set .@enc_type,1;
			break;
		case 3:
			set .@enc_type,2;
			break;
		}
		mes "[Devil Enchant Master]";
		if (.@equip_card[3]) {
			mes "This equipment has been enchanted! You need to initialize first before you want to enchant it again.";
			close;
		}
		mes "The enchant process might fail, and ^ff0000it will reduce partial refine level^000000, but the slotted card and weapon will not be broken! Are you sure you want to continue?";
		next;
		if (select("Next time!:Start now!") == 1) {
			mes "[Devil Enchant Master]";
			mes "Come back again after you have decided!";
			close;
		}
		if (.@equip_card[3]) {
			mes "[Devil Enchant Master]";
			mes "It seems there's a problem, let me take a look.";
			close;
		}

		if (.@enc_type == 1) { // Physical Series
			set .@i, rand(1,1300);
			     if (.@i < 51)    set .@enchant,4734; //Agility5
			else if (.@i < 76)    set .@enchant,4735; //Agility6
			else if (.@i < 88)    set .@enchant,4736; //Agility7
			else if (.@i < 93)    set .@enchant,4737; //Agility8
			else if (.@i < 95)    set .@enchant,4738; //Agility9
			else if (.@i < 96)    set .@enchant,4739; //Agility10
			else if (.@i < 146)   set .@enchant,4724; //Dexterity5
			else if (.@i < 171)   set .@enchant,4725; //Dexterity6
			else if (.@i < 183)   set .@enchant,4726; //Dexterity7
			else if (.@i < 188)   set .@enchant,4727; //Dexterity8
			else if (.@i < 190)   set .@enchant,4728; //Dexterity9
			else if (.@i < 191)   set .@enchant,4729; //Dexterity10
			else if (.@i < 291)   set .@enchant,4704; //Strength5
			else if (.@i < 341)   set .@enchant,4705; //Strength6
			else if (.@i < 366)   set .@enchant,4706; //Strength7
			else if (.@i < 378)   set .@enchant,4707; //Strength8
			else if (.@i < 383)   set .@enchant,4708; //Strength9
			else if (.@i < 384)   set .@enchant,4709; //Strength10
			else if (.@i < 434)   set .@enchant,4754; //Luck5
			else if (.@i < 459)   set .@enchant,4755; //Luck6
			else if (.@i < 471)   set .@enchant,4756; //Luck7
			else if (.@i < 476)   set .@enchant,4757; //Luck8
			else if (.@i < 478)   set .@enchant,4758; //Luck9
			else if (.@i < 479)   set .@enchant,4759; //Luck10
			else if (.@i < 679)   set .@enchant,4744; //Vitality5
			else if (.@i < 779)   set .@enchant,4745; //Vitality6
			else if (.@i < 829)   set .@enchant,4746; //Vitality7
			else if (.@i < 854)   set .@enchant,4747; //Vitality8
			else if (.@i < 866)   set .@enchant,4748; //Vitality9
			else if (.@i < 867)   set .@enchant,4749; //Vitality10
			else if (.@i < 967)   set .@enchant,4808; //Fighting_Spirit4
			else if (.@i < 992)   set .@enchant,4820; //Fighting_Spirit5
			else if (.@i < 1092)  set .@enchant,4835; //Expert_Archer4
			else if (.@i < 1117)  set .@enchant,4836; //Expert_Archer5
			else if (.@i < 1217)  set .@enchant,4835; //Expert_Archer4
			else if (.@i < 1242)  set .@enchant,4836; //Expert_Archer5
			else set .@enchant,0;
		} else if (.@enc_type == 2) { // Magical Series
			set .@i, rand(1,1200);
			     if (.@i < 51)    set .@enchant,4714; //Inteligence5
			else if (.@i < 76)    set .@enchant,4715; //Inteligence6
			else if (.@i < 88)    set .@enchant,4716; //Inteligence7
			else if (.@i < 93)    set .@enchant,4717; //Inteligence8
			else if (.@i < 95)    set .@enchant,4718; //Inteligence9
			else if (.@i < 96)    set .@enchant,4719; //Inteligence10
			else if (.@i < 146)   set .@enchant,4724; //Dexterity5
			else if (.@i < 171)   set .@enchant,4725; //Dexterity6
			else if (.@i < 183)   set .@enchant,4726; //Dexterity7
			else if (.@i < 188)   set .@enchant,4727; //Dexterity8
			else if (.@i < 190)   set .@enchant,4728; //Dexterity9
			else if (.@i < 191)   set .@enchant,4729; //Dexterity10
			else if (.@i < 291)   set .@enchant,4734; //Agility5
			else if (.@i < 341)   set .@enchant,4735; //Agility6
			else if (.@i < 366)   set .@enchant,4736; //Agility7
			else if (.@i < 378)   set .@enchant,4737; //Agility8
			else if (.@i < 383)   set .@enchant,4738; //Agility9
			else if (.@i < 384)   set .@enchant,4739; //Agility10
			else if (.@i < 484)   set .@enchant,4754; //Luck5
			else if (.@i < 534)   set .@enchant,4755; //Luck6
			else if (.@i < 559)   set .@enchant,4756; //Luck7
			else if (.@i < 571)   set .@enchant,4757; //Luck8
			else if (.@i < 576)   set .@enchant,4758; //Luck9
			else if (.@i < 577)   set .@enchant,4759; //Luck10
			else if (.@i < 777)   set .@enchant,4744; //Vitality5
			else if (.@i < 877)   set .@enchant,4745; //Vitality6
			else if (.@i < 927)   set .@enchant,4746; //Vitality7
			else if (.@i < 952)   set .@enchant,4747; //Vitality8
			else if (.@i < 964)   set .@enchant,4748; //Vitality9
			else if (.@i < 969)   set .@enchant,4749; //Vitality10
			else if (.@i < 1069)  set .@enchant,4812; //Spell4
			else if (.@i < 1094)  set .@enchant,4826; //Spell5
			else if (.@i < 1119)  set .@enchant,4761; //Matk2
			else if (.@i < 1124)  set .@enchant,4806; //Matk3
			else set .@enchant,0;
		} else {
			mes "[Devil Enchant Master]";
			mes "Hmm! This item is having a problem, please check it again!";
			close;
		}
		mes "[Devil Enchant Master]";
		if (.@equip_card[3]) {
			mes "This item has been enchanted!";
			close;
		}
		if (!countitem(6484)) {
			mes "Are you listening to me? I will only do for you if you bring the Enchant Book!";
			close;
		}
		set .@equip_refine, getequiprefinerycnt(.@part);
		if (.@enchant == 0) {
			specialeffect EF_SHIELDCHARGE;
			mes "Oh! Unbelievable!! It failed!! Please come again!";
			set .@lost_refine, rand(0,.@equip_refine);
			set .@equip_refine, .@equip_refine - .@lost_refine;
		} else {
			specialeffect EF_REPAIRWEAPON;
			mes "The slot ^9900004^000000 has been enchanted!";
		}
		delitem 6484,1; //Enchant_Book

		// anti-hack
		if (callfunc("F_IsEquipIDHack", .@part, .@equip_id) ||
		    callfunc("F_IsEquipCardHack", .@part, .@equip_card[0], .@equip_card[1], .@equip_card[2], .@equip_card[3]))
			close;

		delequip .@part;

//		GetNonSlotItemSock2 .@equip_refine .@equip_id .@equip_card[0] .@equip_card[1] .@equip_card[2] .@enchant
		getitem2 .@equip_id,1,1,.@equip_refine,0,.@equip_card[0],.@equip_card[1],.@equip_card[2],.@enchant;

		if (.@lost_refine) {
			next;
			mes "[Devil Enchant Master]";
			mes "The failure has reduced the refine by "+callfunc("F_InsertPlural",.@lost_refine,"level")+"! Don't be depressed!";
		}
		close;
	} else if (.@select == 2) {
		if (Zeny < 100000) {
			mes "You need to bring some money to initialize!!";
			close;
		}
		if (.@equip_card[3] < 4700) { // Armor Enchant System
			mes "This item is not enchanted!";
			close;
		}
		if (!getequipisequiped(.@part)) {
			mes "Are you unequipping now?";
			close;
		}
		specialeffect EF_REPAIRWEAPON;
		mes "I initialized the enchant effects.";
		set Zeny, Zeny - 100000;

		// anti-hack
		if (callfunc("F_IsEquipIDHack", .@part, .@equip_id) ||
		    callfunc("F_IsEquipCardHack", .@part, .@equip_card[0], .@equip_card[1], .@equip_card[2], .@equip_card[3]))
			close;

		set .@equip_refine, getequiprefinerycnt(.@part);
		delequip .@part;

//		GetNonSlotItemSock2 .@equip_refine .@equip_id .@equip_card[0] .@equip_card[1] .@equip_card[2] 0
		getitem2 .@equip_id,1,1,.@equip_refine,0,.@equip_card[0],.@equip_card[1],.@equip_card[2],0;

		close;
	} else {
		mes "It seems you have chosen the wrong job??";
		close;
	}
}
