Mercurial > eagle-eye
annotate disturb.pl @ 373:dd3d76f43999
update script for collecting ally information.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Tue, 14 Apr 2009 17:00:40 +0800 |
parents | 9f19fe8d189c |
children |
rev | line source |
---|---|
362 | 1 #!/usr/bin/perl |
2 use strict; | |
3 use Ikariam; | |
4 use Data::Dumper; | |
5 package main; | |
6 my $ikariam = new Ikariam($::server, $::user, $::pass); | |
7 | |
8 if($#ARGV != 2) { die("Usage: $0 blockadeCity myCity travelTime\n"); } | |
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 | 11 |
12 LOOP: while(1) { | |
13 $ikariam->login; | |
14 # delete the old event, and launch a new one. | |
15 my $res = $ikariam->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $::server)); | |
16 my $extractor = new Ikariam::Extractor(content => $res->content); | |
17 my $result = $extractor->{doc}->find(sprintf('//table[@class="locationEvents"]//tr[position() > 1]', $_)); | |
18 foreach my $div ( @$result ) { | |
19 my $extractor = new Ikariam::Extractor(content => $div->toString(1)); | |
20 my $f = $extractor->find('//td[4]/a/@href'); | |
21 my $t = $extractor->find('//td[8]/a/@href'); | |
22 my $from_city = $1 if($f =~ /\?view=island&cityId=(\d+)/); | |
23 my $to_city = $1 if($t =~ /\?view=island&cityId=(\d+)/); | |
24 | |
25 if($from_city == $myCity && $to_city == $blockadeCity) { | |
26 # Cancel the last attack | |
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 | 31 |
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 | 34 $ikariam->changeCity($myCity); |
35 $ikariam->blockadeCity($blockadeCity, { | |
36 blockadeDuration => 8*60*60, | |
37 cargo_fleet_211 => 1, # Flamethrower | |
38 }); | |
39 $ikariam->logout; | |
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 | 42 next LOOP; |
43 } | |
44 } | |
45 | |
46 $ikariam->login; | |
47 $ikariam->changeCity($myCity); | |
48 $ikariam->blockadeCity($blockadeCity, { | |
49 blockadeDuration => 8*60*60, | |
50 cargo_fleet_211 => 1, # Flamethrower | |
51 }); | |
52 $ikariam->logout; | |
53 sleep($travelTime*60); | |
54 } |