# HG changeset patch # User "Rex Tsai " # Date 1227987592 -28800 # Node ID 6bce423892f42dde5bd79fa1d5e61d78cba9141d # Parent c7f4a6f0fbdee7a60beeb8bb8324d0414c866944 updated plunderCity and blockadeCity diff -r c7f4a6f0fbde -r 6bce423892f4 Ikariam.pm --- a/Ikariam.pm Sat Nov 29 02:16:35 2008 +0800 +++ b/Ikariam.pm Sun Nov 30 03:39:52 2008 +0800 @@ -648,6 +648,7 @@ sub plunderCity { my $self = shift; my $cityId = shift; + my $fields = shift; my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=plunder&destinationCityId=%d", $self->{server}, $cityId)); my $extractor = Ikariam::Extractor->new(content => $res->content); @@ -661,11 +662,40 @@ } else { $self->{mech}->submit_form( form_number => 1, - fields => { - # cargo_army_302 => '2', # 劍士 - cargo_army_303 => '3', # 方陣 - } - ); + fields => $fields); + } + } else { + # 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); + } +} + + +sub blockadeCity { + my $self = shift; + my $cityId = shift; + my $fields = shift; + my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=blockade&destinationCityId=%d", $self->{server}, $cityId)); + + my $extractor = Ikariam::Extractor->new(content => $res->content); + # check peace treaty + my $treaty = $extractor->find('//div[@class="warning"]'); + if(!defined($treaty)) { + my @forms = $self->{mech}->forms(); + if($#forms < 1) { + my $city = Ikariam::Cities->retrieve($cityId); + $city->delete; + } else { + $self->{mech}->submit_form( + form_number => 1, + fields => $fields); } } else { # put the id in the friends.txt file. diff -r c7f4a6f0fbde -r 6bce423892f4 warfare.pl --- a/warfare.pl Sat Nov 29 02:16:35 2008 +0800 +++ b/warfare.pl Sun Nov 30 03:39:52 2008 +0800 @@ -100,6 +100,7 @@ my $ally = Ikariam::Ally->retrieve($user->allyId); my $targetAlly = Ikariam::Ally->retrieve($sheep->allyId); # We don't want to piss off the big team. + next CITY if(!defined($ally)); next CITY if($ally->score == 0); next CITY if($targetAlly->score > $ally->score); next CITY if(defined($ally) && $ally->members > 12); @@ -145,7 +146,12 @@ my $victim = $self->locateVictim($cityId, $x, $y, $tradegood); if(defined($victim)) { $self->{ikariam}->changeCity($cityId); - $self->{ikariam}->plunderCity($victim); + $self->{ikariam}->plunderCity($victim, + { + # cargo_army_302 => '2', # 劍士 + cargo_army_303 => '3', # 方陣 + } + ); } }