//================= 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)  Z3RO
//=
//= 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/>.
//=========================================================================
//= Cute Pet Manager
//================= Description ===========================================
//= Exchanges Hunted Items for Tames
//================= Current Version =======================================
//= 1.0
//=========================================================================

//== 1st NPC ===============================================
-	script	CPM1	4_M_ALCHE_C,{
	.@npc$ = "[Cute Pet Manager]";

	setarray .@tame_id[0],Unripe_Apple,Orange_Juice,Rainbow_Carrot,Earthworm_The_Dude,Rotten_Fish,Sweet_Milk,Well_Dried_Bone,Singing_Flower,Dew_Laden_Moss;
	setarray .@tame_amount[0],3,3,3,3,3,3,3,3,3;
	setarray .@hunt_id[0],Jellopy,Jellopy,Clover,Feather_Of_Birds,Shell,Animals_Skin,Animals_Skin,Grasshoppers_Leg,Mushroom_Spore;
	setarray .@hunt_amount[0],500,600,500,500,500,500,600,500,500;
	setarray .@mob_id[0],1002,1113,1063,1049,1011,1167,1107,1052,1014;
	.@tame_gets = 3;

	if (cpm_one == .@tame_gets) {
		mes "[Cute Pet Manager]";
		mes "You have already exchanged";
		mes .@tame_amount + " times for a taming item.";
		mes "You can't exchange anymore.";
		next;
		mes "[Cute Pet Manager]";
		mes "Besides me, there are other";
		mes "Cute Pet Managers. If you want";
		mes "to tame other pets, I suggest";
		mes "you go and see them.";
		close;
	}

	callfunc "cute_pet_manager",.@tame_id,.@tame_amount,.@hunt_id,.@hunt_amount,.@mob_id,cpm_one,.@tame_gets,.@hunt_id2,.@hunt_amount2;
}

//== 2nd NPC ===============================================
-	script	CPM2	4_M_ALCHE_C,{
	.@npc$ = "[Cute Pet Manager]";

	setarray .@tame_id[0],Bitter_Herb,Lusty_Iron,Fatty_Chubby_Earthworm,Deadly_Noxious_Herb,Baked_Yam,Tropical_Banana,Horror_Of_Tribe,No_Recipient,Heart_Of_Her,Old_Broom,Armlet_Of_Obedience,Shining_Stone;
	setarray .@tame_amount[0],2,2,2,2,2,2,2,2,2,2,2,2;
	setarray .@hunt_id[0],Sticky_Mucus,Shell,Bill_Of_Birds,Poison_Spore,Raccoon_Leaf,Yoyo_Tail,Orcish_Voucher,Danggie,Short_Daenggie,Dokkaebi_Horn,Scales_Shell,Dragon_Canine;
	setarray .@hunt_amount[0],500,600,500,300,500,500,500,500,500,500,500,500;
	setarray .@hunt_item_count[0],1,1,1,1,1,1,1,1,1;
	setarray .@mob_id[0],1031,1042,1019,1077,1056,1057,1023,1026,1188,1110,1029;
	.@tame_gets = 2;

	if (cpm_two == .@tame_gets) {
		mes "[Cute Pet Manager]";
		mes "You have already exchanged";
		mes .@tame_amount + " times for a taming item.";
		mes "You can't exchange anymore.";
		next;
		mes "[Cute Pet Manager]";
		mes "Besides me, there are other";
		mes "Cute Pet Managers. If you want";
		mes "to tame other pets, I suggest";
		mes "you go and see them.";
		close;
	}

	callfunc "cute_pet_manager",.@tame_id,.@tame_amount,.@hunt_id,.@hunt_amount,.@mob_id,cpm_two,.@tame_gets,.@hunt_id2,.@hunt_amount2;
}

//== 3rd NPC ===============================================
-	script	CPM3	4_M_ALCHE_C,{
	.@npc$ = "[Cute Pet Manager]";

	setarray .@tame_id[0],Silver_Knife_Of_Chaste,Monster_Juice,Contracts_In_Shadow,Sway_Apron,Prohibition_Red_Candle,Book_Of_Devil;
	setarray .@tame_amount[0],1,1,1,1,1,1;
	setarray .@hunt_id[0],Long_Hair,Solid_Shell,Petite_DiablOfs_Horn,Alices_Apron,Queens_Whip,Evil_Horn;
	setarray .@hunt_amount[0],600,600,600,500,1,100;
	setarray .@hunt_id2[0],0,0,0,0,Executioners_Mitten,0;
	setarray .@hunt_amount2[0],0,0,0,0,20,0;
	setarray .@mob_id[0],1170,1035,1109,1275,1200,1101;
	.@tame_gets = 1;

	if (cpm_three == .@tame_gets) {
		mes "[Cute Pet Manager]";
		mes "You have already exchanged";
		mes .@tame_amount + " times for a taming item.";
		mes "You can't exchange anymore.";
		next;
		mes "[Cute Pet Manager]";
		mes "Besides me, there are other";
		mes "Cute Pet Managers. If you want";
		mes "to tame other pets, I suggest";
		mes "you go and see them.";
		close;
	}

	callfunc "cute_pet_manager",.@tame_id,.@tame_amount,.@hunt_id,.@hunt_amount,.@mob_id,cpm_three,.@tame_gets,.@hunt_id2,.@hunt_amount2;
}

