view sheep.pl @ 17:5ea88404dc74

ignore temp file.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 15:25:48 +0800
parents e68f4cadfabd
children fd44e3a1f800
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(inactivity => 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 cities.status = 'i'
    }
);
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 <= 25
    }
);

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

listSheeps(Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6)));
# listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6)));

sub listSheeps
{
    my @sheeps = @_;

    my $s;
    foreach my $sheep (sort (@sheeps)) {
        # avoid duplicate
        next if($sheep->id == $s); $s = $sheep->id;


        # 查聯盟數量
        my $members = 1;
        unless ($sheep->allyId == '0') {
            $members = Ikariam::User->search(allyId => $sheep->allyId)->count();
        }

        foreach my $c ($sheep->cities) {

            # 假期模式
            next if($c->status eq 'v');

            unless($c->status eq 'i') {
                next if($members > 3);
            }

            printf("%d %s %d,%d,%s of %s (%d),", 
                $sheep->trader_score_secondary, $c->status, $sheep->score, $sheep->army_score_main, $sheep->name, $sheep->ally, $members);

            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