//@unloadnpc Gatcha I#s
//@loadnpc npc/valhalla/saintgear.txt

office,136,24,0	script	Gatcha I	2_VENDING_MACHINE1,{
	if( (gvspin_g1 || gvspin_g2 ) && !spinning1 ){
		mes "[ ^ff0000Gotcha I^000000 ]";
		mes "* * * ^ff0000B L I N K I N G^000000 * * *";
		mes "It looks like the coin slot is jammed.";
		mes "What do you like to do?";
		next;
		if(select("Kick the machine.") == 1){
			specialeffect(EF_COIN, AREA, "Gatcha I");
			sleep2(500);
			specialeffect(EF_COIN, AREA, "Gatcha I");
			sleep2(500);
			specialeffect(EF_COIN, AREA, "Gatcha I");
			mes "[ ^ff0000Gotcha I^000000 ]";
			mes "* * * ^ff0000B L I N K I N G^000000 * * *";
			mes "Refunding credits. . . . please wait...";
			if(gvspin_g1){
				getitembound 30019,gvspin_g1*20,1;
				dispbottom "You have been refunded "+gvspin_g1*20+" "+getitemname(30019);
				gvspin_g1 = 0;
				close;
			}
			if(gvspin_g2){
				getitembound 30248,gvspin_g2*20,1;
				dispbottom "You have been refunded "+gvspin_g2*20+" "+getitemname(30248);
				gvspin_g2 = 0;
				close;
			}
			close;
		}
		close;
	}	
	if(spinning1 == 1 || spinning2 == 1){
		mes "[ ^ff0000Gotcha I^000000 ]";
		mes "Please wait a moment. Spinning session is on going.";
		close;
	}
	mes "[ ^ff0000Gotcha I^000000 ]";
	mes " Hello ^00CC00"+strcharinfo(PC_NAME)+"^000000!";
	mes "Would you like to try the vending machine? Here is the prizes that you may get.";
	next;
	mes "[ ^ff0000Gotcha I^000000 ]";
		mes "Random Items from the list:";
		mes " 5% "+Itemlink(Saint_Ring);
		mes " 5% "+Itemlink(Saint_Necklace);
		mes " 6% "+Itemlink(Saint_Armor);
		mes " 7% "+Itemlink(Saint_Shield);
		mes " 7% "+Itemlink(Saint_Two_Handed_Axe);
		mes " 7% "+Itemlink(Saint_Knuckle);
		mes " 7% "+Itemlink(Saint_Sabre);
		mes " 7% "+Itemlink(Saint_Sphere);
		mes " 7% "+Itemlink(Saint_Staff);
		mes " 7% "+Itemlink(Saint_Dagger);
		mes " 7% "+Itemlink(Saint_Katar);
		mes " 7% "+Itemlink(Saint_Bow);
		mes " 7% "+Itemlink(Saint_Mace);
		mes " 7% "+Itemlink(Saint_Boots);
		mes " 7% "+Itemlink(Saint_Manteau);
	mes "Do you want to try?";
	next;
	switch(select(
	  (countitem(30248))?"Use ^0055FF20 "+getitemname(30248)+"^000000":"Use ^0055FF20 "+getitemname(30019)+"^000000:"+
	  "Refund for ^0055FF5 Green Voucher^000000:"+ 
	  "^777777Never mind.^000000"
	)) {
	case 1: 
		close2;
		if(countitem(30248))
			callfunc "F_Gatcha1",2,20;
		else
			callfunc "F_Gatcha1",1,20;
		end;

	case 2:
		callshop "saintshop1",2;
		npcshopattach "saintshop1";
		end;

	default: 
		mes "[ ^ff0000Gotcha I^000000 ]";
		mes "Okay, take your time and come back when you are ready.";
		close();
	}
	end;

OnSellItem:
	if (getarraysize(@sold_nameid) > 1) {
		dispbottom "Please sell 1 item at a time only.";
		deletearray @sold_quantity, getarraysize(@sold_quantity);
		deletearray @sold_nameid, getarraysize(@sold_nameid);
		end;
	}
	.@ok = 0;
	setarray .@saints[0], 2669, 2743, 15031, 2151, 2560, 2456, 16005, 1748, 1748, 1289, 13051, 1658, 1434, 13423, 1831, 1391;
	for (.@i = 0; .@i < getarraysize(.@saints); ++.@i) {
		if(@sold_nameid == .@saints[.@i]) {
			.@ok = 1;
		}
	}
	if (.@ok) {
		getitembound Green_Voucher,5,1;
		delitem @sold_nameid,@sold_quantity;
	} else {
		dispbottom "You can only sell Saint Items here.";
	}
	deletearray @sold_quantity, getarraysize(@sold_quantity);
	deletearray @sold_nameid, getarraysize(@sold_nameid);
	end;
}

