diff BoosterPack/.svn/text-base/index.pl.svn-base @ 0:0d795f02a8bb tip

initial committ. what was I thinking?
author Robert McIntyre <rlm@mit.edu>
date Mon, 27 Sep 2010 16:57:26 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/BoosterPack/.svn/text-base/index.pl.svn-base	Mon Sep 27 16:57:26 2010 -0400
     1.3 @@ -0,0 +1,150 @@
     1.4 +#!C:/strawberry/perl/bin/perl.exe
     1.5 +
     1.6 +use List::Util qw(first max maxstr min minstr reduce shuffle sum);
     1.7 +use Storable;
     1.8 +use CGI::Ajax;
     1.9 +use CGI;
    1.10 +use Rule;
    1.11 +use Filter;
    1.12 +use Card;
    1.13 +my $q = new CGI;
    1.14 +
    1.15 +
    1.16 +
    1.17 +my $refstruct = retrieve 'CARD.perl';
    1.18 +my @pokes = @$refstruct;
    1.19 +
    1.20 +
    1.21 +
    1.22 +
    1.23 +
    1.24 +my %hash = ( 'gen_pack' => \&gen_pack, 'change_rules' => \&change_rules);
    1.25 +
    1.26 +
    1.27 +
    1.28 +
    1.29 +
    1.30 +
    1.31 +my $pjx = CGI::Ajax->new(%hash);
    1.32 +#$pjx->JSDEBUG(1);
    1.33 +#$pjx->DEBUG(1);
    1.34 +
    1.35 +print $pjx->build_html($q,\&gen); # this outputs the html for the page
    1.36 +
    1.37 +
    1.38 +
    1.39 +
    1.40 +
    1.41 +sub change_rules
    1.42 +{
    1.43 +	my $currentRuleref = retrieve 'rlm/booster.prefs';
    1.44 +	$currentRule = $$currentRuleref;
    1.45 +	$a = shift;
    1.46 +	$currentRule -> setSets(($a));
    1.47 +	store \$currentRule, 'rlm/booster.prefs'; 
    1.48 +	return $a;
    1.49 +  
    1.50 +	
    1.51 +}
    1.52 +
    1.53 +
    1.54 +
    1.55 +
    1.56 +
    1.57 +
    1.58 +
    1.59 +
    1.60 +
    1.61 +
    1.62 +sub gen_pack
    1.63 +{
    1.64 +	sub tag_analyze
    1.65 +	{
    1.66 +
    1.67 +	
    1.68 +	
    1.69 +	my @sets = $currentRule -> getSets();
    1.70 +	#print ERR @sets;
    1.71 +	
    1.72 +	my $card = shift;
    1.73 +	
    1.74 +	#print ERR $card->getPix();
    1.75 +	#print ERR "\n";
    1.76 +	return $card -> hasTags(@sets);
    1.77 +	
    1.78 +		
    1.79 +	}
    1.80 +		
    1.81 +	my $currentRuleref = retrieve 'rlm/booster.prefs';
    1.82 +	$currentRule = $$currentRuleref;
    1.83 +	
    1.84 +	my $mapRules = $currentRule -> getRarityMap();
    1.85 +	my %mapRules = %$mapRules;
    1.86 +	
    1.87 +	
    1.88 +	
    1.89 +	
    1.90 +	#print ERR "@pokes";
    1.91 +	@reduced = filter(\&tag_analyze, @pokes);
    1.92 +	@reduced = shuffle(@reduced);
    1.93 +	
    1.94 +	my @final_list = ();
    1.95 +	my $rnum = $mapRules{"Rare"};
    1.96 +	my $unum = $mapRules{"Uncommon"};
    1.97 +	my $cnum = $mapRules{"Common"};
    1.98 +	
    1.99 +	$holochoose = int(rand(3));
   1.100 +	##########3
   1.101 +	#my $rnum = 500;
   1.102 +	#my $unum      =500;
   1.103 +	#my $cnum = 500;
   1.104 +	#;
   1.105 +	##############
   1.106 +	for $crd(@reduced)
   1.107 +	{
   1.108 +		
   1.109 +		
   1.110 +		if ($holochoose==0 or $holochoose==1 ){if (($crd -> hasTags("Rare"))and  ($rnum>0)){push @r_list, $crd;  $rnum--;}}
   1.111 +		if ($holochoose==2){if (($crd -> hasTags("Rare Holo"))and  ($rnum>0)){push @r_list, $crd;  $rnum--;}}
   1.112 +		#if (($crd -> hasTags("Rare") or $crd -> hasTags("Rare Holo"))and  ($rnum>0)){push @r_list, $crd;  $rnum--;}
   1.113 +		if (($crd -> hasTags("Uncommon"))and  ($unum>0)){push @u_list, $crd;  $unum--;}
   1.114 +		if (($crd -> hasTags("Common"))and  ($cnum>0)){push @c_list, $crd;  $cnum--;}
   1.115 +		if ($rnum+$unum+$cnum == 0){last;}
   1.116 +	}
   1.117 +	
   1.118 +	@final_list = (@r_list,@u_list,@c_list);
   1.119 +	
   1.120 +	
   1.121 +	for $crd(@final_list)
   1.122 +	{
   1.123 +		$rob = $rob."<A HREF=\"javascript:popUp('".$crd->getPix()."')\"><img src = \"".$crd->getPix()."\"></img></A>";	
   1.124 +		
   1.125 +		
   1.126 +	}
   1.127 +	
   1.128 +	#print $rob;
   1.129 +
   1.130 +	#print ERR @reduced;
   1.131 +	#print ERR $rob;
   1.132 +	#print $rob;
   1.133 +	return $rob;
   1.134 +	#close ERR;
   1.135 +	
   1.136 +	
   1.137 +};
   1.138 +
   1.139 +
   1.140 +
   1.141 +
   1.142 +
   1.143 +sub gen
   1.144 +{
   1.145 +open FILE, "<index.html";
   1.146 +return do { local $/; <FILE> };
   1.147 +
   1.148 +};
   1.149 +
   1.150 +#print "done";
   1.151 +
   1.152 +#print &change_rules("Fossil");
   1.153 +#print &gen_pack;