Mercurial > eagle-eye
changeset 290:2cdf6c6bfd0e
merged.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 05 Dec 2008 20:22:20 +0800 |
parents | 4c1eb583b97c (diff) 34fd5bcd4cf8 (current diff) |
children | 73c9bf517155 15c288dd7dc5 |
files | |
diffstat | 6 files changed, 124 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/Ikariam.pm Fri Dec 05 15:39:49 2008 +0800 +++ b/Ikariam.pm Fri Dec 05 20:22:20 2008 +0800 @@ -723,28 +723,59 @@ ); } +sub readCity { + my $self = shift; + my $cityId = shift; + my $data; + + my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=city&id=%d", $self->{server}, $cityId)); + my $extractor = new Ikariam::Extractor(content => $res->content); + + foreach my $i (0..14) { + my @buildings = $extractor->find(sprintf('//li[@id="position%s"]/@class', $i)); + foreach my $building (@buildings) { + if (!($building =~ /buildingGround/) && !($building =~ /townhall/)) { + $data->{locations}[$i] = $building; + + my $span; + my @spans = $extractor->find(sprintf('//li[@id="position%s"]//span[@class="textLabel"]/text()', $i)); + if($#spans >= 1) { + $span = $spans[1]; + } else { + $span = $spans[0]; + } + my (undef, undef, $level) = split(/ /, $span); + $data->{buildings}->{$building} = $level; + } + } + } + + $data->{id} = $cityId; + $data->{name} = $extractor->find('//span[@class="city"]/text()'); + + my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]'); + if($island =~ /(\w+)\[(\d+):(\d+)\]/) { + $data->{island}->{name} = $1; + $data->{island}->{x} = $2; + $data->{island}->{y} = $3; + $data->{island}->{id} = my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]/@href'); + $data->{island}->{id} =~ s/\?view=island&id=(\d+)/$1/; + } + + return $data; +} + sub checkCity { my $self = shift; my $cityId = shift; - $self->changeCity($cityId); + $self->{'cities'}->{$cityId} = $self->readCity($cityId); my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=city&id=%d", $self->{server}, $cityId)); my $extractor = new Ikariam::Extractor(content => $res->content); $self->{'cities'}->{$cityId}->{resources}->{gold} = $extractor->find('//span[@id="value_gold"]/text()'); $self->{'cities'}->{$cityId}->{resources}->{gold} =~ s/,//g; - - $self->{'cities'}->{$cityId}->{name} = $extractor->find('//span[@class="city"]/text()'); - - my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]'); - if($island =~ /(\w+)\[(\d+):(\d+)\]/) { - $self->{'cities'}->{$cityId}->{island}->{name} = $1; - $self->{'cities'}->{$cityId}->{island}->{x} = $2; - $self->{'cities'}->{$cityId}->{island}->{y} = $3; - $self->{'cities'}->{$cityId}->{island}->{id} = my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]/@href'); - $self->{'cities'}->{$cityId}->{island}->{id} =~ s/\?view=island&id=(\d+)/$1/; - } $self->{'cities'}->{$cityId}->{construction} = defined($extractor->find('//*[@class="constructionSite"]')) ? 1 : 0; @@ -763,25 +794,6 @@ $self->{'cities'}->{$cityId}->{resources}->{$good} =~ s/,//g; } - foreach my $i (0..14) { - my @buildings = $extractor->find(sprintf('//li[@id="position%s"]/@class', $i)); - foreach my $building (@buildings) { - if (!($building =~ /buildingGround/) && !($building =~ /townhall/)) { - $self->{'cities'}->{$cityId}->{locations}[$i] = $building; - - my $span; - my @spans = $extractor->find(sprintf('//li[@id="position%s"]//span[@class="textLabel"]/text()', $i)); - if($#spans >= 1) { - $span = $spans[1]; - } else { - $span = $spans[0]; - } - my (undef, undef, $level) = split(/ /, $span); - $self->{'cities'}->{$cityId}->{buildings}->{$building} = $level; - } - } - } - $self->{'cities'}->{$cityId}->{transporters}->{avail} = $extractor->find('//span[@id="value_transAvail"]/text()'); $self->{'cities'}->{$cityId}->{transporters}->{sum} = $extractor->find('//span[@id="value_transSum"]/text()'); $self->{'cities'}->{$cityId}->{transporters}->{sum} =~ s/[\(|\)]//g; @@ -831,6 +843,31 @@ } } +sub checkSafeHouse { + my $self = shift; + my $cityId = shift; + my $data; + + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + foreach (0..$#locations) { + if($locations[$_] eq 'safehouse') { + my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=safehouse&id=%d&position=%d', $self->{server}, $cityId, $_ )); + my $extractor = Ikariam::Extractor->new(content => $res->content); + foreach (1..25) { + my @links = $extractor->find(sprintf('//div[@class="spyinfo" and position() = %d]//a/@href', $_)); + last if($#links < 0); + if ($links[0] =~ /id=(\d+)/) { + $data->{$1}->{city} = $self->readCity($1); + @{$data->{$1}->{risks}} = Ikariam::Extractor->new(content => $self->{mech}->get($links[1])->content)->find('//div[@class="missionRisk"]'); + } + } + last; + } + } + return $data; +} + + sub checkMilitaryAdvisorMilitaryMovements { my $self = shift; my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $self->{server})); @@ -1090,6 +1127,7 @@ # looking for cities foreach my $cityId (keys(%{$self->{'cities'}})) { + $self->changeCity($cityId); $self->checkCity($cityId); $self->checkTownHall($cityId); $self->checkArmies($cityId);
--- a/agent.pl Fri Dec 05 15:39:49 2008 +0800 +++ b/agent.pl Fri Dec 05 20:22:20 2008 +0800 @@ -238,6 +238,12 @@ } } +sub is_shipyard_availble { + my ($self, $city) = @_; + return 0 if(!defined($city->{buildings}->{shipyard})); + return 1; +} + sub is_shipyard_level_enough { my ($self, $city) = @_; return 0 if(!defined($city->{buildings}->{shipyard}));
--- a/enemy.pl Fri Dec 05 15:39:49 2008 +0800 +++ b/enemy.pl Fri Dec 05 20:22:20 2008 +0800 @@ -2,7 +2,7 @@ use strict; use Ikariam; use Data::Dumper; -use YAML qw/LoadFile/; +use YAML qw/Dump LoadFile/; use POSIX qw(strftime); package main; @@ -106,17 +106,32 @@ my $island = Ikariam::Island->retrieve($city->island); my $capture = $city->citylevel * ($city->citylevel - 1) * $u->trader_score_secondary / 10000; - printf("Name: %s\n", $city->cityname); + printf("Name: %s [%s:%s]\n", $city->cityname, $island->x, $island->y); if(defined($city->status)) { printf("Status: <<<%s>>>\n", $city->status); } - printf("Level: %s\n", $city->citylevel); - printf("Island: %s\n", $island->name); printf("Location: [%s:%s] http://%s/index.php?view=island&id=%s&selectCity=%d\n", - $island->x, $island->y, $::server, $island->id, $city->cityId); - printf("Tradegood: %s\n", $tradegoodText[$island->tradegood]); - printf("Wonder: %s\n", $wonderText[$island->wonder]); + $island->x, $island->y, $::server, $island->id, $city->cityId); + if(-f sprintf("spy-%d-dump.yaml", $city->cityId)) { + my $spydata = LoadFile(sprintf("spy-%d-dump.yaml", $city->cityId)); + if($spydata->{city}->{buildings}->{townHall} ne $city->citylevel) { + printf("*OUTDATED* "); + } + printf("Hall: %s, Wall: %s, Port: %s, Safehouse: %s, Risk: %s\n", + $spydata->{city}->{buildings}->{townHall}, + $spydata->{city}->{buildings}->{wall}, + $spydata->{city}->{buildings}->{port}, + $spydata->{city}->{buildings}->{safehouse}, + $spydata->{risks}[1]); + } else { + printf("Level: %s\n", $city->citylevel); + } + printf("Capture: %d\n", $capture); + printf("Tradegood: %s, Wonder: %s\n", + $tradegoodText[$island->tradegood], $wonderText[$island->wonder]); + # printf("Island: %s\n", $island->name); + myTownToVicim($island->id); printf("\n"); }
--- a/planner.pl Fri Dec 05 15:39:49 2008 +0800 +++ b/planner.pl Fri Dec 05 20:22:20 2008 +0800 @@ -96,15 +96,16 @@ ($cities[$i+1]->{distance} - $cities[$i]->{distance})); } printf("\n# %s %s %dm\n", $cities[$i]->{name}, $cities[$i]->{type}, $cities[$i]->{distance}); + printf("# ActionPoint %d/%d\n", $cities[$i]->{actionPoints}, $cities[$i]->{maxActionPoints}); printf('$ikariam->login;' . "\n"); if($cities[$i]->{type} eq "navy") { printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); printf('$ikariam->blockadeCity(%d, {' . "\n", $targetCity->id); - printf('blockadeDuration => 8*60*60,' . "\n"); + printf("\tblockadeDuration => 2*60*60," . "\n"); while (my ($k, $v) = each(%{$cities[$i]->{fleet}})) { if($v > 0) { - printf("cargo_fleet_%s => %s, # %s \n", $fleet->{$k}, $v, $k); + printf("\tcargo_fleet_%s => %s, # %s \n", $fleet->{$k}, $v, $k); } } printf('});' . "\n", $cities[$i]->{id}); @@ -113,7 +114,7 @@ printf('$ikariam->plunderCity(%d, {' . "\n", $targetCity->id); while (my ($k, $v) = each(%{$cities[$i]->{army}})) { if($v > 0) { - printf("cargo_army_%s => %s, # %s \n", $army->{$k}, $v, $k); + printf("\tcargo_army_%s => %s, # %s \n", $army->{$k}, $v, $k); } } printf('});' . "\n", $cities[$i]->{id});
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spy.pl Fri Dec 05 20:22:20 2008 +0800 @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use strict; +use Ikariam; +use Data::Dumper; +use Decision::ParseTree q{ParseTree}; +use YAML qw/LoadFile Dump DumpFile/; + +our $i = new Ikariam($::server, $::user, $::pass); +$i->login; +# $i->check(); +foreach (glob("city-*-dump.yaml")) { + my $city = LoadFile($_); + $i->{'cities'}->{$city->{id}} = $city; + + my $spydata = $i->checkSafeHouse($city->{id}); + foreach (keys(%{$spydata})) { + DumpFile("spy-$_-dump.yaml", $spydata->{$_}); + } +} +$i->logout; +