Example #1
0
 public function getObjects($squarePoints, $radius)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     // Let's replace this :)
     $out = array();
     $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations($squarePoints, max($radius, 3));
     $objects = array();
     foreach ($buildingSQL as $buildingV) {
         $profiler->start('Initializing building');
         $profiler->start('Fetching building race object');
         $race = Dolumar_Races_Race::getRace($buildingV['race']);
         $profiler->stop();
         $profiler->start('Fetching building object');
         $b = Dolumar_Buildings_Building::getBuilding($buildingV['buildingType'], $race, $buildingV['xas'], $buildingV['yas']);
         $village = Dolumar_Players_Village::getVillage($buildingV['village']);
         $b->setVillage($village);
         $profiler->stop();
         $profiler->start('Setting data');
         $b->setData($buildingV['bid'], $buildingV);
         if ($buildingV['destroyDate'] > 0 && $buildingV['destroyDate'] < NOW) {
             $b->setDestroyed(true);
         }
         $profiler->stop();
         $profiler->start('Assigning building to array');
         //$buildings[floor ($buildingV['xas'])][floor ($buildingV['yas'])][] = $b;
         $objects[] = new Dolumar_Map_Object($b);
         $profiler->stop();
         $profiler->stop();
     }
     return $objects;
 }
Example #2
0
 public function moveVillage($x, $y)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $profiler->start('Moving village ' . $this->village->getName());
     $profiler->message('Desired location: (' . $x . ',' . $y . ')');
     $location = $this->getValidLocation($x, $y);
     if ($location) {
         list($x, $y) = $location;
         $profiler->message('Actual location: (' . $x . ',' . $y . ')');
         $tc = $this->village->buildings->getTownCenterLocation();
         $profiler->message('Current castle location: (' . $tc[0] . ',' . $tc[1] . ')');
         // First, calculate the relative position
         $profiler->start('Calculating relative position.');
         $dx = $x - $tc[0];
         $dy = $y - $tc[1];
         $profiler->message('Relative position: (' . $dx . ',' . $dy . ')');
         $profiler->stop();
         $profiler->start('Moving buildings');
         // Fetch all thze buildings & move 'em.
         $buildings = $this->village->buildings->getBuildings();
         foreach ($buildings as $v) {
             // Fetch original location
             list($ox, $oy) = $v->getLocation();
             $nx = $ox + $dx;
             $ny = $oy + $dy;
             $profiler->start('Moving ' . $v->getName() . ' from (' . $ox . ',' . $oy . ') to (' . $nx . ',' . $ny . ')');
             $v->setLocation($nx, $ny);
             $profiler->stop();
         }
         $profiler->stop();
     }
     $profiler->stop();
 }
Example #3
0
 public static function getDistance($loc1, $loc2, $portals, $ignoreImpassable = true)
 {
     if ($loc1[0] == $loc2[0] && $loc1[1] == $loc2[1]) {
         return 0;
     }
     // Show the route
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $profiler->start('Calculating map distance between ' . $loc1[0] . ',' . $loc1[1] . ' and ' . $loc2[0] . ',' . $loc2[1]);
     $locations = array();
     foreach ($portals as $v) {
         $l1 = $v->getCasterLocation();
         $l2 = $v->getTargetLocation();
         $locations[$v->getId()] = array($l1, $l2);
     }
     $profiler->message('Straight line distance: ' . round(self::calculateDistance($loc1[0], $loc1[1], $loc2[0], $loc2[1])));
     // Debug portals
     $profiler->start('Available portals');
     foreach ($locations as $k => $v) {
         list($l1, $l2) = $v;
         $profiler->message('Portal ' . $k . ' goes from ' . $l1[0] . ',' . $l1[1] . ' to ' . $l2[0] . ',' . $l2[1]);
     }
     $profiler->stop();
     $distance = self::getShortestDistance($loc1, $loc2, $portals, $ignoreImpassable);
     if ($distance === false) {
         return false;
     }
     $pd = 0;
     $profiler->start('Route debug... this is what we did');
     foreach ($distance[1] as $v) {
         $profiler->message('Arriving at ' . $v[0] . ',' . $v[1] . ' (' . round($v['d']) . ').');
     }
     $profiler->stop();
     $profiler->stop();
     return $distance[0];
 }
 public function sendMessage($channelId, $message, Neuron_GameServer_Player $player)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     // Here we *must* update the last channelId message
     $id = parent::sendMessage($channelId, $message, $player);
     $cName = $this->sPrefix . 'lastmessage_' . $channelId;
     $profiler->message('Setting ' . $cName . ' to ' . $id);
     //echo 'setting ' . $cName . ' to ' . $id;
     $this->objCache->setCache($cName, $id);
     return $id;
 }
