Mercurial > eagle-eye
comparison Ikariam.pm @ 26:d8117792c6f5
collecting more data from townHall
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 10 Oct 2008 03:20:36 +0800 |
parents | 54ab0becd730 |
children | dd85b55eec2a |
comparison
equal
deleted
inserted
replaced
25:51a35c3d057e | 26:d8117792c6f5 |
---|---|
32 server => $server, | 32 server => $server, |
33 user => $user, | 33 user => $user, |
34 pass => $pass, | 34 pass => $pass, |
35 }; | 35 }; |
36 | 36 |
37 $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "./cookies.txt", autosave => 1)); | 37 $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-cookies.txt", autosave => 1)); |
38 $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate'); | 38 $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate'); |
39 | 39 |
40 return bless $self, $class; | 40 return bless $self, $class; |
41 } | 41 } |
42 | 42 |
79 $user{'name'} = $e->innerText(); | 79 $user{'name'} = $e->innerText(); |
80 | 80 |
81 $e = getElementsByAttribute($elem, "class", "allytag"); | 81 $e = getElementsByAttribute($elem, "class", "allytag"); |
82 $user{'ally'} = $e->innerText(); | 82 $user{'ally'} = $e->innerText(); |
83 | 83 |
84 $e = getElementsByTagName($e, "a"); | 84 $e = getElementsByTagName($e, "a"); |
85 if($e->getAttribute('href') =~ /\?view=allyPage&allyId=(\d+)/) | 85 if($e->getAttribute('href') =~ /\?view=allyPage&allyId=(\d+)/) |
86 { | 86 { |
87 $user{'allyId'} = $1; | 87 $user{'allyId'} = $1; |
88 } | 88 } |
89 | 89 |
237 | 237 |
238 sub check | 238 sub check |
239 { | 239 { |
240 my $self = shift; | 240 my $self = shift; |
241 | 241 |
242 my $aaaa = $self->{'cities'}; | 242 # looking for cities |
243 | 243 foreach my $cityId (keys(%{$self->{'cities'}})) |
244 # 運輸船 | 244 { |
245 # CargoShip | |
246 foreach my $i (keys(%{$self->{'cities'}})) | |
247 { | |
248 | |
249 # search for goods | 245 # search for goods |
250 my $res = $self->{mech}->post(sprintf('http://%s/index.php', $self->{server}), [ | 246 my $res = $self->{mech}->post(sprintf('http://%s/index.php', $self->{server}), [ |
251 action => 'header', | 247 action => 'header', |
252 cityId => $i, | 248 cityId => $cityId, |
253 function => 'changeCurrentCity', | 249 function => 'changeCurrentCity', |
254 id => $i, | 250 id => $cityId, |
255 oldView => 'city', | 251 oldView => 'city', |
256 ]); | 252 ]); |
257 my $c; | 253 |
258 my $status = gunzip \$res->content => \$c | 254 my $content; |
255 gunzip \$res->content => \$content | |
259 or die "gunzip failed: $GunzipError\n"; | 256 or die "gunzip failed: $GunzipError\n"; |
260 | 257 |
261 my $html = HTML::TagParser->new($c); | 258 my $html = HTML::TagParser->new($content); |
262 my @elems; | 259 my @elems; |
263 | 260 |
264 foreach my $j (qw/value_wood value_wine value_marble value_crystal value_sulfur/) { | 261 my ($elem) = $html->getElementsByAttribute("id", "value_gold"); |
265 my ($elem) = $html->getElementsByAttribute("id", $j); | 262 $self->{'cities'}->{$cityId}->{gold} = $elem->innerText(); |
266 $self->{'cities'}->{$i}->{$j} = $elem->innerText(); | 263 $self->{'cities'}->{$cityId}->{gold} =~ s/,//g; |
267 $self->{'cities'}->{$i}->{$j} =~ s/,//g; | 264 |
268 } | 265 my ($elem) = $html->getElementsByAttribute("class", "city"); |
269 | 266 $self->{'cities'}->{$cityId}->{name} = $elem->innerText(); |
270 my %types; | 267 |
271 $types{'army'} = [ qw/undef undef Slinger Swordsman Phalanx Ram Archer Catapult Gunsman Mortar SteamGiant Gyrocopter Bombardier Doctor Cook/ ]; | 268 # check goods |
272 $types{'fleet'} = [ qw/undef undef Ram-Ship BallistaShip Flamethrower CatapultShip MortarShip PaddleWheelRam DivingBoat/ ]; | 269 foreach my $good (qw/wood wine marble crystal sulfur/) { |
273 | 270 my ($elem) = $html->getElementsByAttribute("id", "value_" . $good); |
271 $self->{'cities'}->{$cityId}->{$good} = $elem->innerText(); | |
272 $self->{'cities'}->{$cityId}->{$good} =~ s/,//g; | |
273 } | |
274 | |
275 # check townHall | |
276 $res = $self->{mech}->get(sprintf('http://%s/index.php?view=townHall&id=%d', $self->{server}, $cityId)); | |
277 gunzip \$res->content => \$content | |
278 or die "gunzip failed: $GunzipError\n"; | |
279 | |
280 # check happiness | |
281 # Happiness = Basic bonuses (196 + Capital Bonus + Holiday Bonus(25)) + | |
282 # Wine (Tavern Base(12*level) + | |
283 # Tavern Bonus(80*step)) + | |
284 # Culture (Museum Base(20*level) + | |
285 # Cultural Goods Bonus(50*Cultural Goods)) - | |
286 # Population (population) - | |
287 # Corruption (Corruption rate * population) | |
288 # | |
289 # Growth Rate = Happiness * 0.02 | |
290 $html = HTML::TagParser->new($content); | |
291 | |
292 my @happiness = ("ecstatic", "happy", "neutral", "sad", "outraged"); | |
293 foreach my $j (0..$#happiness) { | |
294 my ($elem) = $html->getElementsByAttribute("class", sprintf("happiness happiness_%s", $happiness[$j])); | |
295 if(defined($elem)) { | |
296 $self->{'cities'}->{$cityId}->{happiness} = $j; | |
297 $self->{'cities'}->{$cityId}->{happiness_text} = $happiness[$j]; | |
298 } | |
299 } | |
300 | |
301 # Space, 房屋數 | |
302 foreach my $j (qw/occupied total/) { | |
303 my ($elem) = $html->getElementsByAttribute("class", sprintf("value %s", $j)); | |
304 if(defined($elem)) { | |
305 $self->{'cities'}->{$cityId}->{"space_" . $j} = $elem->innerText(); | |
306 } | |
307 } | |
308 | |
309 # Actions | |
310 # <span id="value_maxActionPoints">1</span> | |
311 | |
312 # <li class="incomegold incomegold_negative"> | |
313 # <li class="incomegold incomegold_positive"> | |
314 # <span class="value">-178</span> | |
315 | |
316 # <li class="corruption"> | |
317 # <span class="textLabel">腐敗: </span> | |
318 # <span class="value positive"> | |
319 # <span title="目前腐敗程度">33%</span> | |
320 # </span> | |
321 # </li> | |
322 my ($elem) = $html->getElementsByAttribute("title", "目前腐敗程度"); | |
323 if(defined($elem)) { | |
324 $self->{'cities'}->{$cityId}->{corruption} = $elem->innerText(); | |
325 $self->{'cities'}->{$cityId}->{corruption} =~ s/%//g; | |
326 } | |
327 | |
328 # count | |
329 my $cities_type = { | |
330 citizens => 8, | |
331 woodworkers => 10, | |
332 specialworkers => 12, | |
333 scientists => 14, | |
334 }; | |
335 | |
336 @elems = $html->getElementsByAttribute('class', 'count'); | |
337 $self->{'cities'}->{$cityId}->{'cities'} = {}; | |
338 foreach my $type (keys(%$cities_type)) | |
339 { | |
340 $self->{'cities'}->{$cityId}->{'cities'}->{$type} = $elems[$cities_type{$type}]->innerText(); | |
341 } | |
342 | |
343 # production | |
344 # skin/resources/icon_gold.gif | |
345 # skin/resources/icon_wood.gif | |
346 # skin/resources/icon_sulfur.gif (?) | |
347 # skin/resources/icon_research.gif | |
348 | |
349 # foreach my $i (0..$#cities_type) { | |
350 # next if($cities_type[$i] eq 'undef'); | |
351 # if(defined($elems[$i])) { | |
352 # $self->{'cities'}->{$cityId}->{'cities_'.$type}->{$cities_type[$i]} = $elems[$i]->innerText(); | |
353 # } | |
354 # } | |
355 | |
356 # check armies | |
357 my %force_types; | |
358 $force_types{'army'} = [ qw/undef undef Slinger Swordsman Phalanx Ram Archer Catapult Gunsman Mortar SteamGiant Gyrocopter Bombardier Doctor Cook/ ]; | |
359 $force_types{'fleet'} = [ qw/undef undef Ram-Ship BallistaShip Flamethrower CatapultShip MortarShip PaddleWheelRam DivingBoat/ ]; | |
274 foreach my $x (qw/army fleet/) | 360 foreach my $x (qw/army fleet/) |
275 { | 361 { |
276 $self->{'cities'}->{$i}->{$x} = {}; | 362 $self->{'cities'}->{$cityId}->{$x} = {}; |
277 # search army | 363 # search army |
278 $res = $self->{mech}->get(sprintf('http://%s/index.php?view=cityMilitary-%s&id=%d', $self->{server}, $x, $i)); | 364 $res = $self->{mech}->get(sprintf('http://%s/index.php?view=cityMilitary-%s&id=%d', $self->{server}, $x, $cityId)); |
279 $status = gunzip \$res->content => \$c | 365 gunzip \$res->content => \$content |
280 or die "gunzip failed: $GunzipError\n"; | 366 or die "gunzip failed: $GunzipError\n"; |
281 | 367 |
282 $html = HTML::TagParser->new($c); | 368 $html = HTML::TagParser->new($content); |
283 @elems = $html->getElementsByTagName('td'); | 369 @elems = $html->getElementsByTagName('td'); |
284 | 370 foreach my $j (0..$#{$force_types{$x}}) { |
285 foreach my $j (0..$#{$types{$x}}) { | 371 next if($force_types{$x}[$j] eq 'undef'); |
286 next if($types{$x}[$j] eq 'undef'); | |
287 if($elems[$j]->innerText() == '-') { | 372 if($elems[$j]->innerText() == '-') { |
288 $self->{'cities'}->{$i}->{$x}->{$types{$x}[$j]} = 0; | 373 $self->{'cities'}->{$cityId}->{$x}->{$force_types{$x}[$j]} = 0; |
289 } else { | 374 } else { |
290 $self->{'cities'}->{$i}->{$x}->{$types{$x}[$j]} = $elems[$j]->innerText(); | 375 $self->{'cities'}->{$cityId}->{$x}->{$force_types{$x}[$j]} = $elems[$j]->innerText(); |
291 } | 376 } |
292 } | 377 } |
293 } | 378 } |
294 } | 379 } |
295 print Dumper($self->{'cities'}); | 380 # print Dumper($self->{'cities'}); |
381 return $self->{'cities'}; | |
296 } | 382 } |
297 | 383 |
298 sub logout | 384 sub logout |
299 { | 385 { |
300 my $self = shift; | 386 my $self = shift; |