//@unloadnpc Card Recycler#card
//@loadnpc npc/valhalla/cardrecycler.txt


-	shop	card_merge_shop	-1,909:100

morocc,149,112,4	script	Card Recycler#card	4_DR_TORTEL,{
	if (r_spinning) {
		mes "[ ^ff0000King Poring^000000 ]";
		mes "Please wait. I'm still shuffling cards.";
		close;
	}
	if (recycler) {
		mes "[ ^ff0000King Poring^000000 ]";
		mes "Oh I think I failed to send your new card.  Let's do it again.";
		next;
		callsub OnRetry;
		end;
	}
	mes "[ ^ff0000King Poring^000000 ]";
	mes "Dear adventurer, if you have needless cards, don't throw them away. Give them to me and choose Card Reproduction, and I will return you a new card randomly.";
	next;
do{
	.@option = select( "Card Reproduction","Information's" );
	if( .@option == 1 ){
		if( Zeny < .zeny_cost && .zeny_cost ){
			mes "[ ^ff0000King Poring^000000 ]";
			mes "You need ^FF0000"+.zeny_cost+" zeny^000000 per merge.";
			close;
		}
		if( npcshopattach( .shop_npc_name$ ) ){
			deletearray @sold_nameid;
			mes "[ ^ff0000King Poring^000000 ]";;
			mes "Put ^FF0000 "+.card_count+" x Different Card^000000 into the window.";
			callshop .shop_npc_name$,2;
			end;
		}
	
	}
	else{
		mes "[ ^ff0000King Poring^000000 ]";
		mes "You need to give ";
		if ( .zeny_cost) {
			mes "  ^FF0000"+.card_count+" Monster Card + "+.zeny_cost+" Zeny^000000";
		} else {
			mes "  ^FF0000"+.card_count+" Monster Card^000000";
		}
		mes "to get a random card each time.";
		next;
	}

}while( .@option == 2 );
close;

OnSellItem:
	.@sold_size = getarraysize( @sold_nameid );
	if( .@sold_size == .card_count ){
		mes "^0055FF[Card Checking]^000000";
		for( .@i = 0; .@i < .@sold_size; .@i++ ){
			.@item_type[.@i] = getiteminfo( @sold_nameid[.@i],2 );
			.@not_valid = ( .@item_type[.@i] != IT_CARD || @sold_nameid[.@i] < .card_id_range[0] || @sold_nameid[.@i] > .card_id_range[1] );
			mes " ~ "+getitemname( @sold_nameid[.@i] )+"^000000 is "+( ( .@not_valid )?"^FF0000NOT":"a" )+" Card^000000.";
			if( .@not_valid ) .@failed++;
		}
		if( !.@failed ){
			mes "[ ^ff0000King Poring^000000 ]";
			mes " ";
			mes "Confirm to exchange these "+.card_count+" Cards into a random Card ??";
			next;
			if( select( "Yes","No" ) == 1 ){
				if (.zeny_cost) Zeny -= .zeny_cost;
				for( .@i = 0; .@i < .@sold_size; .@i++ )
					delitem @sold_nameid[.@i],1;
					recycler = 1;
					r_spinning = 1;
				close2;
				soundeffect "̽.wav", 0;
				for( .@j = 0; .@j < 13; .@j++ ){
					for( .@i = 0; .@i < 5; .@i++ ){
						cutin "recycler"+.@i,4;
						sleep2 ( .@i * 100 );
					}
				}
				do{

					.@new_card = .cardlist[rand(getarraysize(.cardlist))];
					/*
					.@rate = rand(1,10000);
					if(.@rate <= 100){.@new_card = .card_id_epic[rand(getarraysize(.card_id_special))];}
					else if(.@rate > 100 && .@rate <= 600){.@new_card = .card_id_rare[rand(getarraysize(.card_id_epic))];}
					else if(.@rate > 600 && .@rate <= 2100){.@new_card = .card_id_rare[rand(getarraysize(.card_id_rare))];}
					else if(.@rate > 2100 && .@rate <= 10000){.@new_card = .card_id_common[rand(getarraysize(.card_id_common))];}
					*/
				}while( compare( .forbidden_card$,"|"+.@new_card+"|" ) );
					specialeffect(EF_PRIMECHARGE4, AREA, playerattached());
					cutin callfunc("card_illust",.@new_card),2;
					getitem .@new_card,1;
					recycler = 0;
					r_spinning = 0;
					sleep2(5000);
					cutin("", 255);

				/*
				if(.@rate <= 2000){
					announce "Citizens of Valhalla,Lady Luck shines upon ["+strcharinfo(PC_NAME)+"]!! [Card Recycler] has awarded the player with ["+getitemname(.@new_card)+"]",0;
				}
				*/
			}
		}
		
	}
	else{
		mes "[ ^ff0000King Poring^000000 ]";
		mes "Make sure you input ^FF0000 "+.card_count+" Different Card^000000.";
	}
	cutin "",255;
	close;

