//================= 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
//=
//= 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/>.
//=========================================================================
//= 1.0
//================= Description ===========================================
//= Adds slots and enchantments to 2012 RWC Memory accessories.
//================= Current Version =======================================
//= 1.4
//=========================================================================

prontera,147,61,3	script	Driller#pron	4_M_BARBER,{
	disable_items;
	if (checkweight(Knife,1) == 0) {
		mes "You're carrying too many items in your inventory. Visit Kafra storage and try again.";
		close;
	}
	if (MaxWeight - Weight < 10000) {
		mes "You cannot proceed because you're overweight.";
		close;
	}
	.@part = EQI_ACC_L;
	if (!getequipisequiped(.@part)) {
		mes "[Driller]";
		mes "My job is to drill a card slot into RWC Memorial accessories.";
		next;
		mes "[Driller]";
		mes "I'm sorry but you don't have any item equipped on your right accessory position.";
		close;
	}
	mes "[Driller]";
	mes "My job is to drill a card slot into RWC Memorial accessories. Moreover, I only treat ^ff0000pure items^000000, or those which have not been enchanted.";
	next;
	.@equip_id = getequipid(.@part);
	if (.@equip_id != 2966 && .@equip_id != 2968) {
		mes "[Driller]";
		mes "However, I can see that the accessory you are wearing on the right side cannot be treated. Please equip a RWC Memorial accessory.";
		close;
	}
	mes "[Driller]";
	mes "You should also know that making a card slot it extremely dangerous. ^ff0000Chances to succeed are about 50%.^000000 Do you wish to proceed?";
	next;
	if(select("Cancel", "Let's go!") == 1) {
		mes "[Driller]";
		mes "See ya then.";
		close;
	}
	if (.@equip_id == 2966) {
		.@slotted = 2967; //RWC_2012_Ring_
		.@name$ = "RWC 2012 Memorial Ring";
		.@str$ = "ring";
	} else if (.@equip_id == 2968) {
		.@slotted = 2969; //RWC_2012_Pendant_
		.@name$ = "RWC 2012 Memorial Pendant";
		.@str$ = "pendant";
	} else {
		mes "[Driller]";
		mes "I can't identify the accessory item you're wearing on your right hand. I can't work on it.";
		close;
	}
	if (getequipcardid(.@part,3) > 0) {
		mes "[Driller]";
		mes "This item has already been enchanted. I can't work on this as it is against the rules.";
		close;
	}
	delequip .@part;
	if (rand(1,10) > 5) {
		getitem .@slotted,1;
		specialeffect(EF_REPAIRWEAPON, AREA, playerattached());
		mes "[Driller]";
		mes "Yay! Success! Your "+.@name$+" now has a card slot. Check it out!";
		close;
	} else {
		specialeffect(EF_LORD, AREA, playerattached());
		mes "[Driller]";
		mes "Awww... Damn weak "+.@str$+"... It broke during the procedure. I'm sorry.";
		close;
	}
}

