Esempio n. 1
0
 public function getContent()
 {
     //reloadStatusCounters ();
     $login = Neuron_Core_Login::__getInstance();
     if ($login->isLogin()) {
         return $this->getCounters();
     } else {
         reloadStatusCounters();
         return ' ';
     }
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 public function sendToVillage($target)
 {
     // For now: quick & dirty "instant arrival"
     $db = Neuron_DB_Database::__getInstance();
     // Take a look: is this squad traveling at the moment?
     $current = $db->query("\n\t\t\tSELECT\n\t\t\t\tUNIX_TIMESTAMP(s_start) AS vertrek,\n\t\t\t\tUNIX_TIMESTAMP(s_end) AS aankomst\n\t\t\tFROM\n\t\t\t\tsquad_commands\n\t\t\tWHERE\n\t\t\t\ts_id = " . $this->getId() . "\n\t\t\t\tAND s_end > FROM_UNIXTIME(" . NOW . ")\n\t\t\tORDER BY\n\t\t\t\ts_end DESC\n\t\t\tLIMIT 1\n\t\t");
     if (count($current) > 0) {
         // This squad is currently travelling, this is a recall.
         // Moveing back takes as long as moving overthere.
         $duration = NOW - $current[0]['vertrek'];
         // Remove all others
         $db->query("\n\t\t\t\tDELETE FROM\n\t\t\t\t\tsquad_commands\n\t\t\t\tWHERE\n\t\t\t\t\ts_end < FROM_UNIXTIME(" . NOW . ") OR\n\t\t\t\t\ts_id = " . $this->getId() . "\n\t\t\t");
     } else {
         // Calculate the distance & speed
         $speed = $this->getSpeed();
         $distance = Dolumar_Map_Map::getDistanceBetweenVillages($this->getCurrentLocation(), $target);
         $duration = $distance * 60 * 10 / ($speed * GAME_SPEED_MOVEMENT);
     }
     // Do the actual move
     $db->query("\n\t\t\tUPDATE\n\t\t\t\tvillages_squads\n\t\t\tSET\n\t\t\t\ts_village = " . $target->getId() . "\n\t\t\tWHERE\n\t\t\t\ts_id = " . $this->getId() . "\n\t\t");
     // Update the defense slots
     $db->query("\n\t\t\tUPDATE\n\t\t\t\tsquad_units\n\t\t\tSET\n\t\t\t\ts_slotId = 0,\n\t\t\t\ts_priority = 0\n\t\t\tWHERE\n\t\t\t\ts_id = " . $this->getId() . "\n\t\t");
     // Add the commands
     $db->query("\n\t\t\tINSERT INTO\n\t\t\t\tsquad_commands\n\t\t\tSET\n\t\t\t\ts_id = " . $this->getId() . ",\n\t\t\t\ts_action = 'move',\n\t\t\t\ts_start = FROM_UNIXTIME(" . NOW . "),\n\t\t\t\ts_end = FROM_UNIXTIME(" . (NOW + $duration) . "),\n\t\t\t\ts_from = " . $this->getCurrentLocation()->getId() . ",\n\t\t\t\ts_to = " . $target->getId() . "\n\t\t");
     reloadStatusCounters();
     reloadEverything();
 }
Esempio n. 4
0
 private function getAttackVillage($target)
 {
     $text = Neuron_Core_Text::getInstance();
     // Cannot attack yourself.
     if ($target->getOwner()->equals($this->village->getOwner())) {
         return $this->getChooseUnits($target);
     }
     $canAttack = true;
     if ($target->getOwner()->isClanMember($this->village->getOwner())) {
         $this->error = $text->get('isClanmember', 'challenge', 'battle');
         $canAttack = false;
     }
     $input = $this->getInputData();
     $confirmed = isset($input['confirm']) ? $input['confirm'] == 'yes' : false;
     $squads = $this->getSquadsFromInput($target);
     $specials = $this->getSpecialUnitsFromInput();
     if ($confirmed && count($squads) > 0 && $canAttack) {
         if ($this->village->attackVillage($target, $squads, $specials)) {
             reloadStatusCounters();
             return '<p>' . $text->get('bdone', 'challenge', 'battle') . '</p>';
         } else {
             return $this->getChooseSpecialUnits($target, $squads, $this->village->getError());
         }
     } elseif (count($squads) > 0) {
         return $this->getChooseSpecialUnits($target, $squads);
     } else {
         $text = Neuron_Core_Text::getInstance();
         if (isset($input['selected_troops'])) {
             $this->alert($text->get('dragTroops', 'challenge', 'battle'));
         }
         return $this->getChooseUnits($target);
     }
 }
Esempio n. 5
0
 protected function doCastSpell($objUnit, $objSpell, $objTarget, $visible = true)
 {
     // Just feed the random number generator, just to be sure.
     mt_srand();
     $page = new Neuron_Core_Template();
     $text = Neuron_Core_Text::getInstance();
     $page->setTextSection('result', $this->sTextFile);
     // Now let's start the checking
     $cost = $objSpell->getCost($objUnit, $objTarget);
     if ($this->village->resources->takeResourcesAndRunes($cost)) {
         $dif = $this->getProbability($objUnit, $objSpell, $objTarget);
         $rand = mt_rand(0, 100);
         $objSpell->setVillage($this->village);
         $objSpell->setTarget($objTarget);
         $objSpell->prepare();
         // Some spells are not castable for some reason.
         if (!$objSpell->isCastable()) {
             $page->set('success', false);
             $page->set('message', $text->get($objSpell->getError(), 'errors', $this->sTextFile));
         } else {
             if ($rand < $dif) {
                 $objSpell->execute($visible);
                 reloadStatusCounters();
                 $page->set('success', true);
                 $page->set('message', $objSpell->getSuccessMessage());
                 // Call the trigger!
                 $objUnit->onSuccess();
                 // Update request data (to return to overview)
                 //$this->updateRequestData (array ('building' => $'village' => $this->village->getId ()));
                 $page->set('extra', $objSpell->getExtraContent());
                 $success = true;
             } else {
                 $page->set('success', false);
                 $page->set('message', $objSpell->getFailedMessage());
                 // Call the trigger!
                 $objUnit->onFail();
                 if ($objUnit->isAlive()) {
                     $page->set('retry', true);
                     $page->set('inputData', $this->getInputData());
                 }
                 $success = false;
             }
             $toTarget = $success || !$visible;
             if (!$success) {
                 $visible = true;
             }
             $objTarget = $objSpell->getTarget();
             $log = Dolumar_Players_Logs::getInstance();
             $log->addEffectLog($objTarget, $objSpell, $this->village, $success, $visible, $toTarget, $this->sTextFile);
             reloadEverything();
         }
     } else {
         $page->set('success', false);
         $page->set('error', 'err_resources');
     }
     return $page->parse('magic/result.phpt');
 }
Esempio n. 6
0
 private function processTrainUnits($unit, $amount, $queue = false)
 {
     // Get resources
     $village = $this->getVillage();
     $res = $unit->multiplyCost($unit->getTrainingCost(), $amount);
     // Check building capacity and income etc
     $capacity = $this->getVillage()->getUnitCapacity($this, 'absolute');
     $currentUnits = $this->getVillage()->getUnitBuildingCount($this, 'absolute');
     // Add the new amount
     $currentUnits += $amount * $unit->getRequiredSpace();
     $success = false;
     if ($queue) {
         $success = true;
         $this->getVillage()->premium->addQueueAction('training', array('building' => $this->getId(), 'unit' => $unit->getUnitId(), 'amount' => $amount));
         reloadStatusCounters();
     } elseif ($currentUnits > $capacity) {
         $this->myErrors[] = 'noRoom';
     } elseif (!$village->resources->takeResourcesAndRunes($res)) {
         $this->myErrors[] = 'noResources';
     } else {
         $village->trainUnits($unit, $amount, $this);
         $village->reloadUnits();
         $success = true;
     }
     if (!$success) {
         $text = Neuron_Core_Text::getInstance();
         $error = $this->myErrors[count($this->myErrors) - 1];
         $txterr = $text->get($error, 'training', 'buildings');
         $jsondata = json_encode(array('amount' => $amount, 'unit' => $unit->getClassName(), 'queue' => true));
         // Propose a queued solution.
         $this->objWindow->dialog($txterr, $text->get('queueTraining', 'training', 'buildings'), 'windowAction (this, ' . $jsondata . ');', $text->get('okay', 'main', 'main'), 'void(0);');
     }
     return $success;
 }
Esempio n. 7
0
 private function processQueue()
 {
     $data = $this->getInputData();
     // Check if this player has premium account
     $owner = $this->village->getOwner();
     // Everything is alright.
     if (isset($data['building']) && isset($data['rune']) && isset($data['x']) && isset($data['y'])) {
         // Get building
         $building = Dolumar_Buildings_Building::getBuilding($data['building'], $this->village->getRace());
         if (isset($data['rune'])) {
             $building->setChosenRune($this->village, $data['rune']);
         }
         /*
         	Check if the game allows building this building now
         */
         if (!$building->canBuildBuilding($this->village)) {
             $this->updateContent($this->getContent('techlevel'));
         } elseif (!$building->checkBuildingLevels($this->village)) {
             $this->updateContent($this->getContent('buildinglevel', array('building' => $building->getName(false), 'buildings' => $building->getName(true), 'level' => $this->village->buildings->getBuildingAmount($building) + 1)));
         } else {
             // Everything seems to work out fine.
             // Add to the queue
             $data = array('building' => $building->getBuildingId(), 'rune' => $data['rune'], 'x' => $data['x'], 'y' => $data['y']);
             if ($this->village->premium->addQueueAction('build', $data)) {
                 $text = Neuron_Core_Text::__getInstance();
                 //$this->alert ($text->get ('doneBuild', 'queue', 'building'));
                 reloadStatusCounters();
             } else {
                 $this->alert($this->village->premium->getError(true));
             }
         }
     }
 }
Esempio n. 8
0
 public function cancelCrafting($building, $now = NOW)
 {
     $db = Neuron_DB_Database::getInstance();
     // Fetch the crafting items
     $chk = $db->query("\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\tvillages_items\n\t\t\tWHERE\n\t\t\t\ti_bid = {$building->getId()} AND\n\t\t\t\ti_endCraft > " . $now . "\n\t\t");
     foreach ($chk as $v) {
         $duration = max(1, $v['i_endCraft'] - $v['i_startCraft']);
         $procent = max(0, $now - $v['i_startCraft']) / $duration;
         $amount = floor($procent * $v['i_amount']);
         if ($amount > 0) {
             $db->query("\n\t\t\t\t\tUPDATE\n\t\t\t\t\t\tvillages_items\n\t\t\t\t\tSET\n\t\t\t\t\t\ti_amount = {$amount},\n\t\t\t\t\t\ti_endCraft = " . $now . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\ti_id = {$v['i_id']}\n\t\t\t\t");
         } else {
             $db->query("\n\t\t\t\t\tDELETE FROM\n\t\t\t\t\t\tvillages_items\n\t\t\t\t\tWHERE\n\t\t\t\t\t\ti_id = {$v['i_id']}\n\t\t\t\t");
         }
     }
     reloadStatusCounters();
 }
Esempio n. 9
0
 private function getQueueContent()
 {
     $text = Neuron_Core_Text::__getInstance();
     $res = $this->getUpgradeCost($this->getVillage());
     $data = array('building' => $this->getId(), 'level' => $this->getLevel() + 1, 'rune' => $res['runeId']);
     if ($this->getVillage()->premium->addQueueAction('upgrade', $data)) {
         $text = Neuron_Core_Text::__getInstance();
         //$this->objWindow->alert ($text->get ('doneUpgrade', 'queue', 'building'));
         reloadStatusCounters();
     } else {
         $this->objWindow->alert($this->getVillage()->premium->getError(true));
     }
 }
Esempio n. 10
0
 public function trainUnits($unit, $amount, $building)
 {
     $db = Neuron_Core_Database::__getInstance();
     $duration = floor($unit->getTrainingDuration($this) * $amount);
     $db->insert('villages_units', array('vid' => $this->getId(), 'unitId' => $unit->getUnitId(), 'buildingId' => $building->getBuildingId(), 'bid' => $building->getId(), 'amount' => $amount, 'village' => $this->getId(), 'startTraining' => time(), 'endTraining' => time() + $duration));
     // Log
     $objLogs = Dolumar_Players_Logs::__getInstance();
     $objLogs->addUnitTrained($this, $unit, $amount);
     reloadStatusCounters();
 }