function	script	cute_pet_manager	{
	// getarg(0) -> .@tame_id Array
	// getarg(1) -> .@tame_amount Array
	// getarg(2) -> .@hunt_id Array
	// getarg(3) -> .@hunt_amount Array
	// getarg(4) -> .@mob_id Array
	// getarg(5) -> Attempt Variable
	// getarg(6) -> .@tame_gets Variable
	// getarg(7) -> .@hunt_id2 Array
	// getarg(8) -> .@hunt_amount2 Array

	mes "[Cute Pet Manager]";
	mes "Hello~! I am a Cute Pet Manager";
	mes "who is in charge of public relations";
	mes "for the New Upgraded Cute Pet system.";
	next;
	mes "[Cute Pet Manager]";
	mes "If you have any concerns regarding";
	mes "the Cute Pet system I am here to guide you.";
	mes "Let me know which taming";
	mes "item you want,";
	mes "then I will tell you the monster";
	mes "that you can tame with the item.";
	next;
	mes "Also I will explain what materials";
	mes "you need to bring in order to";
	mes "get the taming item.";
	next;
	mes "[Cute Pet Manager]";
	mes "If you already brought materials";
	mes "to exchange for the taming item,";
	mes "I can exchange it for taming items immediately.";
	next;
	mes "[Cute Pet Manager]";
	mes "However, there is a limit";
	mes "for exchanging taming items.";
	mes "You can only get taming items";
	mes getarg(6) + " times. So please make sure";
	mes "how many times you have exchanged.";
	next;
	mes "[Cute Pet Manager]";
	mes "So, which taming item do you want?";
	mes "Please choose one from the list.";
	next;
	// Create Menu System
	for (.@a = 0; .@a < getarraysize(getarg(0)); ++.@a) {
		.@menu$ += (.@menu$ == "" ? "" : ":") + getitemname(getelementofarray(getarg(0), .@a));
	}
	// Query Player Choice
	.@choice = select(.@menu$) - 1;

	// Store Variables (Less Lookup)
	.@tame_id = getelementofarray(getarg(0), .@choice);
	.@tame_amount = getelementofarray(getarg(1), .@choice);
	.@hunt_id = getelementofarray(getarg(2), .@choice);
	.@hunt_amount = getelementofarray(getarg(3), .@choice);
	.@mob_id = getelementofarray(getarg(4), .@choice);
	.@hunt_id2 = getelementofarray(getarg(7), .@choice);
	.@hunt_amount2 = getelementofarray(getarg(8), .@choice);
	dispbottom "Tame ID: " + .@tame_id;
	dispbottom "Tame Amount: " + .@tame_amount;
	dispbottom "Hunt ID: " + .@hunt_id;
	dispbottom "Hunt Name: " + getitemname(.@hunt_id);
	dispbottom "Hunt Amount: " + .@hunt_amount;
	dispbottom "Mob ID: " + .@mob_id;
	dispbottom "Hunt ID2: " + .@hunt_id2;
	dispbottom "Hunt Amount2: " + .@hunt_amount2;
	if (.@hunt_id2) { .@hunt2_count = countitem(.@hunt_id2); }
	if (countitem(.@hunt_id) >= .@hunt_amount && countitem(Dolly_Capsule) > 0 && .@hunt2_count >= .@hunt_amount2) {
		mes "[Cute Pet Manager]";
		mes "Ah, you have gathered all items";
		mes "with your friends. You can now";
		mes "exchange for an " + getitemname(.@tame_id) + ".";
		mes "Do you want to exchange with me?";
		next;
		if (select("Exchange", "Don't Exchange") == 2) {
			mes "[Cute Pet Manager]";
			mes "You don't? You will come back again.";
			close;
		}
		delitem .@hunt_id, .@hunt_amount;
		delitem 6083, 1;
		set getarg(5), getarg(5) + 1;
		getitem .@tame_id, .@tame_amount;
		mes "[Cute Pet Manager]";
		mes "Wise choice.";
		mes "I hope you and your pet get along.";
		close;
	} else {
		mes "[Cute Pet Manager]";
		mes "You have chosen " + getitemname(.@tame_id) + ".";
		mes "You can use it for taming";
		mes "^FF0000" + strmobinfo(1,.@mob_id) + "^000000 monsters.";
		next;
		mes "[Cute Pet Manager]";
		mes "Bring ^FF0000" + .@hunt_amount + " " + getitemname(.@hunt_id) + "^000000s " + (.@hunt_id2 ? ", ^FF0000" + .@hunt_amount2 + " " + getitemname(.@hunt_id2) : "") + " ^000000 and ^FF00001 Dolly Capsule^000000";
		mes "then you can exchange them";
		mes "for an " + getitemname(.@tame_id) + ".";
		close;
	}
}

//== NPC Duplicates ========================================
prontera,67,212,5	duplicate(CPM1)	Cute Pet Manager#1	4_M_ALCHE_C
prontera,242,92,3	duplicate(CPM2)	Cute Pet Manager#2	4_M_ALCHE_C
prontera,179,92,3	duplicate(CPM3)	Cute Pet Manager#3	4_M_ALCHE_C

geffen,180,125,5	duplicate(CPM1)	Cute Pet Manager#4	4_M_ALCHE_C
geffen,152,66,3	duplicate(CPM2)	Cute Pet Manager#5	4_M_ALCHE_C
geffen,197,95,3	duplicate(CPM3)	Cute Pet Manager#6	4_M_ALCHE_C

morocc,115,83,5	duplicate(CPM1)	Cute Pet Manager#7	4_M_ALCHE_C
morocc,218,130,3	duplicate(CPM2)	Cute Pet Manager#8	4_M_ALCHE_C
morocc,236,225,3	duplicate(CPM3)	Cute Pet Manager#9	4_M_ALCHE_C

payon,109,278,5	duplicate(CPM1)	Cute Pet Manager#10	4_M_ALCHE_C
payon,157,124,3	duplicate(CPM2)	Cute Pet Manager#11	4_M_ALCHE_C
payon,85,237,3	duplicate(CPM3)	Cute Pet Manager#12	4_M_ALCHE_C
