# HG changeset patch # User "Rex Tsai " # Date 1225482729 -28800 # Node ID fab1593cadf1f1ed628246905be61c0756c0386f # Parent 97dfcc0d1e3f0fcafae7cef0a0fd24e743111a47 fixed the combat reading issue. diff -r 97dfcc0d1e3f -r fab1593cadf1 Ikariam.pm --- a/Ikariam.pm Sat Nov 01 02:01:53 2008 +0800 +++ b/Ikariam.pm Sat Nov 01 03:52:09 2008 +0800 @@ -37,7 +37,6 @@ return $self; } -# parse($Content); sub parse { my ($self, $content) = @_; my $string; @@ -68,7 +67,10 @@ return undef unless defined($result); if ( $result->isa( 'XML::LibXML::NodeList' ) ) { - return () if($result->size() == 0); + if($result->size() == 0) { + return undef unless wantarray; + return (); + } foreach ( @$result ) { # $_ is XML::LibXML::Element, XML::LibXML::Node my $literal = $_->to_literal(); @@ -577,17 +579,21 @@ $report{defender} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//th[@class="defenders"]'); $report{winner} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//td[@class="winner"]'); + # the combat we win! $report{targetCity} = $extractor->find('//div[@id="troopsReport"]/div/h3/a/text()'); my $href = $extractor->find('//div[@id="troopsReport"]/div/h3/a/@href'); - # $report{targetCity} = $extractor->find('//td[@class="battle"]/a/text()'); - # my $href = $extractor->find('//td[@class="battle"]/a/@href'); + if(!defined($href)) { + # the combat we lost! + $report{targetCity} = $extractor->find('//td[@class="battle"]/a/text()'); + $href = $extractor->find('//td[@class="battle"]/a/@href'); + } if($href =~ /index\.php\?view=island&id=(\d+)&selectCity=(\d+)/) { $report{island} = $1; $report{city} = $2; } else { + warn($href); warn ("can not read combat reprot $combatId"); - warn ($href); return undef; } $report{gold} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="gold"]'); diff -r 97dfcc0d1e3f -r fab1593cadf1 agent.pl --- a/agent.pl Sat Nov 01 02:01:53 2008 +0800 +++ b/agent.pl Sat Nov 01 03:52:09 2008 +0800 @@ -20,10 +20,6 @@ sub is_attacked { my ($self, $city) = @_; - if($self->{'ikariam'}->{'military'}->{attacks} > 0) { - # notify youself. - system('zenity --warning --title="Ikariam" --text="You are attacked"'); - } return ($self->{'ikariam'}->{'military'}->{attacks} > 0 ) ? 1 : 0; } @@ -292,7 +288,9 @@ # print(Dump($cities->{$cityId}->{parse_path})) if(defined($verbose)); } # print(Dump($cities)) if(defined($verbose)); -DumpFile("dump.yaml", $cities); +DumpFile("cities-dump.yaml", $cities); +DumpFile("research-dump.yaml", $i->{'research'}); +DumpFile("military-dump.yaml", $i->{'military'}); $i->logout;