annotate disturb.pl @ 368:95148fdc1021

added time counting
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 05 Mar 2009 17:35:54 +0800
parents 7274d8f41d5f
children 9f19fe8d189c
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')));
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29 # Create a new one.
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30 $ikariam->changeCity($myCity);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 $ikariam->blockadeCity($blockadeCity, {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 blockadeDuration => 8*60*60,
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
33 cargo_fleet_211 => 1, # Flamethrower
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
34 });
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
35 $ikariam->logout;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
37 sleep($travelTime*60);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
38 next LOOP;
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
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
42 $ikariam->login;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
43 $ikariam->changeCity($myCity);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 $ikariam->blockadeCity($blockadeCity, {
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45 blockadeDuration => 8*60*60,
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46 cargo_fleet_211 => 1, # Flamethrower
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47 });
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
48 $ikariam->logout;
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
49 sleep($travelTime*60);
7f38a5cb769e dirtry trick
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
50 }