示例#1
0
 public function processBattles($now)
 {
     // Check if it has been checked for this
     if ($now <= $this->iLastBattleCheck) {
         return;
     }
     $this->iLastBattleCheck = $now;
     // To not replace all this shit.
     $villageId = $this->objProfile->getId();
     // Start profiler & stuff
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Calculating battles for village ' . $villageId . ' (' . $now . ')');
     // The lock will make sure that every battle will only be calculated one time.
     $lock = Neuron_Core_Lock::__getInstance();
     // First: make sure this village hasn't been calculated yet
     /*
     if ($lock->setSoftLock ('battle_village', $villageId.'_'.$now))
     {
     */
     $dbi = Neuron_DB_Database::getInstance();
     $villageId = intval($villageId);
     $battles = $dbi->query("\n\t\t\t\tSELECT\n\t\t\t\t\tbattleId\n\t\t\t\tFROM\n\t\t\t\t\tbattle\n\t\t\t\tWHERE\n\t\t\t\t\t(vid = {$villageId} OR targetId = {$villageId})\n\t\t\t\t\tAND (\n\t\t\t\t\t\t(fightDate < {$now} AND isFought = '0') OR\n\t\t\t\t\t\tendDate < {$now}\n\t\t\t\t\t)\n\t\t\t\tORDER BY\n\t\t\t\t\tfightDate ASC,\n\t\t\t\t\tendDate ASC,\n\t\t\t\t\tbattleId ASC\n\t\t\t");
     $profiler->start('Processing ' . count($battles) . ' battles.');
     foreach ($battles as $bdata) {
         $profiler->start('Processing battle ' . $bdata['battleId']);
         // Only process every battle ones
         if ($lock->setLock('battle', $bdata['battleId'])) {
             $profiler->start('Lock set, process battles.');
             $battle = Dolumar_Battle_Battle::getBattle($bdata['battleId']);
             //$battle->setData ($aBattle, $this->objProfile);
             // Check for fight execution
             if ($battle->getFightDate() <= $now && !$battle->isFought()) {
                 $profiler->start('Executing battle #' . $battle->getId());
                 // Execute battle
                 $battle->execute();
                 $profiler->stop();
             }
             // Check for fight removal
             if ($battle->getEndDate() <= $now && $battle->isFought()) {
                 $profiler->start('Removing battle #' . $battle->getId());
                 // Do finish battle stuff
                 $battle->removeBattle();
                 $profiler->stop();
             }
             //$battle->__destruct ();
             unset($battle);
             //}
             $lock->releaseLock('battle', $bdata['battleId']);
             $profiler->stop();
             $this->objProfile->reloadData();
             reloadEverything();
         } else {
             $profiler->start('Battle is already locked, not doing anything.');
             $profiler->stop();
         }
         $profiler->stop();
     }
     $profiler->stop();
     $profiler->stop();
 }
示例#2
0
 private function generateSquare($x, $y)
 {
     // Clear some space:
     $this->randCache = array();
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Generating perlin noise square (' . $x . ',' . $y . ')');
     $lx = ($x + 1) * self::PAR_FILE;
     $ly = ($y + 1) * self::PAR_FILE;
     for ($i = $x * self::PAR_FILE; $i < $lx; $i++) {
         for ($j = $y * self::PAR_FILE; $j < $ly; $j++) {
             self::getOneSingleLocation($i, $j);
         }
     }
     $profiler->stop();
 }
示例#3
0
文件: Units.php 项目: Toxicat/dolumar
 /**
  * Return all data from one given order ID
  */
 public function speedupBuild($id, $amount)
 {
     $db = Neuron_DB_Database::getInstance();
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Speeding up training of ' . $id . ' with ' . $amount . ' seconds.');
     $data = $this->getTrainingStatus($id);
     if ($data) {
         $timeLeft = $data['timeLeft'];
         if ($amount > $timeLeft) {
             $amount = $timeLeft;
         }
     }
     $db->query("\n\t\t\tUPDATE\n\t\t\t\tvillages_units\n\t\t\tSET\n\t\t\t\tendTraining = endTraining - {$amount}\n\t\t\tWHERE\n\t\t\t\tuid = {$id}\n\t\t");
     $profiler->stop();
     return;
 }
