# HG changeset patch # User "Rex Tsai " # Date 1236245763 -28800 # Node ID fb3cfa5533ac89d3ca5634a0a66bc02f1837a758 # Parent 95148fdc10218f6080b65be58605942b4ab50d7a# Parent 9c9d7a59420a21d280081c7dfde4fb1717f273fe merged diff -r 9c9d7a59420a -r fb3cfa5533ac Ikariam.pm --- a/Ikariam.pm Sat Feb 14 18:15:18 2009 +0800 +++ b/Ikariam.pm Thu Mar 05 17:36:03 2009 +0800 @@ -242,18 +242,19 @@ my $nodes = jsonToObj($c); my @islands; - print $nodes->{'data'}; +# print Dumper($nodes->{'data'}); foreach my $x (keys %{$nodes->{'data'}}) { foreach my $y (keys(%{$nodes->{data}->{$x}})) { my %island; - $island{id} = $nodes->{data}->{$x}->{$y}[0]; $island{x} = $x; $island{y} = $y; + + $island{id} = $nodes->{data}->{$x}->{$y}[0]; $island{name} = $nodes->{data}->{$x}->{$y}[1]; + $island{tradegood} = $nodes->{data}->{$x}->{$y}[2]; + $island{wonder} = $nodes->{data}->{$x}->{$y}[3]; + $island{people} = $nodes->{data}->{$x}->{$y}[6]; -# $island{tradegood} = $4; -# $island{wonder} = $5; -# $island{people} = $8; push @islands, \%island; } } @@ -637,9 +638,18 @@ my $city = Ikariam::Cities->retrieve($cityId); $city->delete; } else { - $self->{mech}->submit_form( - form_number => 1, - fields => $fields); + $self->{mech}->form_number(1); + + foreach my $k (keys(%{$fields})) { + eval{ + $self->{mech}->field($k, $fields->{$k}) + }; + warn $@ if($@); + } + $self->{mech}->submit(); +# $self->{mech}->submit_form( +# form_number => 1, +# fields => $fields); } } else { # put the id in the friends.txt file. @@ -1261,17 +1271,21 @@ password => $self->{pass}, ]); - my @cities = Ikariam::Extractor->new(content => $res->content)->find('//option[@class="avatarCities coords"]/@value'); + while (1) { + my @cities = Ikariam::Extractor->new(content => $res->content)->find('//option[@class="avatarCities coords"]/@value'); - if($#cities<0) { - die ("login failed\n"); - } - foreach (@cities) { - $self->{'cities'}->{$_} = {}; - $self->{'cities'}->{$_}->{id} = $_; - if(-f "city-$_-dump.yaml") { - $self->{'cities'}->{$_} = LoadFile("city-$_-dump.yaml"); + if($#cities<0) { + warn ("login failed\n"); + next; } + foreach (@cities) { + $self->{'cities'}->{$_} = {}; + $self->{'cities'}->{$_}->{id} = $_; + if(-f "city-$_-dump.yaml") { + $self->{'cities'}->{$_} = LoadFile("city-$_-dump.yaml"); + } + } + last; } } diff -r 9c9d7a59420a -r fb3cfa5533ac agent.pl --- a/agent.pl Sat Feb 14 18:15:18 2009 +0800 +++ b/agent.pl Thu Mar 05 17:36:03 2009 +0800 @@ -33,8 +33,7 @@ my ($self, $city) = @_; # http://ikariam.wikia.com/wiki/Wall_Defense # Basic rule - the wall level must equale or large then townHall level. - return ($city->{buildings}->{wall} >= 24 ? 1 : 0); -# return ($city->{buildings}->{wall} >= $city->{buildings}->{townHall} ? 1 : 0); + return ($city->{buildings}->{wall} >= $city->{buildings}->{townHall} ? 1 : 0); } sub is_academy_enough { @@ -99,6 +98,8 @@ sub is_warehouse_enough { my ($self, $city) = @_; + + return 1; # my @warehouse = (qw/undef undef 0 4 9 16 18 19 20 21 22 23 24 25/); my @warehouse = (qw/undef undef 0 4 9 15 17 18 19 20 21 22 23 24/); my @cities = keys(%{$self->{ikariam}->{cities}}); @@ -439,12 +440,12 @@ # $i->set("tavern", $cityId); # build military! - $tree = LoadFile('military.yaml'); - $cities->{$cityId}->{parse_path} = []; - $cities->{$cityId}->{parse_answer} = undef; - if (my $action = ParseTree($tree, $rules, $cities->{$cityId})) { - triggerAction($action, $cityId); - } +# $tree = LoadFile('military.yaml'); +# $cities->{$cityId}->{parse_path} = []; +# $cities->{$cityId}->{parse_answer} = undef; +# if (my $action = ParseTree($tree, $rules, $cities->{$cityId})) { +# triggerAction($action, $cityId); +# } DumpFile("military-$cityId-dump.yaml", $cities->{$cityId}); # build and upgrade for cities diff -r 9c9d7a59420a -r fb3cfa5533ac attacker_travel.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/attacker_travel.pl Thu Mar 05 17:36:03 2009 +0800 @@ -0,0 +1,143 @@ +#!/usr/bin/perl +use strict; + +use Data::Dumper; +use Ikariam; +use YAML qw/LoadFile/; +# return minutes. +sub travelTime { + my ($x1, $y1, $x2, $y2, $speed) = @_; + $speed = 60 unless(defined($speed)); + if($x1 == $x2 && $y1 == $y2) { + return 600/$speed; + } else { + return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed)); + } +} + +Ikariam::User->has_many(cities => 'Ikariam::Cities'); +Ikariam::Cities->has_a(island => 'Ikariam::Island'); +Ikariam::Cities->set_sql(ally => qq { + SELECT cities.cityid + FROM cities + WHERE cities.ally = ? + }); + + +sub allyTownToVicim { + my $islandId = shift; + + my $mime = Ikariam::User->retrieve(name => $::user); + my $ally = $mime->ally; + my $iterator = Ikariam::Cities->search_ally($mime->ally); + if(my $island = Ikariam::Island->retrieve($islandId)) { + + my @cities = (); + while(my $target = $iterator->next) { + my $city; + $city->{id} = $target->id; + $city->{name} = $target->cityname; + $city->{owner} = $target->owner; + $city->{island}->{id} = $target->island->id; + $city->{island}->{x} = $target->island->x; + $city->{island}->{y} = $target->island->y; + $city->{distance} = + travelTime($target->island->x, $target->island->y, $island->x, $island->y) ; + + push (@cities, $city); + } + + @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities); + + for my $x (0..$#cities) { + printf("%s (%s)\t- ", $cities[$x]->{name}, $cities[$x]->{owner}); + printf("Land %3d Ship %3d Catapult %3d Ram %3d\n", + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 60), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 33), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 26), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 40), + ); +# last if($x > 5); + } + } +} + +sub myTownToVicim { + my $islandId = shift; + + my @cities = (); + foreach (glob("city-*-dump.yaml")) { + my $city = LoadFile($_); + push (@cities, $city); + } + my $n = $#cities; + + + if(my $island = Ikariam::Island->retrieve($islandId)) { + + for my $x (0..$n) { + printf("%s\t- ", $cities[$x]->{name}); + printf("Land %3d Ship %3d Catapult %3d Ram %3d\n", + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 8), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 6), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 10), + ); + } + } +} + +sub cityToIsland { + my (@city, $island); +} + +package main; + +my $userName = $ARGV[0]; +my @cities = (); +if(my $user = Ikariam::User->retrieve(name => $userName)) { + foreach my $target ($user->cities) { + my $island = $target->island; + my $city; + $city->{id} = $target->id; + $city->{name} = $target->cityname; + $city->{island}->{id} = $island->id; + $city->{island}->{x} = $island->x; + $city->{island}->{y} = $island->y; + + push (@cities, $city); + } +} + +my $n = $#cities; + +# Print them out. +# header +printf(" %5s ", undef); +for my $y (0..$n) { + printf ("%5s ", $cities[$y]->{id}); +} +print "\n"; + +# body +for my $x (0..$n) { + printf(" %5s ", $cities[$x]->{id}); + my $total = 0; + for my $y (0..$n) { + my $t = travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $cities[$y]->{island}->{x}, $cities[$y]->{island}->{y}); + printf("%5s ", $t); + $total += $t; + } + printf(" %s", $cities[$x]->{name}); + printf("\n"); +} +printf("\n"); + + +for my $i (0..$n) { + printf("To: %s [%d:%d] http://%s/index.php?view=island&cityId=%s\n", $cities[$i]->{name}, $cities[$i]->{island}->{x}, $cities[$i]->{island}->{y}, $::server, $cities[$i]->{id}); +# myTownToVicim($cities[$i]->{island}->{id}); +# printf("\n"); + allyTownToVicim($cities[$i]->{island}->{id}); + printf("\n"); +} diff -r 9c9d7a59420a -r fb3cfa5533ac defend-network.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/defend-network.pl Thu Mar 05 17:36:03 2009 +0800 @@ -0,0 +1,1 @@ +../gamma/defend-network.pl \ No newline at end of file diff -r 9c9d7a59420a -r fb3cfa5533ac disturb.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/disturb.pl Thu Mar 05 17:36:03 2009 +0800 @@ -0,0 +1,50 @@ +#!/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; +$travelTime = ($travelTime - 10); + +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); +} diff -r 9c9d7a59420a -r fb3cfa5533ac enemy.pl --- a/enemy.pl Sat Feb 14 18:15:18 2009 +0800 +++ b/enemy.pl Thu Mar 05 17:36:03 2009 +0800 @@ -13,8 +13,12 @@ sub travelTime { my ($x1, $y1, $x2, $y2, $speed) = @_; - $speed = 20 unless(defined($speed)); - return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed)); + $speed = 60 unless(defined($speed)); + if($x1 == $x2 && $y1 == $y2) { + return 600/$speed; + } else { + return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed)); + } } sub travelMatrix { @@ -27,10 +31,11 @@ my $city; $city->{id} = $target->id; $city->{name} = $target->cityname; - $city->{island}->{id} = $island->id; - $city->{island}->{x} = $island->x; - $city->{island}->{y} = $island->y; - + if(defined($island)) { + $city->{island}->{id} = $island->id; + $city->{island}->{x} = $island->x; + $city->{island}->{y} = $island->y; + } push (@cities, $city); } } @@ -68,7 +73,7 @@ my @cities = (); foreach (glob("city-*-dump.yaml")) { my $city = LoadFile($_); - $city->{distance} = travelTime($island->x, $island->y, $city->{island}->{x}, $city->{island}->{y}, 20); + $city->{distance} = travelTime($island->x, $island->y, $city->{island}->{x}, $city->{island}->{y}, 60); push (@cities, $city); } @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities); @@ -77,10 +82,10 @@ for my $x (0..$n) { printf("%s (%d)\t- ", $cities[$x]->{name}, $cities[$x]->{id}); printf("Land %3d Ship %3d Catapult %3d Ram %3d\n", - travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y), - travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 8), - travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 6), - travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 10), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 60), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 33), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 26), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 40), ); } } @@ -104,7 +109,7 @@ printf("\nCities\n"); foreach my $city ($u->cities) { my $island = Ikariam::Island->retrieve($city->island); - my $capture = $city->citylevel * ($city->citylevel - 1) * $u->trader_score_secondary / 10000; + next if(!defined($island)); printf("Name: %s [%s:%s]\n", $city->cityname, $island->x, $island->y); if(defined($city->status)) { @@ -123,12 +128,11 @@ $spydata->{city}->{buildings}->{wall}, $spydata->{city}->{buildings}->{port}, $spydata->{city}->{buildings}->{safehouse}, - $spydata->{risks}[1]); + $spydata->{risks}[4]); } else { printf("Level: %s, Rsik %d\n", $city->citylevel, $city->risk); } - printf("Capture: %d\n", $capture); printf("Tradegood: %s, Wonder: %s\n", $tradegoodText[$island->tradegood], $wonderText[$island->wonder]); # printf("Island: %s\n", $island->name); diff -r 9c9d7a59420a -r fb3cfa5533ac planner.pl --- a/planner.pl Sat Feb 14 18:15:18 2009 +0800 +++ b/planner.pl Thu Mar 05 17:36:03 2009 +0800 @@ -4,6 +4,7 @@ use Decision::ParseTree q{ParseTree}; use YAML qw/LoadFile Dump DumpFile/; use Getopt::Std; +use POSIX qw(strftime); Ikariam::Cities->has_a(island => 'Ikariam::Island'); @@ -34,6 +35,12 @@ "DivingBoat" => 212, }; + +sub calcTime { + my ($gooff, $travelTime) = @_; + return (sprintf("%s-%s", strftime("%H:%M", localtime(time+$gooff*60)), strftime("%H:%M", localtime(time+($gooff+$travelTime)*60)))); +} + # return minutes. sub travelTime { my ($x1, $y1, $x2, $y2, $speed) = @_; @@ -47,78 +54,114 @@ package main; -getopts('w'); + if($#ARGV < 2) { - die("Usage: %s targetCity navyCity armyCity wingman1.. wingman2..\n"); + die("Usage: %s -n 1 -a 1 -v 21 targetCity navyCity armyCity wingman1.. wingman2..\n"); } -my $targetCityId = shift(@ARGV); -my $navyCity = shift(@ARGV); -my $armyCity = shift(@ARGV); -my @wingman = @ARGV; +getopts('wa:n:v:'); +$opt_n = defined($opt_n) ? $opt_n : 1; +$opt_a = defined($opt_a) ? $opt_a : 1; +my $vanguard = defined($opt_v) ? $opt_v : 21; +my $targetCityId = shift(@ARGV); my $targetCity = Ikariam::Cities->retrieve($targetCityId); - - +my @cities; # NAVY -my $city = LoadFile(sprintf("city-%s-dump.yaml", $navyCity)); -$city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 33) + 25; -$city->{type} = "navy"; -push (@cities, $city); +foreach my $i (1..$opt_n) { + my $navyCity = shift(@ARGV); + my $city = LoadFile(sprintf("city-%s-dump.yaml", $navyCity)); + $city->{travelTime} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 33); + $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 33) + $vanguard; + if($i == 1) { + $city->{distance} += 8; + } else { + $city->{distance} += 5; + } + $city->{type} = "navy"; + $city->{queue} = "navy" . $i; + push (@cities, $city); +} # ARMY -my $city = LoadFile(sprintf("city-%s-dump.yaml", $armyCity)); -$city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) + 5; -$city->{type} = "army"; -push (@cities, $city); +foreach my $i (1..$opt_a) { + my $armyCity = shift(@ARGV); + my $city = LoadFile(sprintf("city-%s-dump.yaml", $armyCity)); + $city->{travelTime} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); + $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) + $vanguard; + if($i == 1) { + $city->{distance} += 5; + } else { + $city->{distance} += 1; + } + $city->{type} = "army"; + $city->{queue} = "army" . $i; + push (@cities, $city); +} # wingman, army -foreach my $i (0..$#wingman) { - my $cityId = $wingman[$i]; +while(defined($cityId = shift(@ARGV))) { my $city = LoadFile(sprintf("city-%s-dump.yaml", $cityId)); - $city->{type} = "wingman" . ($i+1); + $city->{type} = "wingman"; + $city->{queue} = "wingman"; + $city->{travelTime} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); + $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); if(defined($opt_w)) { - $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) - ($i * 20 + 20); - } else { - $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); + $city->{distance} -= ($i * 20 + 20); } push (@cities, $city); } -@cities = sort { $a->{distance} <=> $b->{distance}; } (@cities); - - # print the code. print <owner, $targetCity->cityname, $targetCity->island->x, $targetCity->island->y); printf ("# http://%s/index.php?view=island&id=%d&selectCity=%d\n", $::server, $targetCity->island->id, $targetCity->id); +printf("#\n"); +printf("my \$delay = 0; # minutes\n"); -for(my $i = ($#cities + 1) ; $i-- ; $i < 0 ) { +@cities = sort { $b->{distance} <=> $a->{distance}; } (@cities); +foreach my $i (0..$#cities) { + printf('printf("%%s %s %s %s %sm\n", calcTime(%s - %s + $delay, %s));', + $cities[$i]->{queue}, $cities[$i]->{name}, $cities[$i]->{id}, $cities[$i]->{travelTime}, + $cities[0]->{distance}, $cities[$i]->{distance}, $cities[$i]->{travelTime}); + printf(" # %s\n", calcTime($cities[0]->{distance} - $cities[$i]->{distance}, $cities[$i]->{travelTime})); +} +printf("printf('Press Enter to start...');\n"); +printf(";\n"); - if($i ne $#cities) { +foreach my $i (0..$#cities) { + if($i ne 0) { # TODO, 計算港口速度 # 減掉 cities[$i+1]->buliding->port 的速度 printf("sleep(%d*60);\n", - ($cities[$i+1]->{distance} - $cities[$i]->{distance})); + ($cities[$i-1]->{distance} - $cities[$i]->{distance})); } - printf("\n# %s %s %dm\n", $cities[$i]->{name}, $cities[$i]->{type}, $cities[$i]->{distance}); + + printf("\n# %s %s %dm\n", $cities[$i]->{name}, $cities[$i]->{queue}, $cities[$i]->{travelTime}); printf("# ActionPoint %d/%d\n", $cities[$i]->{actionPoints}, $cities[$i]->{maxActionPoints}); printf('$ikariam->login;' . "\n"); if($cities[$i]->{type} eq "navy") { printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); printf('$ikariam->blockadeCity(%d, {' . "\n", $targetCity->id); - printf("\tblockadeDuration => 2*60*60," . "\n"); + printf("\tblockadeDuration => 8*60*60," . "\n"); while (my ($k, $v) = each(%{$cities[$i]->{fleet}})) { if($v > 0) { - printf("\tcargo_fleet_%s => %s, # %s \n", $fleet->{$k}, $v, $k); + printf("\tcargo_fleet_%s => %s, # %s (%d)\n", $fleet->{$k}, 0, $k, $v); } } printf('});' . "\n", $cities[$i]->{id}); @@ -127,10 +170,10 @@ printf('$ikariam->plunderCity(%d, {' . "\n", $targetCity->id); while (my ($k, $v) = each(%{$cities[$i]->{army}})) { if($v > 0) { - printf("\tcargo_army_%s => %s, # %s \n", $army->{$k}, $v, $k); + printf("\tcargo_army_%s => %s, # %s (%d)\n", $army->{$k}, $v, $k, $v); } } - printf("\ttransporter => %s, # transporter\n", $cities[$i]->{transporters}->{avail}); + printf("\ttransporter => 0, # transporter (%s)\n", $cities[$i]->{transporters}->{avail}); printf('});' . "\n", $cities[$i]->{id}); } printf('$ikariam->logout;' . "\n"); diff -r 9c9d7a59420a -r fb3cfa5533ac sheep.pl --- a/sheep.pl Sat Feb 14 18:15:18 2009 +0800 +++ b/sheep.pl Thu Mar 05 17:36:03 2009 +0800 @@ -6,11 +6,11 @@ package main; my $mime = Ikariam::User->retrieve ('name' => $::user); my $myAlly = undef; -$myAlly = Ikariam::Ally->retrieve($mime->allyId) - if(defined($mime->allyId) && $mime->allyId ne '0'); +$myAlly = Ikariam::Ally->retrieve($mime->allyId) if(defined($mime->allyId) && $mime->allyId ne '0'); # only challenge the small victims -my $army_score_main = ($mime->army_score_main / 3); +# my $army_score_main = ($mime->army_score_main / 3); +my $army_score_main = $mime->army_score_main; my @tradegoodText = qw/NULL 葡萄酒 大理石 水晶 硫磺/; @@ -33,8 +33,7 @@ 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 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 >= ? ) } ); @@ -64,20 +63,22 @@ # Ignore 假期模式 next if($c->status eq 'v'); - unless($c->status eq 'i') { - # 依照影響力區分 - unless ($sheep->allyId == '0') { - unless (!defined($sheep->allyId) || $sheep->allyId == 0) { - my $ally = Ikariam::Ally->retrieve($sheep->allyId); - next if(!defined($ally)); - next if($ally->score > $myAlly->score); - } - } - } +# unless($c->status eq 'i') { +# # 依照影響力區分 +# unless ($sheep->allyId == '0') { +# unless (!defined($sheep->allyId) || $sheep->allyId == 0) { +# my $ally = Ikariam::Ally->retrieve($sheep->allyId); +# next if(!defined($ally)); +# next if($ally->score > $myAlly->score); +# } +# } +# } + next if($mime->allyId == $sheep->allyId); + next if($c->citylevel <= 5); + next if($c->risk >= 50); my $island = Ikariam::Island->retrieve($c->island); - $line = sprintf("%d %s score %d army %d risk %d %s/%s,", travelTime($::x, $::y, $island->x, $island->y), # $capture, diff -r 9c9d7a59420a -r fb3cfa5533ac victim_travel.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/victim_travel.pl Thu Mar 05 17:36:03 2009 +0800 @@ -0,0 +1,97 @@ +#!/usr/bin/perl +use strict; + +use Data::Dumper; +use Ikariam; +use YAML qw/LoadFile/; + +Ikariam::User->has_many(cities => 'Ikariam::Cities'); + +sub travelTime { + my ($x1, $y1, $x2, $y2, $speed) = @_; + $speed = 60 unless(defined($speed)); + if($x1 == $x2 && $y1 == $y2) { + return 600/$speed; + } else { + return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed)); + } +} + +sub myTownToVicim { + my $islandId = shift; + + my @cities = (); + foreach (glob("city-*-dump.yaml")) { + my $city = LoadFile($_); + push (@cities, $city); + } + my $n = $#cities; + + if(my $island = Ikariam::Island->retrieve($islandId)) { + for my $x (0..$n) { + printf("%s\t- ", $cities[$x]->{name}); + printf("Land %3d Ship %3d Catapult %3d Ram %3d\n", + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 60), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 33), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 26), + travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 40), + ); + } + } +} + +sub cityToIsland { + my (@city, $island); +} + +package main; + +my $userName = $ARGV[0]; +my @cities = (); +if(my $user = Ikariam::User->retrieve(name => $userName)) { + + foreach my $target ($user->cities) { + my $island = Ikariam::Island->retrieve($target->island); + my $city; + $city->{id} = $target->id; + $city->{name} = $target->cityname; + $city->{island}->{id} = $island->id; + $city->{island}->{x} = $island->x; + $city->{island}->{y} = $island->y; + + push (@cities, $city); + } +} + +my $n = $#cities; + +# Print them out. +# header +printf("Defence\n"); +printf(" %5s ", undef); +for my $y (0..$n) { + printf ("%5s ", $cities[$y]->{id}); +} +print "\n"; + +# body +for my $x (0..$n) { + printf(" %5s ", $cities[$x]->{id}); + my $total = 0; + for my $y (0..$n) { + my $t = travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $cities[$y]->{island}->{x}, $cities[$y]->{island}->{y}); + printf("%5s ", $t); + $total += $t; + } + printf(" %s", $cities[$x]->{name}); + printf("\n"); +} +printf("\n"); + + +for my $i (0..$n) { + printf("To: %s [%d:%d] http://%s/index.php?view=island&id=%s&selectCity=%s\n", + $cities[$i]->{name}, $cities[$i]->{island}->{x}, $cities[$i]->{island}->{y}, $::server, $cities[$i]->{island}->{id}, $cities[$i]->{id}); + myTownToVicim($cities[$i]->{island}->{id}); + printf("\n"); +}