//================= 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)  Daegaladh
//= Copyright (C)  Euphy
//= Copyright (C)  L0ne_W0lf
//=
//= 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/>.
//=========================================================================
//= Armor Enchanter
//================= Description ===========================================
//= Add a +1, +2, or +3 random stat to a specified armor.
//================= Current Version =======================================
//= 1.3a
//=========================================================================

prontera,165,60,2	script	Apprentice Craftsman	1_F_MERCHANT_01,{
	disable_items;
	mes "[Apprentice Craftsman]";
	if (Zeny >= 400000) {
		mes "I've been studying ways to enhance an armor to maximize its capability.";
		next;
		mes "[Apprentice Craftsman]";
		mes "Enchanting is an awesome skill that infuses a mysterious status powers into the armor's hidden socket.";
		next;
		mes "[Apprentice Craftsman]";
		mes "However, you have to keep in mind that if there are two armors of the same kind in your possession, the Enchantment will be applied in the order they are placed in your inventory.";
		next;
		mes "[Apprentice Craftsman]";
		mes "In that case, the Enchantment may be applied to an item which you didn't mean to Enchant. So just bring ^5555ffONE Armor^000000 you want enchanted to be safe...";
		next;
		mes "[Apprentice Craftsman]";
		mes "I'm not responsible for what would happen if you have more than one of the same kind in your inventory.";
		next;
		switch(select("Non Slotted Armor.", "Slotted Armor.", "High Grade Armor.", "Maybe next time.")) {
		case 1:
			setarray .@items[0],2307,2309,2314,2316,2321,2325,2327,2328,2330,2332,2334,2335,2341,2344,2346,2348,2350,2337,2386,2394,2395,2396;
			.@j = 50;
			break;
		case 2:
			setarray .@items[0],2311,2318,2319,2320,2308,2310,2315,2317,2322,2324,2326,2331,2333,2336,2342,2345,2347,2349,2351;
			.@j = 55;
			.@k = 1;
			break;
		case 3:
			setarray .@items[0],2364,2365,2391,2374,2375,2376,2377,2378,2379,2380,2381,2382,2387,2388,2389,2390;
			.@j = 60;
			break;
		case 4:
			mes "[Apprentice Craftsman]";
			mes "Please come back when you have any interest in enchanting your armor.";
			close;
		}
		.@menu$ = "";
		for(.@i = 0; .@i<getarraysize(.@items); ++.@i)
			.@menu$ += getitemname(.@items[.@i])+((.@k)?" [1]":"")+":";
		callsub S_EnchantArmor, .@items[select(.@menu$)-1], .@j;
		end;
	}
	mes "I am in charge of Enchanting Armors. Simply put, I've been studying ways to power-up armor.";
	next;
	mes "[Apprentice Craftsman]";
	mes "If by any chance, you would want to enchant your armor, bring me 400,000 zeny and the armor you want to enchant and you are all set to go.";
	close;

S_EnchantArmor:
	.@itemid = getarg(0);
	.@failrate = getarg(1);
	mes "[Apprentice Craftsman]";
	if (countitem(.@itemid) == 1) {
		mes "Socket enchant will cost you 400,000 zeny. And there will be a random option enchanted. Of course, there is a chance of breaking your armor.";
		next;
		mes "[Apprentice Craftsman]";
		mes "First and most importantly.";
		mes "^ff5555Existing Refine Level of the Armor";
		mes "and Cards will be GONE.^000000";
		mes "Do you still want to try an Enchant?";
		next;
		if(select("Hmm... Let me think it over.", "Go ahead.") == 1) {
			mes "[Apprentice Craftsman]";
			mes "Well, I can't blame you. Safety first, eh?";
			mes "Now you have a nice day.";
			close;
		}
		mes "[Apprentice Craftsman]";
		mes "Quite of an adventurer huh? Well, shall we?";
		close2;
		specialeffect(EF_MAPPILLAR, AREA, playerattached());
		if (Zeny < 400000) {
			mes "[Apprentice Craftsman]";
			mes "Sorry, but you don't have enough zeny.";
			close;
		}
		progressbar "ffff00",7;
		Zeny -= 400000;
		delitem .@itemid,1;
		switch (rand(1,.@failrate)) {
			case 1: .@addpart = 4702;break;
			case 2: .@addpart = 4712;break;
			case 3: .@addpart = 4722;break;
			case 4: .@addpart = 4732;break;
			case 5: .@addpart = 4742;break;
			case 6: .@addpart = 4752;break;
			case 7:
			case 8: .@addpart = 4701;break;
			case 9:
			case 10: .@addpart = 4711;break;
			case 11:
			case 12: .@addpart = 4721;break;
			case 13:
			case 14: .@addpart = 4731;break;
			case 15:
			case 16: .@addpart = 4741;break;
			case 17:
			case 18: .@addpart = 4751;break;
			case 19:
			case 20:
			case 21: .@addpart = 4700;break;
			case 22:
			case 23:
			case 24: .@addpart = 4710;break;
			case 25:
			case 26:
			case 27: .@addpart = 4720;break;
			case 28:
			case 29:
			case 30: .@addpart = 4730;break;
			case 31:
			case 32:
			case 33: .@addpart = 4740;break;
			case 34:
			case 35:
			case 36: .@addpart = 4750;break;
			default:
				specialeffect(EF_PHARMACY_FAIL, AREA, playerattached());
				mes "[Apprentice Craftsman]";
				mes "Well that's too bad.";
				mes "The requested equipment has failed to enchant.";
				close;
		}
		getitem2 .@itemid, 1, 1, 0, 0, 0, 0, 0, .@addpart;
	}
	else {
		mes "Hmm? There's nothing to be enchanted!";
		mes "Please come back with just ONE equipment to be enchanted.";
		close;
	}
}
