Mercurial > eagle-eye
changeset 155:1499b0d496b6
merged.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sat, 01 Nov 2008 05:09:02 +0800 |
parents | 637314cc57ed (diff) 25dcc1fffeef (current diff) |
children | ba7a805b3fe4 d4b7d8f51e9f |
files | warfare.pl |
diffstat | 2 files changed, 35 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Ikariam.pm Sat Nov 01 04:29:08 2008 +0800 +++ b/Ikariam.pm Sat Nov 01 05:09:02 2008 +0800 @@ -95,6 +95,7 @@ use strict; use Data::Dumper; use LWP; + use HTTP::Cookies; use WWW::Mechanize; use XML::LibXML qw(:encoding); @@ -142,7 +143,7 @@ # if debug - # LWP::Debug::level('+conns'); + # 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'); @@ -739,6 +740,39 @@ } } +sub checkFriends +{ + # must check cities first, so we know if we have a museum available. + my $self = shift; + + foreach my $cityId (keys(%{$self->{'cities'}})) { + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + foreach (0..$#locations) { + if($locations[$_] eq 'museum') { + my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=museum&id=%d&position=%d', $self->{server}, $cityId, $_ )); + my @hrefs = Ikariam::Extractor->new(content => $res->content)->find('//div[@class="content"]/table/tbody/tr/td/a[1]/@href'); + foreach my $href (@hrefs) { + if ($href =~ /&id=(\d+)&/) { + $self->{'friends'}->{$1} = undef; + } + } + last; + } + } + } + + if(-f "friends.txt") { + # load friends + open(IN, "friends.txt") or die "Unable to open friends.txt\n"; + while(<IN>) { + chomp; + my $friend = Ikariam::User->retrieve(name => $_); + $self->{friends}->{$friend->id} = undef if(defined($friend)); + } + close(IN); + } +} + sub check { my $self = shift;
--- a/warfare.pl Sat Nov 01 04:29:08 2008 +0800 +++ b/warfare.pl Sat Nov 01 05:09:02 2008 +0800 @@ -110,8 +110,6 @@ sub engagement { my ($self, $cityId, $x, $y, $tradegood) = @_; - print($::i); - exit; my $victim = $self->locateVictim($cityId, $x, $y, $tradegood); if(defined($victim)) { $self->{ikariam}->changeCity($cityId);