view 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
line wrap: on
line source

#!/usr/bin/perl
use strict;
use Ikariam;
use Data::Dumper;
package main;
my $ikariam = new Ikariam($::server, $::user, $::pass);

if($#ARGV != 2) { die("Usage: $0 blockadeCity myCity travelTime\n"); }
my ($blockadeCity, $myCity, $travelTime) = @ARGV;

LOOP: while(1) {
    $ikariam->login;
    # delete the old event, and launch a new one.
    my $res = $ikariam->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $::server));
    my $extractor = new Ikariam::Extractor(content => $res->content);
    my $result = $extractor->{doc}->find(sprintf('//table[@class="locationEvents"]//tr[position() > 1]', $_));
    foreach my $div ( @$result ) {
        my $extractor = new Ikariam::Extractor(content => $div->toString(1));
        my $f = $extractor->find('//td[4]/a/@href');
        my $t = $extractor->find('//td[8]/a/@href');
        my $from_city = $1 if($f =~ /\?view=island&cityId=(\d+)/);
        my $to_city = $1 if($t =~ /\?view=island&cityId=(\d+)/);

        if($from_city == $myCity && $to_city == $blockadeCity) {
            # Cancel the last attack
            $ikariam->{mech}->get(sprintf("http://%s/index.php%s", $::server, $extractor->find('//td[9]/a/@href')));

            # Create a new one.
            $ikariam->changeCity($myCity);
            $ikariam->blockadeCity($blockadeCity, {
                    blockadeDuration => 8*60*60,
                    cargo_fleet_211 => 1, # Flamethrower 
                    });
            $ikariam->logout;

            sleep($travelTime*60);
            next LOOP;
        }
    }

    $ikariam->login;
    $ikariam->changeCity($myCity);
    $ikariam->blockadeCity($blockadeCity, {
            blockadeDuration => 8*60*60,
            cargo_fleet_211 => 1, # Flamethrower 
            });
    $ikariam->logout;
    sleep($travelTime*60);
}