view sheep.pl @ 173:e8a244ce5a1d

update the tavern setting
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 02 Nov 2008 04:12:00 +0800
parents 9b8aa30a532c
children 937fc672df56
line wrap: on
line source

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

package main;
my $mime = Ikariam::User->retrieve ('name' => $::user);
# only challenge the small victims
my $army_score_main = ($mime->army_score_main / 3);

my @tradegoodText = qw/NULL 葡萄酒 大理石 水晶 硫磺/;

Ikariam::User->has_many(cities => 'Ikariam::Cities');
Ikariam::User->has_a(ally => 'Ikariam::Ally');
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 
         WHERE user.id == cities.user 
           AND user.trader_score_secondary >= user.army_score_main*3
           AND user.army_score_main <= $army_score_main
           AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? )
    }
);

sub listSheeps
{
    my @sheeps = @_;
    my %results;

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

        # 查聯盟數量
        my $members = 1;
        unless ($sheep->allyId == '0') {
            unless (!defined($sheep->allyId) || $sheep->allyId == 0) {
                my $ally = Ikariam::Ally->retrieve($sheep->allyId);
                $members = $ally->members;
            }
        }

        foreach my $c ($sheep->cities) {
            my $line = "";
            # Ignore 假期模式
            next if($c->status eq 'v');

            unless($c->status eq 'i') {
                # Ignore 聯盟人數大於五
                # TODO 應該依照影響力來分
                next if($members > 10);
            }

            my $island = Ikariam::Island->retrieve($c->island);

            # 所得金錢 = 對方城鎮等級x(對方城鎮等級-1)x對方金錢/10000
            my $capture = $c->citylevel * ($c->citylevel - 1) * $sheep->trader_score_secondary / 10000;

            next if($capture < 200);

            # 測試風險評估
            # $capture = $capture - ($sheep->army_score_main*100);
                        
            $line = sprintf("%d %s score %d army %d %s/%s(%d),", 
                $capture,
                $c->status, $sheep->score, $sheep->army_score_main, $sheep->name, $sheep->ally, $members);

            $line .= sprintf("\"%s\" %d [%d,%d] %s http://%s/index.php?view=island&id=%d&selectCity=%d\n",
                $c->cityname, $c->citylevel, 
                $island->x, $island->y,
                $tradegoodText[$island->tradegood],
                $::server,
                $island->id,
                $c->cityId
            );

            printf("%s", $line);
        }
    }
}

__MAIN__:

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)));