annotate 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
rev   line source
rlm@0 1 #!C:/strawberry/perl/bin/perl.exe
rlm@0 2
rlm@0 3 use List::Util qw(first max maxstr min minstr reduce shuffle sum);
rlm@0 4 use Storable;
rlm@0 5 use CGI::Ajax;
rlm@0 6 use CGI;
rlm@0 7 use Rule;
rlm@0 8 use Filter;
rlm@0 9 use Card;
rlm@0 10 my $q = new CGI;
rlm@0 11
rlm@0 12
rlm@0 13
rlm@0 14 my $refstruct = retrieve 'CARD.perl';
rlm@0 15 my @pokes = @$refstruct;
rlm@0 16
rlm@0 17
rlm@0 18
rlm@0 19
rlm@0 20
rlm@0 21 my %hash = ( 'gen_pack' => \&gen_pack, 'change_rules' => \&change_rules);
rlm@0 22
rlm@0 23
rlm@0 24
rlm@0 25
rlm@0 26
rlm@0 27
rlm@0 28 my $pjx = CGI::Ajax->new(%hash);
rlm@0 29 #$pjx->JSDEBUG(1);
rlm@0 30 #$pjx->DEBUG(1);
rlm@0 31
rlm@0 32 print $pjx->build_html($q,\&gen); # this outputs the html for the page
rlm@0 33
rlm@0 34
rlm@0 35
rlm@0 36
rlm@0 37
rlm@0 38 sub change_rules
rlm@0 39 {
rlm@0 40 my $currentRuleref = retrieve 'rlm/booster.prefs';
rlm@0 41 $currentRule = $$currentRuleref;
rlm@0 42 $a = shift;
rlm@0 43 $currentRule -> setSets(($a));
rlm@0 44 store \$currentRule, 'rlm/booster.prefs';
rlm@0 45 return $a;
rlm@0 46
rlm@0 47
rlm@0 48 }
rlm@0 49
rlm@0 50
rlm@0 51
rlm@0 52
rlm@0 53
rlm@0 54
rlm@0 55
rlm@0 56
rlm@0 57
rlm@0 58
rlm@0 59 sub gen_pack
rlm@0 60 {
rlm@0 61 sub tag_analyze
rlm@0 62 {
rlm@0 63
rlm@0 64
rlm@0 65
rlm@0 66 my @sets = $currentRule -> getSets();
rlm@0 67 #print ERR @sets;
rlm@0 68
rlm@0 69 my $card = shift;
rlm@0 70
rlm@0 71 #print ERR $card->getPix();
rlm@0 72 #print ERR "\n";
rlm@0 73 return $card -> hasTags(@sets);
rlm@0 74
rlm@0 75
rlm@0 76 }
rlm@0 77
rlm@0 78 my $currentRuleref = retrieve 'rlm/booster.prefs';
rlm@0 79 $currentRule = $$currentRuleref;
rlm@0 80
rlm@0 81 my $mapRules = $currentRule -> getRarityMap();
rlm@0 82 my %mapRules = %$mapRules;
rlm@0 83
rlm@0 84
rlm@0 85
rlm@0 86
rlm@0 87 #print ERR "@pokes";
rlm@0 88 @reduced = filter(\&tag_analyze, @pokes);
rlm@0 89 @reduced = shuffle(@reduced);
rlm@0 90
rlm@0 91 my @final_list = ();
rlm@0 92 my $rnum = $mapRules{"Rare"};
rlm@0 93 my $unum = $mapRules{"Uncommon"};
rlm@0 94 my $cnum = $mapRules{"Common"};
rlm@0 95
rlm@0 96 $holochoose = int(rand(3));
rlm@0 97 ##########3
rlm@0 98 #my $rnum = 500;
rlm@0 99 #my $unum =500;
rlm@0 100 #my $cnum = 500;
rlm@0 101 #;
rlm@0 102 ##############
rlm@0 103 for $crd(@reduced)
rlm@0 104 {
rlm@0 105
rlm@0 106
rlm@0 107 if ($holochoose==0 or $holochoose==1 ){if (($crd -> hasTags("Rare"))and ($rnum>0)){push @r_list, $crd; $rnum--;}}
rlm@0 108 if ($holochoose==2){if (($crd -> hasTags("Rare Holo"))and ($rnum>0)){push @r_list, $crd; $rnum--;}}
rlm@0 109 #if (($crd -> hasTags("Rare") or $crd -> hasTags("Rare Holo"))and ($rnum>0)){push @r_list, $crd; $rnum--;}
rlm@0 110 if (($crd -> hasTags("Uncommon"))and ($unum>0)){push @u_list, $crd; $unum--;}
rlm@0 111 if (($crd -> hasTags("Common"))and ($cnum>0)){push @c_list, $crd; $cnum--;}
rlm@0 112 if ($rnum+$unum+$cnum == 0){last;}
rlm@0 113 }
rlm@0 114
rlm@0 115 @final_list = (@r_list,@u_list,@c_list);
rlm@0 116
rlm@0 117
rlm@0 118 for $crd(@final_list)
rlm@0 119 {
rlm@0 120 $rob = $rob."<A HREF=\"javascript:popUp('".$crd->getPix()."')\"><img src = \"".$crd->getPix()."\"></img></A>";
rlm@0 121
rlm@0 122
rlm@0 123 }
rlm@0 124
rlm@0 125 #print $rob;
rlm@0 126
rlm@0 127 #print ERR @reduced;
rlm@0 128 #print ERR $rob;
rlm@0 129 #print $rob;
rlm@0 130 return $rob;
rlm@0 131 #close ERR;
rlm@0 132
rlm@0 133
rlm@0 134 };
rlm@0 135
rlm@0 136
rlm@0 137
rlm@0 138
rlm@0 139
rlm@0 140 sub gen
rlm@0 141 {
rlm@0 142 open FILE, "<index.html";
rlm@0 143 return do { local $/; <FILE> };
rlm@0 144
rlm@0 145 };
rlm@0 146
rlm@0 147 #print "done";
rlm@0 148
rlm@0 149 #print &change_rules("Fossil");
rlm@0 150 #print &gen_pack;