comparison Ikariam.pm @ 284:10f14db31151

added new dump spy info function
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 04 Dec 2008 03:22:11 +0800
parents 6bce423892f4
children 2ddd2bd21ef2
comparison
equal deleted inserted replaced
281:0d2c2a379c63 284:10f14db31151
725 725
726 sub checkCity { 726 sub checkCity {
727 my $self = shift; 727 my $self = shift;
728 my $cityId = shift; 728 my $cityId = shift;
729 729
730 $self->changeCity($cityId);
731 730
732 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=city&id=%d", $self->{server}, $cityId)); 731 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=city&id=%d", $self->{server}, $cityId));
733 my $extractor = new Ikariam::Extractor(content => $res->content); 732 my $extractor = new Ikariam::Extractor(content => $res->content);
734
735 $self->{'cities'}->{$cityId}->{resources}->{gold} = $extractor->find('//span[@id="value_gold"]/text()');
736 $self->{'cities'}->{$cityId}->{resources}->{gold} =~ s/,//g;
737
738 $self->{'cities'}->{$cityId}->{name} = $extractor->find('//span[@class="city"]/text()');
739
740 my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]');
741 if($island =~ /(\w+)\[(\d+):(\d+)\]/) {
742 $self->{'cities'}->{$cityId}->{island}->{name} = $1;
743 $self->{'cities'}->{$cityId}->{island}->{x} = $2;
744 $self->{'cities'}->{$cityId}->{island}->{y} = $3;
745 $self->{'cities'}->{$cityId}->{island}->{id} = my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]/@href');
746 $self->{'cities'}->{$cityId}->{island}->{id} =~ s/\?view=island&id=(\d+)/$1/;
747 }
748
749 $self->{'cities'}->{$cityId}->{construction} = defined($extractor->find('//*[@class="constructionSite"]')) ? 1 : 0;
750
751 # maxCapacity
752 my $page = $extractor->{doc}->toString(1);
753 if($page =~ /maxCapacity : {\s+wood: (\d+),\s+wine: (\d+),\s+marble: (\d+),\s+crystal: (\d+),\s+sulfur: (\d+)\s+}/s) {
754 $self->{'cities'}->{$cityId}->{maxCapacity}->{wood} = $1;
755 $self->{'cities'}->{$cityId}->{maxCapacity}->{wine} = $2;
756 $self->{'cities'}->{$cityId}->{maxCapacity}->{marble} = $3;
757 $self->{'cities'}->{$cityId}->{maxCapacity}->{crystal} = $4;
758 $self->{'cities'}->{$cityId}->{maxCapacity}->{sulfur} = $5;
759 }
760
761 foreach my $good (qw/wood wine marble crystal sulfur/) {
762 $self->{'cities'}->{$cityId}->{resources}->{$good} = $extractor->find(sprintf('//span[@id="value_%s"]', $good));
763 $self->{'cities'}->{$cityId}->{resources}->{$good} =~ s/,//g;
764 }
765 733
766 foreach my $i (0..14) { 734 foreach my $i (0..14) {
767 my @buildings = $extractor->find(sprintf('//li[@id="position%s"]/@class', $i)); 735 my @buildings = $extractor->find(sprintf('//li[@id="position%s"]/@class', $i));
768 foreach my $building (@buildings) { 736 foreach my $building (@buildings) {
769 if (!($building =~ /buildingGround/) && !($building =~ /townhall/)) { 737 if (!($building =~ /buildingGround/) && !($building =~ /townhall/)) {
778 } 746 }
779 my (undef, undef, $level) = split(/ /, $span); 747 my (undef, undef, $level) = split(/ /, $span);
780 $self->{'cities'}->{$cityId}->{buildings}->{$building} = $level; 748 $self->{'cities'}->{$cityId}->{buildings}->{$building} = $level;
781 } 749 }
782 } 750 }
751 }
752
753 $self->{'cities'}->{$cityId}->{name} = $extractor->find('//span[@class="city"]/text()');
754
755 my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]');
756 if($island =~ /(\w+)\[(\d+):(\d+)\]/) {
757 $self->{'cities'}->{$cityId}->{island}->{name} = $1;
758 $self->{'cities'}->{$cityId}->{island}->{x} = $2;
759 $self->{'cities'}->{$cityId}->{island}->{y} = $3;
760 $self->{'cities'}->{$cityId}->{island}->{id} = my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]/@href');
761 $self->{'cities'}->{$cityId}->{island}->{id} =~ s/\?view=island&id=(\d+)/$1/;
762 }
763
764 return $self->{'cities'}->{$cityId} if(wantarray());
765
766 $self->{'cities'}->{$cityId}->{resources}->{gold} = $extractor->find('//span[@id="value_gold"]/text()');
767 $self->{'cities'}->{$cityId}->{resources}->{gold} =~ s/,//g;
768
769 $self->{'cities'}->{$cityId}->{construction} = defined($extractor->find('//*[@class="constructionSite"]')) ? 1 : 0;
770
771 # maxCapacity
772 my $page = $extractor->{doc}->toString(1);
773 if($page =~ /maxCapacity : {\s+wood: (\d+),\s+wine: (\d+),\s+marble: (\d+),\s+crystal: (\d+),\s+sulfur: (\d+)\s+}/s) {
774 $self->{'cities'}->{$cityId}->{maxCapacity}->{wood} = $1;
775 $self->{'cities'}->{$cityId}->{maxCapacity}->{wine} = $2;
776 $self->{'cities'}->{$cityId}->{maxCapacity}->{marble} = $3;
777 $self->{'cities'}->{$cityId}->{maxCapacity}->{crystal} = $4;
778 $self->{'cities'}->{$cityId}->{maxCapacity}->{sulfur} = $5;
779 }
780
781 foreach my $good (qw/wood wine marble crystal sulfur/) {
782 $self->{'cities'}->{$cityId}->{resources}->{$good} = $extractor->find(sprintf('//span[@id="value_%s"]', $good));
783 $self->{'cities'}->{$cityId}->{resources}->{$good} =~ s/,//g;
783 } 784 }
784 785
785 $self->{'cities'}->{$cityId}->{transporters}->{avail} = $extractor->find('//span[@id="value_transAvail"]/text()'); 786 $self->{'cities'}->{$cityId}->{transporters}->{avail} = $extractor->find('//span[@id="value_transAvail"]/text()');
786 $self->{'cities'}->{$cityId}->{transporters}->{sum} = $extractor->find('//span[@id="value_transSum"]/text()'); 787 $self->{'cities'}->{$cityId}->{transporters}->{sum} = $extractor->find('//span[@id="value_transSum"]/text()');
787 $self->{'cities'}->{$cityId}->{transporters}->{sum} =~ s/[\(|\)]//g; 788 $self->{'cities'}->{$cityId}->{transporters}->{sum} =~ s/[\(|\)]//g;
828 } 829 }
829 last; 830 last;
830 } 831 }
831 } 832 }
832 } 833 }
834
835 sub checkSafeHouse {
836 my $self = shift;
837 my $cityId = shift;
838 my $data;
839
840 my @locations = @{$self->{'cities'}->{$cityId}->{locations}};
841 foreach (0..$#locations) {
842 if($locations[$_] eq 'safehouse') {
843 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=safehouse&id=%d&position=%d', $self->{server}, $cityId, $_ ));
844 my $extractor = Ikariam::Extractor->new(content => $res->content);
845 foreach (1..25) {
846 my @links = $extractor->find(sprintf('//div[@class="spyinfo" and position() = %d]//a/@href', $_));
847 last if($#links < 0);
848 if ($links[0] =~ /id=(\d+)/) {
849 @{$data->{$1}->{city}} = $self->checkCity($1);
850 @{$data->{$1}->{risks}} = Ikariam::Extractor->new(content => $self->{mech}->get($links[1])->content)->find('//div[@class="missionRisk"]');
851 }
852 }
853 last;
854 }
855 }
856 return $data;
857 }
858
833 859
834 sub checkMilitaryAdvisorMilitaryMovements { 860 sub checkMilitaryAdvisorMilitaryMovements {
835 my $self = shift; 861 my $self = shift;
836 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $self->{server})); 862 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $self->{server}));
837 my $extractor = new Ikariam::Extractor(content => $res->content); 863 my $extractor = new Ikariam::Extractor(content => $res->content);
1088 # //li[@id="advResearch"]/a[@class="normalalert"] 1114 # //li[@id="advResearch"]/a[@class="normalalert"]
1089 # //li[@id="advDiplomacy"]/a[@class="normalalert"] 1115 # //li[@id="advDiplomacy"]/a[@class="normalalert"]
1090 1116
1091 # looking for cities 1117 # looking for cities
1092 foreach my $cityId (keys(%{$self->{'cities'}})) { 1118 foreach my $cityId (keys(%{$self->{'cities'}})) {
1119 $self->changeCity($cityId);
1093 $self->checkCity($cityId); 1120 $self->checkCity($cityId);
1094 $self->checkTownHall($cityId); 1121 $self->checkTownHall($cityId);
1095 $self->checkArmies($cityId); 1122 $self->checkArmies($cityId);
1096 $self->checkTavern($cityId); 1123 $self->checkTavern($cityId);
1097 $self->checkAcademy($cityId); 1124 $self->checkAcademy($cityId);