Mercurial > eagle-eye
comparison Ikariam.pm @ 286:2ddd2bd21ef2
list spydata when check enemies
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Thu, 04 Dec 2008 21:54:00 +0800 |
parents | 10f14db31151 |
children | 24de33db8284 |
comparison
equal
deleted
inserted
replaced
285:c864134ebe3e | 286:2ddd2bd21ef2 |
---|---|
721 cityId => $cityId, | 721 cityId => $cityId, |
722 } | 722 } |
723 ); | 723 ); |
724 } | 724 } |
725 | 725 |
726 sub checkCity { | 726 sub readCity { |
727 my $self = shift; | 727 my $self = shift; |
728 my $cityId = shift; | 728 my $cityId = shift; |
729 | 729 my $data; |
730 | 730 |
731 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)); |
732 my $extractor = new Ikariam::Extractor(content => $res->content); | 732 my $extractor = new Ikariam::Extractor(content => $res->content); |
733 | 733 |
734 foreach my $i (0..14) { | 734 foreach my $i (0..14) { |
735 my @buildings = $extractor->find(sprintf('//li[@id="position%s"]/@class', $i)); | 735 my @buildings = $extractor->find(sprintf('//li[@id="position%s"]/@class', $i)); |
736 foreach my $building (@buildings) { | 736 foreach my $building (@buildings) { |
737 if (!($building =~ /buildingGround/) && !($building =~ /townhall/)) { | 737 if (!($building =~ /buildingGround/) && !($building =~ /townhall/)) { |
738 $self->{'cities'}->{$cityId}->{locations}[$i] = $building; | 738 $data->{locations}[$i] = $building; |
739 | 739 |
740 my $span; | 740 my $span; |
741 my @spans = $extractor->find(sprintf('//li[@id="position%s"]//span[@class="textLabel"]/text()', $i)); | 741 my @spans = $extractor->find(sprintf('//li[@id="position%s"]//span[@class="textLabel"]/text()', $i)); |
742 if($#spans >= 1) { | 742 if($#spans >= 1) { |
743 $span = $spans[1]; | 743 $span = $spans[1]; |
744 } else { | 744 } else { |
745 $span = $spans[0]; | 745 $span = $spans[0]; |
746 } | 746 } |
747 my (undef, undef, $level) = split(/ /, $span); | 747 my (undef, undef, $level) = split(/ /, $span); |
748 $self->{'cities'}->{$cityId}->{buildings}->{$building} = $level; | 748 $data->{buildings}->{$building} = $level; |
749 } | 749 } |
750 } | 750 } |
751 } | 751 } |
752 | 752 |
753 $self->{'cities'}->{$cityId}->{name} = $extractor->find('//span[@class="city"]/text()'); | 753 $data->{name} = $extractor->find('//span[@class="city"]/text()'); |
754 | 754 |
755 my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]'); | 755 my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]'); |
756 if($island =~ /(\w+)\[(\d+):(\d+)\]/) { | 756 if($island =~ /(\w+)\[(\d+):(\d+)\]/) { |
757 $self->{'cities'}->{$cityId}->{island}->{name} = $1; | 757 $data->{island}->{name} = $1; |
758 $self->{'cities'}->{$cityId}->{island}->{x} = $2; | 758 $data->{island}->{x} = $2; |
759 $self->{'cities'}->{$cityId}->{island}->{y} = $3; | 759 $data->{island}->{y} = $3; |
760 $self->{'cities'}->{$cityId}->{island}->{id} = my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]/@href'); | 760 $data->{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/; | 761 $data->{island}->{id} =~ s/\?view=island&id=(\d+)/$1/; |
762 } | 762 } |
763 | 763 |
764 return $self->{'cities'}->{$cityId} if(wantarray()); | 764 return $data; |
765 } | |
766 | |
767 sub checkCity { | |
768 my $self = shift; | |
769 my $cityId = shift; | |
770 | |
771 $self->{'cities'}->{$cityId} = $self->readCity($cityId); | |
772 | |
773 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=city&id=%d", $self->{server}, $cityId)); | |
774 my $extractor = new Ikariam::Extractor(content => $res->content); | |
765 | 775 |
766 $self->{'cities'}->{$cityId}->{resources}->{gold} = $extractor->find('//span[@id="value_gold"]/text()'); | 776 $self->{'cities'}->{$cityId}->{resources}->{gold} = $extractor->find('//span[@id="value_gold"]/text()'); |
767 $self->{'cities'}->{$cityId}->{resources}->{gold} =~ s/,//g; | 777 $self->{'cities'}->{$cityId}->{resources}->{gold} =~ s/,//g; |
768 | 778 |
769 $self->{'cities'}->{$cityId}->{construction} = defined($extractor->find('//*[@class="constructionSite"]')) ? 1 : 0; | 779 $self->{'cities'}->{$cityId}->{construction} = defined($extractor->find('//*[@class="constructionSite"]')) ? 1 : 0; |
844 my $extractor = Ikariam::Extractor->new(content => $res->content); | 854 my $extractor = Ikariam::Extractor->new(content => $res->content); |
845 foreach (1..25) { | 855 foreach (1..25) { |
846 my @links = $extractor->find(sprintf('//div[@class="spyinfo" and position() = %d]//a/@href', $_)); | 856 my @links = $extractor->find(sprintf('//div[@class="spyinfo" and position() = %d]//a/@href', $_)); |
847 last if($#links < 0); | 857 last if($#links < 0); |
848 if ($links[0] =~ /id=(\d+)/) { | 858 if ($links[0] =~ /id=(\d+)/) { |
849 @{$data->{$1}->{city}} = $self->checkCity($1); | 859 $data->{$1}->{city} = $self->readCity($1); |
850 @{$data->{$1}->{risks}} = Ikariam::Extractor->new(content => $self->{mech}->get($links[1])->content)->find('//div[@class="missionRisk"]'); | 860 @{$data->{$1}->{risks}} = Ikariam::Extractor->new(content => $self->{mech}->get($links[1])->content)->find('//div[@class="missionRisk"]'); |
851 } | 861 } |
852 } | 862 } |
853 last; | 863 last; |
854 } | 864 } |