public function prepare() { $db = Neuron_Core_Database::__getInstance(); // Do the area trick // Count amount of town centers on the map /* $buildings = $db->select ( 'map_buildings', array ('COUNT(*) AS aantal'), "buildingType = 1" ); $towns = $buildings[0]['aantal']; $radius = ceil (abs (sqrt ($towns / pi ())) * MAXBUILDINGRADIUS * 2); */ // Count the farest building $buildings = $db->select('map_buildings', array('MAX((SQRT((xas*yas)+(xas*yas)))) AS distance'), "buildingType = 1"); $radius = count($buildings) > 0 ? $buildings[0]['distance'] : 100; // Extend the radius $radius *= 1.25; // Max sure the radius doesn't exceed the maximum radius $radius = max(250, ceil($radius)); $radius = min(MAXMAPSTRAAL, $radius); // Load the start value $server = Neuron_GameServer::getServer(); $start = $server->getData('prepRadD'); $start = isset($start) ? $start : 0; echo "\n\nPreparing map for new players!\n"; // Now let's prepare this radius! $this->prepareCircle($start, $radius); }
public function processInput() { $db = Neuron_Core_Database::__getInstance(); $input = $this->getInputData(); // Loop and collect data $squads = $this->village->getSquads(false, false, false); $slots = $this->village->getDefenseSlots(); $rows = $this->countRows($squads, $slots); $units = array(); // First: make a list of all units foreach ($squads as $squad) { foreach ($squad->getUnits() as $unit) { $units[$squad->getId() . '_' . $unit->getUnitId()] = $unit; } } // Next: loop trough the slots foreach ($slots as $slotId => $slot) { for ($i = 0; $i < $rows; $i++) { $value = isset($input['slot_' . $slotId . '_' . $i]) ? $input['slot_' . $slotId . '_' . $i] : null; if (isset($units[$value])) { $db->update('squad_units', array('s_slotId' => $slotId, 's_priority' => $i), "s_id = '" . $units[$value]->getSquad()->getId() . "'\n\t\t\t\t\t\t\tAND u_id = '" . $units[$value]->getUnitId() . "'"); unset($units[$value]); } else { // You may not set a second one without a first one! break; } } } // Next: remove all non-assigned troop foreach ($units as $v) { $db->update('squad_units', array('s_slotId' => 0, 's_priority' => 0), "s_id = '" . $v->getSquad()->getId() . "'\n\t\t\t\t\tAND u_id = '" . $v->getUnitId() . "'"); } $this->updateContent($this->getContent('saved', false)); }
public function setSettings() { $text = Neuron_Core_Text::__getInstance(); $db = Neuron_Core_Database::__getInstance(); // Window settings $this->setSize('250px', '295px'); $this->setPlayer(); }
public static function getEquipmentId($name) { $db = Neuron_Core_Database::__getInstance(); // Fetch equipment name $e_id = $db->select('equipment', array('e_id'), "e_name = '" . $name . "'"); if (count($e_id) == 0) { $e_id = $db->insert('equipment', array('e_name' => $name)); } else { $e_id = $e_id[0]['e_id']; } return $e_id; }
private function generateNewKey($plid) { $db = Neuron_Core_Database::__getInstance(); $okay = false; while (!$okay) { // Let's go mad. $key = substr(md5(rand(-999999999999999.0, 999999999999999.0)), rand(0, 15), 15); $check = $db->select('invitation_codes', array('invCode'), "invCode = '{$key}'"); if (count($check) == 0) { $db->insert('invitation_codes', array('plid' => $plid, 'invCode' => $key, 'invLeft' => 15)); $okay = true; } } $this->invKey = $key; $this->invLeft = 15; }
private function getTrainUnit($input) { $db = Neuron_Core_Database::__getInstance(); if ($this->isTrainingUnits()) { $text = Neuron_Core_Text::__getInstance(); $page = new Neuron_Core_Template(); $page->set('working', $text->get('working', 'training', 'buildings')); $page->set('toReturn', $text->getClickTo($text->get('toReturn', 'training', 'buildings'))); return $page->parse('buildings/working.tpl'); } else { $page = new Neuron_Core_Template(); $unit = Dolumar_Units_Unit::getUnitFromName($input['unit'], $this->getVillage()->getRace(), $this->getVillage()); // Check if this unit is trainable here $checkUnit = false; foreach ($this->getCheckedAvailableUnits() as $v) { if ($v->getUnitId() == $unit->getUnitId()) { $checkUnit = true; } } if ($unit && $checkUnit) { $showForm = true; if (isset($input['amount']) && is_numeric($input['amount']) && $input['amount'] > 0) { $showForm = !$this->processTrainUnits($unit, ceil($input['amount']), isset($input['queue'])); } if ($showForm) { return $this->getChooseAmount($input, $unit); } else { return $this->getCustomContent(); } } else { $page = new Neuron_Core_Template(); $text = Neuron_Core_Text::__getInstance(); $text->setFile('buildings'); $text->setSection('training'); // Title $page->set('train', $text->get('train')); $page->set('section', 'notFound'); $page->set('error', $text->get('unitNotFound')); return $page->parse('buildings/training.tpl'); } } }
public function setSettings() { $text = Neuron_Core_Text::__getInstance(); $db = Neuron_Core_Database::__getInstance(); // Window settings $this->setSize('315px', '300px'); $o = $this->getRequestData(); $l = $db->getDataFromQuery($db->customQuery("\n\t\t\tSELECT\n\t\t\t\tmap_buildings.*, villages.race\n\t\t\tFROM\n\t\t\t\tmap_buildings\n\t\t\tLEFT JOIN\n\t\t\t\tvillages ON map_buildings.village = villages.vid\n\t\t\tWHERE\n\t\t\t\tmap_buildings.bid = '" . $db->makeSafe($o['bid']) . "'\n\t\t\t\tAND (destroyDate = 0 OR destroyDate > " . NOW . ")\n\t\t")); if (count($l) == 1) { $race = Dolumar_Races_Race::getRace($l[0]['race']); $this->building = Dolumar_Buildings_Building::getBuilding($l[0]['buildingType'], $race, $l[0]['xas'], $l[0]['yas']); if ($l[0]['village']) { $this->building->setVillage(Dolumar_Players_Village::getVillage($l[0]['village'])); } $this->building->setWindow($this); $this->building->setData($l[0]['bid'], $l[0]); $this->setTitle($this->getTitle()); } else { $this->building = false; $this->setTitle('Oh-Ow...'); } }
private function chooseNickname() { $db = Neuron_Core_Database::__getInstance(); // Check for input $data = $this->getInputData(); $login = Neuron_Core_Login::__getInstance(); $error = ''; $username = ''; $showForm = true; $me = Neuron_GameServer::getPlayer(); if (isset($data['username'])) { $username = $data['username']; if ($me->setNickname($username)) { return $this->getPlayerInitialization(true); } else { $error = $me->getError(); } } if ($showForm) { $text = Neuron_Core_Text::__getInstance(); $text->setFile('account'); $text->setSection('nickname'); $page = new Neuron_Core_Template(); if (!empty($error)) { $page->set('error', $text->get($error)); } if (empty($username) && isset($_SESSION['openid_nickname'])) { $username = $_SESSION['openid_nickname']; } $page->set('chooseName', $text->get('chooseName')); $page->set('welcome', $text->get('welcome')); $page->set('username', $text->get('username')); $page->set('submit', $text->get('submit')); $page->set('username_value', Neuron_Core_Tools::output_form($username)); return $page->parse('gameserver/account/chooseNickname.tpl'); } }
public function addUnitTrained($objVillage, $objUnit, $amount) { $db = Neuron_Core_Database::__getInstance(); $id = $db->insert('game_log_training', array('u_id' => $objUnit->getUnitId(), 'lt_amount' => $amount)); $this->addLogEntry($objVillage, 'trained', $id); }
private function processChallengeInput($target) { $text = Neuron_Core_Text::__getInstance(); $text->setFile('battle'); $text->setSection('challenge'); $db = Neuron_Core_Database::__getInstance(); if ($target->isFound()) { $this->updateContent(); } else { $this->updateContent('<p class="false">' . $text->get('teamNotFound') . '</p>'); } }
public function withdraw() { if ($this->canWithdraw()) { // Logs $logs = Dolumar_Players_Logs::getInstance(); $logs->addWithdrawBattle($this); $db = Neuron_Core_Database::__getInstance(); //$battle = $this->getData (); // Calculate the "return home" time $duration = NOW - $this->getStartDate(); // Double return time $duration = $duration * 2; //die ('duration: '. $duration); // Update mysql $db->update('battle', array('isFought' => 1, 'arriveDate' => NOW - 1, 'endDate' => NOW + $duration, 'fightDate' => NOW - 1, 'endFightDate' => NOW - 1, 'bLogId' => 0), "battleId = '{$this->getId()}'"); $this->reloadData(); // Removal //$this->doRemoveBattle (); } }
public function getHTML($error = null) { $page = new Neuron_Core_Template(); $page->setTextSection('chooseTarget', 'main'); $page->set('canTargetSelf', $this->bTargetSelf); $page->set('vid', $this->objVillage->getId()); // Return action if (isset($this->sReturnAction)) { $page->set('returnUrl', $this->sReturnAction); $page->set('returnText', $this->sReturnText); } $sQuery = null; if (isset($this->aInput['sVillageName'])) { $sQuery = $this->aInput['sVillageName']; unset($this->aInput['sVillageName']); } $page->set('input', $this->aInput); $page->set('query', Neuron_Core_Tools::output_varchar($sQuery)); // Fetch all troops if (!empty($sQuery)) { $db = Neuron_Core_Database::__getInstance(); $page->set('hasSearched', true); $l = $db->getDataFromQuery($db->customQuery("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t*\n\t\t\t\t\tFROM\n\t\t\t\t\t\tvillages\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tvname LIKE '%" . $db->escape($sQuery) . "%'\n\t\t\t\t\t\tAND isActive = 1\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\tFIELD(vname, '" . $db->escape($sQuery) . "', vname),\n\t\t\t\t\t\tvname ASC\n\t\t\t\t\tLIMIT 10\n\t\t\t\t")); if (count($l) > 0) { foreach ($l as $v) { $village = Dolumar_Players_Village::getVillage($v['vid'], false); $village->setData($v); $tc = $village->buildings->getTownCenter(); if ($tc) { $loc = $tc->getLocation(); $page->addListValue('results', array('id' => $village->getId(), 'name' => Neuron_Core_Tools::output_varchar($village->getName()), 'location' => $loc[0] . ',' . $loc[1])); } } } } elseif ($this->bShowTargets) { $db = Neuron_DB_Database::__getInstance(); // Popular targets /* $l = $db->getDataFromQuery ( $db->customQuery (" SELECT l_vid, villages.* FROM game_log LEFT JOIN villages ON game_log.l_vid = villages.vid WHERE (l_action = 'attack' OR l_action = 'defend') AND l_vid != ".$this->objVillage->getId ()." AND l_subId = ".$this->objVillage->getId ()." AND isActive = 1 GROUP BY l_vid ORDER BY l_date ASC LIMIT 10 ") ); */ $l = $this->objVillage->visits->getLastVisits(); if (count($l) > 0) { foreach ($l as $village) { // Only add active villages if ($village->isActive()) { $tc = $village->buildings->getTownCenter(); if ($tc) { $loc = $tc->getLocation(); $page->addListValue('results', array('id' => $village->getId(), 'name' => Neuron_Core_Tools::output_varchar($village->getName()), 'location' => $loc[0] . ',' . $loc[1])); } } } } } if (isset($error)) { $page->set('external_error', $error); } return $page->parse('neuron/structure/chooseTarget.phpt'); }
public function getVillageRanking() { $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; if (isset($data['village'])) { $village = Dolumar_Players_Village::getVillageFromId($data['village']); $myVillageId = $data['village']; $myRank = $village->getRank(); $myDefaultPage = floor($myRank[0] / $perPage) + 1; } else { $myVillageId = 0; // Load "main village" from this user $myself = Neuron_GameServer::getPlayer(); if ($myself) { $village = $myself->getMainVillage(); if ($village) { $myVillageId = $village->getId(); $myRank = $village->getRank(); $myDefaultPage = floor($myRank[0] / $perPage) + 1; } } } $currentPage = isset($input['page']) ? $input['page'] : $myDefaultPage; $limit = Neuron_Core_Tools::splitInPages($page, Dolumar_Players_Ranking::countRanking(), $currentPage, $perPage, 6); $l = Dolumar_Players_Ranking::getRanking($limit['start'], $limit['perpage']); // Get my villages $myself = Neuron_GameServer::getPlayer(); if ($myself && $myself->isPremium()) { $distances = $myself->getVillages(); } else { $distances = array(); } $i = $limit['start']; foreach ($l as $v) { $i++; // Calcualte the distances $w_distances = array(); foreach ($distances as $k => $vv) { $w_distances[$k] = Neuron_Core_Tools::output_distance(Dolumar_Map_Map::getDistanceBetweenVillages($vv, $v), true, true); } $page->addListValue('ranking', array($i, Neuron_Core_Tools::output_varchar($v->getName()), $v->getId(), $v->getNetworth(), $v->getId() == $myVillageId, $w_distances)); //$v->__destruct (); } // Add the footnote $t_distances = array(); foreach ($distances as $k => $v) { $t_distances[$k] = Neuron_Core_Tools::output_varchar($v->getName()); } $page->set('distances', $t_distances); return $page->parse('ranking/ranking.tpl'); }
public function setName($name, $desc) { $db = Neuron_Core_Database::__getInstance(); $db->update('clans', array('c_name' => $name, 'c_description' => $desc), "c_id = " . $this->getId()); $this->reloadData(); }
public function releaseLock($sType, $id) { $db = Neuron_Core_Database::__getInstance(); $db->remove('n_locks', "l_type = '" . $sType . "' AND l_lid = " . intval($id)); $this->releaseSoftLock($sType, $id); if (isset($this->locks[$sType])) { unset($this->locks[$sType][$id]); } }
public static function getBuildingsFromLocations($points = array(), $range = 5) { $profiler = Neuron_Profiler_Profiler::__getInstance(); $profiler->start('Loading buildings from multiple points'); $db = Neuron_Core_Database::__getInstance(); $select = "FALSE "; foreach ($points as $v) { $select .= "OR ( xas < '" . ($v[0] + $range) . "' AND xas > '" . ($v[0] - $range) . "' AND yas < '" . ($v[1] + $range) . "' AND yas > '" . ($v[1] - $range) . "') "; } $sql = "\n\t\t\tSELECT\n\t\t\t\tmap_buildings.*,\n\t\t\t\tvillages.race\n\t\t\tFROM\n\t\t\t\tmap_buildings\n\t\t\tLEFT JOIN\n\t\t\t\tvillages ON map_buildings.village = villages.vid\n\t\t\tWHERE\n\t\t\t\t(\n\t\t\t\t\tmap_buildings.destroyDate = '0'\n\t\t\t\t\tOR map_buildings.destroyDate > '" . (time() - RUINS_DURATION) . "'\n\t\t\t\t)\n\t\t\t\tAND\n\t\t\t\t(\n\t\t\t\t\t{$select}\n\t\t\t\t)\n\t\t\tORDER BY\n\t\t\t\tmap_buildings.destroyDate = '0' DESC,\n\t\t\t\tmap_buildings.destroyDate DESC\n\t\t"; $buildingSQL = $db->getDataFromQuery($db->customQuery($sql)); $profiler->stop(); return $buildingSQL; }
public static function countVillages($showInactive = true) { $db = Neuron_Core_Database::__getInstance(); if ($showInactive) { $l = $db->getDataFromQuery($db->customQuery("\n\t\t\t\tSELECT\n\t\t\t\t\tCOUNT(vid) as aantal\n\t\t\t\tFROM\n\t\t\t\t\tvillages\n\t\t\t")); } else { $l = $db->getDataFromQuery($db->customQuery("\n\t\t\t\tSELECT\n\t\t\t\t\tCOUNT(vid) as aantal\n\t\t\t\tFROM\n\t\t\t\t\tvillages\n\t\t\t\tLEFT JOIN\n\t\t\t\t\tn_players ON villages.plid = n_players.plid\n\t\t\t\tWHERE\n\t\t\t\t\tn_players.isKillVillages = '0'\n\t\t\t")); } return $l[0]['aantal']; }
private function getClosebyClans() { // Fetch all players within the available radius $db = Neuron_Core_Database::__getInstance(); // sqrt (pow ($x1 - $x2, 2) + pow ($y1 - $y2, 2) ) $player = Neuron_GameServer::getPlayer(); $selectors = "FALSE OR "; $villages = $player->getVillages(); // No villages = no nearby clans. if (count($villages) == 0) { return array(); } foreach ($villages as $v) { $townCenter = $v->buildings->getTownCenter(); if ($townCenter) { list($x, $y) = $townCenter->getLocation(); $selectors .= "SQRT(POW(xas-" . $x . ",2)+POW(yas-" . $y . ",2)) < " . MAXCLANDISTANCE . " OR "; } } $selectors = substr($selectors, 0, -4); $sSQL = "\n\t\t\tSELECT\n\t\t\t\tclans.*\n\t\t\tFROM\n\t\t\t\tmap_buildings\n\t\t\tLEFT JOIN\n\t\t\t\tvillages ON map_buildings.village = villages.vid\n\t\t\tLEFT JOIN\n\t\t\t\tn_players ON villages.plid = n_players.plid\n\t\t\tLEFT JOIN\n\t\t\t\tclan_members ON n_players.plid = clan_members.plid\n\t\t\tLEFT JOIN\n\t\t\t\tclans ON clan_members.c_id = clans.c_id\n\t\t\tWHERE\n\t\t\t\t(\n\t\t\t\t\tmap_buildings.buildingType = 1\n\t\t\t\t\tAND \n\t\t\t\t\t(\n\t\t\t\t\t\t{$selectors}\n\t\t\t\t\t)\n\t\t\t\t\tAND clans.c_name IS NOT NULL\n\t\t\t\t)\n\t\t\tGROUP BY\n\t\t\t\tclans.c_id\n\t\t"; $sql = $db->getDataFromQuery($db->customQuery($sSQL)); $out = array(); foreach ($sql as $v) { $out[] = new Dolumar_Players_Clan($v['c_id'], $v); } return $out; }
public static function countAll() { $db = Neuron_Core_Database::__getInstance(); $total = $db->select('n_players', array('count(plid) AS total')); $total = count($total) > 0 ? $total[0]['total'] : 1; return $total; }
public function isMoving() { $db = Neuron_Core_Database::__getInstance(); // Check if moving $chk = $db->select('squad_commands', array('sc_id'), "s_id = " . $this->getId() . " \n\t\t\tAND s_end > FROM_UNIXTIME(" . NOW . ")"); return !count($chk) == 0; }
public function trainTechnology($technology) { $db = Neuron_Core_Database::__getInstance(); // Fetch technology id $techIds = $db->select('technology', array('techId'), "techName = '" . $db->escape($technology->getString()) . "'"); if (count($techIds) == 0) { $techId = $db->insert('technology', array('techName' => $technology->getString())); } else { $techId = $techIds[0]['techId']; } $db->insert('villages_tech', array('vid' => $this->objProfile->getId(), 'techId' => $techId, 'startDate' => time(), 'endDate' => time() + $technology->getDuration())); $objLogs = Dolumar_Players_Logs::__getInstance(); $objLogs->addResearchDone($this->objProfile, $technology); reloadStatusCounters(); return true; }
public function killUnit() { $db = Neuron_Core_Database::__getInstance(); $id = $this->getId(); if ($id > 0) { $db->remove('villages_specialunits', "vsu_id = " . $id); } $this->isAlive = false; }
public function getBuildingBuildings() { // Load unfinished buildings $db = Neuron_Core_Database::__getInstance(); $buildings = $db->select('map_buildings', array('*'), "(readyDate > '" . time() . "' OR lastUpgradeDate > '" . time() . "') AND destroyDate = '0' AND village = '" . $this->objMember->getId() . "'"); return $buildings; }
protected function getCustomContent($input) { $db = Neuron_Core_Database::__getInstance(); $text = Neuron_Core_Text::__getInstance(); $text->setFile('buildings'); $text->setSection('townCenter'); $page = new Neuron_Core_Template(); // Just to make sure we're not displaying old rune scouts. $this->getVillage()->resources->getRunes(); // Change village name if (isset($input['villageName'])) { $input['villageName'] = strip_tags($input['villageName']); if (!$this->getVillage()->setName($input['villageName'])) { $page->set('changename_err', $text->get($this->getVillage()->getError())); } else { reloadEverything(); } } // Let's check if we are already searching for runes $runeCheck = $db->select('villages_scouting', array('count(scoutId)'), "vid = '" . $this->getVillage()->getId() . "'"); $alreadyScouting = $runeCheck[0]['count(scoutId)'] > 0; if (isset($input['do'])) { if ($input['do'] == 'scout') { $this->hideGeneralOptions(); $this->hideTechnologyUpgrades(); $currentPage = isset($input['pageid']) ? $input['pageid'] : 1; if ($currentPage < 1) { $currentPage = 1; } Neuron_Core_Tools::splitInPages($page, $currentPage * 4 + 8, $currentPage, 4, 4, array('do' => 'scout'), null, 'pageid'); if ($alreadyScouting) { $page->set('scoutResults', $text->get('alreadyScouting')); $page->set('scoutResult_isGood', false); } else { if (isset($input['runes']) && is_numeric($input['runes'])) { $runes = intval($input['runes']); // Let's start scouting $village = $this->getVillage(); //$cost = $village->getScoutLandsCost ($runes); if ($village->scout($runes)) { $page->set('scoutResults', $text->get('doneScouting')); $page->set('scoutResult_isGood', true); } else { $page->set('scoutResults', $text->get('searchNoRunes')); $page->set('scoutResult_isGood', false); } } else { $scoutoptions = array(); $start = ($currentPage - 1) * 4 + 1; $end = $start + 4; for ($i = $start; $i < $end; $i++) { $duration = $this->getVillage()->getScoutLandsDuration($i); $cost = $this->resourceToText($this->getVillage()->getScoutLandsCost($i)); $duration = Neuron_Core_Tools::getDuration($duration); $scoutoptions[] = array('runes' => $i, 'scoutDuration' => $duration, 'scoutCost' => $cost); } $page->set('scoutoptions', $scoutoptions); } } return $page->parse('buildings/townCenter_scoutRunes.phpt'); } else { if ($input['do'] == 'explore') { /* * TODO ;-) * $village = $this->getVillage (); $village->lookForNPCs (); */ } } } $page->set('vid', $this->getVillage()->getId()); // Search for new runes $page->set('searchRunes', $text->get('searchRunes')); $page->set('scoutLands', $text->get('scoutLands')); $page->set('scoutCost', $text->get('scoutCost')); // Change name $page->set('changeName', $text->get('changeName')); $page->set('villageName', $text->get('villageName')); $page->set('change', $text->get('change')); $page->set('villageName_value', Neuron_Core_Tools::output_varchar($this->getVillage()->getName())); $page->set('overview', $text->getClickTo($text->get('overview'))); $page->set('techniques', $text->getClickTo($text->get('techniques'))); $page->set('toScout', $text->getClickTo($text->get('toScout'))); return $page->parse('buildings/townCenter.phpt'); }
protected function getPlayerInitialization($registrationTracker = false) { // Check if we can actually register $server = Neuron_GameServer::getServer(); if (!$server->canRegister()) { return '<p>This server has gone into "endgame" mode. You can not register here anymore. But stay tuned, a new game will start soon.</p>'; } $data = $this->getInputData(); $me = Neuron_GameServer::getPlayer(); if (isset($data['race'])) { // Check for clans $clan = isset($data['clan']) ? intval($data['clan']) : 0; $location = isset($data['location']) ? $data['location'] : null; $objClan = false; if ($clan > 0) { $objClan = new Dolumar_Players_Clan($clan); if ($objClan->isFound()) { // Check for password if ($objClan->isPasswordProtected()) { // Break out of the function if the password is not correct. if (!isset($data['password']) || !$objClan->checkPassword($data['password'])) { return $this->requestClanPassword($data['race'], $objClan); } } $members = $objClan->getMembers(); if (count($members) > 0) { $member = $members[rand(0, count($members) - 1)]; // Fetch towncenter $village = $member->getMainVillage(); if ($village) { // Overwrite location with the location of this towncenter. $location = $village->buildings->getTownCenterLocation(); } else { $location = array(0, 0); } } else { $location = array(0, 0); } } } if ($me->initializeAccount($data['race'], $location, $objClan)) { // Scroll to the right location $me = Neuron_GameServer::getPlayer(); $home = $me->getHomeLocation(); $this->mapJump($home[0], $home[1]); // Reload area $this->reloadLocation($home[0], $home[1]); reloadEverything(); return $this->getContent(false); } else { //return $this->getPlayerInitialization (); } } $text = Neuron_Core_Text::__getInstance(); $text->setFile('account'); $text->setSection('selectRace'); $data = $this->getInputData(); // Show form $page = new Neuron_Core_Template(); $error = Neuron_GameServer::getPlayer()->getError(); if (!empty($error)) { $page->set('error', $text->get($error, 'errors', 'account', $error)); } // Loop trough races foreach (Dolumar_Races_Race::getRaces() as $k => $v) { $race = Dolumar_Races_Race::getFromId($k); if ($race->canPlayerSelect(Neuron_GameServer::getPlayer())) { $page->addListValue('races', array($text->get($v, 'races', 'races', $v), $text->get($v, 'desc', 'races', 'null'), $k)); } } $page->sortList('races'); // Some text values $page->set('submit', $text->get('submit')); $page->set('select', $text->get('select')); $page->set('location', $text->get('location')); if ($registrationTracker === true) { $tracker = Neuron_GameServer::getPlayer()->getTrackerUrl('registration'); $page->set('tracker_url', htmlentities($tracker)); } // Locations $page->addListValue('directions', array($text->get('r', 'directions', 'main'), 'r')); $page->addListValue('directions', array($text->get('n', 'directions', 'main'), 'n')); $page->addListValue('directions', array($text->get('ne', 'directions', 'main'), 'ne')); $page->addListValue('directions', array($text->get('e', 'directions', 'main'), 'e')); $page->addListValue('directions', array($text->get('es', 'directions', 'main'), 'es')); $page->addListValue('directions', array($text->get('s', 'directions', 'main'), 's')); $page->addListValue('directions', array($text->get('sw', 'directions', 'main'), 'sw')); $page->addListValue('directions', array($text->get('w', 'directions', 'main'), 'w')); $page->addListValue('directions', array($text->get('wn', 'directions', 'main'), 'wn')); // Fetch a list of all clans $db = Neuron_Core_Database::__getInstance(); $clans = $db->select('clans', array('*')); // Add a list of all clans ;-) foreach ($clans as $v) { $clan = new Dolumar_Players_Clan($v['c_id'], $v); $page->addListValue('clans', array('id' => $clan->getId(), 'name' => Neuron_Core_Tools::output_varchar($clan->getName()), 'isLocked' => $clan->isPasswordProtected(), 'isFull' => $clan->isFull())); } return $page->parse('account/selectRace.phpt'); }
public function doCastSpell($objVillage, $objTarget, $visible = true) { $db = Neuron_Core_Database::__getInstance(); // First: get the id $id = $this->getId(); $db->insert('boosts', array('b_targetId' => $objTarget->getId(), 'b_fromId' => $objVillage->getId(), 'b_type' => 'spell', 'b_ba_id' => $id, 'b_start' => NOW, 'b_end' => NOW + $this->getDuration(), 'b_secret' => $visible ? '0' : '1')); $objTarget->reloadActiveBoosts(); }
public static function getUnitId_static($classname) { static $ids; if (!isset($ids[$classname])) { $db = Neuron_Core_Database::__getInstance(); $l = $db->getDataFromQuery($db->customQuery("\n\t\t\t\tSELECT\n\t\t\t\t\tunitId\n\t\t\t\tFROM\n\t\t\t\t\tunits\n\t\t\t\tWHERE\n\t\t\t\t\tunitName = '" . $classname . "'\n\t\t\t\tFOR UPDATE\n\t\t\t")); if (count($l) == 1) { $id = $l[0]['unitId']; } else { $id = $db->insert('units', array('unitName' => $classname)); } $ids[$classname] = $id; } return $ids[$classname]; }
public static function countRankingFromOpenAuth($authType, $authUIDs = array()) { $db = Neuron_Core_Database::__getInstance(); if (!is_array($authUIDs)) { return 0; } else { $where = "p.authType = '" . $db->escape($authType) . "' AND (FALSE"; // Actual where values: foreach ($authUIDs as $v) { $where .= " OR authUID = '" . $db->escape($v) . "'"; } $where .= ')'; $query = "\n\t\t\t\tSELECT\n\t\t\t\t\tcount(v.vid) AS aantal\n\t\t\t\tFROM\n\t\t\t\t\tn_players p\n\t\t\t\tRIGHT JOIN\n\t\t\t\t\tvillages v ON p.plid = v.plid\n\t\t\t\tWHERE\n\t\t\t\t\t{$where}\n\t\t\t"; $l = $db->getDataFromQuery($db->customQuery($query)); if (count($l) == 1) { return $l[0]['aantal']; } else { return 0; } } }
// Append new window xml $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) {
private function getCraftItem($id, $input) { $db = Neuron_Core_Database::__getInstance(); // Check if this building is crafting already $l = $db->select('villages_items', array('i_id'), "i_bid = '" . $this->getId() . "' AND i_endCraft > '" . time() . "'"); if (count($l) > 0) { $text = Neuron_Core_Text::__getInstance(); $page = new Neuron_Core_Template(); $page->set('working', $text->get('working', 'crafting', 'buildings')); $page->set('toReturn', $text->getClickTo($text->get('toReturn', 'crafting', 'buildings'))); return $page->parse('buildings/working.tpl'); } else { $equipment = $this->getCraftableItems(); // Search for key $key = false; $equips = $this->getCraftableItems(); foreach ($equips as $k => $v) { if ($v->getId() == $id) { $key = $k; } } if ($key !== false) { $item = $equips[$key]; $text = Neuron_Core_Text::__getInstance(); $text->setFile('buildings'); $text->setSection('crafting'); // Check for input if (isset($input['amount']) && is_numeric($input['amount'])) { $aantal = abs(floor($input['amount'])); $cost = $item->getCraftCost($this->getVillage(), $aantal); // Remove resources if ($this->getVillage()->resources->takeResourcesAndRunes($cost)) { $this->getVillage()->craftEquipment($this, $item, $item->getCraftDuration($this->getVillage(), $aantal), $aantal); //return $this->getOverview (); return '<p>' . $text->get('done') . '</p>'; } else { $error = $text->get('noResources'); } } $page = new Neuron_Core_Template(); // Get max craftable $player = $this->getVillage()->getOwner(); if ($player->isPremium()) { $page->set('maxcraftable', Neuron_Core_Tools::putIntoText($text->get('maxcraftable'), array('amount' => $this->calculateMaxCraftable($item), 'items' => $item->getName(true)))); } if (isset($error)) { $page->set('error', $error); } $page->set('title', $text->get('title')); $page->set('amount', $text->get('amount')); $page->set('submit', $text->get('submit')); $page->set('itemId', $item->getId()); $page->set('section', 'crafting'); $page->set('cost', $this->getCost($item)); $page->set('duration', Neuron_Core_Tools::putIntoText($text->get('duration'), array($item->getName(), Neuron_Core_Tools::getDuration($item->getCraftDuration($this->getVillage()))))); $page->set('stats', Neuron_Core_Tools::output_text($item->getStats_text(), false)); $page->set('about', Neuron_Core_Tools::putIntoText($text->get('craft'), array($item->getName(true)))); $page->set('return', $text->getClickTo($text->get('toReturn'))); return $page->parse('buildings/crafting.tpl'); } else { return $this->getOverview(); } } }