prontera,147,59,3	script	Goldberg#pron	4_M_OILMAN,{
	disable_items;
	if (checkweight(Knife,1) == 0) {
		mes "You are carrying too many items. Come back after you have organized your inventory.";
		close;
	}
	if (MaxWeight - Weight < 10000) {
		mes "You cannot proceed because you're overweight.";
		close;
	}
	mes "[Goldberg]";
	mes "Hello! I am in charge of enchanting RWC Memorial accessories with some mystic powers.";
	next;
	.@part = EQI_ACC_L;
	if (!getequipisequiped(.@part)) {
		mes "[Goldberg]";
		mes "I'm sorry but you don't have any item equipped on your right accessory position.";
		close;
	}
	.@equip_id = getequipid(.@part);
	if (.@equip_id < 2966 || .@equip_id > 2969) {
		mes "[Goldberg]";
		mes "However, I can see that the accessory you are wearing is not something I can work on. Please equip a RWC Memorial accessory.";
		close;
	}
	.@select = select("Sorry, not interested.", "Please, empower my accessory.", "Remove the Enchant.")-1;
	if (.@select == 0) {
		mes "[Goldberg]";
		mes "Alright, then, see you next time...";
		close;
	}
	.@equip_refine = getequiprefinerycnt(.@part);
	setarray .@equip_card[0], getequipcardid(.@part,0),getequipcardid(.@part,1),getequipcardid(.@part,2),getequipcardid(.@part,3);
	if (.@select == 1) {
		switch(getequipid(.@part)) {
		case 2966:
			setarray .@option[0],2,2,4,4;
			break;
		case 2967:
			setarray .@option[0],0,2,4,4;
			break;
		case 2968:
			setarray .@option[0],1,1,3,3;
			break;
		case 2969:
			setarray .@option[0],0,1,3,3;
			break;
		default:
			mes "[Goldberg]";
			mes "I'm sorry, but I cannot work on the accessory you are currently wearing.";
			mes "If you have equipped your RWC Memorial accessory on the left side, try to swap it to the right side.";
			close;
		}
		for(.@i = 3; .@i >= 0; --.@i) {
			if (.@equip_card[.@i] == 0) {
				.@slot = .@i;
				.@op_type = .@option[.@i];
				break;
			}
		}
		switch(.@op_type) {
		case 4:
			mes "[Goldberg]";
			mes "Which enchantment would you like to infuse?";
			next;
			setarray .@enchant_select[0],1,2,3,4;
			.@i = select("Cancel", "Fighting Spirit", "ATK (%)", "Max HP", "HP")-2;
			break;
		case 3:
			setarray .@enchant_select[0],5,6,7;
			.@i = select("Cancel", "Spell", "MATK (%)", "SP")-2;
			break;
		case 2:
			mes "[Goldberg]";
			mes "^ff0000Be careful! There is about a 25% chance that the enchantment will fail. If this happens, the item will be destroyed.^000000 Which enchantment would you like to infuse?";
			next;
			setarray .@enchant_select[0],8,9,10,11,12,13,14;
			.@i = select("Cancel", "STR", "AGI", "VIT", "INT", "DEX", "LUK", "SP")-2;
			break;
		case 1:
			mes "[Goldberg]";
			mes "^ff0000There is about a 25% chance that the enchantment will fail. If this happens, the item will be destroyed.^000000 Which enchantment would you like to infuse?";
			next;
			setarray .@enchant_select[0],8,9,10,11,12,13,15,16;
			.@i = select("Cancel", "STR", "AGI", "VIT", "INT", "DEX", "LUK", "MHP", "HP")-2;
			break;
		case 0:
			mes "[Goldberg]";
			mes "Your accessory has received so many enchantments that I can hardly work on it anymore.";
			close;
		}
		if (.@i == -1) {
			mes "[Goldberg]";
			mes "Alright, then, see you next time.";
			close;
		}
		mes "[Goldberg]";
		mes "The power of the enchantment will be randomly chosen. ^ff0000Once infused, the enchantment cannot be removed.^000000 Shall we continue?";
		next;
		if(select("No, please stop.", "Yes, please proceed.") == 1) {
			mes "[Goldberg]";
			mes "Alright, then, see you next time...";
			close;
		}
		.@enchant_type = .@enchant_select[.@i];
		if (!getequipisequiped(.@part)) {
			mes "[Goldberg]";
			mes "Do not take off your equipment while I'm working, okay?";
			close;
		}
		switch(.@enchant_type) {
		case 1:
			setarray .@enc[0],4811,4810,4809; //Fighting_Spirit1,Fighting_Spirit2,Fighting_Spirit3
			break;
		case 2:
			setarray .@enc[0],4819,4766,4767; //Atk1,Atk2,Atk3
			break;
		case 3:
			setarray .@enc[0],4861,4862,4867; //MHP1,MHP2,MHP3
			break;
		case 4:
			setarray .@enc[0],4795,4796,4797; //HP100,HP200,HP300
			break;
		case 5:
			setarray .@enc[0],4760,4761,4806; //Matk1,Matk2,Matk3
			break;
		case 6:
			setarray .@enc[0],4815,4814,4813; //Spell1,Spell2,Spell3
			break;
		case 7:
			setarray .@enc[0],4870,4800,4871; //SP25,SP50,SP75
			break;
		case 8:
			setarray .@enc[0],4700,4701,4702; //Strength1,Strength2,Strength3
			break;
		case 9:
			setarray .@enc[0],4730,4731,4732; //Agility1,Agility2,Agility3
			break;
		case 10:
			setarray .@enc[0],4740,4741,4742; //Vitality1,Vitality2,Vitality3
			break;
		case 11:
			setarray .@enc[0],4710,4711,4712; //Inteligence1,Inteligence2,Inteligence3
			break;
		case 12:
			setarray .@enc[0],4720,4721,4722; //Dexterity1,Dexterity2,Dexterity3
			break;
		case 13:
			setarray .@enc[0],4750,4751,4752; //Luck1,Luck2,Luck3
			break;
		case 14:
			setarray .@enc[0],4870,4800,4871; //SP25,SP50,SP75
			break;
		case 15:
			setarray .@enc[0],4861,4862,4867; //MHP1,MHP2,MHP3
			break;
		case 16:
			setarray .@enc[0],4795,4796,4797; //HP100,HP200,HP300
			break;
		default:
			mes "[Goldberg]";
			mes "We have got a problem, let me check it up.";
			close;
		}

		if (.@enchant_type < 8)
			.@i = rand(1,300); // 0% break chance.
		else
			.@i = rand(1,400); // 25% break chance.

		     if (.@i < 151) .@enchant = .@enc[0];
		else if (.@i < 251) .@enchant = .@enc[1];
		else if (.@i < 301) .@enchant = .@enc[2];
		else .@enchant = 9;

		.@equip_card[.@slot] = .@enchant;
		if (.@slot == 2 && .@enchant == 0) {
			.@equip_card[3] = 0;
		} else if (.@slot == 1 && .@enchant == 0) {
			.@equip_card[2] = 0;
			.@equip_card[3] = 0;
		} else if (.@slot == 0 && .@enchant == 0) {
			.@equip_card[1] = 0;
			.@equip_card[2] = 0;
			.@equip_card[3] = 0;
		}

		delequip .@part;
		if (.@enchant == 9) {
			mes "[Goldberg]";
			mes "Oh gosh!";
 			mes "The item was not strong enough to bear the enchantment and thus got destroyed. I am sorry.";
			specialeffect(EF_LORD, AREA, playerattached());
			close;
		}
		if (.@enchant == 0) { // Should never happen.
			mes "[Goldberg]";
			mes "Oh... It looks like there was an instability of some sort between all the powers infused. This caused all the enchantments to vanish. It is a shame, but please try again!";
		} else {
			mes "[Goldberg]";
			mes "Great!";
			mes "The enchantment is a success! It will be applied in socket No.^990000"+(.@slot+1)+"^000000.";
			specialeffect(EF_REPAIRWEAPON, AREA, playerattached());
		}

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

		close;
	} else if (.@select == 2) {
		mes "[Goldberg]";
		mes "I will just initialize the enchant option without doing anything to the slotted card. You wanna continue?";
		next;
		if(select("I will stop.", "Yep, sure, go on.") == 1) {
			mes "[Goldberg]";
			mes "Come back if you change your mind.";
			close;
		}
		if (countitem(RWC_Inicializer) == 0) {
			mes "[Goldberg]";
			mes "I'm sorry. But you don't have the RWC Initialization coupon. Can you check your inventory?";
			close;
		}
		if (.@equip_card[3] == 0) {
			mes "[Goldberg]";
			mes "Hm... this equipment is clean. I cannot initialize it if there's nothing! Check it again.";
			close;
		}
		specialeffect(EF_REPAIRWEAPON, AREA, playerattached());
		mes "[Goldberg]";
		mes "The enchant option in your item will be initialized.";
		delitem RWC_Inicializer,1;
		delequip .@part;

		//GetNonSlotItemSock2 .@equip_refine .@equip_id .@equip_card[0] .@equip_card[1] .@equip_card[2] .@equip_card[3]
		for(.@i = 0; .@i < 4; ++.@i) {
			if (.@equip_card[.@i] >= 4700) // Armor Enchant System
				.@equip_card[.@i] = 0;
		}
		getitem2 .@equip_id,1,1,.@equip_refine,0,.@equip_card[0],.@equip_card[1],.@equip_card[2],.@equip_card[3];

		close;
	}
}
