Mercurial > eagle-eye
changeset 126:3196b1f5dc13
merged changes.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 31 Oct 2008 00:51:49 +0800 |
parents | bdf025bc50ea (current diff) 4374173bab47 (diff) |
children | a5517f0abb85 3756298f8e4b |
files | |
diffstat | 3 files changed, 35 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/Ikariam.pm Thu Oct 30 15:10:07 2008 +0800 +++ b/Ikariam.pm Fri Oct 31 00:51:49 2008 +0800 @@ -475,6 +475,15 @@ $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; # maxCapacity @@ -687,7 +696,6 @@ } } - sub checkArmies { my $self = shift; @@ -728,8 +736,7 @@ # //li[@id="advDiplomacy"]/a[@class="normalalert"] # looking for cities - foreach my $cityId (keys(%{$self->{'cities'}})) - { + foreach my $cityId (keys(%{$self->{'cities'}})) { $self->checkCity($cityId); $self->checkTownHall($cityId); $self->checkArmies($cityId);
--- a/scan.pl Thu Oct 30 15:10:07 2008 +0800 +++ b/scan.pl Fri Oct 31 00:51:49 2008 +0800 @@ -13,8 +13,7 @@ return; } - foreach my $h_city (@cities) - { + foreach my $h_city (@cities) { $h_city->{island} = $island; $h_city->{'time'} = time; my $c = Ikariam::Cities->retrieve($h_city->{cityId}); @@ -28,7 +27,7 @@ $c->update(); my $user = Ikariam::User->retrieve($h_city->{'user'}); - next if (defined($user) && $user->time le (time - 60*60*1)); + next if (defined($user) && defined($user->time) && $user->time le (time - 60*60*1)); saveUser($h_city->{owner}); } @@ -96,6 +95,7 @@ } else { die("Usage: $0\nUsage: $0 x y\n"); } + foreach my $h_island (@islands) { printf("checking island %d\n", $h_island->{id});
--- a/warfare.pl Thu Oct 30 15:10:07 2008 +0800 +++ b/warfare.pl Fri Oct 31 00:51:49 2008 +0800 @@ -10,18 +10,21 @@ use Data::Dumper; Ikariam::User->has_many(cities => 'Ikariam::Cities'); -Ikariam::User->has_a(ally => 'Ikariam::Ally'); Ikariam::Cities->has_a(user => 'Ikariam::User'); Ikariam::Cities->has_a(island => 'Ikariam::Island'); Ikariam::Cities->set_sql(sheeps => qq { SELECT cities.cityId FROM user, cities - WHERE user.id == cities.user - AND user.army_score_main == 0 + WHERE user.id = cities.user + AND user.army_score_main = 0 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? ) + AND cities.tradegood != ? ORDER BY cities.citylevel * (cities.citylevel - 1) * user.trader_score_secondary / 10000 DESC LIMIT 30 } ); +# $island->tradegood, +# qw/NULL 葡萄酒 大理石 水晶 硫磺/; +# 不打與自己相同的資源 Ikariam::Report->set_sql(victim => qq { SELECT report.id FROM report @@ -50,23 +53,24 @@ sub is_army_available { my ($self, $city) = @_; - return ($city->{army}->{Swordsman} > 2 ) ? 1 : 0; + return ($city->{army}->{Swordsman} >= 2 ) ? 1 : 0; } sub locateVictim { my ($self, $city, $x, $y) = @_; - my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6)); + my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6), $tradegood); foreach my $city (@cities) { my $sheep = $city->user; my $island = $city->island; - # Ignore 假期模式 + # Ignore the user in vacation which we can not attack. next if($city->status eq 'v'); unless ($city->status eq 'i') { - unless ($sheep->allyId == '0') { - my $ally = $sheep->ally; - # Ignore 聯盟人數大於10 + unless (!defined($sheep->allyId) || $sheep->allyId == 0) { + my $ally = Ikariam::Ally->retrieve($sheep->allyId); + # Ignore the ally which have more then 10 members. + # We don't want to piss off the big team. next if(defined($ally) && $ally->members > 10); } } @@ -75,19 +79,20 @@ my $c = Ikariam::Report->search_victim($city->cityId, time - 24*60*60 - 7*60*60)->count(); # check the current plunders foreach (@{$self->{ikariam}->{'military'}->{'homeland'}}) { - # 出發跟回家都要計算唷 + # counting for both leaving and coming back. $c++ if($_->{to} == $city->cityId || $_->{from} == $city->cityId); } + # we attack one city maximum 4 times a day. next if($c >= 4); # { - # if(1) { my $capture = $city->citylevel * ($city->citylevel - 1) * $sheep->trader_score_secondary / 10000; - my $line = sprintf("%d %s [%d,%d] %s (%d) %s/%s. Attacked %d", + my $line = sprintf("%d %s [%d,%d] %s (%d) %s Attacked %d", $capture, $city->status, $island->x, $island->y, $city->cityname, $city->cityId, - $sheep->name, $sheep->ally, $c); + $sheep->name, $c); + printf("%s\n", $line); # } return $city->cityId; @@ -96,8 +101,8 @@ } sub engagement { - my ($self, $cityId, $x, $y) = @_; - my $victim = $self->locateVictim($cityId, $x, $y); + my ($self, $cityId, $x, $y, $tradegood) = @_; + my $victim = $self->locateVictim($cityId, $x, $y, $tradegood); if(defined($victim)) { $self->{ikariam}->changeCity($cityId); $self->{ikariam}->plunderCity($victim); @@ -108,9 +113,6 @@ package main; -if($#ARGV != 1) { die("Usage: $0 x y\n"); } -my ($x, $y) = @ARGV; - our $i = new Ikariam($::server, $::user, $::pass); our $rules = Ikariam::Warfare::Rules->new($i); @@ -118,7 +120,6 @@ my $cities = $i->check; $i->checkMilitaryAdvisorCombatReports(); - foreach my $cityId (keys(%$cities)) { print Dump($i->{'military'}); # build and upgrade for cities @@ -126,7 +127,8 @@ $cities->{$cityId}->{parse_path} = []; $cities->{$cityId}->{parse_answer} = undef; if(ParseTree($tree, $rules, $cities->{$cityId}) eq 'engagement') { - $rules->engagement($cityId, $x, $y); + my $island = Ikariam::Island->retrive($cities->{$cityId}->{island}->{id}); + $rules->engagement($cityId, $island->{x}, $island->{y}, $island->tradegood); sleep(30); $i->checkMilitaryAdvisorMilitaryMovements(); }