Mercurial > eagle-eye
annotate sheep.pl @ 336:ff816ffffbd8
fixed timing issue
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Thu, 12 Feb 2009 03:25:20 +0800 |
parents | 7077be1a14d5 |
children | 6296a9cd6878 |
rev | line source |
---|---|
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1 #!/usr/bin/perl |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
2 use strict; |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
3 use Ikariam; |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
4 use Data::Dumper; |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
5 |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
6 package main; |
95
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
7 my $mime = Ikariam::User->retrieve ('name' => $::user); |
240
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
8 my $myAlly = undef; |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
9 $myAlly = Ikariam::Ally->retrieve($mime->allyId) |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
10 if(defined($mime->allyId) && $mime->allyId ne '0'); |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
11 |
95
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
12 # only challenge the small victims |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
13 my $army_score_main = ($mime->army_score_main / 3); |
302
efffa408eec5
refined the output of spy information
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
295
diff
changeset
|
14 $army_score_main = 300; |
95
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
15 |
18 | 16 my @tradegoodText = qw/NULL 葡萄酒 大理石 水晶 硫磺/; |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
17 |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
18 Ikariam::User->has_many(cities => 'Ikariam::Cities'); |
102
94c9cde99e19
check the ally by right phe ally page, not counting the members we scanned.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
95
diff
changeset
|
19 Ikariam::User->has_a(ally => 'Ikariam::Ally'); |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
20 Ikariam::User->set_sql(inactivity => qq { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
21 SELECT user.id |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
22 FROM user, cities, island |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
23 WHERE user.id == cities.user |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
24 AND cities.island == island.id |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
25 AND island.x <= ? |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
26 AND island.x >= ? |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
27 AND island.y <= ? |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
28 AND island.y >= ? |
15 | 29 AND cities.status = 'i' |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
30 } |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
31 ); |
22
552528bb4917
refined the cache timeout is 12 hours.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
32 |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
33 Ikariam::User->set_sql(sheeps => qq { |
24 | 34 SELECT user.id |
35 FROM user, cities | |
36 WHERE user.id == cities.user | |
95
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
37 AND user.trader_score_secondary >= user.army_score_main*3 |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
38 AND user.army_score_main <= $army_score_main |
24 | 39 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? ) |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
40 } |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
41 ); |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
42 |
324 | 43 sub travelTime { |
44 my ($x1, $y1, $x2, $y2, $speed) = @_; | |
45 $speed = 20 unless(defined($speed)); | |
46 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed)); | |
47 } | |
48 | |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
49 sub listSheeps |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
50 { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
51 my @sheeps = @_; |
24 | 52 my %results; |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
53 |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
54 my $s; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
55 foreach my $sheep (sort (@sheeps)) { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
56 # avoid duplicate |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
57 next if($sheep->id == $s); $s = $sheep->id; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
58 |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
59 foreach my $c ($sheep->cities) { |
24 | 60 my $line = ""; |
61 # Ignore 假期模式 | |
15 | 62 next if($c->status eq 'v'); |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
63 |
15 | 64 unless($c->status eq 'i') { |
240
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
65 # 依照影響力區分 |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
66 unless ($sheep->allyId == '0') { |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
67 unless (!defined($sheep->allyId) || $sheep->allyId == 0) { |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
68 my $ally = Ikariam::Ally->retrieve($sheep->allyId); |
249
c30080146c05
fixed the sheep.pl for ignore user without ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
241
diff
changeset
|
69 next if(!defined($ally)); |
240
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
70 next if($ally->score > $myAlly->score); |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
71 } |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
72 } |
15 | 73 } |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
74 |
24 | 75 my $island = Ikariam::Island->retrieve($c->island); |
76 | |
77 # 所得金錢 = 對方城鎮等級x(對方城鎮等級-1)x對方金錢/10000 | |
65
3a611c51b99b
for the new world, we only have sheep with a little gold. poor people.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
78 my $capture = $c->citylevel * ($c->citylevel - 1) * $sheep->trader_score_secondary / 10000; |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
79 |
102
94c9cde99e19
check the ally by right phe ally page, not counting the members we scanned.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
95
diff
changeset
|
80 next if($capture < 200); |
33
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
81 |
134
21df8eb17a52
commented an idea for risk assessment
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
102
diff
changeset
|
82 # 測試風險評估 |
21df8eb17a52
commented an idea for risk assessment
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
102
diff
changeset
|
83 # $capture = $capture - ($sheep->army_score_main*100); |
21df8eb17a52
commented an idea for risk assessment
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
102
diff
changeset
|
84 |
295
15c288dd7dc5
checking spy risks
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
249
diff
changeset
|
85 $line = sprintf("%d %s score %d army %d risk %d %s/%s,", |
324 | 86 travelTime($::x, $::y, $island->x, $island->y), |
87 # $capture, | |
295
15c288dd7dc5
checking spy risks
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
249
diff
changeset
|
88 $c->status, $sheep->score, $sheep->army_score_main, $c->risk, $sheep->name, $sheep->ally); |
24 | 89 |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
65
diff
changeset
|
90 $line .= sprintf("\"%s\" %d [%d,%d] %s http://%s/index.php?view=island&id=%d&selectCity=%d\n", |
24 | 91 $c->cityname, $c->citylevel, |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
92 $island->x, $island->y, |
18 | 93 $tradegoodText[$island->tradegood], |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
65
diff
changeset
|
94 $::server, |
33
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
95 $island->id, |
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
96 $c->cityId |
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
97 ); |
24 | 98 |
99 printf("%s", $line); | |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
100 } |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
101 } |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
102 } |
95
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
103 |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
104 __MAIN__: |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
105 |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
106 if($#ARGV != 1) { die("Usage: $0 x y\n"); } |
324 | 107 our ($x, $y) = @ARGV; |
95
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
108 |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
109 listSheeps(Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6))); |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
110 # listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6))); |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
111 |