//===== rAthena Script =======================================
//= Enchants NPCs.
//===== Description: =========================================
//= Temporal Boots enchants NPCs.
//===== Changelogs: ==========================================
//= 1.0 First Version merged from idathena.
//=     Credit exneval. [Capuche]
//============================================================

// Merchant
//============================================================
glast_01,210,273,5	script	Hugin's Butler#pa0829	1_F_04,{
	disable_items;
	if (MaxWeight - Weight < 1000) {
		mes "Your bag is too heavy. Reduce some weight and come back.";
		close;
	}
	mes "[Hugin's Butler]";
	mes "Bring Temporal Crystal items for various Temporal boots items. Pick something you want.";
	next;
	switch( select( "Cancel", "Buy Temporal Boots (Need 1 Temporal Crystal)", "Upgrade Temporal Boots (Need 5 Temporal Crystals)", "Upgrade Modified Boots (Need 5 Temporal Crystals)" ) ) {
	case 1:
		mes "[Hugin's Butler]";
		mes "Come back whenever you want.";
		close;
	case 2:
		if (countitem(6607) > 0) {
			mes "[Hugin's Butler]";
			mes "Take these Temporal Boots. We can upgrade your Temporal Boots with 5 Temporal Crystals.";
			delitem 6607,1;// Temporal_Crystal
			getitem 2499,1;// Temporal_Boots
			close;
		}
		mes "[Hugin's Butler]";
		mes "You need more Temporal Crystals. Come back when you get some more Temporal Crystals during your travel through Old Glast Heim.";
		close;
	case 3:
		setarray .@equip_type[0],
			22000,	// Temporal_STR_Boots
			22001,	// Temporal_INT_Boots
			22002,	// Temporal_AGI_Boots
			22003,	// Temporal_VIT_Boots
			22004,	// Temporal_DEX_Boots
			22005;	// Temporal_LUK_Boots
		break;
	case 4:
		setarray .@equip_type[0],
			22107,	// Modified_STR_Boots
			22108,	// Modified_INT_Boots
			22109,	// Modified_AGI_Boots
			22110,	// Modified_VIT_Boots
			22111,	// Modified_DEX_Boots
			22112;	// Modified_LUK_Boots
		break;
	}
	if (!getequipisequiped(EQI_SHOES)) {
		mes "[Hugin's Butler]";
		mes "Only the item you are wearing can be upgraded.";
		mes "Wear the ^0000FFTemporal Boots^000000 you want to upgrade, and then talk to me once again.";
		close;
	}
	if (getequipid(EQI_SHOES) != 2499) {
		mes "[Hugin's Butler]";
		mes "You are not wearing the Temporal Boots. Talk to me once you're wearing them.";
		close;
	}
	if (countitem(6607) < 5) {
		mes "[Hugin's Butler]";
		mes "Not enough Temporal Crystals. You need 5 Temporal Crystals to upgrade your item.";
		close;
	}
	mes "[Hugin's Butler]";
	mes "You can trade ^0000FF1 Temporal Boots and 5 Temporal Crystals^000000 for 1 of the following items. ^FF0000Previous refine rate will not be retained with these new ones^000000.";
	next;
	.@s = select( "Cancel", "Str Boots", "Int Boots", "Agi Boots", "Vit Boots", "Dex Boots", "Luk Boots" ) - 2;
	if (.@s == -1) {
		mes "[Hugin's Butler]";
		mes "Come back anytime you want.";
		close;
	}
	setarray .@type$[0], "Strength", "Intelligence", "Agility", "Vitality", "Dexterity", "Lucky";
	mes "[Hugin's Butler]";
	mes "Are you sure about buying Temporal ^FF0000" + .@type$[.@s] + "^000000 Boots? There's no refunds.";
	next;
	if (select( "Think again", "Yes, I am sure." ) == 1) {
		mes "[Hugin's Butler]";
		mes "Ok, come back again when you are sure.";
		close;
	}
	mes "[Hugin's Butler]";
	mes "The boots have been upgraded as you want.";
	if (getequipid(EQI_SHOES) == 2499) {
		delequip EQI_SHOES;
		delitem 6607,5;// Temporal_Crystal
		getitem .@equip_type[.@s],1;
	}
	close;
}