示例#4
0
 private function loadBuildings()
 {
     if (!isset($this->buildings)) {
         $profiler = Neuron_Profiler_Profiler::__getInstance();
         $profiler->start('Loading buildings');
         $db = Neuron_Core_Database::__getInstance();
         $buildingsDBData = $db->getDataFromQuery($db->customQuery("\n\t\t\t\tSELECT\n\t\t\t\t\t*\n\t\t\t\tFROM\n\t\t\t\t\tmap_buildings\n\t\t\t\tWHERE\n\t\t\t\t\tvillage = '" . $this->objMember->getId() . "'\n\t\t\t\t\tAND (destroyDate = 0 OR destroyDate > " . NOW . ")\n\t\t\t"));
         $this->buildings = array();
         $this->buildingCount = array();
         $this->buildingCount_all = array();
         $this->buildingLevelSum = array();
         foreach ($buildingsDBData as $v) {
             $b = Dolumar_Buildings_Building::getBuilding($v['buildingType'], $this->objMember->getRace(), $v['xas'], $v['yas']);
             $b->setData($v['bid'], $v);
             $b->setVillage($this->objMember);
             $this->buildings[$v['bid']] = $b;
             if ($b->isFinishedBuilding()) {
                 // Count the buildings
                 if (!isset($this->buildingCount[$v['buildingType']])) {
                     $this->buildingCount[$v['buildingType']] = 0;
                 }
                 $this->buildingCount[$v['buildingType']]++;
                 if (!isset($this->buildingLevelSum[$v['buildingType']])) {
                     $this->buildingLevelSum[$v['buildingType']] = 0;
                 }
                 $this->buildingLevelSum[$v['buildingType']] += $v['bLevel'];
             }
             // Count the buildings
             if (!isset($this->buildingCount_all[$v['buildingType']])) {
                 $this->buildingCount_all[$v['buildingType']] = 0;
             }
             $this->buildingCount_all[$v['buildingType']]++;
         }
         $profiler->stop();
     }
 }
示例#5
0
文件: Map.php 项目: Toxicat/dolumar
 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;
 }
示例#6
0
 public function setLocationCache($x, $y, $data)
 {
     if (!self::USE_MYSQL) {
         return;
     }
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Setting cache for (' . $x . ',' . $y . ')');
     $x = intval($x);
     $y = intval($y);
     $this->dbObj->query("\n\t\t\tINSERT INTO\n\t\t\t\t" . $this->sTable . "\n\t\t\t(\n\t\t\t\tt_ix, t_iy, t_tile, t_random, t_height, t_distance\n\t\t\t)\n\t\t\tVALUES\n\t\t\t(\n\t\t\t\t{$x},\n\t\t\t\t{$y},\n\t\t\t\t'{$data[0]}',\n\t\t\t\t'{$data[1]}',\n\t\t\t\t'{$data[2]}',\n\t\t\t\tSQRT(({$x}*{$x})+({$y}*{$y}))\n\t\t\t)\n\t\t");
     $this->aTiles[$x][$y] = $data;
     // Now it's in mysql, we remove the memcached area.
     $this->objMemcache->removeCache($this->getCacheName($x, $y));
     $profiler->stop();
 }
示例#7
0
 public function delayFightDate($duration, $pendingBattles)
 {
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Delaying fight');
     //echo 'Delaying fight '.$this->getId ().' to '.$duration."\n";
     $aproxBattleDuration = ceil(60 * 10 / GAME_SPEED_MOVEMENT);
     $pendingBattles = $pendingBattles - 1;
     $this->loadData();
     $db = Neuron_Core_Database::__getInstance();
     if ($this->data['fightDate'] <= $duration) {
         $timestamp = $duration + $aproxBattleDuration;
         $db->update('battle', array('fightDate' => $timestamp, 'endFightDate' => $timestamp + $aproxBattleDuration, 'endDate' => $timestamp + $this->data['goHomeDuration'] + 1), "battleId = " . $this->getId());
         $this->data['fightDate'] = $timestamp;
         $this->data['endDate'] = $timestamp + $this->data['goHomeDuration'];
     }
     $profiler->stop();
 }
示例#8
0
 public function setLocationCache($x, $y, $data)
 {
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Setting cache for (' . $x . ',' . $y . ')');
     $this->dbObj->query("\n\t\t\tINSERT INTO\n\t\t\t\tb_tiles\n\t\t\t(\n\t\t\t\tt_ix, t_iy, t_tile, t_random, t_height\n\t\t\t)\n\t\t\tVALUES\n\t\t\t(\n\t\t\t\t'{$x}',\n\t\t\t\t'{$y}',\n\t\t\t\t'{$data[0]}',\n\t\t\t\t'{$data[1]}',\n\t\t\t\t'{$data[2]}'\n\t\t\t)\n\t\t");
     $this->aTiles[$x][$y] = $data;
     $profiler->stop();
 }
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  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.
 */