function	script	F_Gatcha1	{
	spinning1 = 0;
	if (getarg(0) == 1){
		if( countitem(30019) < getarg(1) ){
			mes "[ ^ff0000Gotcha I^000000 ]";
			mes "Sorry, you don't have enough ^ff0000"+getitemname(30019)+"^000000.  You can obtain voucher from Event Reward or from killing a BOSS MONSTER.";
			close();
		} 
	}
	if (getarg(0) == 2){
		if( countitem(30248) < getarg(1) ){
			mes "[ ^ff0000Gotcha I^000000 ]";
			mes "Sorry, you don't have enough ^ff0000"+getitemname(30248)+"^000000.";
			close();
		} 
	}
	if(getarg(0) == 1){
		delitem 30019,getarg(1);
		gvspin_g1 += 1;
		spinning1 = 1;
		dispbottom "You used "+getarg(1)+" "+getitemname(30019)+" for Gotcha I spin.";
	}
	if(getarg(0) == 2){
		delitem 30248,getarg(1);
		gvspin_g2 += 1;
		spinning1 = 1;
		dispbottom "You used "+getarg(1)+" "+getitemname(30248)+" for Gotcha I spin.";
	}	
	setarray @rewardItens[0],
		2669, 1, 6,	// Warp Free Ticket
		2743, 1, 6,	// Battle Manual
		15031, 1, 6,	// armor
		2151, 1, 7,	// shield
		2560, 1, 7,	// manteau
		2456, 1, 7,	// shoes
		16005, 1, 7,	// mace
		1748, 1, 7,	// bow
		1289, 1, 7,	// katar
		13051, 1, 7,	// dagger
		1658, 1, 7,	// Staff
		1434, 1, 7,	// spear
		13423, 1, 7,	// sword
		1831, 1, 7,	// fist
		1391, 1, 7;	// axe
						
	// List of special items to be announced:
	setarray .@SpecialItem, 2669,2743;

	// Here lives the tchumbirabirom ff the thing!
	setarray @jingleBell[0], 75, 90, 120, 200, 500;

	setarray @arrayDefault[0], 0;
	.@ii = 0;
	// List of roulette items: Item / quantity / chance
	for(.@i = 0; .@i < getarraysize(@rewardItens); .@i = .@i+3){ 
		.@ii++;
		.@arrayDefault[.@ii] = .@arrayDefault[.@ii-1] + @rewardItens[.@i+2];
	}
	.@sorte = rand(0,.@arrayDefault[getarraysize(.@arrayDefault)-1]);	
	.@lenLista = getarraysize(@rewardItens)/3;


	for(.@i = 0; .@i < getarraysize(.@arrayDefault); .@i++)
		if(.@sorte > .@arrayDefault[.@i] && .@sorte <= .@arrayDefault[.@i+1]){
			.@c = 0;
			soundeffect "̽.wav", 0;
			for(.@j = 0; .@j < (getarraysize(@jingleBell)*.@lenLista); .@j++){
				cutin "jingle_"+.@j%.@lenLista,4;
				if(.@c >= getarraysize(@jingleBell)-1)
					if((.@j%.@lenLista) == (.@i)){
						announce "Attention Heroes! [ "+strcharinfo(0)+" ] Just won the item [ "+getitemname(@rewardItens[.@i*3])+" ] from Gotcha I Machine.", bc_all;
						if(getarg(0) == 1){
							gvspin_g1 -= 1;
							spinning1 = 0;
							getitem @rewardItens[.@i*3], @rewardItens[(.@i*3)+1];
						} else {
							gvspin_g2 -= 1;
							spinning1 = 0;
							getitembound @rewardItens[.@i*3], @rewardItens[(.@i*3)+1],1;
						}
				
						sleep2 3000;
						cutin "", 255;
						//close2;	
						end;
					}
				if(!(.@j%.@lenLista))
					.@c++;
				sleep2 @jingleBell[.@c];
				cutin "", 255;
			}
		}
	end;

}

-	shop	saintshop1	FAKE_NPC,501:50
