Mercurial > eagle-eye
diff Ikariam.pm @ 189:7150e7b3dbec
merge
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 02 Nov 2008 22:32:09 +0800 |
parents | c6c6db6eea76 |
children | 5501ce37b50f |
line wrap: on
line diff
--- a/Ikariam.pm Sun Nov 02 22:31:06 2008 +0800 +++ b/Ikariam.pm Sun Nov 02 22:32:09 2008 +0800 @@ -142,7 +142,7 @@ # if debug - # LWP::Debug::level('+trace'); + LWP::Debug::level('+trace'); $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-cookies.txt", autosave => 1)); $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate'); @@ -312,23 +312,18 @@ delete($info{'ally'}) } else { my $href = $extractor->find(sprintf('//li[@id="cityLocation%s"]//li[@class="ally"]/a/@href', $i)); - # http://s2.ikariam.tw/index.php?view=allyPage&allyId=264&oldView=island&id=569 if($href =~ /&allyId=(\d+)&/) { $info{'allyId'} = $1; } } # Ally Id - my $href = $extractor->find(sprintf('//li[@id="cityLocation%s"]//a[@class="messageSend"]/@href', $i)); - # ?view=sendMessage&type=0&with=20204&destinationCityId=64165&oldView=island if ($href =~ /with=(\d+)&destinationCityId=(\d+)/) { $info{'user'} = $1; $info{'cityId'} = $2; - # ?view=sendAllyMessage&allyId=1192&oldView=island&id=721 } else { - # 聯盟 - # this is me. + # 聯盟 this is me. my $id = $extractor->find(sprintf('//li[@id="cityLocation%s"]/a/@id', $i)); if($id =~ /city_(\d+)/) { $info{'user'} = undef; # FIXME @@ -372,6 +367,7 @@ } } + # for tavern only sub set { my $self = shift; @@ -391,13 +387,151 @@ $self->{mech}->submit_form( form_number => 1, fields => { - amount => $self->{'cities'}->{$cityId}->{$type}->{maxValue}, - } + amount => $self->{'cities'}->{$cityId}->{$type}->{maxValue}, + } ); } } +sub is_shipyard_upgrading { + my $self = shift; + my $cityId = shift; + my $type = "shipyard"; + + my $position = -1; + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + foreach (1..2) { + $position = $_ if($locations[$_] eq $type); + } + + if($position != -1) { + my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); + if(defined(Ikariam::Extractor->new(content => $res->content)->find('//div[@class="isUpgrading"]'))) { + return 1; + } else { + return 0; + } + } + return 0; +} + +sub is_navy_trainning { + my $self = shift; + my $cityId = shift; + my $type = "shipyard"; + + my $position = -1; + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + foreach (1..2) { + $position = $_ if($locations[$_] eq $type); + } + + if($position != -1) { + my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); + if(defined(Ikariam::Extractor->new(content => $res->content)->find('//div[@id="unitConstructionList"]//h4'))) { + return 1; + } else { + return 0; + } + } + # FIXME we can not found the shipyard + return 0; +} + +sub buildShips { + my $self = shift; + my $shipType = shift; + my $cityId = shift; + my $type = 'shipyard'; + + warn("buildShips $shipType"); + my $position = -1; + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + foreach (1..2) { + $position = $_ if($locations[$_] eq $type); + } + + if($position != -1) { + my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); + $self->{mech}->submit_form( + form_number => 1, + fields => { + $shipType => 1, + } + ); + } +} + +sub is_army_trainning { + my $self = shift; + my $cityId = shift; + my $type = "barracks"; + + my $position = -1; + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + foreach (2..$#locations) { + $position = $_ if($locations[$_] eq $type); + } + + if($position != -1) { + my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); + if(defined(Ikariam::Extractor->new(content => $res->content)->find('//div[@id="unitConstructionList"]//h4'))) { + return 1; + } else { + return 0; + } + } + # FIXME we can not found the shipyard + return 0; +} + +sub is_barracks_upgrading { + my $self = shift; + my $cityId = shift; + my $type = 'barracks'; + + my $position = -1; + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + foreach (2..$#locations) { + $position = $_ if($locations[$_] eq $type); + } + + if($position != -1) { + my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); + if(defined(Ikariam::Extractor->new(content => $res->content)->find('//div[@class="isUpgrading"]'))) { + return 1; + } else { + return 0; + } + } + return 0; +} + +sub buildUnits { + my $self = shift; + my $unitType = shift; + my $cityId = shift; + my $type = 'barracks'; + + warn("buildShips $unitType"); + my $position = -1; + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + foreach (2..$#locations) { + $position = $_ if($locations[$_] eq $type); + } + + if($position != -1) { + my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); + $self->{mech}->submit_form( + form_number => 1, + fields => { + $unitType => 1, + } + ); + } +} + sub build { my $self = shift; my $type = shift; @@ -433,7 +567,7 @@ my $self = shift; my $param = shift; # defense. - die("run $param not implemented yet."); + warn ("run $param not implemented yet."); } sub research @@ -474,11 +608,19 @@ $self->{mech}->submit_form( form_number => 1, fields => { - cargo_army_302 => '2', - } + cargo_army_302 => '2', # 劍士 + } ); } else { - warn ($treaty); + # put the id in the friends.txt file. + Ikariam::Cities->has_a(user => 'Ikariam::User'); + my $city = Ikariam::Cities->retrieve($cityId); + my $sheep = $city->user; + + open(OUT, ">>friends.txt") or Carp::carp("can not open friends.txt"); + print OUT $sheep->name . "\n"; + close(OUT); + Carp::carp($treaty); } } @@ -607,7 +749,6 @@ } } } - # print(Dumper($self->{'military'})); } sub checkMilitaryAdvisorReportView { @@ -1002,6 +1143,7 @@ } foreach(@cities) { $self->{'cities'}->{$_} = {}; + $self->{'cities'}->{$_}->{id} = $_; } }