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(); }
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'); }
private function getChooseSpecialUnits($target, $squads, $error = null) { $page = new Neuron_Core_Template(); $page->setTextSection('specialUnits', 'battle'); $page->set('error', $error); $page->set('target', Neuron_Core_Tools::output_varchar($target->getName())); $page->set('targetId', $target->getId()); $distance = Dolumar_Map_Map::getDistanceBetweenVillages($this->village, $target, false); $page->set('distance', Neuron_Core_Tools::output_distance($distance)); foreach ($this->village->getAttackSlots($target) as $k => $v) { if (isset($squads[$k])) { $unitId = $squads[$k]->getSquad()->getId() . '_' . $squads[$k]->getUnitId(); $page->addListValue('slots', array('id' => $k, 'unit' => $unitId)); } } $duration = $this->village->battle->getMoveDuration($squads, $distance); if ($duration > 60 * 60 * 24) { $page->set('duration', $duration); } $honour = Dolumar_Battle_Battle::getHonourPenalty($this->village, $target); if ($honour > 0) { //$bigger = round ( ($this->village->getScore () / $target->getScore ()) * 100) - 100; $bigger = round(Dolumar_Battle_Battle::getSizeDifference($this->village, $target) * 100 - 100); $page->set('honour', $honour); $page->set('size', $bigger); } // Fetch thze special units $units = $this->village->getSpecialUnits(); foreach ($units as $v) { $actions = $v->getEffects(); // Prepare the actions $aActions = array(); foreach ($actions as $action) { if ($action instanceof Dolumar_Effects_Battle) { $aActions[] = array('name' => $action->getName(), 'id' => $action->getId(), 'cost' => Neuron_Core_Tools::resourceToText($action->getCost($v, $target), false, false, false, 'rune', false)); } } if (count($aActions) > 0) { asort($aActions); // Add the special unit to the list $page->addListValue('specialunits', array('id' => $v->getId(), 'name' => Neuron_Core_Tools::output_varchar($v->getName(false, true)), 'actions' => $aActions)); } } return $page->parse('battle/specialUnits.phpt'); }
public function getVillageProfile($objVillage) { if (!$objVillage || !$objVillage->isFound()) { return '<p>Village not found.</p>'; return null; } $text = Neuron_Core_Text::__getInstance(); $text->setFile('village'); $text->setSection('profile'); $townCenter = $objVillage->buildings->getTownCenter(); if ($townCenter) { $l = $townCenter->getLocation(); } else { $l = array('?', '?'); } $page = new Neuron_Core_Template(); $page->set('village', Neuron_Core_Tools::output_varchar($objVillage->getName())); $page->set('location', $text->get('location')); $page->set('villageProfile', $text->get('villageProfile')); $page->set('location_value', '[' . $l[0] . ',' . $l[1] . ']'); $page->set('locX', $l[0]); $page->set('locY', $l[1]); // Owner $owner = $objVillage->getOwner(); $page->set('owner', $text->get('owner')); $page->set('owner_value', Neuron_Core_Tools::output_varchar($owner->getNickname())); $page->set('pid', $owner->getId()); // Ranking $rank = $objVillage->getRank(); $page->set('rank', $text->get('rank')); $page->set('rank_value', Neuron_Core_Tools::putIntoText($text->get('ranking'), array($rank[0], $rank[1]))); // Race $race = $objVillage->getRace(); $page->set('race', $text->get('race')); $page->set('race_value', Neuron_Core_Tools::output_varchar($race->getRaceName())); $page->set('score', $objVillage->getNetworth()); $me = Neuron_GameServer::getPlayer(); if ($me && $objVillage->isActive()) { foreach ($me->getVillages() as $v) { if (!$v->equals($objVillage)) { // Register the visit $v->visits->registerVisit($objVillage); $page->addListValue('challenges', array(Neuron_Core_Tools::putIntoText($text->get('challenge'), array(Neuron_Core_Tools::output_varchar($v->getName()))), htmlentities(json_encode(array('vid' => $v->getId(), 'target' => $objVillage->getId()))))); $distance = Dolumar_Map_Map::getDistanceBetweenVillages($v, $objVillage); $page->addListValue('distances', array('id' => $v->getId(), 'name' => Neuron_Core_Tools::output_varchar($v->getName()), 'distance' => Neuron_Core_Tools::output_distance($distance, false, false))); } } } elseif (!$objVillage->isActive()) { $page->set('notActive', $text->get('notActive')); } // Set honour $page->set('honour_value', $objVillage->honour->getHonour()); return $page->parse('villageProfile.tpl'); }
public function getTransferDuration(Dolumar_Players_Village $target) { //return 30; $distance = Dolumar_Map_Map::getDistanceBetweenVillages($this->getVillage(), $target, true); // Speed for the "marketing managers" $speed = 15; //return (GAME_SPEED_RESOURCES * $distance * 60 * 10) / (GAME_SPEED_RESOURCES * $speed); return $distance * 60 * 10 / (GAME_SPEED_RESOURCES * $speed); //return $duration; //return 10; }
<?php $village1 = Neuron_Core_Tools::getInput('_GET', 'village1', 'int'); $village2 = Neuron_Core_Tools::getInput('_GET', 'village2', 'int'); $v1 = Dolumar_Players_Village::getVillage($village1); $v2 = Dolumar_Players_Village::getVillage($village2); echo 'Calculating distance between ' . $v1->getName() . ' to ' . $v2->getName() . '<br />'; $l1 = $v1->buildings->getTownCenterLocation(); $l2 = $v2->buildings->getTownCenterLocation(); $distance = Dolumar_Map_Map::getDistanceBetweenVillages($v1, $v2); $straight = Dolumar_Map_Map::calculateDistance($l1[0], $l1[1], $l2[0], $l2[1]); $profiler = Neuron_Profiler_Profiler::getInstance(); echo '<h2>Profiler</h2>'; echo '<pre>'; echo $profiler; echo '</pre>'; echo '<p>Distance: <strong>' . $distance . '</strong><br />'; echo 'Straight line distance: <strong>' . $straight . '</strong></p>';
public function moveUnit($target) { // Calculate distance $distance = Dolumar_Map_Map::getDistanceBetweenVillages($this->getLocation(), $target); $duration = $this->getTravelDuration($distance); // Update $db = Neuron_Core_Database::__getInstance(); $db->update('villages_specialunits', array('vsu_moveStart' => Neuron_Core_Tools::timestampToMysqlDatetime(time()), 'vsu_moveEnd' => Neuron_Core_Tools::timestampToMysqlDatetime(time() + $duration), 'vsu_location' => $target->getId()), "vsu_id = " . $this->getId()); }
public function attackVillage($oTarget, $oUnits, $specialUnits = array()) { if (count($oUnits) > 0) { $db = Neuron_Core_Database::__getInstance(); // First: check if special units are valid $aSpecialUnits = array(); foreach ($specialUnits as $v) { $action = $v[0]->getEffect($v[1]); if ($action && $action instanceof Dolumar_Effects_Battle) { $aSpecialUnits[] = array($v[0], $action); } } // Second: calculate the sum of all resource cost $aResources = array(); foreach ($aSpecialUnits as $v) { foreach ($v[1]->getCost($v, $oTarget) as $res => $am) { if (isset($aResources[$res])) { $aResources[$res] += $am; } else { $aResources[$res] = $am; } } } // Thirdly: withdraw the required amount if (!$this->objProfile->resources->takeResourcesAndRunes($aResources)) { $this->error = 'no_resources'; } else { $afstand = Dolumar_Map_Map::getDistanceBetweenVillages($this->objProfile, $oTarget); $naarVillage = $this->getMoveDuration($oUnits, $afstand, true); $naarHuis = $this->getMoveDuration($oUnits, $afstand, false); $fightDate = NOW + $naarVillage; // Honour!!! $honour = Dolumar_Battle_Battle::getHonourPenalty($this->objProfile, $oTarget); $slotsamount = count($this->getAttackSlots($oTarget)); // Insert battle $battleId = $db->insert('battle', array('vid' => $this->objProfile->getId(), 'targetId' => $oTarget->getId(), 'startDate' => NOW, 'arriveDate' => NOW + $naarVillage, 'fightDate' => $fightDate, 'endDate' => $fightDate + $naarHuis + 1, 'goHomeDuration' => $naarHuis, 'iHonourLose' => $honour, 'iBattleSlots' => $slotsamount)); // Add troops foreach ($oUnits as $slot => $unit) { $db->insert('battle_squads', array('bs_bid' => $battleId, 'bs_squadId' => $unit->getSquad()->getId(), 'bs_unitId' => $unit->getUnitId(), 'bs_vid' => $unit->getVillage()->getId(), 'bs_slot' => $slot)); } // Add special troops foreach ($aSpecialUnits as $v) { $db->insert('battle_specialunits', array('bsu_bid' => $battleId, 'bsu_vsu_id' => $v[0]->getId(), 'bsu_ba_id' => $v[1]->getId(), 'bsu_vid' => $this->objProfile->getId())); } // Notify players $pl_attacker = $this->objProfile->getOwner(); $pl_defender = $oTarget->getOwner(); $notExtra = array('attacker' => $this->objProfile, 'defender' => $oTarget, 'pl_attacker' => $this->objProfile->getOwner(), 'pl_defender' => $oTarget->getOwner()); $pl_attacker->sendNotification('attacking', 'battle', array('defender' => $oTarget, 'pl_defender' => $oTarget->getOwner(), 'village' => $this->objProfile, 'player' => $this->objProfile->getOwner()), $pl_attacker, true); $pl_defender->sendNotification('defending', 'battle', array('attacker' => $this->objProfile, 'pl_attacker' => $this->objProfile->getOwner(), 'village' => $oTarget, 'player' => $oTarget), $pl_attacker, false); // Done return true; } } else { $this->error = 'no_troops'; return false; } }
private function commandMoveUnit($building, $unit) { $input = $this->getInputData(); $id = isset($input['target']) ? intval($input['target']) : null; if ($id > 0 && $id != $unit->getLocation()->getId()) { // Calculate distance & duration $target = Dolumar_Players_Village::getVillage($id); if (!$target) { return '<p>Invalid input: target village not found.</p>'; } if (isset($input['confirm'])) { $page = new Neuron_Core_Template(); $page->setTextSection('moveUnit', 'thievery'); $page->set('input', array('building' => $building->getId())); // Move the bloody unit $unit->moveUnit($target); return $page->parse('thieves/doneMoving.phpt'); } else { $page = new Neuron_Core_Template(); $page->setTextSection('moveUnit', 'thievery'); $distance = Dolumar_Map_Map::getDistanceBetweenVillages($unit->getLocation(), $target); // Calculate duration $duration = $unit->getTravelDuration($distance); $page->set('input', array_merge($input, array('confirm' => 'true'))); $page->set('distance', Neuron_Core_Tools::output_distance($distance)); $page->set('duration', Neuron_Core_Tools::getDuration($duration)); return $page->parse('thieves/moveThief.phpt'); } } else { $structure = new Neuron_Structure_ChooseTarget($this->getInputData(), $this->village, true, true); $structure->setReturnData(array('building' => $building->getId())); return $structure->getHTML(); } }