// Enchant and Socket NPC
//============================================================
glast_01,212,273,4	script	Hugin's Magician#pa0829	1_F_01,{
	disable_items;
	if (MaxWeight - Weight < 1000) {
		mes "Your bag is too heavy. Reduce some weight and come back.";
		close;
	}
	mes "[Hugin's Magician]";
	mes "So you came to enchant the Temporal Boots. Be aware that Boots with sockets cannot be enchanted, and this upgrade is only possible for the boots you are wearing.";
	next;
	if (select( "How does the enchanting work?", "Give effect to my Temporal Boots" ) == 1) {
		mes "[Hugin's Magician]";
		mes "You can keep obtain ^0000FFCoagulated Spell^000000 through your travel times.";
		next;
		mes "[Hugin's Magician]";
		mes "I can enchant your Temporal Boots items depands on the amount of that item. ^0000FFNot normal type boots^000000. Only possible for those 6 expanded version boots.";
		next;
		mes "[Hugin's Magician]";
		mes "But, once you put a socket into the item, you cannot enchant it. Make sure to remember that.";
		next;
		mes "[Hugin's Magician]";
		mes "I don't give out effect randomly. You can pick which effect you want for the item.";
		next;
		mes "[Hugin's Magician]";
		mes "Of course it is for 4th slot only. You can have small effect at the start, and then the effect gets stronger.";
		next;
		mes "[Hugin's Magician]";
		mes "To get to the final option upgrade, it will require way more Coagulated Spell items. Don't forget that.";
		next;
		mes "[Hugin's Magician]";
		mes "Once the 4th slot completes the best option, you get to have a random bonus effect to the 3rd slot. With.. certain payment~";
		next;
		mes "[Hugin's Magician]";
		mes "Also, you don't lose the item even if the enchant fails, we also guarantee keeping card and refine rate. But we can't initialize enchanting.";
		next;
		mes "[Hugin's Magician]";
		mes "Phew...";
		mes "Anyways, that's all for basic enchant information. Now you should see for yourself.";
		close;
	}
	if (!getequipisequiped(EQI_SHOES)) {
		mes "[Hugin's Magician]";
		mes "Are you wearing the item?";
		close;
	}
	.@equip_id = getequipid(EQI_SHOES);

	setarray .@enchant_1[0],4808,4832,4814,4741,4869,4752;// Fighting_Spirit4	Expert_Archer1	Spell2	Vitality2	DelayafterAttack1Lv	Luck3
	setarray .@enchant_2[0],4820,4833,4813,4742,4872,4753;// Fighting_Spirit5	Expert_Archer2	Spell3	Vitality3	DelayafterAttack2Lv	Luck4
	setarray .@enchant_3[0],4821,4834,4812,4861,4873,4754;// Fighting_Spirit6	Expert_Archer3	Spell4	MHP1		DelayafterAttack3Lv	Luck5
	setarray .@enchant_4[0],4822,4835,4826,4862,4881,4755;// Fighting_Spirit7	Expert_Archer4	Spell5	MHP2		DelayafterAttack4Lv	Luck6
	setarray .@enchant_cost[0],1,4,15,30,10;

	switch(.@equip_id) {
	case 22000:	// Temporal_STR_Boots
	case 22001:	// Temporal_INT_Boots
	case 22002:	// Temporal_AGI_Boots
	case 22003:	// Temporal_VIT_Boots
	case 22004:	// Temporal_DEX_Boots
	case 22005:	// Temporal_LUK_Boots

	case 22107:	// Modified_STR_Boots
	case 22108:	// Modified_INT_Boots
	case 22109:	// Modified_AGI_Boots
	case 22110:	// Modified_VIT_Boots
	case 22111:	// Modified_DEX_Boots
	case 22112:	// Modified_LUK_Boots
		.@equip_name$ = getequipname(EQI_SHOES);
		setarray .@card[0],
			getequipcardid(EQI_SHOES,0),
			getequipcardid(EQI_SHOES,1),
			getequipcardid(EQI_SHOES,2),
			getequipcardid(EQI_SHOES,3);
		copyarray .@equip_card[0], .@card[0], 4;	// for final check
		.@equip_refine = getequiprefinerycnt(EQI_SHOES);

		if (.@card[2] > 0) {
			mes "[Hugin's Magician]";
			mes "These boots have already passed the enchanting limit. We can't enchant them any more.";
			close;
		}
		if (.@card[3] == 0) {// 4th slot 1st try enchanting
			.@cost = .@enchant_cost[0];
			mes "[Hugin's Magician]";
			mes "Want to enchant ^0000FF" + .@equip_name$ + "^000000?";
			mes "For the 1st enchanting, you need ^0000FF" + .@cost + "^000000 Coagulated Spell items.";
			next;
			.@s = select( "Quit", "Fighting Spirit", "Archery", "Spell", "Vitality", "Attack Speed", "Lucky" ) - 2;
			if (.@s == -1) {
				mes "[Hugin's Magician]";
				mes "Ok, come back when you are ready.";
				close;
			}
			.@card[3] = .@enchant_1[.@s];
			.@string$ = "enchant number ^6300001^000000.";
		}
		else {
			for ( .@enchant_num = 1; .@enchant_num < 5; .@enchant_num++ ) {
				for ( .@enchant_type = 0; .@enchant_type < 6 && .@card[3] != getd( ".@enchant_" + .@enchant_num + "[" + .@enchant_type + "]" ); .@enchant_type++ )
					continue;
				if (.@enchant_type < 6)
					break;
			}
			if (.@enchant_num == 5) {
				mes "[Hugin's Magician]";
				mes "Something wrong happened.";
				close;
			}
			.@cost = .@enchant_cost[.@enchant_num];

			mes "[Hugin's Magician]";
			if (.@enchant_num == 4) {
				.@card[2] = callfunc("F_Rand",4875,4876,4877,4878,4879,4880);// Bear's_Power, Runaway_Magic, Speed_Of_Light, Muscle_Fool, Hawkeye, Lucky_Day
				.@string$ = "^990000Bonus effect ^000000 upgrade.";
				mes "4th slot is already upgraded to the final option. Would you like a random bonus effect for the 3rd slot? You need ^0000ff" + .@cost + "^000000 Coagulated Spell items.";
			}
			else {
				.@number = .@enchant_num + 1;
				.@card[3] = getd( ".@enchant_" + (.@enchant_num+1) + "[" + .@enchant_type + "]" );
				.@string$ = "enchant number ^630000" + .@number + "^000000.";
				mes "Enchanting ^0000FF" + .@equip_name$ + "^000000's 4th slot as ^0000FF" + .@number + "^000000 level effect. Requires ^0000FF" + .@cost + "^000000 Coagulated Spell items.";
			}
			next;
			if (select("Quit","Effect Upgrade!") == 1) {
				mes "[Hugin's Magician]";
				mes "Ok, come back when you are ready.";
				close;
			}
		}
		if (countitem(6608) < .@cost) {
			mes "[Hugin's Magician]";
			mes "Hmm, you are missing " + (.@cost - countitem(6608)) + " Coagulated Spell items. Go get more, and then we can talk about more enchants.";
			close;
		}
		specialeffect2 EF_REPAIRWEAPON;
		delitem 6608,.@cost;// Coagulated_Spell

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

		delequip EQI_SHOES;
		mes "[Hugin's Magician]";
		mes "Trying for " + .@string$;
		getitem2 .@equip_id,1,1,.@equip_refine,0,0,0,.@card[2],.@card[3];
		close;
	default:
		mes "[Hugin's Magician]";
		mes "This is not the right item for this enchant.";
		mes "Remember, only those 6 types of Temporal Boots are available for enchanting.";
		close;
	}
}