OnRetry:
	close2;
	r_spinning = 1;
	soundeffect "̽.wav", 0;
	for( .@j = 0; .@j < 13; .@j++ ){
		for( .@i = 0; .@i < 5; .@i++ ){
			cutin "recycler"+.@i,4;
			sleep2 ( .@i * 100 );
		}
	}
	do{
		.@new_card = .cardlist[rand(getarraysize(.cardlist))];
		dispbottom .@new_card;
	}while ( compare( .forbidden_card$,"|"+.@new_card+"|" ) );
		specialeffect(EF_PRIMECHARGE4, AREA, playerattached());
		cutin callfunc("card_illust",.@new_card),2;
		getitem .@new_card,1;
		recycler = 0;
		r_spinning = 0;
		sleep2(5000);
		cutin("", 255);
		return;	


OnInit:
	// how many card requried to change to 1 New card
	.card_count = 3;

	// zeny required for this process.
	.zeny_cost = 0;

	// list of card that cant be used to exchange/get.
	.forbidden_card$ = "|4111|4142|4047|4054|4065|4083|4099|4121|4123|4128|4131|4132|4134|4135|4137|4138|";

	// current card id range.
	setarray .card_id_range,4001,4453;

	setarray .cardlist[0],
	
4001,4002,4003,4004,4005,4006,4007,4008,4009,4010,
4011,4012,4013,4014,4015,4016,4017,4019,4020,4021,
4022,4023,4024,4025,4026,4027,4028,4029,4030,4031,
4032,4033,4034,4035,4036,4037,4038,4039,4041,4042,
4043,4044,4045,4046,4048,4049,4050,4051,4052,4053,
4055,4056,4057,4058,4060,4061,4062,4063,4064,
4066,4067,4068,4069,4070,4071,4072,4073,4074,4075,
4076,4077,4078,4079,4080,4081,4082,4083,4084,4085,
4086,4087,4088,4089,4090,4091,4092,4093,4094,4095,
4096,4097,4098,4099,4100,4101,4102,4103,4104,4105,
4106,4107,4108,4109,4110,4111,4112,4113,4114,4115,
4116,4117,4118,4119,4120,4122,4125,4127,4129,4133,
4136,4141,4149,4150,4151,4152,4153,4154,4156,4157,
4158,4159,4160,4161,4162,4164,4165,4166,4167,4170,
4172,4173,4175,4176,4177,4178,4180,4181,4182,4184,
4185,4186,4187,4188,4189,4190,4191,4192,4193,4194,
4195,4196,4199,4200,4201,4202,4204,4205,4206,4208,
4209,4210,4212,4213,4214,4215,4216,4217,4218,4219,
4220,4221,4222,4223,4224,4225,4226,4227,4228,4229,
4230,4231,4232,4233,4234,4235,4239,4240,
4242,4243,4244,4245,4246,4247,4248,4249,4251,4252,
4253,4255,4256,4257,4258,4259,4260,4261,4262,4264,
4265,4267,4268,4269,4270,4271,4272,4273,4274,4275,
4277,4278,4279,4280,4281,4282,4283,4284,4285,
4287,4288,4289,4292,4293,4294,4295,4296,4297,
4298,4299,4301,4304,4307,4308,4309,4310,4311,
4312,4313,4314,4315,4316,4319,4321,4322,4323,4325,
4326,4327,4328,4329,4331,4409,4410,4411,4412,4413,
4414,4415,4416,4417,4418,4420,4421,4422,4424,
4431,4432,4433,4434,4435,4436,4437,4438,4439;


	.shop_npc_name$ = "card_merge_shop";
	end;
}