global $imageCache;
global $output;
global $imagecounter;
$imagecounter = 1;
$diameter = isset($_GET['tiles']) ? $_GET['tiles'] : 5;
$loadExtra = isset($_GET['overlap']) ? $_GET['overlap'] : 3;
// Start profiler
$profiler = Neuron_Profiler_Profiler::__getInstance();
$profiler->start('Generating all JSON map requests');
$output = '';
$imageCache = array();
function map_image_cache(Neuron_GameServer_Map_Display_Sprite $image)
{
    global $imageCache;
    global $output;
    global $imagecounter;
    $id = $image->getURI();
    if (!isset($imageCache[$id])) {
        $intid = md5($id);
        $imageCache[$id] = $imagecounter;
        $output['images'][$imagecounter] = array('id' => $intid, 'url' => $image->getURI());
        $imagecounter++;
    }
示例#10
0
 public function speedupBuild($amount)
 {
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Speeding up building ' . $this->getId() . ' with ' . $amount . ' seconds.');
     // Now let's check if $amount is bigger than timeleft
     if ($amount > $this->getTimeLeft()) {
         $amount = $this->getTimeLeft();
     }
     $result = $this->delayBuild(0 - $amount);
     $profiler->stop();
     return $result;
 }
示例#11
0
 private function loadUnits($now = NOW)
 {
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     if (!isset($this->myUnits[$now])) {
         $profiler->start('Loading units');
         $profiler->start('Loading units from database');
         $db = Neuron_Core_Database::__getInstance();
         $dbi = Neuron_DB_Database::getInstance();
         $l = $db->getDataFromQuery($db->customQuery("\n\t\t\t\tSELECT\n\t\t\t\t\tu.*,\n\t\t\t\t\tunits.unitName,\n\t\t\t\t\tSUM(squad_units.s_amount) AS amountInSquads\n\t\t\t\tFROM\n\t\t\t\t\tvillages_units u\n\t\t\t\tLEFT JOIN\n\t\t\t\t\tunits ON u.unitId = units.unitId\n\t\t\t\tLEFT JOIN\n\t\t\t\t\tsquad_units ON u.unitId = squad_units.u_id AND squad_units.v_id = u.vid\n\t\t\t\tWHERE\n\t\t\t\t\tu.vid = " . $this->getId() . "\n\t\t\t\tGROUP BY uid\n\t\t\t"));
         $profiler->stop();
         $profiler->start('Loading squads in battle');
         // Load thze units in thze battle
         $bts = $db->getDataFromQuery($db->customQuery("\n\t\t\t\tSELECT\n\t\t\t\t\t*\n\t\t\t\tFROM\n\t\t\t\t\tbattle_squads\n\t\t\t\tLEFT JOIN\n\t\t\t\t\tsquad_units ON battle_squads.bs_squadId = squad_units.s_id\n\t\t\t\tWHERE\n\t\t\t\t\tbattle_squads.bs_vid = " . $this->getId() . "\n\t\t\t"));
         $squadsIB = array();
         foreach ($bts as $bt) {
             if (isset($squadsIB[$bt['u_id']])) {
                 $squadsIB[$bt['u_id']] += $bt['s_amount'];
             } else {
                 $squadsIB[$bt['u_id']] = $bt['s_amount'];
             }
         }
         $profiler->stop();
         $profiler->start('Loading supporting squads.');
         // Load thze squads that are not at home.
         $query = "\n\t\t\t\tSELECT\n\t\t\t\t\tsquad_units.u_id,\n\t\t\t\t\tsquad_units.s_amount\n\t\t\t\tFROM\n\t\t\t\t\tvillages_squads\n\t\t\t\tLEFT JOIN\n\t\t\t\t\tsquad_units ON villages_squads.s_id = squad_units.s_id\n\t\t\t\tLEFT JOIN\n\t\t\t\t\tsquad_commands ON (villages_squads.s_id = squad_commands.s_id \n\t\t\t\t\t\tAND squad_commands.s_end > FROM_UNIXTIME(" . NOW . "))\n\t\t\t\tWHERE\n\t\t\t\t\t(\n\t\t\t\t\t\tvillages_squads.v_id = {$this->getId()} AND\n\t\t\t\t\t\tvillages_squads.s_village != 0 AND\n\t\t\t\t\t\tvillages_squads.s_village != {$this->getId()}\n\t\t\t\t\t) AND squad_commands.s_action IS NULL\n\t\t\t";
         $supportingdb = $dbi->query($query);
         $supporting = array();
         foreach ($supportingdb as $v) {
             if (isset($supporting[$v['u_id']])) {
                 $supporting[$v['u_id']] += $v['s_amount'];
             } else {
                 $supporting[$v['u_id']] = $v['s_amount'];
             }
         }
         $profiler->stop();
         $profiler->start('Counting the units');
         $o = array();
         foreach ($l as $v) {
             // Calculate the amount (for training)
             if ($v['endTraining'] < $now) {
                 $amount = $v['amount'] - $v['killedAmount'];
             } else {
                 $duration = max(1, $v['endTraining'] - $v['startTraining']);
                 $procent = max(0, $now - $v['startTraining']) / $duration;
                 $amount = floor($procent * $v['amount']) - $v['killedAmount'];
             }
             $toFeed = $amount;
             // Make new class + withdraw units in combat
             if (!isset($o[$v['unitName']])) {
                 $o[$v['unitName']] = Dolumar_Units_Unit::getUnitFromName($v['unitName'], $this->getRace(), $this);
                 // Calculate the amount of "gone" troops".
                 $away = isset($supporting[$v['unitId']]) ? $supporting[$v['unitId']] : 0;
                 $toFeed -= $away;
                 if (isset($squadsIB[$v['unitId']])) {
                     $available = $amount - $squadsIB[$v['unitId']];
                 } else {
                     $available = $amount;
                 }
                 $o[$v['unitName']]->putInSquads($v['amountInSquads']);
             } else {
                 $available = $amount;
                 $inSquads = 0;
             }
             // Increase amounts
             if ($v['village'] == $this->getId()) {
                 $o[$v['unitName']]->addAmount($available, $toFeed, $amount);
             } else {
                 $o[$v['unitName']]->addAmount(0, $toFeed, $amount);
             }
             // Unit capacity counter
             if (isset($this->unitCapacityCount[$v['buildingId']])) {
                 $this->unitCapacityCount[$v['buildingId']]['current'] += $amount * $o[$v['unitName']]->getRequiredSpace();
                 $this->unitCapacityCount[$v['buildingId']]['absolute'] += ($v['amount'] - $v['killedAmount']) * $o[$v['unitName']]->getRequiredSpace();
             } else {
                 $this->unitCapacityCount[$v['buildingId']] = array('current' => $amount * $o[$v['unitName']]->getRequiredSpace(), 'absolute' => ($v['amount'] - $v['killedAmount']) * $o[$v['unitName']]->getRequiredSpace());
             }
         }
         $profiler->stop();
         $this->myUnits[$now] = $o;
         $profiler->stop();
     }
 }
示例#12
0
 private function loadBattleCounters($vilsIdOrTarget)
 {
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Generating new battle counters');
     $db = Neuron_Core_Database::__getInstance();
     // Load battles
     $t = $db->select('battle', array('*'), "endDate > '" . NOW . "' {$vilsIdOrTarget}");
     $text = Neuron_Core_Text::getInstance();
     $text->setSection('status', 'statusbar');
     foreach ($t as $v) {
         $profiler->start('Loaded battle counter: ' . $v['battleId']);
         $village = Dolumar_Players_Village::getVillage($v['vid']);
         $target = Dolumar_Players_Village::getVillage($v['targetId']);
         $output = array('target' => $this->getVillageName($target));
         $battle = Dolumar_Battle_Battle::getBattle($v['battleId']);
         if ($v['arriveDate'] > NOW) {
             if ($battle->isVisible()) {
                 $txt = Neuron_Core_Tools::putIntoText($text->get('battle_sending'), $output);
                 if ($battle->canWithdraw(Neuron_GameServer::getPlayer())) {
                     $confirm = $text->get('confirmWithdraw', 'battle');
                     $txt .= ' (<a href="javascript:void(0);" class="action" ' . 'onclick="confirmAction(this,{\'action\':\'withdrawbattle\',\'battle\':' . $v['battleId'] . '},\'' . $confirm . '\');">' . $text->get('withdraw', 'battle') . '</a>)';
                 }
                 $this->addCounter($v['arriveDate'], $village, $txt, 'troops sending', true);
             }
         } elseif ($v['fightDate'] >= NOW) {
             $this->addCounter($v['fightDate'], $village, Neuron_Core_Tools::putIntoText($text->get('battle_preparing'), $output), 'troops preparing', true);
         } elseif ($v['endFightDate'] > NOW) {
             // Get my village id
             $me = Neuron_GameServer::getPlayer();
             if ($me->getId() == $village->getOwner()->getId()) {
                 $sOnClick = 'openWindow(\'battle\', {\'vid\':\'' . $village->getId() . '\',\'report\':' . $v['bLogId'] . '});';
             } else {
                 $sOnClick = 'openWindow(\'battle\', {\'vid\':\'' . $target->getId() . '\',\'report\':' . $v['bLogId'] . '});';
             }
             $this->addCounter($v['endFightDate'], $village, '<a href="javascript:void(0);" onclick="' . $sOnClick . '">' . Neuron_Core_Tools::putIntoText($text->get('battle_fighting'), $output) . '</a>.', 'troops fighting', true);
         } elseif ($v['isFought']) {
             $this->addCounter($v['endDate'], $village, Neuron_Core_Tools::putIntoText($text->get('battle_returning'), $output), 'troops returning', true);
         }
         $profiler->stop();
     }
     $profiler->stop();
 }