Esempio n. 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();
 }
Esempio n. 2
0
 public static function getVillage($id, $syncBattle = NOW, $cronStuff = false, $noStatic = false)
 {
     $in = self::$instances;
     $id = intval($id);
     if (empty($id) || $id == 0) {
         return new Dolumar_Players_DummyVillage();
     }
     $lock = Neuron_Core_Lock::__getInstance();
     if (!defined('DISABLE_STATIC_FACTORY') && !$noStatic) {
         // Initialize the village
         if (!isset($in[$id]) || !$in[$id]->isInitialized) {
             $in[$id] = new Dolumar_Players_Village($id, $cronStuff);
         }
         $village = $in[$id];
     } else {
         $village = new Dolumar_Players_Village($id, $cronStuff);
     }
     $village->setBattleProcessData($syncBattle);
     return $village;
 }
Esempio n. 3
0
 private function processTransfers()
 {
     if ($this->areTransfersProcessed) {
         return true;
     }
     $db = Neuron_DB_Database::getInstance();
     $this->areTransfersProcessed = true;
     $transfers = $db->query("\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\tvillages_transfers\n\t\t\tWHERE\n\t\t\t\tto_vid = {$this->objMember->getId()} AND\n\t\t\t\tt_date_received < FROM_UNIXTIME(" . NOW . ") AND\n\t\t\t\tt_isReceived = '0'\n\t\t");
     if (count($transfers) > 0) {
         $objLock = Neuron_Core_Lock::__getInstance();
         if ($objLock->setLock('prcTransfer', $this->objMember->getId())) {
             try {
                 // Reload the transfers (lock bestendig)
                 $transfers = $db->query("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\tvillages_transfers\n\t\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\t\tvillages_transfers_items USING(t_id)\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tto_vid = {$this->objMember->getId()} AND\n\t\t\t\t\t\t\tt_date_received < FROM_UNIXTIME(" . NOW . ") AND\n\t\t\t\t\t\t\tt_isReceived = '0'\n\t\t\t\t\t");
                 $resources = array();
                 $runes = array();
                 $equipment = array();
                 $transactions = array();
                 foreach ($transfers as $v) {
                     switch ($v['ti_type']) {
                         case 'RESOURCE':
                             if (isset($resources[$v['ti_key']])) {
                                 $resources[$v['ti_key']] += $v['ti_amount'];
                             } else {
                                 $resources[$v['ti_key']] = $v['ti_amount'];
                             }
                             break;
                         case 'RUNE':
                             if (isset($runes[$v['ti_key']])) {
                                 $runes[$v['ti_key']] += $v['ti_amount'];
                             } else {
                                 $runes[$v['ti_key']] = $v['ti_amount'];
                             }
                             break;
                         case 'EQUIPMENT':
                             if (isset($equipment[$v['ti_key']])) {
                                 $equipment[$v['ti_key']] += $v['ti_amount'];
                             } else {
                                 $equipment[$v['ti_key']] = $v['ti_amount'];
                             }
                             break;
                     }
                     $transactions[$v['t_id']] = true;
                 }
                 foreach (array_keys($transactions) as $v) {
                     // Now make sure we don't give these resources again
                     $db->query("\n\t\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\t\tvillages_transfers\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\tt_isReceived = '1'\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tt_id = {$v}\n\t\t\t\t\t\t");
                 }
             } catch (Exception $error) {
                 error_log("Transfer error: " . $error->getMessage());
             }
             $objLock->releaseLock('prcTransfer', $this->objMember->getId());
             $logcontainer = new Dolumar_Logable_GeneralContainer();
             // Now let's add 'em resources
             if (count($resources) > 0) {
                 $logcontainer->add(new Dolumar_Logable_ResourceContainer($resources));
                 $this->giveResources($resources);
             }
             if (count($runes) > 0) {
                 $logcontainer->add(new Dolumar_Logable_RuneContainer($runes));
                 $this->giveRunes($runes);
             }
             if (count($equipment) > 0) {
                 $this->giveEquipment($equipment);
             }
             // Now we just need to log it
             $objLogs = Dolumar_Players_Logs::__getInstance();
             $objLogs->addCompleteTransferLog($this->objMember, $logcontainer);
         } else {
             error_log("Could not lock for transfers: " . $this->objMember->getId());
         }
     }
 }
Esempio n. 4
0
 public function doUpgradeBuilding()
 {
     $res = $this->getUpgradeCost($this->getVillage());
     $objLock = Neuron_Core_Lock::__getInstance();
     if ($objLock->setLock('upgradebuilding', $this->getId())) {
         $return = false;
         $duration = $this->getUpgradeTime($this->getVillage());
         // Check some stuff
         if (!$this->isFinished()) {
             $this->sError = 'unfinished';
         } elseif (!$this->getVillage()->readyToBuild()) {
             $this->sError = 'busy';
         } elseif (!$this->getVillage()->resources->takeResourcesAndRunes($res)) {
             $this->sError = $this->getVillage()->resources->getError();
         } else {
             $db = Neuron_Core_Database::__getInstance();
             // Reload buildings & runes
             $this->getVillage()->buildings->reloadBuildings();
             $this->getVillage()->resources->reloadRunes();
             $this->getVillage()->buildings->increaseBuildingLevel($this, $this->getLevel() + 1);
             // Update duration
             $db->update('map_buildings', array('lastUpgradeDate' => time() + $duration, 'bLevel' => '++'), "bid = '" . $this->id . "'");
             // Reload windows
             if (isset($this->objWindow)) {
                 reloadEverything();
                 reloadStatusCounters();
                 $loc = $this->getLocation();
                 $this->objWindow->reloadLocation($loc[0], $loc[1]);
             }
             $runes = array();
             if (isset($res['runeId']) && isset($res['runeAmount'])) {
                 $runes[$res['runeId']] = $res['runeAmount'];
             }
             unset($res['runeId']);
             unset($res['runeAmount']);
             $this->addUsedResources($res, $runes);
             $this->getVillage()->onUpgrade($this);
             $return = true;
         }
         $objLock->releaseLock('upgradebuilding', $this->getId());
         return $return;
     } else {
         return false;
     }
 }