
office,119,27,6	script	Quest Shop	4_M_HUMERCHANT,{ callfunc "vqshop"; }


// Script Core
//============================================================
-	script	vquest_shop	FAKE_NPC,{
function vAdd; function vChk; function vSlot; function vA_An;
OnInit:
	
	freeloop(1);

// -----------------------------------------------------------
//  Basic shop settings.
// -----------------------------------------------------------

	set .Announce,1;	// Announce quest completion? (1: yes / 0: no)
	set .ShowSlot,1;	// Show item slots? (2: all equipment / 1: if slots > 0 / 0: never)
	set .ShowID,0;  	// Show item IDs? (1: yes / 0: no)
	set .ShowZeny,0;	// Show Zeny cost, if any? (1: yes / 0: no)
	set .MaxStack,1;	// Max number of quest items purchased at one time.

// -----------------------------------------------------------
//  Points variable -- optional quest requirement.
//	setarray .points$[0],"<variable name>","<display name>";
// -----------------------------------------------------------

	setarray .points$[0],"#CASHPOINTS","Credit Points";

// -----------------------------------------------------------
//  Shop IDs -- to add shops, copy dummy data at bottom of file.
//	setarray .Shops$[1],"<Shop 1>","<Shop 2>"{,...};
// -----------------------------------------------------------

	setarray .vShops$[1],"Special Quest","Quest Costumes","Recolored Strong Hair","Recolored Dropping Cat";

// -----------------------------------------------------------
//  Quest items -- do NOT use a reward item more than once!
//	Add(<shop ID>,<reward ID>,<reward amount>,
//	    <Zeny cost>,<point cost>,<chances>
//	    <required item ID>,<required item amount>{,...});
// -----------------------------------------------------------

/* MvP Quest */
vAdd(1,5567,1,100000,0,60,1468,1,658,1,2507,1,2246,1);			// bright fury
vAdd(1,5780,1,100000,0,60,10008,1,5053,1,750,1,7036,1);			// tendrillion hat
vAdd(1,5919,1,100000,0,60,7020,1,661,1,2234,1,751,1);			// Camellia Hairpin
vAdd(1,19574,1,100000,0,60,5007,1,7169,10);				// Costume lord of the death helm
vAdd(1,18663,1,100000,0,60,2235,1,1015,10,1009,5,2268,1);		// sunglasses baseball hat
vAdd(1,5564,1,100000,0,60,7018,1,1124,1,5019,1,1223,1);			// crown of deceit
vAdd(1,5323,1,100000,0,60,2249,1,1029,10,2334,1,1237,1);		// misstrance crown
vAdd(1,5805,1,100000,0,60,2258,1,1525,1,1236,1,1363,1);			// victorious coronet

/* 2018-04-16 Release */
vAdd(2,19827,1,1000000,0,100,7106,100,7166,100);		// Costume Amistr Cap
vAdd(2,19624,1,1000000,0,100,2278,10,992,100,980,5);	// costume blank eyes
vAdd(2,31059,1,1000000,0,100,2220,10,720,10,510,50);	// costume sailor hat

/* Initial Release - Limited
vAdd(2,19998,1,10000,0,100,658,5,967,200,954,100,975,1,2227,1);		// Costume Dragon Turtle Hat
vAdd(2,20019,1,10000,0,100,968,5,916,200,978,1,2247,1);			// Costume Artisant Beret
vAdd(2,19997,1,10000,0,100,10006,1,1020,500,7035,1,983,1,932,100);	// Costume Bomb Hat
*/
/* 25-02-2018 Release
vAdd(2,20269,1,100000,0,100,982,10,7065,100,2209,10);			// Costume white fox ear ribbon	
vAdd(2,20037,1,100000,0,100,978,10,2221,1,938,100);			// Costume owlduke silk hat
*/
/* 16-03-2018 Release 
vAdd(2,20459,1,1000000,0,100,2233,1,2213,1,511,20,508,20);		// costume valhalla idol
//vAdd(2,20382,1,1000000,0,100,7323,500,507,100);			// costume silver sniper doll
vAdd(2,20006,1,1000000,0,100,983,10,2292,1,726,20);			// Costume dark night mask
*/

// Recolored Strong Hair
vAdd(3,20248,1,0,2000,100,18740,1,983,1);	// Black Strong Hair
vAdd(3,20249,1,0,2000,100,18740,1,975,1);	// Red Strong Hair
vAdd(3,20250,1,0,2000,100,18740,1,982,1);	// White Strong Hair

vAdd(4,5231,1,0,1000,100,5231,1,983,1);	// Brown Drooping Cat
vAdd(4,5232,1,0,1000,100,5231,1,980,1);	// Pink Drooping Cat
vAdd(4,5233,1,0,1000,100,5231,1,978,1);	// Blue Drooping Cat
vAdd(4,5234,1,0,1000,100,5231,1,976,1);	// Yellow Drooping Cat

// -----------------------------------------------------------

	freeloop(0);
	set .menu$,"";
	for(set .@i,1; .@i<=getarraysize(.vShops$); set .@i,.@i+1) {
		set .menu$, .menu$+.vShops$[.@i]+":";
		npcshopdelitem "vqshop"+.@i,909;
	}
	end;

OnMenu:
	set .@size, getarraysize(@i);
	if (!.@size) set .@i, select(.menu$);
	else if (.@size == 1) set .@i, @i[0];
	else {
		for(set .@j,0; .@j<.@size; set .@j,.@j+1)
			set .@menu$, .@menu$+.vShops$[@i[.@j]]+":";
		set .@i, @i[select(.@menu$)-1];
	}
	deletearray @i[0],getarraysize(@i);
	if (.vShops$[.@i] == "") {
		message strcharinfo(PC_NAME),"An error has occurred.";
		end;
	}
	dispbottom "Select one item at a time.";
	callshop "vqshop"+.@i,1;
	npcshopattach "vqshop"+.@i;
	end;

OnBuyItem:
	disable_items();
	setarray .@q[0],@bought_nameid[0],((@bought_quantity[0] > .MaxStack)?.MaxStack:@bought_quantity[0]);
	copyarray .@q[3],getd(".q_"+.@q[0]+"[0]"),getarraysize(getd(".q_"+.@q[0]));
	set .@q[2],.@q[1]*.@q[3];
	if (!.@q[2] || .@q[2] > 30000) {
		message strcharinfo(PC_NAME),"You can't purchase that many "+getitemname(.@q[0])+".";
		end;
	}
	mes "[Quest Shop]";
	mes "Item: ^0055FF"+((.@q[2] > 1)?.@q[2]+"x ":"")+vSlot(.@q[0])+"^000000";
	if (.@q[6]) mes " > ^FF0000"+.@q[6]+"%^000000 Success Rate";
	mes "Requirements:";
	if (.@q[4]) mes " > "+vChk(Zeny,.@q[4]*.@q[1])+(.@q[4]*.@q[1])+" Zeny^000000";
	if (.@q[5]) mes " > "+vChk(callfunc("F_CheckCredit"),.@q[5]*.@q[1])+(.@q[5]*.@q[1])+" "+.points$[1]+" ("+callfunc("F_CheckCredit")+"/"+(.@q[5]*.@q[1])+")^000000";
	if (.@q[7]) for(set .@i,7; .@i<getarraysize(.@q); set .@i,.@i+2)
		mes " > "+vChk(countitem(.@q[.@i]),.@q[.@i+1]*.@q[1])+((.ShowID)?"{"+.@q[.@i]+"} ":"")+vSlot(.@q[.@i])+" ("+countitem(.@q[.@i])+"/"+(.@q[.@i+1]*.@q[1])+")^000000";
	next;
	setarray @qe[1], getiteminfo(.@q[0], ITEMINFO_LOC), getiteminfo(.@q[0], ITEMINFO_VIEWSPRITE);
	if (@qe[2] > 0 && ((@qe[1] & EQP_HEAD_LOW) || (@qe[1] & EQP_HEAD_TOP) || (@qe[1] & EQP_HEAD_MID) || (@qe[1] & EQP_COSTUME_HEAD_TOP) || (@qe[1] & EQP_COSTUME_HEAD_MID) || (@qe[1] & EQP_COSTUME_HEAD_LOW) || (@qe[1] & EQP_GARMENT) || (@qe[1] & EQP_COSTUME_GARMENT)))
		set .@preview,1;
	addtimer 1000, strnpcinfo(NPC_NAME)+"::OnEnd";
	while(1) {
		switch(select(" ~ Purchase ^0055FF"+ getitemname(.@q[0]) +"^000000", ((.@preview && !@qe[7])?" ~ Preview...": ""), " ~ ^777777Cancel^000000")) {
		case 1:
			if (@qe[0]) {
				mes "[Quest Shop]";
				mes "You're missing one or more quest requirements.";
				close;
			}
			if (!checkweight(.@q[0],.@q[2])) {
				mes "[Quest Shop]";
				mes "^FF0000You need "+(((.@q[2]*getiteminfo(.@q[0],6))+Weight-MaxWeight)/10)+" additional weight capacity to complete this trade.^000000";
				close;
			}
			if (.@q[4]) Zeny -= (.@q[4]*.@q[1]);
			if (.@q[5]) callfunc "F_UpdateCredit",-(.@q[5]*.@q[1]);
			if (.@q[7]) for(set .@i,7; .@i<getarraysize(.@q); set .@i,.@i+2)
				delitem .@q[.@i],.@q[.@i+1]*.@q[1];
			if ( rand( 100 ) < .@q[6] ) {
				getitem .@q[0],.@q[2];
				if (.Announce) chanmsg("#system",""+strcharinfo(PC_NAME)+" has created "+((.@q[2] > 1)?.@q[2]+"x "+getitemname(.@q[0]):vA_An(getitemname(.@q[0])))+"!");
			} else {
				mes "[Quest Shop]";
				mes "^FF0000Opppsss!!! You failed to craft the item.^000000";
				close;
			}				
			close;
		case 2:
			setarray @qe[3], getlook(LOOK_HEAD_BOTTOM), getlook(LOOK_HEAD_TOP), getlook(LOOK_HEAD_MID), getlook(LOOK_ROBE), 1;
			if ((@qe[1] & 1) || (@qe[1] & 4096)) changelook LOOK_HEAD_BOTTOM, @qe[2];
			else if ((@qe[1] & 256) || (@qe[1] & 1024)) changelook LOOK_HEAD_TOP, @qe[2];
			else if ((@qe[1] & 512) || (@qe[1] & 2048)) changelook LOOK_HEAD_MID, @qe[2];
			else if ((@qe[1] & 4) || (@qe[1] & 8192)) changelook LOOK_ROBE, @qe[2];
		case 3:
			close;
		}
	}

OnEnd:
	if (@qe[7]) {
		changelook LOOK_HEAD_BOTTOM, @qe[3];
		changelook LOOK_HEAD_TOP, @qe[4];
		changelook LOOK_HEAD_MID, @qe[5];
		changelook LOOK_ROBE, @qe[6];
	}
	deletearray @qe[0],8;
	end;

function vAdd {
	if (getitemname(getarg(1)) == "null") {
		debugmes "Quest reward #"+getarg(1)+" invalid (skipped).";
		return;
	}
	setarray .@j[0],getarg(2),getarg(3),getarg(4),getarg(5);
	for(set .@i,6; .@i<getargcount(); set .@i,.@i+2) {
		if (getitemname(getarg(.@i)) == "null") {
			debugmes "Quest requirement #"+getarg(.@i)+" invalid (skipped).";
			return;
		} else
			setarray .@j[.@i-2],getarg(.@i),getarg(.@i+1);
	}
	copyarray getd(".q_"+getarg(1)+"[0]"),.@j[0],getarraysize(.@j);
	npcshopadditem "vqshop"+getarg(0),getarg(1),((.ShowZeny)?getarg(3):0);
	return;
}

function vChk {
	if (getarg(0) < getarg(1)) {
		set @qe[0],1;
		return "^FF0000";
	} else
		return "^00FF00";
}

function vSlot {
	set .@s$,getitemname(getarg(0));
	switch(.ShowSlot) {
		case 1: if (!getitemslots(getarg(0))) return .@s$;
		case 2: if (getiteminfo(getarg(0),2) == 4 || getiteminfo(getarg(0),2) == 5) return .@s$+" ["+getitemslots(getarg(0))+"]";
		default: return .@s$;
	}
}

function vA_An {
	setarray .@A$[0],"a","e","i","o","u";
	set .@B$, "_"+getarg(0);
	for(set .@i,0; .@i<5; set .@i,.@i+1)
		if (compare(.@B$,"_"+.@A$[.@i])) return "an "+getarg(0);
	return "a "+getarg(0);
}




}

function	script	vqshop	{
	deletearray @i[0],getarraysize(@i);
	for(set .@i,0; .@i<getargcount(); set .@i,.@i+1)
		set @i[.@i],getarg(.@i);
	doevent "vquest_shop::OnMenu";
	end;
}

// Dummy shop data -- copy as needed.
//============================================================
-	shop	vqshop1	FAKE_NPC,909:-1
-	shop	vqshop2	FAKE_NPC,909:-1
-	shop	vqshop3	FAKE_NPC,909:-1
-	shop	vqshop4	FAKE_NPC,909:-1
-	shop	vqshop5	FAKE_NPC,909:-1