glast_01,210,270,0	script	Hugin's Craftsman#pa0829	4_F_JOB_BLACKSMITH,{
	disable_items;
	if (MaxWeight - Weight < 1000) {
		mes "Your bag is too heavy. Reduce some weight and come back.";
		close;
	}
	mes "[Hugin's Craftsman]";
	mes "That Magician always says that enchanting Temporal Boots is the best. But, I think quite different.";
	next;
	mes "[Hugin's Craftsman]";
	mes "I think putting a slot into the item would be the best. Even with some risk of failing.";
	next;
	mes "[Hugin's Craftsman]";
	mes "Bring me ^0000FF5 Temporal Crystals^000000, and I will try to put a slot into your advanced Temporal Boots. But, it's possible to ^FF0000fail and break the item^000000. Is that ok?";
	next;
	if (select( "Cancel", "Take the risk and try to add a slot" ) == 1) {
		mes "[Hugin's Craftsman]";
		mes "Ok, come back anytime you want.";
		close;
	}
	if (!getequipisequiped(EQI_SHOES)) {
		mes "[Hugin's Craftsman]";
		mes "Are you sure you are wearing the item?";
		close;
	}
	.@equip_id = getequipid(EQI_SHOES);
	switch(.@equip_id) {
	case 22000:	callsub( S_Slot,22006 );	// Temporal_STR_Boots
	case 22001:	callsub( S_Slot,22009 );	// Temporal_INT_Boots
	case 22002:	callsub( S_Slot,22010 );	// Temporal_AGI_Boots
	case 22003:	callsub( S_Slot,22007 );	// Temporal_VIT_Boots
	case 22004:	callsub( S_Slot,22008 );	// Temporal_DEX_Boots
	case 22005:	callsub( S_Slot,22011 );	// Temporal_LUK_Boots

	case 22107:	callsub( S_Slot,22113 );	// Modified_STR_Boots
	case 22108:	callsub( S_Slot,22114 );	// Modified_INT_Boots
	case 22109:	callsub( S_Slot,22115 );	// Modified_AGI_Boots
	case 22110:	callsub( S_Slot,22116 );	// Modified_VIT_Boots
	case 22111:	callsub( S_Slot,22117 );	// Modified_DEX_Boots
	case 22112:	callsub( S_Slot,22118 );	// Modified_LUK_Boots
	default:
		mes "[Hugin's Craftsman]";
		mes "This is not it! We need ^0000FFAdvanced Temporal Boots^000000 items! The item ^0000FFwith a stat effect and without a slot^000000!";
		close;
	}

