
office,118,38,6	script	Quest Shop#1	4_M_HUMERCHANT,{ callfunc "qshop"; }


// Script Core
//============================================================
-	script	quest_shop	FAKE_NPC,{
function Add; function Chk; function Slot; function A_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 .Shops$[1],"Quest Headgear","Special Exchange Headgears","Bunny Band Exchange","Mage Hat","Beanie","Deviruchi Hat","Ribbon","Strong Hair","Usables";

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

	//Add(1,19972,1,1000000,0,2228,1,980,10,7347,50);	// Costume Protect Of Crown
	//Add(1,20433,1,1000000,0,2226,1,7038,100,975,10);	// Costume Louise Red Hat
	//Add(1,19624,1,1000000,0,2278,10,992,100,980,5);	// costume blank eyes
	//Add(1,31059,1,1000000,0,2220,10,720,10,510,50);	// costume sailor hat
	//Add(1,20035,1,100000,0,749,3,510,100);		// costume miracle blue rose
	//Add(1,20382,1,100000,0,7323,500,507,100);		// costume silver sniper doll


	//Add(1,20269,1,100000,0,982,10,1022,100,7038,100);	// Costume white fox ear ribbon	
	//Add(1,20037,1,100000,0,978,10,2221,1,938,100);	// Costume owlduke silk hat
	// vip only Add(1,20006,1,50000,0,983,10,2228,1);	// Costume dark night mask
	//Add(1,20397,1,500000,0,1062,500,7447,500,2228,1);	// Costume Jack	
	//Add(1,19571,1,500000,0,509,100,2610,10,2228,1);	// Costume White Musang Hat

	//Add(1,20267,1,500000,0,5016,1,982,10,7065,100);	// costume penguin cap
	//Add(1,20455,1,500000,0,5016,1,983,10,7152,100);	// costume republic hat
	//Add(1,20295,1,100000,0,741,10,619,10,975,10);		// costume poring sunglasses
	//Add(1,19510,1,100000,0,7317,100,5037,10,983,10);	// costume screw stuck in head

	//Add(1,20406,1,500000,0,1957,1,2608,10,983,10,7315,100);	// Costume Chain of Commandments
	//Add(1,31160,1,500000,0,2229,1,916,300,982,10,7315,100);	// costume rune helm
	//Add(1,20076,1,500000,0,5192,2,715,300,976,10,7315,100);	// Costume Idun Feather Ears

	//Add(1,30285,1,500000,0,5118,1,712,300,975,10,966,100);		// Costume Very Cute Doll
	//Add(1,30286,1,500000,0,10003,1,7013,300,976,10,1023,100);	// Little_Aquarium_Costume
	//Add(1,30287,1,500000,0,5191,1,1020,300,983,10,7161,100);	// Monochrome_Ribbon_Hat_Costume
	//Add(1,30289,1,500000,0,2504,1,7065,300,976,10,7215,100);	// Nekomimi_Cape_Costume

	/*
	Add(1,30290,1,500000,0,5192,2,715,300,976,10,7315,100);	// Laser_of_Eagle_Costume
	Add(1,30291,1,500000,0,5192,2,715,300,976,10,7315,100);	// Rabbit_Ear_Egg_Shell_Costume
	Add(1,30292,1,500000,0,5192,2,715,300,976,10,7315,100);	// Green_Egg_Shell_Costume
	*/

	Add(1,19509,1,250000,0,2243,1,7168,200,975,10,518,30);		// costume butterfly wing ears
	Add(1,19687,1,250000,0,2243,1,995,10,975,20,608,15);		// costume lush rose


	Add(2,30253,1,100000,3000,5014,1);			// CRO Mermaid Headphone
	Add(2,18664,1,0,3000,5104,3,983,10);			// Blind glasses
	Add(2,30174,1,0,3000,5002,1,982,1);			// CRO Galaxy Circlet	
	Add(2,5254,1,0,3000,2229,1,1039,500);			// Deviling Hat [1]
	Add(2,5389,1,0,3000,5074,1,5043,1);			// Angel Spirit
	Add(2,5569,1,0,3000,2274,1,982,1);			// CRO Gemini Diadem
	Add(2,5546,1,0,3000,2258,1,975,1);			// CRO Aries Crown
	Add(2,5653,1,0,3000,2255,1,983,1);			// CRO Darkness Helm	
	Add(2,5300,1,0,3000,5007,1,999,10);			// CRO Bullock Helm
	Add(2,18597,1,0,3000,2246,1,1019,10);			// CRO Mercury riser
	Add(2,5135,1,0,3000,2296,1,975,1);			// CRO Cyclops
	Add(2,5656,1,0,3000,2225,1,1020,50);			// CRO Scooter Helm
	Add(2,5564,1,0,3000,2235,1,976,1); 			// CRO Crown of Deceit
	Add(2,5467,1,0,3000,2229,1,1036,25); 			// CRO helm of dragon
	Add(2,30020,1,0,3000,978,1,2280,1);			// CRO Wanderer's Sakkat


	Add(3,30025,1,0,1000,2214,1,975,1);			// Red Ribbon
	Add(3,30026,1,0,1000,2214,1,980,1);			// Orange Ribbon
	Add(3,30027,1,0,1000,2214,1,981,1);			// Violet Ribbon
	Add(3,30028,1,0,1000,2214,1,978,1);			// Blue Ribbon
	Add(3,30029,1,0,1000,2214,1,982,1);			// Grey Ribbon

	Add(4,5238,1,0,1000,2252,1,975,1);			// Red_Wizardry_Hat
	Add(4,5239,1,0,1000,2252,1,982,1);			// Gray_Wizardry_Hat
	Add(4,5240,1,0,1000,2252,1,980,1);			// Brown_Wizardry_Hat
	Add(4,5241,1,0,1000,2252,1,978,1);			// Blue Mage Hat
	Add(4,5242,1,0,1000,2252,1,976,1);			// Yellow Mage Hat

	Add(5,5235,1,0,1000,5076,1,980,1);			// Brown Beanie
	Add(5,5236,1,0,1000,5076,1,978,1);			// Blue Beanie
	Add(5,5237,1,0,1000,5076,1,981,1);			// Pink Beanie

	Add(6,5227,1,0,1000,5038,1,975,1);			// Red Deviruchi Hat
	Add(6,5228,1,0,1000,5038,1,982,1);			// Gray Deviruchi Hat
	Add(6,5229,1,0,1000,5038,1,980,1);			// Brown Deviruchi Hat

	Add(7,5191,1,0,1000,2208,1,983,1);			// Black Ribbon
	Add(7,5192,1,0,1000,2208,1,976,1);			// Yellow Ribbon
	Add(7,5193,1,0,1000,2208,1,979,1);			// Green Ribbon
	Add(7,5194,1,0,1000,2208,1,981,1);			// Pink Ribbon
	Add(7,5195,1,0,1000,2208,1,975,1);			// Red Ribbon
	Add(7,5196,1,0,1000,2208,1,980,1);			// Orange Ribbon
	Add(7,5197,1,0,1000,2208,1,982,1);			// White Ribbon

	Add(8,20248,1,0,1000,18740,1,983,1);			// Black Strong Hair
	Add(8,20249,1,0,1000,18740,1,975,1);			// Red Strong Hair
	Add(8,20250,1,0,1000,18740,1,982,1);			// White Strong Hair

	Add(9,12103,1,10000,0,604,300);				// Bloody Branch
// -----------------------------------------------------------

	freeloop(0);
	set .menu$,"";
	for(set .@i,1; .@i<=getarraysize(.Shops$); set .@i,.@i+1) {
		set .menu$, .menu$+.Shops$[.@i]+":";
		npcshopdelitem "qshop"+.@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$+.Shops$[@i[.@j]]+":";
		set .@i, @i[select(.@menu$)-1];
	}
	deletearray @i[0],getarraysize(@i);
	if (.Shops$[.@i] == "") {
		message strcharinfo(PC_NAME),"An error has occurred.";
		end;
	}
	dispbottom "Select one item at a time.";
	callshop "qshop"+.@i,1;
	npcshopattach "qshop"+.@i;
	end;

OnBuyItem:
	disable_items();
	// .@q[] : RewardID, BoughtAmt, RewardAmt, BaseAmt, ReqZeny, ReqPts, { ReqItem, ReqAmt, ... }
	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 ":"")+Slot(.@q[0])+"^000000";
	mes "Requirements:";
	if (.@q[4]) mes " > "+Chk(Zeny,.@q[4]*.@q[1])+(.@q[4]*.@q[1])+" Zeny^000000";
	//if (.@q[5]) mes " > "+Chk(getd(.points$[0]),.@q[5]*.@q[1])+(.@q[5]*.@q[1])+" "+.points$[1]+" ("+getd(.points$[0])+"/"+(.@q[5]*.@q[1])+")^000000";
	if (.@q[5]) mes " > "+Chk(callfunc("F_CheckCredit"),.@q[5]*.@q[1])+(.@q[5]*.@q[1])+" "+.points$[1]+" ("+callfunc("F_CheckCredit")+"/"+(.@q[5]*.@q[1])+")^000000";
	if (.@q[6]) for(set .@i,6; .@i<getarraysize(.@q); set .@i,.@i+2)
		mes " > "+Chk(countitem(.@q[.@i]),.@q[.@i+1]*.@q[1])+((.ShowID)?"{"+.@q[.@i]+"} ":"")+Slot(.@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[5]) setd .points$[0], getd(.points$[0])-(.@q[5]*.@q[1]);
			if (.@q[6]) for(set .@i,6; .@i<getarraysize(.@q); set .@i,.@i+2)
				delitem .@q[.@i],.@q[.@i+1]*.@q[1];
			getitem .@q[0],.@q[2];
			if (.Announce) chanmsg("#system",""+strcharinfo(PC_NAME)+" has created "+((.@q[2] > 1)?.@q[2]+"x "+getitemname(.@q[0]):A_An(getitemname(.@q[0])))+"!");
			//specialeffect2 EF_FLOWERLEAF;
			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 Add {
	if (getitemname(getarg(1)) == "null") {
		debugmes "Quest reward #"+getarg(1)+" invalid (skipped).";
		return;
	}
	setarray .@j[0],getarg(2),getarg(3),getarg(4);
	for(set .@i,5; .@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 "qshop"+getarg(0),getarg(1),((.ShowZeny)?getarg(3):0);
	return;
}

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

function Slot {
	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 A_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	qshop	{
	deletearray @i[0],getarraysize(@i);
	for(set .@i,0; .@i<getargcount(); set .@i,.@i+1)
		set @i[.@i],getarg(.@i);
	doevent "quest_shop::OnMenu";
	end;
}


// Dummy shop data -- copy as needed.
//============================================================
-	shop	qshop1	FAKE_NPC,909:-1
-	shop	qshop2	FAKE_NPC,909:-1
-	shop	qshop3	FAKE_NPC,909:-1
-	shop	qshop4	FAKE_NPC,909:-1
-	shop	qshop5	FAKE_NPC,909:-1
-	shop	qshop6	FAKE_NPC,909:-1
-	shop	qshop7	FAKE_NPC,909:-1
-	shop	qshop8	FAKE_NPC,909:-1
-	shop	qshop9	FAKE_NPC,909:-1

