comparison Ikariam.pm @ 172:ba03aa8abdb2

reading Tavern's infomration
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 02 Nov 2008 00:30:02 +0800
parents 637314cc57ed
children e8a244ce5a1d
comparison
equal deleted inserted replaced
162:e49137521123 172:ba03aa8abdb2
526 $self->{'cities'}->{$cityId}->{transporters}->{sum} = $extractor->find('//span[@id="value_transSum"]/text()'); 526 $self->{'cities'}->{$cityId}->{transporters}->{sum} = $extractor->find('//span[@id="value_transSum"]/text()');
527 $self->{'cities'}->{$cityId}->{transporters}->{sum} =~ s/[\(|\)]//g; 527 $self->{'cities'}->{$cityId}->{transporters}->{sum} =~ s/[\(|\)]//g;
528 $self->{'cities'}->{$cityId}->{maxActionPoints} = $extractor->find('//span[@id="value_maxActionPoints"]');; 528 $self->{'cities'}->{$cityId}->{maxActionPoints} = $extractor->find('//span[@id="value_maxActionPoints"]');;
529 } 529 }
530 530
531 sub checkTavern {
532 my $self = shift;
533 my $cityId = shift;
534
535 my @locations = @{$self->{'cities'}->{$cityId}->{locations}};
536 # init
537 $self->{'cities'}->{$cityId}->{'tavern'}->{'maxValue'} = 0;
538 $self->{'cities'}->{$cityId}->{'tavern'}->{'iniValue'} = 0;
539 foreach (0..$#locations) {
540 if($locations[$_] eq 'tavern') {
541 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=tavern&id=%d&position=%d', $self->{server}, $cityId, $_ ));
542 my $extractor = Ikariam::Extractor->new(content => $res->content);
543 if($extractor->{doc}->toString(0) =~ /maxValue : (\d+),\s+overcharge : \d+,\s+iniValue : (\d+),/) {
544 $self->{'cities'}->{$cityId}->{'tavern'}->{'maxValue'} = $1;
545 $self->{'cities'}->{$cityId}->{'tavern'}->{'iniValue'} = $2;
546 }
547 last;
548 }
549 }
550 }
531 551
532 sub checkMilitaryAdvisorMilitaryMovements { 552 sub checkMilitaryAdvisorMilitaryMovements {
533 my $self = shift; 553 my $self = shift;
534 # TODO
535 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $self->{server})); 554 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $self->{server}));
536 my $extractor = new Ikariam::Extractor(content => $res->content); 555 my $extractor = new Ikariam::Extractor(content => $res->content);
537 556
538 $self->{'military'}->{wars} = 0; 557 $self->{'military'}->{wars} = 0;
539 $self->{'military'}->{attack} = 0; 558 $self->{'military'}->{attack} = 0;
791 # looking for cities 810 # looking for cities
792 foreach my $cityId (keys(%{$self->{'cities'}})) { 811 foreach my $cityId (keys(%{$self->{'cities'}})) {
793 $self->checkCity($cityId); 812 $self->checkCity($cityId);
794 $self->checkTownHall($cityId); 813 $self->checkTownHall($cityId);
795 $self->checkArmies($cityId); 814 $self->checkArmies($cityId);
815 $self->checkTavern($cityId);
796 } 816 }
797 return $self->{'cities'}; 817 return $self->{'cities'};
798 } 818 }
799 819
800 sub getNetIncome { 820 sub getNetIncome {