S_Slot:
	.@equip_id = getequipid(EQI_SHOES);
	mes "[Hugin's Craftsman]";
	mes "And ^FF0000all enchant or refine rates will be lost if you fail this.^000000";
	mes "Still want to risk it?";
	next;
	if (select( "Cancel", "I am ok with it!" ) == 1) {
		mes "[Hugin's Craftsman]";
		mes "Ok, come back anytime you want.";
		close;
	}
	mes "[Hugin's Craftsman]";
	mes "Once again, ^FF0000That Magician won't enchant any item with a slot.^000000";
	mes "Still want to proceed?";
	next;
	if (select( "Cancel", "I understand. Try to slot it." ) == 1) {
		mes "[Hugin's Craftsman]";
		mes "Ok, come back anytime you want.";
		close;
	}
	if (countitem(6607) < 5) {
		mes "[Hugin's Craftsman]";
		mes "You must bring ^0000FF5 Temporal Crystal items^000000. Nothing is free you know...";
		close;
	}
	delitem 6607,5;// Temporal_Crystal
	if (getequipid(EQI_SHOES) == .@equip_id) {
		delequip EQI_SHOES;
		if (rand(1,100) < 50) {
			mes "[Hugin's Craftsman]";
			mes "Arrggg, we failed. Better luck next time.";
			specialeffect2 EF_PHARMACY_FAIL;
			close;
		}
		mes "[Hugin's Craftsman]";
		mes "Successful! Here you go.";
		specialeffect2 EF_MAXPOWER;
		getitem getarg(0),1;
	}
	close;
}

