comparison warfare.pl @ 122:11541129a389

fixed for counting ally members.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 30 Oct 2008 16:19:24 +0800
parents d3bece9b06b2
children f8c97e5d77ab
comparison
equal deleted inserted replaced
121:0bab14dddf60 122:11541129a389
8 package Ikariam::Warfare::Rules; 8 package Ikariam::Warfare::Rules;
9 use strict; 9 use strict;
10 use Data::Dumper; 10 use Data::Dumper;
11 11
12 Ikariam::User->has_many(cities => 'Ikariam::Cities'); 12 Ikariam::User->has_many(cities => 'Ikariam::Cities');
13 Ikariam::User->has_a(ally => 'Ikariam::Ally');
14 Ikariam::Cities->has_a(user => 'Ikariam::User'); 13 Ikariam::Cities->has_a(user => 'Ikariam::User');
15 Ikariam::Cities->has_a(island => 'Ikariam::Island'); 14 Ikariam::Cities->has_a(island => 'Ikariam::Island');
16 Ikariam::Cities->set_sql(sheeps => qq { 15 Ikariam::Cities->set_sql(sheeps => qq {
17 SELECT cities.cityId 16 SELECT cities.cityId
18 FROM user, cities 17 FROM user, cities
48 return ($city->{actionPoints} > ($city->{maxActionPoints}/2) ) ? 1 : 0; 47 return ($city->{actionPoints} > ($city->{maxActionPoints}/2) ) ? 1 : 0;
49 } 48 }
50 49
51 sub is_army_available { 50 sub is_army_available {
52 my ($self, $city) = @_; 51 my ($self, $city) = @_;
53 return ($city->{army}->{Swordsman} > 2 ) ? 1 : 0; 52 return ($city->{army}->{Swordsman} >= 2 ) ? 1 : 0;
54 } 53 }
55 54
56 sub locateVictim { 55 sub locateVictim {
57 my ($self, $city, $x, $y) = @_; 56 my ($self, $city, $x, $y) = @_;
58 my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6)); 57 my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6));
62 my $island = $city->island; 61 my $island = $city->island;
63 62
64 # Ignore 假期模式 63 # Ignore 假期模式
65 next if($city->status eq 'v'); 64 next if($city->status eq 'v');
66 unless ($city->status eq 'i') { 65 unless ($city->status eq 'i') {
67 unless ($sheep->allyId == '0') { 66 unless (!defined($sheep->allyId) || $sheep->allyId == 0) {
68 my $ally = $sheep->ally; 67 my $ally = Ikariam::Ally->retrieve($sheep->allyId);
69 # Ignore 聯盟人數大於10 68 # Ignore the ally which have more then 10 members.
69 # We don't want to piss off the big team.
70 next if(defined($ally) && $ally->members > 10); 70 next if(defined($ally) && $ally->members > 10);
71 } 71 }
72 } 72 }
73 73
74 # check if we over-attacked 74 # check if we over-attacked
75 my $c = Ikariam::Report->search_victim($city->cityId, time - 24*60*60 - 7*60*60)->count(); 75 my $c = Ikariam::Report->search_victim($city->cityId, time - 24*60*60 - 7*60*60)->count();
76 # check the current plunders 76 # check the current plunders
77 foreach (@{$self->{ikariam}->{'military'}->{'homeland'}}) { 77 foreach (@{$self->{ikariam}->{'military'}->{'homeland'}}) {
78 # 出發跟回家都要計算唷 78 # counting for both leaving and coming back.
79 $c++ if($_->{to} == $city->cityId || $_->{from} == $city->cityId); 79 $c++ if($_->{to} == $city->cityId || $_->{from} == $city->cityId);
80 } 80 }
81 # we attack one city maximum 4 times a day.
81 next if($c >= 4); 82 next if($c >= 4);
82 83
83 # { 84 # {
84 # if(1) {
85 my $capture = $city->citylevel * ($city->citylevel - 1) * $sheep->trader_score_secondary / 10000; 85 my $capture = $city->citylevel * ($city->citylevel - 1) * $sheep->trader_score_secondary / 10000;
86 my $line = sprintf("%d %s [%d,%d] %s (%d) %s/%s. Attacked %d", 86 my $line = sprintf("%d %s [%d,%d] %s (%d) %s Attacked %d",
87 $capture, $city->status, 87 $capture, $city->status,
88 $island->x, $island->y, 88 $island->x, $island->y,
89 $city->cityname, $city->cityId, 89 $city->cityname, $city->cityId,
90 $sheep->name, $sheep->ally, $c); 90 $sheep->name, $c);
91
91 printf("%s\n", $line); 92 printf("%s\n", $line);
92 # } 93 # }
93 return $city->cityId; 94 return $city->cityId;
94 } 95 }
95 return undef; 96 return undef;