annotate sheep.pl @ 62:a4c364888197

add ikriam game binding lib python version
author hychen@mluna
date Wed, 22 Oct 2008 04:04:32 +0800
parents d2ac1e198ce4
children 3a611c51b99b
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
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
40 AND user.trader_score_secondary >= 20
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') {
e68f4cadfabd fixed the 假期模式
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 11
diff changeset
76 next if($members > 3);
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
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
82 my $robbery = $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
24
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
84 next if($robbery < 2000);
33
d183277b4d93 refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 24
diff changeset
85
24
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
86 $line = sprintf("%d %s army %d %s/%s(%d),",
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
87 $robbery,
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
88 $c->status, $sheep->army_score_main, $sheep->name, $sheep->ally, $members);
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
89
33
d183277b4d93 refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 24
diff changeset
90 $line .= sprintf("\"%s\" %d [%d,%d] %s http://s2.ikariam.tw/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],
33
d183277b4d93 refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 24
diff changeset
94 $island->id,
d183277b4d93 refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 24
diff changeset
95 $c->cityId
d183277b4d93 refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 24
diff changeset
96 );
24
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
97
93d4e6ffe330 refined the SQL.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 23
diff changeset
98 printf("%s", $line);
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
99 }
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
100 }
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 # find_or_create