comparison Ikariam.pm @ 242:5f6f845bbb1d

check if the city still exist.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Mon, 10 Nov 2008 14:19:43 +0800
parents 937fc672df56
children a654d43731f0
comparison
equal deleted inserted replaced
241:64549ddddf4a 242:5f6f845bbb1d
626 sub plunderCity { 626 sub plunderCity {
627 my $self = shift; 627 my $self = shift;
628 my $cityId = shift; 628 my $cityId = shift;
629 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=plunder&destinationCityId=%d", $self->{server}, $cityId)); 629 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=plunder&destinationCityId=%d", $self->{server}, $cityId));
630 630
631 my $extractor = Ikariam::Extractor->new(content => $res->content);
631 # check peace treaty 632 # check peace treaty
632 my $treaty = Ikariam::Extractor->new(content => $res->content)->find('//div[@class="warning"]'); 633 my $treaty = $extractor->find('//div[@class="warning"]');
633 if(!defined($treaty)) { 634 if(!defined($treaty)) {
634 $self->{mech}->submit_form( 635 my @forms = $self->{mech}->forms();
635 form_number => 1, 636 if($#forms < 1) {
636 fields => { 637 my $city = Ikariam::Cities->retrieve($cityId);
637 cargo_army_302 => '3', # 劍士 638 $city->delete;
639 } else {
640 $self->{mech}->submit_form(
641 form_number => 1,
642 fields => {
643 cargo_army_302 => '3', # 劍士
638 } 644 }
639 ); 645 );
646 }
640 } else { 647 } else {
641 # put the id in the friends.txt file. 648 # put the id in the friends.txt file.
642 Ikariam::Cities->has_a(user => 'Ikariam::User'); 649 Ikariam::Cities->has_a(user => 'Ikariam::User');
643 my $city = Ikariam::Cities->retrieve($cityId); 650 my $city = Ikariam::Cities->retrieve($cityId);
644 my $sheep = $city->user; 651 my $sheep = $city->user;