annotate disturb.pl @ 376:6ca0677a361e

refiend output format and fixed timing issue.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Tue, 14 Apr 2009 17:02:17 +0800
parents 9f19fe8d189c
children
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;
364
7274d8f41d5f refined the timing for sending ships
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 362
diff changeset
10 $travelTime = ($travelTime - 10);
362
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
12 LOOP: while(1) {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
13 $ikariam->login;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
14 # delete the old event, and launch a new one.
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
15 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
16 my $extractor = new Ikariam::Extractor(content => $res->content);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
17 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
18 foreach my $div ( @$result ) {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
19 my $extractor = new Ikariam::Extractor(content => $div->toString(1));
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
20 my $f = $extractor->find('//td[4]/a/@href');
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
21 my $t = $extractor->find('//td[8]/a/@href');
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
22 my $from_city = $1 if($f =~ /\?view=island&cityId=(\d+)/);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
23 my $to_city = $1 if($t =~ /\?view=island&cityId=(\d+)/);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
24
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
25 if($from_city == $myCity && $to_city == $blockadeCity) {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
26 # Cancel the last attack
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
27 $ikariam->{mech}->get(sprintf("http://%s/index.php%s", $::server, $extractor->find('//td[9]/a/@href')));
372
9f19fe8d189c withdraw the ship 10 minutes first, we have only need 2 ships for blocking a town.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 364
diff changeset
28 $ikariam->logout;
9f19fe8d189c withdraw the ship 10 minutes first, we have only need 2 ships for blocking a town.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 364
diff changeset
29
9f19fe8d189c withdraw the ship 10 minutes first, we have only need 2 ships for blocking a town.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 364
diff changeset
30 sleep(60);
362
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 # Create a new one.
372
9f19fe8d189c withdraw the ship 10 minutes first, we have only need 2 ships for blocking a town.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 364
diff changeset
33 $ikariam->login;
362
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
34 $ikariam->changeCity($myCity);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
35 $ikariam->blockadeCity($blockadeCity, {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36 blockadeDuration => 8*60*60,
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
37 cargo_fleet_211 => 1, # Flamethrower
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 $ikariam->logout;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
40
372
9f19fe8d189c withdraw the ship 10 minutes first, we have only need 2 ships for blocking a town.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 364
diff changeset
41 sleep(($travelTime-1)*60);
362
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
42 next LOOP;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
43 }
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 }
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46 $ikariam->login;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47 $ikariam->changeCity($myCity);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
48 $ikariam->blockadeCity($blockadeCity, {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
49 blockadeDuration => 8*60*60,
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
50 cargo_fleet_211 => 1, # Flamethrower
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
51 });
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
52 $ikariam->logout;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
53 sleep($travelTime*60);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
54 }