view sheep.pl @ 8:e4b3168d0319

implemented sheep and enemy scripts.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 04:23:01 +0800
parents
children f590b5ea5e55
line wrap: on
line source

#!/usr/bin/perl
use strict;
use Ikariam;
use Data::Dumper;

package main;

Ikariam::User->has_many(cities => 'Ikariam::Cities');
Ikariam::User->set_sql(sheeps => qq {
    SELECT user.id 
      FROM user, cities, island
      WHERE user.id == cities.user
        AND cities.island == island.id
        AND island.x <= ?
        AND island.x >= ?
        AND island.y <= ?
        AND island.y >= ?
        AND user.score >= 500 
        AND user.army_score_main <= 20
    }
);

if($#ARGV != 1) {
    die("Usage: $0 x y\n");
}
my ($x, $y) = @ARGV;

my @sheeps = Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6));
my $s;
foreach my $sheep (sort (@sheeps)) {
    # avoid duplicate
    next if($sheep->id == $s); $s = $sheep->id;

    # 查聯盟數量
    next if(Ikariam::User->search(allyId => $sheep->allyId)->count() > 3);

    printf("%s (%s),%d,%d\n", $sheep->name, $sheep->ally, $sheep->score, $sheep->army_score_main);
    # print Dumper($sheep->_data_hash);
    foreach my $c ($sheep->cities) {
        # print Dumper($c->_data_hash);
        my $island = Ikariam::Island->retrieve($c->island);
        printf("%s,%d,(%d,%d),http://s2.ikariam.tw/index.php?view=island&id=%d\n", $c->cityname, $c->citylevel, 
            $island->x, $island->y,
            $island->id);
    }
    printf("\n");
}

# find_or_create