annotate sheep.pl @ 86:a8acf50bf7bb

implemented a simple MilityExpenditure counting
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 26 Oct 2008 14:30:58 +0800
parents 27b16506231f
children 6527b4b20d60
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;
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 15
diff changeset
7 my @tradegoodText = qw/NULL 葡萄酒 大理石 水晶 硫磺/;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
9 Ikariam::User->has_many(cities => 'Ikariam::Cities');
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
10 Ikariam::User->set_sql(inactivity => qq {
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
11 SELECT user.id
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
12 FROM user, cities, island
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
13 WHERE user.id == cities.user
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
14 AND cities.island == island.id
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
15 AND island.x <= ?
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
16 AND island.x >= ?
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
17 AND island.y <= ?
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
18 AND island.y >= ?
15
e68f4cadfabd fixed the 假期模式
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 11
diff changeset
19 AND cities.status = 'i'
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
20 }
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
21 );
24
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
22 #Ikariam::User->set_sql(sheeps => qq {
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
23 # SELECT user.id
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
24 # FROM user, cities, island
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
25 # WHERE user.id == cities.user
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
26 # AND cities.island == island.id
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
27 # AND island.x <= ?
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
28 # AND island.x >= ?
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
29 # AND island.y <= ?
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
30 # AND island.y >= ?
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
31 # AND user.trader_score_secondary >= 50000
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
32 # AND user.army_score_main <= 100
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
33 # }
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
34 #);
22
552528bb4917 refined the cache timeout is 12 hours.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
35
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36 Ikariam::User->set_sql(sheeps => qq {
24
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
37 SELECT user.id
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
38 FROM user, cities
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
39 WHERE user.id == cities.user
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
40 AND user.trader_score_secondary >= 200
41
5849b6fdc76c removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 33
diff changeset
41 AND user.army_score_main <= 100
24
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
42 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
43 }
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 );
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46 if($#ARGV != 1) {
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47 die("Usage: $0 x y\n");
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
48 }
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
49 my ($x, $y) = @ARGV;
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
50
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
51 listSheeps(Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6)));
15
e68f4cadfabd fixed the 假期模式
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 11
diff changeset
52 # listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6)));
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
53
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
54 sub listSheeps
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
55 {
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
56 my @sheeps = @_;
24
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
57 my %results;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
58
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
59 my $s;
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
60 foreach my $sheep (sort (@sheeps)) {
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
61 # avoid duplicate
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
62 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
63
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
64 # 查聯盟數量
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
65 my $members = 1;
15
e68f4cadfabd fixed the 假期模式
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 11
diff changeset
66 unless ($sheep->allyId == '0') {
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
67 $members = Ikariam::User->search(allyId => $sheep->allyId)->count();
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
68 }
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
69
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
70 foreach my $c ($sheep->cities) {
24
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
71 my $line = "";
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
72 # Ignore 假期模式
15
e68f4cadfabd fixed the 假期模式
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 11
diff changeset
73 next if($c->status eq 'v');
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
74
15
e68f4cadfabd fixed the 假期模式
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 11
diff changeset
75 unless($c->status eq 'i') {
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
76 next if($members > 5);
15
e68f4cadfabd fixed the 假期模式
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 11
diff changeset
77 }
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
78
24
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
79 my $island = Ikariam::Island->retrieve($c->island);
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
80
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
81 # 所得金錢 = 對方城鎮等級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
82 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
83
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
84 next if($capture < 100);
33
d183277b4d93 refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 24
diff changeset
85
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 65
diff changeset
86 $line = sprintf("%d %s score %d army %d %s/%s(%d),",
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
87 $capture,
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 65
diff changeset
88 $c->status, $sheep->score, $sheep->army_score_main, $sheep->name, $sheep->ally, $members);
24
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
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
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
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
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 15
diff changeset
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
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
98
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
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 }
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
103 # find_or_create