view index.pl @ 9:9652dc713ba6 boosterpack

working on adding to rlmcintyre.com
author Robert McIntyre <rlm@mit.edu>
date Sat, 26 Jun 2010 20:06:08 -0400
parents 8c6d2ce90677
children
line wrap: on
line source
1 #!/usr/bin/perl
5 use List::Util qw(first max maxstr min minstr reduce shuffle sum);
6 use Storable;
7 use CGI::Ajax;
8 use CGI;
9 use Rule;
10 use Filter;
11 use Card;
12 my $q = new CGI;
16 my $refstruct = retrieve 'CARD.perl';
17 my @pokes = @$refstruct;
19 open ERR, ">./error.log";
20 print ERR "hi";
23 my %hash = ( 'gen_pack' => \&gen_pack, 'change_rules' => \&change_rules);
30 my $pjx = CGI::Ajax->new(%hash);
31 #$pjx->JSDEBUG(1);
32 #$pjx->DEBUG(1);
34 print $pjx->build_html($q,\&gen); # this outputs the html for the page
40 sub change_rules
41 {
42 my $currentRuleref = retrieve 'rlm/booster.prefs';
43 $currentRule = $$currentRuleref;
44 $a = shift;
45 $currentRule -> setSets(($a));
46 store \$currentRule, 'rlm/booster.prefs';
47 return $a;
50 }
61 sub gen_pack
62 {
67 sub tag_analyze
68 {
72 my @sets = $currentRule -> getSets();
73 print ERR @sets;
75 my $card = shift;
77 #print ERR $card->getPix();
78 #print ERR "\n";
79 return $card -> hasTags(@sets);
82 }
84 my $currentRuleref = retrieve 'rlm/booster.prefs';
85 $currentRule = $$currentRuleref;
87 my $mapRules = $currentRule -> getRarityMap();
88 my %mapRules = %$mapRules;
93 print ERR "@pokes";
94 @reduced = filter(\&tag_analyze, @pokes);
95 @reduced = shuffle(@reduced);
97 my @final_list = ();
98 my $rnum = $mapRules{"Rare"};
99 my $unum = $mapRules{"Uncommon"};
100 my $cnum = $mapRules{"Common"};
102 $holochoose = int(rand(3));
103 ##########3
104 #my $rnum = 500;
105 #my $unum =500;
106 #my $cnum = 500;
107 #;
108 ##############
109 for $crd(@reduced)
110 {
113 if ($holochoose==0 or $holochoose==1 ){if (($crd -> hasTags("Rare"))and ($rnum>0)){push @r_list, $crd; $rnum--;}}
114 if ($holochoose==2){if (($crd -> hasTags("Rare Holo"))and ($rnum>0)){push @r_list, $crd; $rnum--;}}
115 #if (($crd -> hasTags("Rare") or $crd -> hasTags("Rare Holo"))and ($rnum>0)){push @r_list, $crd; $rnum--;}
116 if (($crd -> hasTags("Uncommon"))and ($unum>0)){push @u_list, $crd; $unum--;}
117 if (($crd -> hasTags("Common"))and ($cnum>0)){push @c_list, $crd; $cnum--;}
118 if ($rnum+$unum+$cnum == 0){last;}
119 }
121 @final_list = (@r_list,@u_list,@c_list);
124 for $crd(@final_list)
125 {
126 $rob = $rob."<A HREF=\"javascript:popUp('".$crd->getPix()."')\"><img src = \"".$crd->getPix()."\"></img></A>";
129 }
131 #print $rob;
133 print ERR @reduced;
134 print ERR $rob;
135 print $rob;
136 return $rob;
137 close ERR;
140 };
146 sub gen
147 {
148 open FILE, "<index.html";
149 return do { local $/; <FILE> };
151 };
153 #print "done";
155 #print &change_rules("Fossil");
156 print ERR &gen_pack;