//@unloadnpc Spin-2-Win
//@loadnpc npc/amatsu/features/spin2win.txt

office,118,35,0	script	Spin-2-Win	2_VENDING_MACHINE1,{
	mes "[ ^ff0000Spin-2-Win^000000 ]";
	mes " Hello ^00CC00"+strcharinfo(PC_NAME)+"^000000!";
	mes "Would you like to play Spin-2-Win? Here is the prizes that you may get.";
	next;
	mes "[ ^ff0000Spin-2-Win^000000 ]";
		mes "Random Items from the list:";
		mes " 5x "+Itemlink(Cargo_Free_Ticket);
		mes " 2x "+Itemlink(Handsei);
		mes " 3x "+Itemlink(Battle_Manual100);
		mes " 3x "+Itemlink(Bubble_Gum);
		mes " 5x "+Itemlink(Giant_Fly_Wing);
		mes " 30x "+Itemlink(Siege_White_Potion);
		mes " 30x "+Itemlink(Siege_Blue_Potion);
		mes " 5x "+Itemlink(Mega_Resist_Potion);
		mes " 10x "+Itemlink(Inc_Agi_10_Scroll);
		mes " 10x "+Itemlink(Blessing_10_Scroll);
		mes " 2x "+Itemlink(Convex_Mirror);
		mes " 1x "+Itemlink(Max_Weight_Up_Scroll);
	mes "Do you want to spin now?";
	next;
	if (select("No, thanks", "Yes, I'm sure") == 2) {
		if( countitem(Spin2Win) == 0 ){
			mes "[ ^ff0000Spin-2-Win^000000 ]";
			mes "Sorry, you don't have "+getitemname(Spin2Win)+" coin.  You can obtain coins from daily reward.";
			close();
		}
		mes "[ ^ff0000Spin-2-Win^000000 ]";
		mes "^00CC00Spinning.... Please wait....^000000";
		setarray @rewardItens[0], 
			30005, 5, 10,	// Cargo Free Ticket
			668, 2, 9,	// Warp Free Ticket
			14533, 3, 8,	// Battle Manual
			12210, 3, 7,	// Bubble Gum
			12212, 5, 3,	// Giant Fly
			11503, 30, 6,	// White SIege
			11504, 30, 5,	// BLue Siege
			12299, 5, 4,	// Mega Resist
			12216, 10, 3,	// Inc Agi
			12215, 10, 2,	// Blessings
			30028, 2, 1,	// Convex Mirror
			7776, 1, 1;	// Gym Pass
							
		// List of special items to be announced:
		setarray .@SpecialItem, 7776;

		// 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)){
						delitem 30010,1;
						if(.@SpecialItem == @rewardItens[.@i*3])
							announce "[ Spin 2 Win ]: Attention Heroes! "+strcharinfo(0)+" Just won the item '"+getitemname(@rewardItens[.@i*3])+"'!", bc_all;
						dispbottom "[ Spin 2 Win ]: Congratulations, you were awarded "+@rewardItens[(.@i*3)+1]+" " + getitemname(@rewardItens[.@i*3]);
						getitem @rewardItens[.@i*3], @rewardItens[(.@i*3)+1];
						sleep2 3000;
						cutin "", 255;
						close2;	
						end;
					}
				if(!(.@j%.@lenLista))
					.@c++;
				sleep2 @jingleBell[.@c];
				cutin "", 255;
			}
		}
		end;
	}
	mes "[ ^ff0000Spin-2-Win^000000 ]";
	mes "Okay, take your time and come back when you are ready.";
	close();	
}
