示例#1
0
 public function getContent()
 {
     $player = Neuron_GameServer::getPlayer();
     if ($player && $player->isPlaying()) {
         $page = new Neuron_Core_Template();
         // Check for welcome message
         if (isset($_SESSION['welcome_html'])) {
             $page->set('welcome', $_SESSION['welcome_html']);
         }
         $server = Neuron_GameServer_Server::getInstance();
         $txt = $server->getText('headline');
         $page->set('headline', isset($txt) ? Neuron_Core_Tools::output_text($txt) : null);
         $page->set('nickname', $player->getDisplayName());
         $page->set('isPremium', $player->isPremium());
         $page->set('date', date(DATE, $player->getPremiumEndDate()));
         $page->set('isFreePremium', !$player->isProperPremium());
         $msg = Neuron_GameServer_Mappers_CachedChatMapper::getInstance();
         $messages = $msg->countUnreadMessages($player);
         $page->set('inbox', $messages);
         $clans = $player->getClans();
         $page->set('hasclan', count($clans) > 0);
         if (count($clans) > 0) {
             $objlogs = Dolumar_Players_ClanLogs::getInstance();
             $objlogs->clearMyVillages();
             foreach ($player->getVillages() as $village) {
                 $objlogs->addMyVillage($village);
             }
             $logs = $objlogs->getClanLogs($clans, 0, 3);
             foreach ($logs as $v) {
                 $page->addListValue('logs', array('date' => date(DATETIME, $v['timestamp']), 'text' => $objlogs->getLogText($v)));
             }
         }
         // Fetch thze news
         if (defined('GAMENEWS_RSS_URL')) {
             $text = Neuron_Core_Text::getInstance();
             $localized_link = str_replace('{lang}', $text->getCurrentLanguage(), GAMENEWS_RSS_URL);
             $rss = new Neuron_Core_RSSParser($localized_link);
             $rss->setCache(Neuron_Core_Cache::getInstance('newsfeed/'));
             foreach ($rss->getItems(3) as $v) {
                 $page->addListValue('gamenews', array('date' => $v['date'] ? date(DATETIME, $v['date']) : null, 'title' => $v['title'], 'url' => $v['url']));
             }
         }
         return $page->parse('dolumar/welcome/welcome.phpt');
     }
     return false;
 }
示例#2
0
 public function stealRunes($amount)
 {
     $db = Neuron_Core_Database::__getInstance();
     // Shizzle the wizzle
     $amount = floor($amount);
     $totalRunes = $this->resources->getTotalRunes();
     // You shall not destroy the town center.
     if ($amount > $totalRunes - 5) {
         $amount = max(0, $totalRunes - 5);
     }
     $runes = $this->resources->getRunes();
     $okay = true;
     // sqrt (pow ($loc1[0] - $loc2[0], 2) + pow ($loc1[1] - $loc2[1], 2) )
     $buildings = $this->getBuildingsToDestroy($amount);
     $buildingIndex = 0;
     $output = array();
     $sum = 0;
     while ($sum < $amount && $okay) {
         if (count($runes) > 0) {
             // Pick random rune.
             $keys = array_keys($runes);
             $k = $keys[rand(0, count($keys) - 1)];
             $v = $runes[$k];
             if ($v == 0) {
                 unset($runes[$k]);
             } else {
                 // Remove - or at least lower - the amount of available runes.
                 if ($v == 1) {
                     unset($runes[$k]);
                 } else {
                     $runes[$k]--;
                 }
                 // Add rune
                 if (!isset($output[$k])) {
                     $output[$k] = 1;
                 } else {
                     $output[$k]++;
                 }
                 $sum++;
             }
         } elseif (count($buildings) > 0) {
             // Start destructing
             if (isset($buildings[$buildingIndex])) {
                 //$runes = $buildings[$buildingIndex]->getUsedRunes ();
                 $res = $buildings[$buildingIndex]->getUsedResources(true, true);
                 if (isset($res['runeId']) && $res['runeAmount'] > 0) {
                     // destroy the building
                     $buildings[$buildingIndex]->destructBuilding();
                     // calculate the amount of runes we still need to steal
                     $tekort = $amount - $sum;
                     // if this building generate more runes than needed, only give the needed
                     $runeAmount = $res['runeAmount'];
                     if ($tekort < $runeAmount) {
                         $runeAmount = $tekort;
                     }
                     // Add rune to the "steal pool"
                     if (!isset($output[$res['runeId']])) {
                         $output[$res['runeId']] = $runeAmount;
                     } else {
                         $output[$res['runeId']] += $runeAmount;
                     }
                     // Increment i so that it includes the last additions.
                     $sum += $runeAmount;
                 }
                 $buildingIndex++;
             }
         } else {
             $okay = false;
         }
     }
     $this->resources->reloadRunes();
     // Remove the runes
     $stolenRunes = array();
     foreach ($output as $k => $v) {
         if ($this->resources->removeRune($k, $v)) {
             $stolenRunes[$k] = $v;
         } else {
             customMail('*****@*****.**', 'Dolumar: Not enough runes!', "Battle stealing error line 2143:\n\n" . Neuron_GameServer_Server::getInstance()->getServerName() . print_r($output, true) . "\n\n" . print_r($this, true));
         }
     }
     // After the battle: reload runes
     //$this->resources->reloadRunes (); shouldn't  be necesarry. Let's limit the mysql queries.
     $this->buildings->reloadBuildings();
     return $stolenRunes;
 }