//===== rAthena Script ======================================= 
//= RWC 2012 Enchants
//===== By: ================================================== 
//= Euphy
//===== Current Version: ===================================== 
//= 1.0
//===== Compatible With: ===================================== 
//= rAthena Project
//===== Description: ========================================= 
//= [Official Conversion]
//= Adds slots and enchantments to 2012 RWC Memory accessories.
//===== Additional Comments: ================================= 
//= 1.0 First Version. [Euphy]
//============================================================ 

prontera,147,61,3	script	Driller#pron	87,{
	disable_items;
	if (checkweight(1201,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;
	}
	set .@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;
	set .@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) {
		set .@slotted, 2967; //RWC_2012_Ring_
		set .@name$,"RWC 2012 Memorial Ring";
		set .@str$,"ring";
	} else if (.@equip_id == 2968) {
		set .@slotted, 2969; //RWC_2012_Pendant_
		set .@name$,"RWC 2012 Memorial Pendant";
		set .@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;
		specialeffect2 EF_REPAIRWEAPON;
		mes "[Driller]";
		mes "Yay! Success! Your "+.@name$+" now has a card slot. Check it out!";
		close;
	} else {
		specialeffect2 EF_LORD;
		mes "[Driller]";
		mes "Awww... Damn weak "+.@str$+"... It broke during the procedure. I'm sorry.";
		close;
	}
}

prontera,147,59,3	script	Goldberg#pron	878,{
	disable_items;
	if (checkweight(1201,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;
	set .@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;
	}
	set .@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;
	}
	set .@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;
	}
	set .@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(set .@i,3; .@i>=0; set .@i,.@i-1) {
			if (.@equip_card[.@i] == 0) {
				set .@slot, .@i;
				set .@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;
			set .@i, select("Cancel:Fighting Spirit:ATK (%):Max HP:HP")-2;
			break;
		case 3:
			setarray .@enchant_select[0],5,6,7;
			set .@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;
			set .@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;
			set .@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;
		}
		set .@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)
			set .@i, rand(1,300); // 0% break chance.
		else
			set .@i, rand(1,400); // 25% break chance.

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

		set .@equip_card[.@slot], .@enchant;
		if (.@slot == 2 && .@enchant == 0) {
			set .@equip_card[3],0;
		} else if (.@slot == 1 && .@enchant == 0) {
			set .@equip_card[2],0;
			set .@equip_card[3],0;
		} else if (.@slot == 0 && .@enchant == 0) {
			set .@equip_card[1],0;
			set .@equip_card[2],0;
			set .@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.";
			specialeffect2 EF_LORD;
			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.";
			specialeffect2 EF_REPAIRWEAPON;
		}

//		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(6665) == 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;
		}
		specialeffect2 EF_REPAIRWEAPON;
		mes "[Goldberg]";
		mes "The enchant option in your item will be initialized.";
		delitem 6665,1; //RWC_Inicializer
		delequip .@part;
	
//		GetNonSlotItemSock2 .@equip_refine .@equip_id .@equip_card[0] .@equip_card[1] .@equip_card[2] .@equip_card[3]
		for(set .@i,0; .@i<4; set .@i,.@i+1) {
			if (.@equip_card[.@i] >= 4700) // Armor Enchant System
				set .@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;
	}
}
