Mercurial > eagle-eye
comparison agent.pl @ 79:9d92e8c12f58
rewrited the code in XPath.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 24 Oct 2008 21:46:33 +0800 |
parents | 27b16506231f |
children | 7ab5fc8c847c |
comparison
equal
deleted
inserted
replaced
78:4120f560f214 | 79:9d92e8c12f58 |
---|---|
16 return bless $self, $class; | 16 return bless $self, $class; |
17 } | 17 } |
18 | 18 |
19 sub is_attacked { | 19 sub is_attacked { |
20 my ($self, $city) = @_; | 20 my ($self, $city) = @_; |
21 return ($city->{force}->{attacks} > 0 ) ? 1 : 0; | 21 # XXX |
22 return ($city->{wars}->{attacks} > 0 ) ? 1 : 0; | |
22 } | 23 } |
23 | 24 |
24 sub is_constructing { | 25 sub is_constructing { |
25 my ($self, $city) = @_; | 26 my ($self, $city) = @_; |
26 return ($city->{construction} > 0 ) ? 1 : 0; | 27 return ($city->{construction} > 0 ) ? 1 : 0; |
169 | 170 |
170 package main; | 171 package main; |
171 our $i = new Ikariam($::server, $::user, $::pass); | 172 our $i = new Ikariam($::server, $::user, $::pass); |
172 $i->login; | 173 $i->login; |
173 my $cities = $i->check; | 174 my $cities = $i->check; |
174 | |
175 my $rules = Ikariam::Cities::Rules->new; | 175 my $rules = Ikariam::Cities::Rules->new; |
176 my $tree = LoadFile('building.yaml'); | 176 my $tree = LoadFile('building.yaml'); |
177 # print Dumper($tree); | 177 # print Dumper($tree); |
178 # show cities. | 178 # show cities. |
179 foreach my $cityId (keys(%$cities)) { | 179 foreach my $cityId (keys(%$cities)) { |
180 printf("%s http://%s/index.php?view=city&id=%d\n", | 180 printf("%s http://%s/index.php?view=city&id=%d\n", |
181 $cities->{$cityId}->{name}, $::server, $cityId); | 181 $cities->{$cityId}->{name}, $::server, $cityId); |
182 printf("construction: %s\n", $cities->{$cityId}->{construction}); | 182 printf("construction: %s\n", $cities->{$cityId}->{construction}); |
183 | 183 |
184 foreach my $thing (qw/resources space force buildings citizens army fleet/) { | 184 # foreach my $thing (qw/resources space wars buildings citizens army fleet/) { |
185 foreach my $thing (qw/resources space buildings citizens army fleet/) { | |
185 printf("<%s>\n", uc($thing)); | 186 printf("<%s>\n", uc($thing)); |
186 foreach my $i (keys(%{$cities->{$cityId}->{$thing}})) { | 187 foreach my $i (keys(%{$cities->{$cityId}->{$thing}})) { |
187 printf("%s %s, ", $i, $cities->{$cityId}->{$thing}->{$i}); | 188 printf("%s %s, ", $i, $cities->{$cityId}->{$thing}->{$i}); |
188 } | 189 } |
189 print("\n"); | 190 print("\n"); |
205 } else { | 206 } else { |
206 | 207 |
207 } | 208 } |
208 } | 209 } |
209 # Debug | 210 # Debug |
210 # print(Dumper($cities->{$cityId}->{parse_path})); | 211 print(Dumper($cities->{$cityId}->{parse_path})); |
211 } | 212 } |
212 | 213 |
213 $i->logout; | 214 $i->logout; |
214 | 215 |
215 | 216 |
216 sub triggerAction { | 217 sub triggerAction { |
217 my ($action, $cityId) = @_; | 218 my ($action, $cityId) = @_; |
218 | 219 |
219 my ($func, $param) = split(/_/,$action); | 220 my ($func, $param) = split(/_/,$action); |
220 printf('$i->%s("%s", %s);'. "\n\n", $func, $param, $cityId); | 221 printf('$i->%s("%s", %s);'. "\n\n", $func, $param, $cityId); |
221 eval(sprintf('$i->%s("%s", %s);', $func, $param, $cityId)); | 222 # eval(sprintf('$i->%s("%s", %s);', $func, $param, $cityId)); |
222 warn $@ if $@; | 223 # warn $@ if $@; |
223 } | 224 } |