Example #5
0
 protected function calculateIncome($level = null)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     if (!isset($level)) {
         $level = $this->getLevel();
     }
     // 40 for every level
     $income = $this->INCOME * GAME_SPEED_RESOURCES * 1.1 * $level;
     // Manipulated by honour!
     $profiler->start('Fetching honour');
     $income *= $this->getVillage()->honour->getHonour() / 100;
     $profiler->stop();
     // Bonusses (in resources)
     $profiler->start('Fetching locations');
     $bonus = $this->loadNearebyLocation();
     if (isset($bonus[$this->RESOURCE])) {
         $income += $income / 100 * $bonus[$this->RESOURCE];
     }
     $profiler->stop();
     //$income = (floor ($income * 4 * GAME_SPEED_RESOURCES) / 4);
     $income = floor($income);
     return $income;
 }
            $root->appendChild($updates);
        }
    } catch (Exception $e) {
        // Send a mail
        error_log((string) $e);
        if (defined('OUTPUT_DEBUG_DATA') && OUTPUT_DEBUG_DATA) {
            echo $e;
        }
    }
    $profiler->stop();
}
$profiler->stop();
$pgen->stop();
// Database
$db = Neuron_Core_Database::__getInstance();
$profiler = Neuron_Profiler_Profiler::getInstance();
// Let's add some additional data
$run = $dom->createElement('runtime');
$run->appendChild($dom->createElement('session_id', session_id()));
$run->appendChild($dom->createElement('parsetime', $pgen->gen(4)));
$run->appendChild($dom->createElement('mysqlcount', $db->getCounter()));
$content = $dom->createCDATASection($profiler);
$element = $run->appendChild($dom->createElement('profiler'));
$element->appendChild($content);
$content = $dom->createCDATASection(print_r($_REQUEST, true));
$run->appendChild($dom->createElement('request'))->appendChild($content);
$root->appendChild($run);
// Go for alerts
if (isset($GLOBALS['javascriptAlertErrors'])) {
    foreach ($GLOBALS['javascriptAlertErrors'] as $v) {
        $alert = $dom->createCDATASection($v);
 private function getOpenWindows()
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $out = array();
     // List all open windows
     $updatewindows = isset($_POST['updatewindow']) ? $_POST['updatewindow'] : null;
     if (is_array($updatewindows)) {
         $profiler->start('Ordering windows on priority');
         // Order window on input (put input first)
         $aantal = count($updatewindows);
         for ($i = 0; $i < $aantal; $i++) {
             $vervangen = $i;
             // Loop trough last, fine the one with more input.
             for ($j = $i + 1; $j < $aantal; $j++) {
                 if (isset($updatewindows[$j]['sInputData']) && strlen($updatewindows[$j]['sInputData']) > strlen($updatewindows[$vervangen]['sInputData'])) {
                     $vervangen = $j;
                 }
             }
             // Vervangen
             $temp = $updatewindows[$i];
             $updatewindows[$i] = $updatewindows[$vervangen];
             $updatewindows[$vervangen] = $temp;
         }
         $profiler->stop();
         //foreach ($updatewindows as $v)
         for ($i = 0; $i < count($updatewindows); $i++) {
             $v = $updatewindows[$i];
             if (is_array($v) && count($v) == 4) {
                 // Put everything in a big TRY
                 $profiler->start('Loading window ' . $v['sWindowId']);
                 try {
                     $window = $this->getWindow($v['sWindowId']);
                     if ($window) {
                         $window->setDivId($v['sDialogId']);
                         // Set request data
                         if (isset($v['sRequestData'])) {
                             $window->setRequestData($v['sRequestData']);
                         }
                         // Set input data
                         $window->setJsonInputData($v['sInputData']);
                         // Initialize
                         $window->setSettings();
                     }
                     $out[] = $window;
                 } catch (Exception $e) {
                     // Send a mail
                     error_log((string) $e);
                     if (defined('OUTPUT_DEBUG_DATA') && OUTPUT_DEBUG_DATA) {
                         echo $e;
                     }
                 }
                 $profiler->stop();
             }
         }
     }
     return $out;
 }
Example #8
0
 private function doMeleeAttack($actor, $target, $team, $isFlank = false, $isTargetFacingEnemy = false)
 {
     $pr = Neuron_Profiler_Profiler::getInstance();
     $pr->start('Executing a melee attack.');
     // Get amount of attacking units
     $amount = $actor->getAmount() - $actor->getKillUnitsQue() + $actor->getKilledInRound();
     // Current frontage is calculated on moving.
     // except when this is a flank attack
     // In that case something weird happens: everyone
     // in the flanking unit fights to a total amount
     // of the defending frontage multiplier
     if ($isFlank) {
         // Is this a flank to flank attack?
         if ($isTargetFacingEnemy) {
             // No. Calculate the frontage based on the frontage
             // multiplier used by the target
             $multiplier = $target->getCurrentFrontage() / $target->getStat('frontage');
             $frontage = $actor->getStat('frontage') * $multiplier;
             $actor->setCurrentFrontage($frontage);
         } else {
             // Yes. Just recalculate the frontage
             $frontages = $this->getFrontages($actor, $target);
             $actor->setCurrentFrontage($frontages[0]);
             $target->setCurrentFrontage($frontages[1]);
         }
     }
     // Make sure only the first row fights
     $frontage = $actor->getCurrentFrontage();
     // Shouldn't happen, but well, just to make sure.
     $frontage = max(1, $frontage);
     $amount = min($frontage, $amount);
     // Get the amount of defending units
     $defending = $target->getAmount() - $target->getKillUnitsQue();
     // Calculate the total amount of damage
     $damage = $amount * $actor->getStat('melee');
     // Don't forget the resistance!
     $damage -= $damage * $target->getStat($actor->getAttackType()) / 100;
     // Now how many units is that?
     $casualties = min($defending, $damage / $target->getStat('hp'));
     $casualties = $target->queKillUnits($casualties);
     // Log this action
     $this->objLogger->addLog_casualties($actor, $target, $casualties, 'melee', $team);
     $pr->stop();
 }
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
define('MAP_PERLIN_NO_CACHE', true);
function color_cache($im, $color)
{
    global $color_cache;
    if (!isset($color_cache[$color[0] . '_' . $color[1] . '_' . $color[2]])) {
        $color_cache[$color[0] . '_' . $color[1] . '_' . $color[2]] = imagecolorallocate($im, $color[0], $color[1], $color[2]);
    }
    return $color_cache[$color[0] . '_' . $color[1] . '_' . $color[2]];
}
Neuron_Profiler_Profiler::getInstance()->setForceActivate(false);
if (isset($_GET['x']) && isset($_GET['y'])) {
    $extension = 'png';
    $cache = Neuron_Core_Cache::__getInstance('worldmap/');
    $width = Neuron_Core_Tools::getInput('_GET', 'width', 'int', 250);
    $height = Neuron_Core_Tools::getInput('_GET', 'height', 'int', 250);
    $zoom = Neuron_Core_Tools::getInput('_GET', 'zoom', 'int', 0);
    $x = Neuron_Core_Tools::getInput('_GET', 'x', 'int', 0);
    $y = Neuron_Core_Tools::getInput('_GET', 'y', 'int', 0);
    // Fetch cache
    $cachename = 'gw4_' . $zoom . '_' . $x . '_' . $y . '_' . $width . 'x' . $height;
    $image = $cache->getCache($cachename, 60 * 60 * 24 * 7);
    //$image = false;
    if ($image) {
        header("Content-type: image/" . $extension);
        header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 60 * 12) . " GMT");
 private function file_get_contents($url)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $profiler->start('Fetching ' . $url);
     //Initialize the Curl session
     $ch = curl_init();
     //Set curl to return the data instead of printing it to the browser.
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //Set the URL
     curl_setopt($ch, CURLOPT_URL, $url);
     // Set a reasonable timeout
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
     //Execute the fetch
     $data = curl_exec($ch);
     if ($error = curl_error($ch)) {
         $profiler->message('Error: ' . $error);
     }
     //Close the connection
     curl_close($ch);
     $profiler->stop();
     return $data;
 }
