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