// Temporal shoes slotted - npc enchant
glast_01,184,283,4	script	Dark magic master#pa082	1_F_01,{
	disable_items;
	if ((MaxWeight - Weight) < 1000) {
		mes "Your bag is too heavy. Reduce some weight and come back.";
		close;
	}
	if (checkweight(1201,1) == 0) {
		mes "You seem to be carrying too many items. Put some items in storage and come back again.";
		close;
	}
	// requirements
	.@coagulated_id = 6608;// Coagulated_Spell
	.@polluted_id = 6755;// Polluted_Spell
	.@cost_zeny = 100000;

	mes "[Dark magic master]";
	mes "I deal with the Temporal Boots with socket only.";
	next;
	if (select( "How does the enchanting work?", "Give effect to my Temporal Boots" ) == 1) {
		mes "[Dark magic master]";
		mes "You should ask Hugin's magic master all the basic things. I want deeper conversation about enchating work.";
		next;
		mes "[Dark magic master]";
		mes "I need 4 items. ^0000ff" + callfunc("F_InsertComma",.@cost_zeny) + ", " + getitemname(.@polluted_id) + ", " + getitemname(.@coagulated_id) + ", Temporal Boots(Socket) Series^000000. If you don't have any of these, I cannot help you.";
		next;
		mes "[Dark magic master]";
		mes "It's my small hobby.. To enchant Socketed Temporal Boots using polluted and coagulated spell.";
		next;
		mes "[Dark magic master]";
		mes "Of course, you must cope with bigger risk of destruction whenever you'd like to enchant again and again.";
		next;
		mes "[Dark magic master]";
		mes "The enchant order is same as Hugin's magic master's enchantment. Please refer to his explanation.";
		close;
	}
	.@equip_id = getequipid(EQI_SHOES);

	switch(.@equip_id) {
	case 22006:	// Temporal_Str_Boots_
	case 22007:	// Temporal_Vit_Boots_
	case 22008:	// Temporal_Dex_Boots_
	case 22009:	// Temporal_Int_Boots_
	case 22010:	// Temporal_Agi_Boots_
	case 22011:	// Temporal_Luk_Boots_
	case 22113:	// Modified_Str_Boots_
	case 22114:	// Modified_Int_Boots_
	case 22115:	// Modified_Agi_Boots_
	case 22116:	// Modified_Vit_Boots_
	case 22117:	// Modified_Dex_Boots_
	case 22118:	// Modified_Luk_Boots_
		break;
	case -1:
		mes "[Dark magic master]";
		mes "Are you wearing the item?";
		close;
	default:
		mes "[Dark magic master]";
		mes "This is not the right item for this enchant. Remember, only those 6 types of Temporal Boots with socket are available for hidden enchanting..";
		close;
	}
	// enchants ID
	setarray .@enchant_1[0],4808,4832,4814,4741,4869,4752;// Fighting_Spirit4	Expert_Archer1	Spell2	Vitality2	DelayafterAttack1Lv	Luck3
	setarray .@enchant_2[0],4820,4833,4813,4742,4872,4753;// Fighting_Spirit5	Expert_Archer2	Spell3	Vitality3	DelayafterAttack2Lv	Luck4
	setarray .@enchant_3[0],4821,4834,4812,4861,4873,4754;// Fighting_Spirit6	Expert_Archer3	Spell4	MHP1		DelayafterAttack3Lv	Luck5
	setarray .@enchant_4[0],4822,4835,4826,4862,4881,4755;// Fighting_Spirit7	Expert_Archer4	Spell5	MHP2		DelayafterAttack4Lv	Luck6

	// requirements amount
	setarray .@en_amount_coag[0],3,10,20,40,50;
	setarray .@en_amount_polluted[0],1,2,4,7,10;

	// (custom) chances of success (official value unknown)
	setarray .@chances[0],100,70,70,70,70;

	// data of item equipped
	.@equip_name$ = getequipname(EQI_SHOES);
	setarray .@card[0],
		getequipcardid(EQI_SHOES,0),
		getequipcardid(EQI_SHOES,1),
		getequipcardid(EQI_SHOES,2),
		getequipcardid(EQI_SHOES,3);
	copyarray .@equip_card[0], .@card[0], 4;
	.@equip_refine = getequiprefinerycnt(EQI_SHOES);

	if (.@card[2] > 0) {
		mes "[Dark magic master]";
		mes "These boots have already passed the enchanting limit. We can't enchant them any more.";
		close;
	}
	if (.@card[3] == 0) {// 4th slot 1st try enchanting
		.@amount_coag = .@en_amount_coag[0];
		.@amount_poll = .@en_amount_polluted[0];

		mes "[Dark magic master]";
		mes "Want to enchant ^0000ff" + .@equip_name$ + " (Socket)^000000? For the 1st enchanting, you need ^0000ff" + .@amount_poll + " " + getitemname(.@polluted_id) + ", " + .@amount_coag + " " + getitemname(.@coagulated_id) + ", and " + callfunc("F_InsertComma",.@cost_zeny) + " zeny^000000.";
		mes "It has some risk of failing..";
		next;
		.@s = select( "Quit", "Fighting Spirit", "Archery", "Spell", "Vitality", "Attack Speed", "Lucky" ) - 2;
		if (.@s == -1) {
			mes "[Dark magic master]";
			mes "Ok, come back when you are ready.";
			close;
		}
		.@card[3] = .@enchant_1[.@s];
		.@string$ = "enchant number ^6300001^000000.";
		.@num = 0;
	}
	else {
		for ( .@num = 1; .@num < 5; .@num++ ) {
			for ( .@type = 0; .@type < 6 && .@card[3] != getd( ".@enchant_" + .@num + "[" + .@type + "]" ); .@type++ )
				continue;
			if (.@type < 6)
				break;
		}
		if (.@num == 5) {
			mes "[Dark magic master]";
			mes "Something wrong happened.";
			close;
		}
		.@amount_coag = .@en_amount_coag[.@num];
		.@amount_poll = .@en_amount_polluted[.@num];

		mes "[Dark magic master]";
		if (.@num == 4) {
			.@card[2] = callfunc("F_Rand",4875,4876,4877,4878,4879,4880);// Bear's_Power, Runaway_Magic, Speed_Of_Light, Muscle_Fool, Hawkeye, Lucky_Day
			.@string$ = "^990000 Bonus effect ^000000 upgrade.";
			mes "Would you like a random bonus effect for the 3rd slot? You need ^0000ff" + .@amount_poll + " " + getitemname(.@polluted_id) + ", " + .@amount_coag + " " + getitemname(.@coagulated_id) + ", and " + callfunc("F_InsertComma",.@cost_zeny) + " zeny^000000. But it has high risk of failing..";
		}
		else {
			.@level = .@num + 1;
			.@card[3] = getd( ".@enchant_" + (.@num+1) + "[" + .@type + "]" );
			.@string$ = "enchant number ^990000" + .@level + "^000000.";
			mes "Enchanting ^0000ff" + .@equip_name$ + " (Socket)^000000's 4th slot as ^0000ff" + .@level + "^000000 level effect. Requires ^0000ff" + .@amount_poll + " " + getitemname(.@polluted_id) + ", " + .@amount_coag + " " + getitemname(.@coagulated_id) + ", and " + callfunc("F_InsertComma",.@cost_zeny) + " z^000000. It has some risk of failing..";
		}
		next;
		if (select( "Quit", "Effect Upgrade!" ) == 1) {
			mes "[Dark magic master]";
			mes "Ok, come back when you are ready.";
			close;
		}
	}
	if (countitem(.@coagulated_id) < .@amount_coag) {
		mes "[Dark magic master]";
		mes "Hmm, you are missing " + (.@amount_coag - countitem(.@coagulated_id)) + " " + getitemname(.@coagulated_id) + " items. Go get more, and then we can talk about more enchants.";
		close;
	}
	if (countitem(.@polluted_id) < .@amount_poll) {
		mes "[Dark magic master]";
		mes "Hmm, you are missing " + (.@amount_poll - countitem(.@polluted_id)) + " " + getitemname(.@polluted_id) + " items. Go get more, and then we can talk about more enchants.";
		close;
	}
	if (Zeny < .@cost_zeny) {
		mes "[Dark magic master]";
		mes "You must bring ^0000ff" + callfunc("F_InsertComma",.@cost_zeny) + " zeny^000000. Nothing is free you know...";
		close;
	}
	delitem .@coagulated_id, .@amount_coag;
	delitem .@polluted_id, .@amount_poll;
	Zeny -= .@cost_zeny;

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

	delequip EQI_SHOES;
	if (.@chances[.@num] < rand(1,100)) {
		specialeffect2 EF_LORD;
		mes "[Dark magic master]";
		mes "Arrggg, we failed. Better luck next time.";
		close;
	}
	specialeffect2 EF_REPAIRWEAPON;
	mes "[Hugin's Magician]";
	mes "Trying for " + .@string$;
	getitem2 .@equip_id,1,1,.@equip_refine,0,0,0,.@card[2],.@card[3];
	close;
}