Example #11
0
 /**
  *	Check if a move can be executed (and set the correct error if not)
  */
 private function canReach(Neuron_GameServer_Map_Location $end, $isTargetAnObject = false)
 {
     $start = $this->getLocation();
     Neuron_Profiler_Profiler::getInstance()->message('Check if we can go from ' . $start . ' to ' . $end);
     // Too far? Don't bother about anything else
     if ($this->getMap()->getMinimalDistance($start, $end) > $this->getMovePoints()) {
         $this->error = 'not_enough_movepoints';
         Neuron_Profiler_Profiler::getInstance()->message('Precheck failed');
         return false;
     }
     // Otherwise: check the path
     $path = $this->getMap()->getPath($this->getSide(), $start, $end, $this->getMovePoints() + 1, $isTargetAnObject);
     if ($path === false) {
         Neuron_Profiler_Profiler::getInstance()->message('No path found.');
         $this->error = 'no_path_found';
     } else {
         if ($path->getCost() > $this->getMovePoints()) {
             $this->error = 'not_enough_movepoints';
         } else {
             return $path;
         }
     }
     return false;
 }
Example #12
0
 private function _takeResources($gold, $wood, $stone, $iron, $grain, $gems)
 {
     $db = Neuron_Core_Database::__getInstance();
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $profiler->start('Taking resources away: ' . $gold . ' ' . $wood . ' ' . $stone . ' ' . $iron . ' ' . $grain . ' ' . $gems);
     $this->loadData();
     // Make sure this doesn't go over the capacity
     $capacity = $this->getCapacity();
     $resources = $this->getResources();
     // Build a WHERE clause according to "the positives"
     $where = "(vid = {$this->objMember->getId()} AND lastResRefresh = {$this->lastReload})";
     //echo "Taking resources:\n";
     $a = array('gold', 'wood', 'stone', 'iron', 'grain', 'gems');
     foreach ($a as $v) {
         //echo "- " . $v . " = " . $$v . " CAP " . $capacity[$v] . " ";
         //echo " CUR " . $resources[$v] . " ";
         // If $v is negative (= ADDING!) AND it's bigger then our currenct capacity
         if (${$v} < 0 && abs(${$v}) + $resources[$v] > $capacity[$v]) {
             ${$v} = 0 - max(0, $capacity[$v] - $resources[$v]);
             $profiler->start('Capacity overflow for ' . $v . ', taking ' . ${$v} . ' instead');
             $profiler->stop();
         } elseif (${$v} > 0) {
             $where .= " AND " . $v . " >= " . ${$v};
         }
         //echo "CALC " . $$v . "\n";
     }
     // Show what we got:
     $data = array($gold, $wood, $stone, $iron, $grain, $gems);
     if ($gold == 0 && $wood == 0 && $stone == 0 && $iron == 0 && $grain == 0 && $gems == 0) {
         $profiler->stop();
         return true;
     } else {
         $profiler->start('We are going to take: ' . print_r($data, true));
         // Update the database
         $a = $db->update('villages', array('gold' => $gold > 0 ? '--' . $gold : '++' . abs($gold), 'wood' => $wood > 0 ? '--' . $wood : '++' . abs($wood), 'stone' => $stone > 0 ? '--' . $stone : '++' . abs($stone), 'iron' => $iron > 0 ? '--' . $iron : '++' . abs($iron), 'grain' => $grain > 0 ? '--' . $grain : '++' . abs($grain), 'gems' => $gems > 0 ? '--' . $gems : '++' . abs($gems)), $where) == 1;
         //customMail ('*****@*****.**', 'res debug', $db->getLatestQuery ());
         $profiler->stop();
         // Cached resources
         if ($a) {
             $this->data['gold'] -= $gold;
             $this->data['wood'] -= $wood;
             $this->data['stone'] -= $stone;
             $this->data['iron'] -= $iron;
             $this->data['grain'] -= $grain;
             $this->data['gems'] -= $gems;
         }
         $profiler->stop();
         return $a;
     }
 }
