annotate disturb.pl @ 363:3b2658751efa

fixed wall level
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 01 Mar 2009 11:09:44 +0800
parents 7f38a5cb769e
children 7274d8f41d5f
rev   line source
362
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
1 #!/usr/bin/perl
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
2 use strict;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
3 use Ikariam;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
4 use Data::Dumper;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
5 package main;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
6 my $ikariam = new Ikariam($::server, $::user, $::pass);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
7
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
8 if($#ARGV != 2) { die("Usage: $0 blockadeCity myCity travelTime\n"); }
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
9 my ($blockadeCity, $myCity, $travelTime) = @ARGV;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
10
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11 LOOP: while(1) {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
12 $ikariam->login;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
13 # delete the old event, and launch a new one.
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
14 my $res = $ikariam->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $::server));
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
15 my $extractor = new Ikariam::Extractor(content => $res->content);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
16 my $result = $extractor->{doc}->find(sprintf('//table[@class="locationEvents"]//tr[position() > 1]', $_));
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
17 foreach my $div ( @$result ) {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
18 my $extractor = new Ikariam::Extractor(content => $div->toString(1));
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
19 my $f = $extractor->find('//td[4]/a/@href');
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
20 my $t = $extractor->find('//td[8]/a/@href');
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
21 my $from_city = $1 if($f =~ /\?view=island&cityId=(\d+)/);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
22 my $to_city = $1 if($t =~ /\?view=island&cityId=(\d+)/);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
23
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
24 if($from_city == $myCity && $to_city == $blockadeCity) {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
25 # Cancel the last attack
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
26 $ikariam->{mech}->get(sprintf("http://%s/index.php%s", $::server, $extractor->find('//td[9]/a/@href')));
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
27
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28 # Create a new one.
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29 $ikariam->changeCity($myCity);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30 $ikariam->blockadeCity($blockadeCity, {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 blockadeDuration => 8*60*60,
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 cargo_fleet_211 => 1, # Flamethrower
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
33 });
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
34 $ikariam->logout;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
35
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36 sleep($travelTime*60);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
37 next LOOP;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
38 }
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
39 }
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
40
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
41 $ikariam->login;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
42 $ikariam->changeCity($myCity);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
43 $ikariam->blockadeCity($blockadeCity, {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 blockadeDuration => 8*60*60,
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45 cargo_fleet_211 => 1, # Flamethrower
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46 });
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47 $ikariam->logout;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
48 sleep($travelTime*60);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
49 }