//@unloadnpc Card Recycler#card
//@loadnpc npc/amatsu/event/cardrecycle.txt


-	shop	card_merge_shop	-1,909:100

prontera,144,177,0	script	Card Recycler#card	4_M_ZONDAOYAJI,{

do{
	.@option = select( "Merge your [ "+.card_count+" ] cards","Information's" );
	if( .@option == 1 ){
		if( Zeny < .zeny_cost ){
			mes "[ ^ff0000Card Recycler^000000 ]";
			mes "You need ^FF0000"+.zeny_cost+" zeny^000000 per merge.";
			close;
		}
		if( npcshopattach( .shop_npc_name$ ) ){
			deletearray @sold_nameid;
			mes "[ ^ff0000Card Recycler^000000 ]";
			mes "Put ^FF0000 "+.card_count+" x Different Card^000000 into the window.";
			callshop .shop_npc_name$,2;
			end;
		}
	
	}
	else{
		mes "[ ^ff0000Card Recycler^000000 ]";
		mes "You need to give ";
		mes "  ^FF0000"+.card_count+" Monster Card + "+.zeny_cost+" Zeny^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 "[ ^ff0000Card Recycler^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;
				mes "[ ^ff0000Card Recycler^000000 ]";
				mes "Rolling a random card.....";
				soundeffect "̽.wav", 0;
				for( .@i = 0; .@i < getarraysize(.card_id_cutin); .@i++ ){
						.@r = rand(getarraysize(.card_id_cutin));
						cutin card_illust( .card_id_cutin[.@r] ),4;
						sleep2 ( .@i * 50 );
				}
				do{
					.@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+"|" ) );
				cutin card_illust( .@new_card ),4;
				if(.@rate <= 2000){
					announce "Citizens of Midgard,Lady Luck shines upon ["+strcharinfo(PC_NAME)+"]!! [Card Recycler] has awarded the player with ["+getitemname(.@new_card)+"]",0;
				}
				mes " ";
				mes "Gained a New Card: ";
				mes " ~ ^0055FF"+getitemname( .@new_card )+"^000000";
				getitem .@new_card,1;
				close2;
				cutin "",255;
				end;
			}
		}
		
	}
	else{
		mes "[ ^ff0000Card Recycler^000000 ]";
		mes "Make sure you input ^FF0000 "+.card_count+" Different Card^000000.";
	}
	close2;
	cutin "",255;
	end;

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

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

	// 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,4331;
	
	setarray .card_id_common[0],
				4010,	// Willow Card
				4020,	// Familiar Card
				4021,	// Rocker Card
				4114,	// Argiope Card
				4023,	// Baby Desert Card
				4019,	// Hornet Card
				4072,	// Golem Card
				4113,	// Marionette Card
				4110,	// Ghoul Card
				4038;	// Zombie Card
	
	setarray .card_id_rare[0],
				4049,	// Vadon Card
				4003,	// Pupa Card
				4073,	// Pirate Skeleton Card
				4139,	// Joker Card
				4086;	// Soldier Skeleton Card
				
	setarray .card_id_epic[0],
				4053,	// Vitata Card
				4040,	// Creamy Card
				4044,	// Smokie Card
				4103;	// Horong Card

	setarray .card_id_special[0],
				4133,	// Raydric Card
				4058,	// Thara Frog Card
				4035,	// Hydra Card
				4105;	// Marc Card

	setarray .card_id_cutin[0],
				4010,4020,4021,4114,4023,
				4019,4072,4113,4110,4038,
				4049,4003,4073,4139,4086,
				4053,4040,4044,4103,4133,
				4058,4035,4105;
	.shop_npc_name$ = "card_merge_shop";
	end;
}


