changeset 125:4374173bab47

collect hometown island information.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 31 Oct 2008 00:20:41 +0800
parents f8c97e5d77ab
children 3196b1f5dc13 362184763c04
files Ikariam.pm warfare.pl
diffstat 2 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/Ikariam.pm	Thu Oct 30 17:25:20 2008 +0800
+++ b/Ikariam.pm	Fri Oct 31 00:20:41 2008 +0800
@@ -475,6 +475,15 @@
 
     $self->{'cities'}->{$cityId}->{name} = $extractor->find('//span[@class="city"]/text()');
 
+    my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]');
+    if($island =~ /(\w+)\[(\d+):(\d+)\]/) {
+        $self->{'cities'}->{$cityId}->{island}->{name} = $1;
+        $self->{'cities'}->{$cityId}->{island}->{x} = $2;
+        $self->{'cities'}->{$cityId}->{island}->{y} = $3;
+        $self->{'cities'}->{$cityId}->{island}->{id} = my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]/@href');
+        $self->{'cities'}->{$cityId}->{island}->{id} =~ s/\?view=island&id=(\d+)/$1/;
+    }
+    
     $self->{'cities'}->{$cityId}->{construction} = defined($extractor->find('//*[@class="constructionSite"]')) ? 1 : 0;
 
     # maxCapacity
@@ -687,7 +696,6 @@
     }
 }
 
-
 sub checkArmies
 {
     my $self = shift;
@@ -728,8 +736,7 @@
     # //li[@id="advDiplomacy"]/a[@class="normalalert"]
 
     # looking for cities
-    foreach my $cityId (keys(%{$self->{'cities'}})) 
-    {
+    foreach my $cityId (keys(%{$self->{'cities'}})) {
         $self->checkCity($cityId);
         $self->checkTownHall($cityId);
         $self->checkArmies($cityId);
--- a/warfare.pl	Thu Oct 30 17:25:20 2008 +0800
+++ b/warfare.pl	Fri Oct 31 00:20:41 2008 +0800
@@ -15,12 +15,16 @@
 Ikariam::Cities->set_sql(sheeps => qq {
         SELECT cities.cityId
           FROM user, cities 
-         WHERE user.id == cities.user 
-           AND user.army_score_main == 0
+         WHERE user.id = cities.user 
+           AND user.army_score_main = 0
            AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? )
+           AND cities.tradegood != ?
          ORDER BY cities.citylevel * (cities.citylevel - 1) * user.trader_score_secondary / 10000 DESC LIMIT 30
     }
 );
+# $island->tradegood, 
+# qw/NULL 葡萄酒 大理石 水晶 硫磺/;
+# 不打與自己相同的資源
 Ikariam::Report->set_sql(victim => qq {
         SELECT report.id
           FROM report
@@ -54,7 +58,7 @@
 
 sub locateVictim {
     my ($self, $city, $x, $y) = @_;
-    my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6));
+    my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6), $tradegood);
 
     foreach my $city (@cities) {
         my $sheep = $city->user;
@@ -97,8 +101,8 @@
 }
 
 sub engagement {
-    my ($self, $cityId, $x, $y) = @_;
-    my $victim = $self->locateVictim($cityId, $x, $y);
+    my ($self, $cityId, $x, $y, $tradegood) = @_;
+    my $victim = $self->locateVictim($cityId, $x, $y, $tradegood);
     if(defined($victim)) {
         $self->{ikariam}->changeCity($cityId);
         $self->{ikariam}->plunderCity($victim);
@@ -109,9 +113,6 @@
 
 package main;
 
-if($#ARGV != 1) { die("Usage: $0 x y\n"); }
-my ($x, $y) = @ARGV;
-
 our $i = new Ikariam($::server, $::user, $::pass);
 our $rules = Ikariam::Warfare::Rules->new($i);
 
@@ -119,7 +120,6 @@
 my $cities = $i->check;
 $i->checkMilitaryAdvisorCombatReports();
 
-
 foreach my $cityId (keys(%$cities)) {
     print Dump($i->{'military'});
     # build and upgrade for cities
@@ -127,7 +127,8 @@
     $cities->{$cityId}->{parse_path} = [];
     $cities->{$cityId}->{parse_answer} = undef;
     if(ParseTree($tree, $rules, $cities->{$cityId}) eq 'engagement') {
-        $rules->engagement($cityId, $x, $y);
+        my $island = Ikariam::Island->retrive($cities->{$cityId}->{island}->{id});
+        $rules->engagement($cityId, $island->{x}, $island->{y}, $island->tradegood);
         sleep(30);
         $i->checkMilitaryAdvisorMilitaryMovements();
     }