//===== rAthena Script =======================================
//= Cute Pet Manager
//===== By: ==================================================
//= Z3R0
//===== Current Version: =====================================
//= 1.0
//===== Compatible With: =====================================
//= rAthena Project
//===== Description: =========================================
//= [Official Conversion]
//= Exchanges Hunted Items for Tames
//===== Additional Comments: =================================
//= 1.0 First / Optimized Version
//============================================================

// 1st NPC
-	script	CPM1	750,{
	
	set .@npc$, "[Cute Pet Manager]";
	
	setarray .@tame_id[0],619,620,622,623,624,627,628,629,630;
	setarray .@tame_amount[0],3,3,3,3,3,3,3,3,3;
	setarray .@hunt_id[0],909,909,705,916,935,919,919,940,921;
	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;
	set .@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	750,{
	
	set .@npc$, "[Cute Pet Manager]";
	
	setarray .@tame_id[0],621,625,632,631,633,634,635,636,659,637,639,640;
	setarray .@tame_amount[0],2,2,2,2,2,2,2,2,2,2,2,2;
	setarray .@hunt_id[0],938,935,925,7033,945,942,931,901,1094,1021,936,1035;
	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;
	set .@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	750,{
	
	set .@npc$, "[Cute Pet Manager]";
	
	setarray .@tame_id[0],638,626,641,661,660,642;
	setarray .@tame_amount[0],1,1,1,1,1,1;
	setarray .@hunt_id[0],1020,943,1038,7047,1970,923;
	setarray .@hunt_amount[0],600,600,600,500,1,100;
	setarray .@hunt_id2[0],0,0,0,0,7017,0;
	setarray .@hunt_amount2[0],0,0,0,0,20,0;
	setarray .@mob_id[0],1170,1035,1109,1275,1200,1101;
	set .@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 (set .@a, 0; .@a < getarraysize(getarg(0)); set .@a, .@a + 1) { 
		set .@menu$, .@menu$ + (.@menu$ == "" ? "" : ":") + getitemname(getelementofarray(getarg(0), .@a));
	}
	
	// Query Player Choice
	set .@choice, select(.@menu$) - 1;

	// Store Variables (Less Lookup)
	set .@tame_id, getelementofarray(getarg(0), .@choice);
	set .@tame_amount, getelementofarray(getarg(1), .@choice);
	set .@hunt_id, getelementofarray(getarg(2), .@choice);
	set .@hunt_amount, getelementofarray(getarg(3), .@choice);
	set .@mob_id, getelementofarray(getarg(4), .@choice);
	set .@hunt_id2, getelementofarray(getarg(7), .@choice);
	set .@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) { set .@hunt2_count, countitem(.@hunt_id2); }
	if (countitem(.@hunt_id) >= .@hunt_amount && countitem(6083) > 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	750
prontera,242,92,3	duplicate(CPM2)	Cute Pet Manager#2	750
prontera,179,92,3	duplicate(CPM3)	Cute Pet Manager#3	750

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

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

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