Mercurial > eagle-eye
comparison Ikariam.pm @ 270:6bce423892f4
updated plunderCity and blockadeCity
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sun, 30 Nov 2008 03:39:52 +0800 |
parents | 285d5b39ef2c |
children | 10f14db31151 |
comparison
equal
deleted
inserted
replaced
269:c7f4a6f0fbde | 270:6bce423892f4 |
---|---|
646 } | 646 } |
647 | 647 |
648 sub plunderCity { | 648 sub plunderCity { |
649 my $self = shift; | 649 my $self = shift; |
650 my $cityId = shift; | 650 my $cityId = shift; |
651 my $fields = shift; | |
651 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=plunder&destinationCityId=%d", $self->{server}, $cityId)); | 652 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=plunder&destinationCityId=%d", $self->{server}, $cityId)); |
652 | 653 |
653 my $extractor = Ikariam::Extractor->new(content => $res->content); | 654 my $extractor = Ikariam::Extractor->new(content => $res->content); |
654 # check peace treaty | 655 # check peace treaty |
655 my $treaty = $extractor->find('//div[@class="warning"]'); | 656 my $treaty = $extractor->find('//div[@class="warning"]'); |
659 my $city = Ikariam::Cities->retrieve($cityId); | 660 my $city = Ikariam::Cities->retrieve($cityId); |
660 $city->delete; | 661 $city->delete; |
661 } else { | 662 } else { |
662 $self->{mech}->submit_form( | 663 $self->{mech}->submit_form( |
663 form_number => 1, | 664 form_number => 1, |
664 fields => { | 665 fields => $fields); |
665 # cargo_army_302 => '2', # 劍士 | 666 } |
666 cargo_army_303 => '3', # 方陣 | 667 } else { |
667 } | 668 # put the id in the friends.txt file. |
668 ); | 669 Ikariam::Cities->has_a(user => 'Ikariam::User'); |
670 my $city = Ikariam::Cities->retrieve($cityId); | |
671 my $sheep = $city->user; | |
672 | |
673 open(OUT, ">>friends.txt") or Carp::carp("can not open friends.txt"); | |
674 print OUT $sheep->name . "\n"; | |
675 close(OUT); | |
676 Carp::carp($treaty); | |
677 } | |
678 } | |
679 | |
680 | |
681 sub blockadeCity { | |
682 my $self = shift; | |
683 my $cityId = shift; | |
684 my $fields = shift; | |
685 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=blockade&destinationCityId=%d", $self->{server}, $cityId)); | |
686 | |
687 my $extractor = Ikariam::Extractor->new(content => $res->content); | |
688 # check peace treaty | |
689 my $treaty = $extractor->find('//div[@class="warning"]'); | |
690 if(!defined($treaty)) { | |
691 my @forms = $self->{mech}->forms(); | |
692 if($#forms < 1) { | |
693 my $city = Ikariam::Cities->retrieve($cityId); | |
694 $city->delete; | |
695 } else { | |
696 $self->{mech}->submit_form( | |
697 form_number => 1, | |
698 fields => $fields); | |
669 } | 699 } |
670 } else { | 700 } else { |
671 # put the id in the friends.txt file. | 701 # put the id in the friends.txt file. |
672 Ikariam::Cities->has_a(user => 'Ikariam::User'); | 702 Ikariam::Cities->has_a(user => 'Ikariam::User'); |
673 my $city = Ikariam::Cities->retrieve($cityId); | 703 my $city = Ikariam::Cities->retrieve($cityId); |