// Items exchange for card
glast_01,216,292,5	script	Portrait collector#0002	4_M_OILMAN,{
	disable_items;
	if ((MaxWeight - Weight) < 1000) {
		mes "Your bag is too heavy. Reduce some weight and come back.";
		close;
	}
	if (checkweight(1201,1) == 0) {
		mes "You seem to be carrying too many items. Put some items in storage and come back again.";
		close;
	}
	.@coagulated_id = 6608;		// Coagulated_Spell
	.@polluted_id = 6755;		// Polluted_Spell
	.@white_card = 4608;		// White_Knightage_Card
	.@khalitzburg_card = 4609;	// Khaliz_Knightage_Card

	mes "[Portrait collector]";
	mes "I have been collecting portraits for an year already. Now it's time to show people my collection.";
	next;
	mes "[Portrait collector]";
	mes "Hey, do you have a lot of " + getitemname(.@polluted_id) + " or " + getitemname(.@coagulated_id) + "? If so, why don't you trade a nice portrait that I have?";
	next;
	switch( select( "Cancel", "Exchange for " + getitemname(.@white_card), "Exchange for " + getitemname(.@khalitzburg_card) ) ) {
	case 1:
		mes "[Portrait collector]";
		mes "Well, OK. Come back when you are ready.";
		close;
	case 2:
		.@reward_id = .@white_card;
		.@amount_coag = 3000;
		.@amount_polluted = 70;
		break;
	case 3:
		.@reward_id = .@khalitzburg_card;
		.@amount_coag = 5000;
		.@amount_polluted = 100;
		break;
	}
	mes "[Portrait collector]";
	mes "What would you like in exchange for the " + getitemname(.@reward_id) + "?";
	next;
	if (countitem(.@coagulated_id) < .@amount_coag)
		.@color$[0] = "^666666";
	if (countitem(.@polluted_id) < .@amount_polluted)
		.@color$[1] = "^666666";
	switch( select( "Cancel", sprintf("%s%s %s^000000", .@color$[0], callfunc("F_InsertComma",.@amount_coag), getitemname(.@coagulated_id)), sprintf("%s%s %s^000000", .@color$[1], callfunc("F_InsertComma",.@amount_polluted), getitemname(.@polluted_id)) ) ) {
	case 1:
		mes "[Portrait collector]";
		mes "Well, OK. Come back when you are ready.";
		close;
	case 2:
		.@id = .@coagulated_id;
		.@amount = .@amount_coag;
		break;
	case 3:
		.@id = .@polluted_id;
		.@amount = .@amount_polluted;
		break;
	}
	if (countitem(.@id) < .@amount) {
		mes "[Portrait collector]";
		mes "Hmm, you don't have enough Spell now. Go get more.";
		close;
	}
	mes "[Portrait collector]";
	mes "Are you sure that you won't regret it?";
	next;
	if (select( "Cancel", "Sure" ) == 1) {
		mes "[Portrait collector]";
		mes "Well, OK. Come back when you are ready.";
		close;
	}
	mes "[Portrait collector]";
	mes "Cool, let's make a deal.";
	delitem .@id, .@amount;
	getitem .@reward_id,1;
	close;
}
