view index.pl @ 4:90181bbf7a0c boosterpack

[svn r6] added Dylan's awesome stuff.
author robert
date Tue, 08 Sep 2009 06:05:47 -0400
parents 2e849c856026
children e91d6f908222
line wrap: on
line source
1 #!C:/strawberry/perl/bin/perl.exe
3 use List::Util qw(first max maxstr min minstr reduce shuffle sum);
4 use Storable;
5 use CGI::Ajax;
6 use CGI;
7 use Rule;
8 use Filter;
9 use Card;
10 my $q = new CGI;
14 my $refstruct = retrieve 'CARD.perl';
15 my @pokes = @$refstruct;
21 my %hash = ( 'gen_pack' => \&gen_pack, 'change_rules' => \&change_rules);
28 my $pjx = CGI::Ajax->new(%hash);
29 #$pjx->JSDEBUG(1);
30 #$pjx->DEBUG(1);
32 print $pjx->build_html($q,\&gen); # this outputs the html for the page
38 sub change_rules
39 {
40 my $currentRuleref = retrieve 'rlm/booster.prefs';
41 $currentRule = $$currentRuleref;
42 $a = shift;
43 $currentRule -> setSets(($a));
44 store \$currentRule, 'rlm/booster.prefs';
45 return $a;
48 }
59 sub gen_pack
60 {
61 sub tag_analyze
62 {
66 my @sets = $currentRule -> getSets();
67 #print ERR @sets;
69 my $card = shift;
71 #print ERR $card->getPix();
72 #print ERR "\n";
73 return $card -> hasTags(@sets);
76 }
78 my $currentRuleref = retrieve 'rlm/booster.prefs';
79 $currentRule = $$currentRuleref;
81 my $mapRules = $currentRule -> getRarityMap();
82 my %mapRules = %$mapRules;
87 #print ERR "@pokes";
88 @reduced = filter(\&tag_analyze, @pokes);
89 @reduced = shuffle(@reduced);
91 my @final_list = ();
92 my $rnum = $mapRules{"Rare"};
93 my $unum = $mapRules{"Uncommon"};
94 my $cnum = $mapRules{"Common"};
96 for $crd(@reduced)
97 {
98 if (($crd -> hasTags("Rare") or $crd -> hasTags("Rare Holo"))and ($rnum>0)){push @r_list, $crd; $rnum--;}
99 if (($crd -> hasTags("Uncommon"))and ($unum>0)){push @u_list, $crd; $unum--;}
100 if (($crd -> hasTags("Common"))and ($cnum>0)){push @c_list, $crd; $cnum--;}
101 if ($rnum+$unum+$cnum == 0){last;}
102 }
104 @final_list = (@r_list,@u_list,@c_list);
107 for $crd(@final_list)
108 {
109 $rob = $rob."<img src = \"".$crd->getPix()."\"></img>";
110 }
112 #print $rob;
114 #print ERR @reduced;
115 #print ERR $rob;
116 #print $rob;
117 return $rob;
118 #close ERR;
121 };
127 sub gen
128 {
129 open FILE, "<index.html";
130 return do { local $/; <FILE> };
131 };
133 #print "done";
135 #print &change_rules("Fossil");
136 #print &gen_pack;