Mercurial > eagle-eye
annotate disturb.pl @ 364:7274d8f41d5f
refined the timing for sending ships
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sun, 01 Mar 2009 11:10:10 +0800 |
parents | 7f38a5cb769e |
children | 9f19fe8d189c |
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'))); | |
28 | |
29 # Create a new one. | |
30 $ikariam->changeCity($myCity); | |
31 $ikariam->blockadeCity($blockadeCity, { | |
32 blockadeDuration => 8*60*60, | |
33 cargo_fleet_211 => 1, # Flamethrower | |
34 }); | |
35 $ikariam->logout; | |
36 | |
37 sleep($travelTime*60); | |
38 next LOOP; | |
39 } | |
40 } | |
41 | |
42 $ikariam->login; | |
43 $ikariam->changeCity($myCity); | |
44 $ikariam->blockadeCity($blockadeCity, { | |
45 blockadeDuration => 8*60*60, | |
46 cargo_fleet_211 => 1, # Flamethrower | |
47 }); | |
48 $ikariam->logout; | |
49 sleep($travelTime*60); | |
50 } |