Example #13
0
 public function procBonusses($function, $arguments = array(), $now = NOW, $since = NOW)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $profiler->start('Processing bonusses ' . $function);
     // If $now is lower then $since, $since is probably empty.
     if ($since > $now) {
         $since = $now;
     }
     // First: technologies
     //$this->loadTechnology ();
     /*
     if (!isset ($arguments[0]))
     {
     	$arguments[0] = array ();
     }
     */
     $profiler->start('Processing technologies');
     $profiler->start('Loading technologies');
     $technologies = $this->getTechnologies();
     $profiler->stop();
     $profiler->start('Processing technologies');
     foreach ($technologies as $technology) {
         if (method_exists($technology, $function)) {
             $arguments[0] = call_user_func_array(array($technology, $function), $arguments);
         }
     }
     $profiler->stop();
     $profiler->stop();
     // Second: spells
     // This time, the $now and $then variables are higly important. We only want spells that are
     // active between $since and $now.
     $profiler->start('Processing active effects');
     $profiler->start('Loading effects');
     $boosts = $this->getActiveBoosts($since, $now);
     $profiler->stop();
     $profiler->start('Processing effects');
     foreach ($boosts as $v) {
         if (method_exists($v, $function)) {
             $arguments[0] = call_user_func_array(array($v, $function), $arguments);
         }
     }
     $profiler->stop();
     $profiler->stop();
     $profiler->stop();
     return $arguments[0];
 }
 public function sendMessage($channelId, $message, Neuron_GameServer_Player $player)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $db = Neuron_DB_Database::getInstance();
     $profiler->message('Sending message');
     return $db->query("\n\t\t\tINSERT INTO\n\t\t\t\tn_chat_messages\n\t\t\tSET\n\t\t\t\tc_c_id = '{$db->escape($channelId)}',\n\t\t\t\tc_plid = '{$player->getId()}',\n\t\t\t\tc_date = NOW(),\n\t\t\t\tc_message = '{$db->escape($message)}'\n\t\t");
 }