comparison warfare.pl @ 125:4374173bab47

collect hometown island information.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 31 Oct 2008 00:20:41 +0800
parents f8c97e5d77ab
children a5517f0abb85
comparison
equal deleted inserted replaced
124:f8c97e5d77ab 125:4374173bab47
13 Ikariam::Cities->has_a(user => 'Ikariam::User'); 13 Ikariam::Cities->has_a(user => 'Ikariam::User');
14 Ikariam::Cities->has_a(island => 'Ikariam::Island'); 14 Ikariam::Cities->has_a(island => 'Ikariam::Island');
15 Ikariam::Cities->set_sql(sheeps => qq { 15 Ikariam::Cities->set_sql(sheeps => qq {
16 SELECT cities.cityId 16 SELECT cities.cityId
17 FROM user, cities 17 FROM user, cities
18 WHERE user.id == cities.user 18 WHERE user.id = cities.user
19 AND user.army_score_main == 0 19 AND user.army_score_main = 0
20 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? ) 20 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? )
21 AND cities.tradegood != ?
21 ORDER BY cities.citylevel * (cities.citylevel - 1) * user.trader_score_secondary / 10000 DESC LIMIT 30 22 ORDER BY cities.citylevel * (cities.citylevel - 1) * user.trader_score_secondary / 10000 DESC LIMIT 30
22 } 23 }
23 ); 24 );
25 # $island->tradegood,
26 # qw/NULL 葡萄酒 大理石 水晶 硫磺/;
27 # 不打與自己相同的資源
24 Ikariam::Report->set_sql(victim => qq { 28 Ikariam::Report->set_sql(victim => qq {
25 SELECT report.id 29 SELECT report.id
26 FROM report 30 FROM report
27 WHERE report.city = ? 31 WHERE report.city = ?
28 AND report.date >= ? 32 AND report.date >= ?
52 return ($city->{army}->{Swordsman} >= 2 ) ? 1 : 0; 56 return ($city->{army}->{Swordsman} >= 2 ) ? 1 : 0;
53 } 57 }
54 58
55 sub locateVictim { 59 sub locateVictim {
56 my ($self, $city, $x, $y) = @_; 60 my ($self, $city, $x, $y) = @_;
57 my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6)); 61 my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6), $tradegood);
58 62
59 foreach my $city (@cities) { 63 foreach my $city (@cities) {
60 my $sheep = $city->user; 64 my $sheep = $city->user;
61 my $island = $city->island; 65 my $island = $city->island;
62 66
95 } 99 }
96 return undef; 100 return undef;
97 } 101 }
98 102
99 sub engagement { 103 sub engagement {
100 my ($self, $cityId, $x, $y) = @_; 104 my ($self, $cityId, $x, $y, $tradegood) = @_;
101 my $victim = $self->locateVictim($cityId, $x, $y); 105 my $victim = $self->locateVictim($cityId, $x, $y, $tradegood);
102 if(defined($victim)) { 106 if(defined($victim)) {
103 $self->{ikariam}->changeCity($cityId); 107 $self->{ikariam}->changeCity($cityId);
104 $self->{ikariam}->plunderCity($victim); 108 $self->{ikariam}->plunderCity($victim);
105 } 109 }
106 } 110 }
107 111
108 1; 112 1;
109 113
110 package main; 114 package main;
111 115
112 if($#ARGV != 1) { die("Usage: $0 x y\n"); }
113 my ($x, $y) = @ARGV;
114
115 our $i = new Ikariam($::server, $::user, $::pass); 116 our $i = new Ikariam($::server, $::user, $::pass);
116 our $rules = Ikariam::Warfare::Rules->new($i); 117 our $rules = Ikariam::Warfare::Rules->new($i);
117 118
118 $i->login; 119 $i->login;
119 my $cities = $i->check; 120 my $cities = $i->check;
120 $i->checkMilitaryAdvisorCombatReports(); 121 $i->checkMilitaryAdvisorCombatReports();
121
122 122
123 foreach my $cityId (keys(%$cities)) { 123 foreach my $cityId (keys(%$cities)) {
124 print Dump($i->{'military'}); 124 print Dump($i->{'military'});
125 # build and upgrade for cities 125 # build and upgrade for cities
126 my $tree = LoadFile('warfare.yaml'); 126 my $tree = LoadFile('warfare.yaml');
127 $cities->{$cityId}->{parse_path} = []; 127 $cities->{$cityId}->{parse_path} = [];
128 $cities->{$cityId}->{parse_answer} = undef; 128 $cities->{$cityId}->{parse_answer} = undef;
129 if(ParseTree($tree, $rules, $cities->{$cityId}) eq 'engagement') { 129 if(ParseTree($tree, $rules, $cities->{$cityId}) eq 'engagement') {
130 $rules->engagement($cityId, $x, $y); 130 my $island = Ikariam::Island->retrive($cities->{$cityId}->{island}->{id});
131 $rules->engagement($cityId, $island->{x}, $island->{y}, $island->tradegood);
131 sleep(30); 132 sleep(30);
132 $i->checkMilitaryAdvisorMilitaryMovements(); 133 $i->checkMilitaryAdvisorMilitaryMovements();
133 } 134 }
134 print Dump($cities->{$cityId}->{parse_path}); 135 print Dump($cities->{$cityId}->{parse_path});
135 } 136 }