Ejemplo n.º 1
0
 public function getPlayerRanking()
 {
     $text = Neuron_Core_Text::__getInstance();
     $db = Neuron_Core_Database::__getInstance();
     $input = $this->getInputData();
     $page = new Neuron_Core_Template();
     $text->setFile('ranking');
     $text->setSection('ranking');
     $page->set('title', $text->get('villageRating'));
     $page->set('village', $text->get('village'));
     $page->set('value', $text->get('value'));
     $data = $this->getRequestData();
     $perPage = 25;
     $myDefaultPage = 1;
     $myVillageId = 0;
     // Load "main village" from this user
     $myself = Neuron_GameServer::getPlayer();
     if ($myself) {
         $me = $myself->getId();
         $rank = $myself->getRank();
         $myDefaultPage = floor($rank[0] / $perPage) + 1;
     } else {
         $me = 0;
     }
     $currentPage = isset($input['page']) ? $input['page'] : $myDefaultPage;
     $limit = Neuron_Core_Tools::splitInPages($page, Dolumar_Players_Ranking::countPlayerRanking(), $currentPage, $perPage, 6);
     $l = Dolumar_Players_Ranking::getPlayerRanking($limit['start'], $limit['perpage']);
     $i = $limit['start'];
     foreach ($l as $v) {
         $i++;
         $page->addListValue('ranking', array($i, Neuron_Core_Tools::output_varchar($v->getName()), $v->getId(), $v->getScore(), $v->getId() == $me));
         //$v->__destruct ();
     }
     return $page->parse('ranking/players.tpl');
 }
Ejemplo n.º 2
0
 /**
  * Determine if it's time to take a step forwards
  */
 public function updateStatus()
 {
     $state = $this->getData('gamestate');
     if (!$state) {
         $this->setData('gamestate', self::GAMESTATE_PLAYING);
         return;
     }
     switch ($state) {
         case self::GAMESTATE_PLAYING:
             // If the server has been running for xxx months, go to next step
             $duration = GAME_RUNNING_DURATION;
             $start = $this->getStartDate();
             $timepassed = time() - $start;
             if ($timepassed > $duration) {
                 // Initiate end game
                 $this->setData('gamestate', self::GAMESTATE_ENDGAME_STARTED);
                 // And notify all players
                 Neuron_GameServer_Player_Guide::addPublicMessage('end_scroll', array(), 'guide', 'scared');
             }
             break;
         case self::GAMESTATE_ENDGAME_FINISHED:
             $this->setData('end_date', time());
             $this->setData('gamestate', self::GAMESTATE_WAITINGFORRESET);
             $server = Neuron_GameServer::getServer();
             $out = array();
             $out['winner'] = '';
             $out['members'] = '';
             $out['ranking'] = '';
             $out['members'] = '';
             $out['villages'] = '';
             $out['clans'] = '';
             $out['players'] = '';
             $winner = $server->getData('winner');
             if ($winner) {
                 $clan = Dolumar_Players_Clan::getFromId($winner);
                 if ($clan) {
                     $out['winner'] = Neuron_Core_Tools::output_varchar($clan->getName());
                     foreach ($clan->getMembers() as $v) {
                         $out['members'] .= "- " . Neuron_Core_Tools::output_varchar($v->getName()) . "\n";
                     }
                 }
             }
             // Ranking
             $players = Dolumar_Players_Ranking::getPlayerRanking(0, 5);
             $i = 0;
             foreach ($players as $v) {
                 $i++;
                 $out['players'] .= $i . ". " . $v->getName() . ' (' . $v->getScore() . ')' . "\n";
             }
             $villages = Dolumar_Players_Ranking::getRanking(0, 5);
             $i = 0;
             foreach ($villages as $v) {
                 $i++;
                 $out['villages'] .= $i . ". " . $v->getName() . ' (' . $v->getNetworth() . ')' . "\n";
             }
             $ranking = Dolumar_Players_Ranking::getClanRanking(0, 5);
             $i = 0;
             foreach ($ranking as $v) {
                 $i++;
                 $out['clans'] .= $i . ". " . $v->getName() . ' (' . $v->getNetworth() . ')' . "\n";
             }
             $out['servername'] = $this->getServerName();
             $out['serverurl'] = ABSOLUTE_URL;
             // Send out the bloody newsletter
             if (!defined('IS_TESTSERVER') || !IS_TESTSERVER) {
                 $this->sendNewsletter('serverreset', $out);
             }
             break;
         case self::GAMESTATE_WAITINGFORRESET:
             if ($this->getData('end_date') <= NOW - 60 * 60 * 23) {
                 $this->reset();
             }
             break;
     }
 }