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


office,118,35,0	script	Spin-2-Win	2_VENDING_MACHINE1,{
	mes "[ Spin-2-Win ]";
	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 "[ Spin-2-Win ]";
	if (#mobile) {
		mes "Random Items from the list:";
		mes "10x ^00CC00Yggdrasil Berry^000000";
		mes " 2x ^00CC00Old Card Album^000000";
		mes " 1x ^00CC00Cool Summer Outfit^000000";
		mes " 1x ^00CC00Accessory Box^000000";
		mes " 1x ^00CC00Side Cap^000000";
		mes " 1x ^00CC00Cat Foot Hairpin^000000";
		mes " 1x ^00CC00Power of Thor^000000";
		mes " 1x ^00CC00Snake Head [1]^000000";
		mes " 1x ^00CC00Cap of Blindness [1]^000000";
		mes " 1x ^00CC00Dragonic Bone Head[1]^000000";
		mes " 1x ^00CC00Cat Ears Beret^000000";
		mes " 1x ^00CC00Robo Eye^000000";
	} else {
		mes "Random Items from the list:";
		mes "10x "+Itemlink(Yggdrasilberry);
		mes " 2x "+Itemlink(Old_Card_Album);
		mes " 1x "+Itemlink(Cool_Summer_Outfit);
		mes " 1x "+Itemlink(Accessory_Box);
		mes " 1x "+Itemlink(Side_Cap);
		mes " 1x "+Itemlink(Cat_Foot_Hairpin);
		mes " 1x "+Itemlink(Power_Of_Thor);
		mes " 1x "+Itemlink(Snake_Head);
		mes " 1x "+Itemlink(Cap_Of_Blindness);
		mes " 1x "+Itemlink(Bone_Head);
		mes " 1x "+Itemlink(Cat_Ears_Beret);
		mes " 1x "+Itemlink(Robo_Eye);
	}
	mes "[ Spin-2-Win ]";
	mes "Do you want to spin now?";
	next;
	if (select("No, thanks", "Yes, I'm sure") == 2) {
		if(countitem(30293)==0){
			mes "[ Spin-2-Win ]";
			mes "Sorry, you don't have Spin2Win coin.  You can obtain coins from daily reward or the Item Mall.";
			close();
		}
		mes "[ Spin-2-Win ]";
		mes "^00CC00Spinning.... Please wait....^000000";		
		delitem 30293,1;
		// List of roulette items: Item / quantity / chance
		setarray @rewardItens[0], 
			607, 10, 10,	// 10x Yggdrasil Seed
			616, 2, 9,	// 1x Old Card Album
			12260, 1, 8,	// 1x Cool Summer Outfit
			12106, 1, 7,	// 1x Jewelry Box
			5535, 1, 6,	// 1x Side Cap
			5446, 1, 5,	// 1x Catfoot Hairpin
			5495, 1, 4,	// 1x Power of Thor
			5388, 1, 3,	// 1x SnakeHead
			5304, 1, 2,	// 1x Cap Of Blindness
			5398, 1, 1,	// 1x BoneHead
			18600, 1, 1,	// 1x Cat Ear Berret
			5325, 1, 1;	// 1x Robo Eye
								
		// List of special items to be announced:
		setarray .@SpecialItem, 5325;

		// Here lives the tchumbirabirom ff the thing!
		setarray @jingleBell[0], 75, 90, 120, 200, 500;
		
		setarray @arrayDefault[0], 0;
		.@ii = 0;
		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)){
							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]);
							//dispbottom "[ Spin 2 Win ]: Congratulations, you were awarded 1 Spin 2 Win Point";
							getitem @rewardItens[.@i*3], @rewardItens[(.@i*3)+1];
							//#Spin2Win += 1;
							//sc_start SC_Xmas,600000,0;
							sleep2 3000;
							cutin "", 255;
							close2;	
							end;
						}
					if(!(.@j%.@lenLista))
						.@c++;
					sleep2 @jingleBell[.@c];
					cutin "", 255;
				}
			}
		close2;
		end;
	}
	mes "[ Spin-2-Win ]";
	mes "Okay, take your time and come back when you are ready.";
	close();	
}