comparison Ikariam.pm @ 81:d57920014cb4

split buliding.yaml to city.yaml and overall.yaml
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sat, 25 Oct 2008 00:42:59 +0800
parents 7ab5fc8c847c
children 82acbba33b97
comparison
equal deleted inserted replaced
80:7ab5fc8c847c 81:d57920014cb4
63 my $result = $self->{doc}->find($query); 63 my $result = $self->{doc}->find($query);
64 64
65 return undef unless defined($result); 65 return undef unless defined($result);
66 66
67 if ( $result->isa( 'XML::LibXML::NodeList' ) ) { 67 if ( $result->isa( 'XML::LibXML::NodeList' ) ) {
68 return undef if($result->size() == 0); 68 return () if($result->size() == 0);
69 foreach ( @$result ) { 69 foreach ( @$result ) {
70 # $_ is XML::LibXML::Element, XML::LibXML::Node 70 # $_ is XML::LibXML::Element, XML::LibXML::Node
71 my $literal = $_->to_literal() , "\n"; 71 my $literal = $_->to_literal() , "\n";
72 utf8::encode($literal); 72 utf8::encode($literal);
73 # warn $_->toString(1) , "\n"; 73 # warn $_->toString(1) , "\n";
413 my $type = shift; 413 my $type = shift;
414 my $cityId = shift; 414 my $cityId = shift;
415 415
416 # check if we are researching the same stuff 416 # check if we are researching the same stuff
417 my $res = $self->{mech}->get(sprintf('http://%s/index.php?action=CityScreen&function=changeResearch&id=%s&researchType=%s', $self->{server}, $cityId, $type)); 417 my $res = $self->{mech}->get(sprintf('http://%s/index.php?action=CityScreen&function=changeResearch&id=%s&researchType=%s', $self->{server}, $cityId, $type));
418
419 # my $content;
420 # gunzip \$res->content => \$content
421 # or die "gunzip failed: $GunzipError\n";
422 #
423 # print ($content);
424 } 418 }
425 419
426 sub checkResearch { 420 sub checkResearch {
427 my $self = shift; 421 my $self = shift;
428 my $cityId = shift; 422 my $cityId = shift;
475 foreach my $building (@buildings) { 469 foreach my $building (@buildings) {
476 if (!($building =~ /buildingGround/) && !($building =~ /townhall/)) { 470 if (!($building =~ /buildingGround/) && !($building =~ /townhall/)) {
477 $self->{'cities'}->{$cityId}->{locations}[$i] = $building; 471 $self->{'cities'}->{$cityId}->{locations}[$i] = $building;
478 472
479 my $span; 473 my $span;
480 if($building eq 'townHall') { 474 my @spans = $extractor->find(sprintf('//*[@id="position%s"]//span[@class="textLabel"]/text()', $i));
481 # this is stupid, the new vession give two cityTown information. 475 if($#spans>=1) {
482 $span = ($extractor->find(sprintf('//*[@id="position%s"]//span[@class="textLabel"]/text()', $i)))[1]; 476 $span = $spans[1];
483 } else { 477 } else {
484 $span = $extractor->find(sprintf('//*[@id="position%s"]//span[@class="textLabel"]/text()', $i)); 478 $span = $spans[0];
485 } 479 }
486 my (undef, undef, $level) = split(/ /, $span); 480 my (undef, undef, $level) = split(/ /, $span);
487 $self->{'cities'}->{$cityId}->{buildings}->{$building} = $level; 481 $self->{'cities'}->{$cityId}->{buildings}->{$building} = $level;
488 } 482 }
489 } 483 }
497 491
498 492
499 sub checkMilitaryAdvisorMilitaryMovements { 493 sub checkMilitaryAdvisorMilitaryMovements {
500 my $self = shift; 494 my $self = shift;
501 # TODO 495 # TODO
502 # http://s2.ikariam.tw/index.php?view=militaryAdvisorMilitaryMovements 496 # http://%s/index.php?view=militaryAdvisorMilitaryMovements
503 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $self->{server})); 497 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $self->{server}));
498 my $extractor = new Ikariam::Extractor(content => $res->content);
499
500 my @homeland = $extractor->find('//div[@id="homeland"]');
501 my @elsewhere = $extractor->find('//div[@id="elsewhere"]');
502 $self->{'military'}->{attacks} = $#elsewhere+1;
503 $self->{'military'}->{wars} = $#homeland+1;
504
505 # there are some details.
506 #<div id="homeland" class="content">
507 # <ul id="battleReports">
508 # <li class="groundfight">
509 # <div class="type"/>
510 # <div class="report">
511 # <table cellspacing="0" cellpadding="0" class="repTable">
512 # <tbody><tr>
513 # <th colspan="2">
514 # 攻擊 卍严破碎虛空焱卐 </th>
515 # </tr>
516 # </tbody></table>
517 # </div>
518 # <br class="clearfloat"/>
519 # </li>
520 # <li class="enroute" style="height: 52px;">
521 # <script type="text/javascript">
522 # Event.onDOMReady(function() {
523 # getCountdown({
524 # enddate: 1224863393,
525 # currentdate: 1224862910,
526 # el: "researchCountDown11396440"
527 # }, 3, " ", "", true, true);
528 # });
529 # </script>
530 # <div class="type">
531 # <div id="researchCountDown11396440" class="time">5分 46秒</div><div class="undefined"> Finished 23:49:23</div>
532 # </div>
533 # <div class="report">
534 #來自 <a href="?view=island&amp;cityId=98496">松鼠城</a> 的 3 兵力正在前往 <a href="?view=island&amp;cityId=82959">卍严破碎虛空焱卐</a> 的途中。 </div>
535 # <div class="action">
536 # <div class="return">
537 # <a href="?action=transportOperations&amp;function=forceReturn&amp;actionRequest=46cc5fdb56b8cb0e65e2116ff9f61512&amp;eventId=11396440&amp;oldView=militaryAdvisorMilitaryMovements" title="返回">返回</a>
538 # </div>
539 # </div>
540 # <br class="clearfloat"/>
541 # </li>
542 # </ul>
543 #</div>
544
545
546 # <div id="elsewhere" class="content">
547 # <ul id="battleReports">
548 # <li class="groundfight">
549 # <div class="type"/>
550 # <div class="report">
551 # <table cellspacing="0" cellpadding="0" class="repTable">
552 # <tbody><tr>
553 # <th colspan="2">
554 # 攻擊 Rex </th>
555 # </tr>
556 # </tbody></table>
557 # </div>
558 # <br class="clearfloat"/>
559 # </li>
560 # <li class="enroute">
561 # <script type="text/javascript">
562 # Event.onDOMReady(function() {
563 # getCountdown({
564 # enddate: 1224877160,
565 # currentdate: 1224861666,
566 # el: "researchCountDown159638"
567 # }, 3, " ", "", true, true);
568 # });
569 # </script>
570 # <div class="type">
571 # <div id="researchCountDown159638" class="time">4時 17分 35秒</div>
572 # </div>
573 # <div class="report">
574 #來自 <a href="?view=island&amp;cityId=6078">水晶交換各種資源</a> 的 3 兵力正在前往 <a href="?view=island&amp;cityId=6077">Rex</a> 的途中。 </div>
575 # </li>
576 # </ul>
577 # </div>
504 } 578 }
505 579
506 sub checkMilitaryAdvisorCombatReports { 580 sub checkMilitaryAdvisorCombatReports {
507 my $self = shift; 581 my $self = shift;
508 my $content; 582 my $content;
509 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorCombatReports', $self->{server})); 583 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorCombatReports', $self->{server}));
510 gunzip \$res->content => \$content 584 gunzip \$res->content => \$content
511 or die "gunzip failed: $GunzipError\n"; 585 or die "gunzip failed: $GunzipError\n";
512 586
513 # TODO 587 # TODO
514 # military
515 $self->{'military'}->{wars}->{attacks} = 0;
516 $self->{'military'}->{wars}->{wars} = 0;
517 # $self->{'cities'}->{$cityId}->{wars}->{attacks} = $1 if($content =~ /敵人攻擊: (\d+)/);
518 # $self->{'cities'}->{$cityId}->{wars}->{wars} = $1 if($content =~ /我方軍隊行程: (\d+)/);
519 588
520 # list down reports. 589 # list down reports.
521 # /index.php?view=militaryAdvisorReportView&amp;combatId=1887662 590 # /index.php?view=militaryAdvisorReportView&amp;combatId=1887662
522 # //form[@id='finishedReports']//a 591 # //form[@id='finishedReports']//a
523 } 592 }
596 my $self = shift; 665 my $self = shift;
597 666
598 # MilitaryAdvisor 667 # MilitaryAdvisor
599 $self->checkMilitaryAdvisorMilitaryMovements(); 668 $self->checkMilitaryAdvisorMilitaryMovements();
600 $self->checkMilitaryAdvisorCombatReports(); 669 $self->checkMilitaryAdvisorCombatReports();
670 $self->{'research'} = $self->checkResearch((keys(%{$self->{'cities'}}))[0]);
671
672 # alerts
673 # //li[@id="advCities"]/a[@class="normalalert"]
674 # //li[@id="advMilitary"]/a[@class="normalalert"]
675 # //li[@id="advResearch"]/a[@class="normalalert"]
676 # //li[@id="advDiplomacy"]/a[@class="normalalert"]
601 677
602 # looking for cities 678 # looking for cities
603 foreach my $cityId (keys(%{$self->{'cities'}})) 679 foreach my $cityId (keys(%{$self->{'cities'}}))
604 { 680 {
605 $self->checkCity($cityId); 681 $self->checkCity($cityId);
606 $self->checkTownHall($cityId); 682 $self->checkTownHall($cityId);
607 $self->checkArmies($cityId); 683 $self->checkArmies($cityId);
608 $self->{'cities'}->{$cityId}->{'research'} = $self->checkResearch($cityId); 684 }
609 }
610 print Dumper($self->{'cities'});
611 return $self->{'cities'}; 685 return $self->{'cities'};
612 } 686 }
613 687
614 sub logout 688 sub logout
615 { 689 {