//================= Hercules Script =======================================
//=       _   _                     _
//=      | | | |                   | |
//=      | |_| | ___ _ __ ___ _   _| | ___  ___
//=      |  _  |/ _ \ '__/ __| | | | |/ _ \/ __|
//=      | | | |  __/ | | (__| |_| | |  __/\__ \
//=      \_| |_/\___|_|  \___|\__,_|_|\___||___/
//================= License ===============================================
//= This file is part of Hercules.
//= http://herc.ws - http://github.com/HerculesWS/Hercules
//=
//= Copyright (C) 2012-2015  Hercules Dev Team
//= Copyright (C)  Euphy
//= Copyright (C)  Skorm
//=
//= Hercules is free software: you can redistribute it and/or modify
//= it under the terms of the GNU General Public License as published by
//= the Free Software Foundation, either version 3 of the License, or
//= (at your option) any later version.
//=
//= This program is distributed in the hope that it will be useful,
//= but WITHOUT ANY WARRANTY; without even the implied warranty of
//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//= GNU General Public License for more details.
//=
//= You should have received a copy of the GNU General Public License
//= along with this program.  If not, see <http://www.gnu.org/licenses/>.
//=========================================================================
//= Upgrade Weapon Enchants
//================= Description ===========================================
//= Adds enchantments to Upgrade weapons.
//================= Current Version =======================================
//= 1.1
//=========================================================================

prt_in,28,73,3	script	Devil Enchant Master#prq	1_M_SMITH,{
	disable_items;
	if (checkweight(Knife,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(Enchant_Book)) {
			mes "[Devil Enchant Master]";
			mes "Are you listening to me? I will only do for you if you bring the Enchant Book!";
			close;
		}
		.@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;
		}
		.@select = 2;
		break;
	}
	.@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;
	}
	.@equip_id = getequipid(.@part);
	.@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;
	}
	.@equip_refine = getequiprefinerycnt(.@part);

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