comparison Ikariam.pm @ 34:91e387b51aa0

added more rules checking
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sat, 11 Oct 2008 05:19:43 +0800
parents de5de6d472f9
children 7d1e353520ca
comparison
equal deleted inserted replaced
33:d183277b4d93 34:91e387b51aa0
257 257
258 my $html = HTML::TagParser->new($content); 258 my $html = HTML::TagParser->new($content);
259 my @elems; 259 my @elems;
260 260
261 my ($elem) = $html->getElementsByAttribute("id", "value_gold"); 261 my ($elem) = $html->getElementsByAttribute("id", "value_gold");
262 $self->{'cities'}->{$cityId}->{gold} = $elem->innerText(); 262 $self->{'cities'}->{$cityId}->{resources}->{gold} = $elem->innerText();
263 $self->{'cities'}->{$cityId}->{gold} =~ s/,//g; 263 $self->{'cities'}->{$cityId}->{resources}->{gold} =~ s/,//g;
264 264
265 my ($elem) = $html->getElementsByAttribute("class", "city"); 265 my ($elem) = $html->getElementsByAttribute("class", "city");
266 $self->{'cities'}->{$cityId}->{name} = $elem->innerText(); 266 $self->{'cities'}->{$cityId}->{name} = $elem->innerText();
267 267
268 my ($elem) = $html->getElementsByAttribute("class", 'constructionSite'); 268 my ($elem) = $html->getElementsByAttribute("class", 'constructionSite');
270 $self->{'cities'}->{$cityId}->{construction} = 1 if(defined($elem)); 270 $self->{'cities'}->{$cityId}->{construction} = 1 if(defined($elem));
271 271
272 # check goods 272 # check goods
273 foreach my $good (qw/wood wine marble crystal sulfur/) { 273 foreach my $good (qw/wood wine marble crystal sulfur/) {
274 my ($elem) = $html->getElementsByAttribute("id", "value_" . $good); 274 my ($elem) = $html->getElementsByAttribute("id", "value_" . $good);
275 $self->{'cities'}->{$cityId}->{$good} = $elem->innerText(); 275 $self->{'cities'}->{$cityId}->{resources}->{$good} = $elem->innerText();
276 $self->{'cities'}->{$cityId}->{$good} =~ s/,//g; 276 $self->{'cities'}->{$cityId}->{resources}->{$good} =~ s/,//g;
277 } 277 }
278 278
279 # search locations 279 # search locations
280 foreach my $i (0..14) { 280 foreach my $i (0..14) {
281 my ($elem) = $html->getElementsByAttribute("id", "position" . $i); 281 my ($elem) = $html->getElementsByAttribute("id", "position" . $i);
286 my (undef, undef, $level) = split(/ /, $span->innerText()); 286 my (undef, undef, $level) = split(/ /, $span->innerText());
287 $self->{'cities'}->{$cityId}->{buildings}->{$building} = $level; 287 $self->{'cities'}->{$cityId}->{buildings}->{$building} = $level;
288 } 288 }
289 } 289 }
290 290
291 # $res = $self->{mech}->get(sprintf('http://%s/index.php?view=townHall&id=%d', $self->{server}, $cityId)); 291 $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $self->{server}, $cityId));
292 # gunzip \$res->content => \$content 292 gunzip \$res->content => \$content
293 # or die "gunzip failed: $GunzipError\n"; 293 or die "gunzip failed: $GunzipError\n";
294 294
295 295 $self->{'cities'}->{$cityId}->{force}->{attacks} = $1 if($content =~ /敵人攻擊: (\d+)/);
296 $self->{'cities'}->{$cityId}->{force}->{wars} = $1 if($content =~ /我方軍隊行程: (\d+)/);
297 # if($content =~ /更新戰鬥報告: (\d+)/);
298 # if($content =~ /新的戰鬥報告: (\d+)/);
296 299
297 # check townHall 300 # check townHall
298 $res = $self->{mech}->get(sprintf('http://%s/index.php?view=townHall&id=%d', $self->{server}, $cityId)); 301 $res = $self->{mech}->get(sprintf('http://%s/index.php?view=townHall&id=%d', $self->{server}, $cityId));
299 gunzip \$res->content => \$content 302 gunzip \$res->content => \$content
300 or die "gunzip failed: $GunzipError\n"; 303 or die "gunzip failed: $GunzipError\n";