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 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; } }
public function processInput() { $player = Neuron_GameServer::getPlayer(); if (!$player) { return; } $input = $this->getInputData(); if (isset($input['cancelQueue'])) { $db = Neuron_DB_Database::__getInstance(); $queue = intval($input['cancelQueue']); // Get all villages $villages = Neuron_GameServer::getPlayer()->getVillages(); if (count($villages) > 0) { $villageSelector = ''; foreach ($villages as $v) { // Make sure the battles are processed. $v->processBattles(); $villageSelector .= 'pq_vid = ' . $v->getId() . ' OR '; } $villageSelector = substr($villageSelector, 0, -3); // Make sure you can only remove your own queues $db->query("\n\t\t\t\t\tDELETE FROM\n\t\t\t\t\t\tpremium_queue\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tpq_id = {$queue} AND\n\t\t\t\t\t\t{$villageSelector}\n\t\t\t\t"); } } elseif (isset($input['action'])) { switch ($input['action']) { case 'withdrawbattle': $battleid = isset($input['battle']) ? $input['battle'] : 0; if ($battleid) { // Fetch battle $battle = Dolumar_Battle_Battle::getBattle($battleid); if ($battle && $battle->getAttacker()->getOwner()->equals($player)) { $battle->withdraw(); } } break; } } $this->getFreshCounters(); $this->updateContent(); }
public function getReport($objVillage = null, $logid = null, $bShowFight = false, $forceView = false) { $id = $this->id; $text = Neuron_Core_Text::__getInstance(); $text->setFile('battle'); $text->setSection('report'); $this->loadData(); if ($this->data) { $v = $this->data; $page = new Neuron_Core_Template(); $attacker = $this->getAttacker(); $defender = $this->getDefender(); $page->set('reportid', $this->id); $page->set('title', $text->get('title')); $page->set('attacker', $text->get('attacker')); $page->set('defender', $text->get('defender')); $page->set('date', $text->get('date')); $page->set('victory', $text->get('victory')); $page->set('unit', $text->get('unit')); $page->set('amount', $text->get('amount')); $page->set('died', $text->get('died')); $page->set('noDefending', $text->get('noDefending')); $page->set('secretUnits', $text->get('secretUnits')); if (!$attacker instanceof Dolumar_Players_DummyVillage) { $page->set('attacker_value', Neuron_Core_Tools::output_varchar($attacker->getName())); } if (!$defender instanceof Dolumar_Players_DummyVillage) { $page->set('defender_value', Neuron_Core_Tools::output_varchar($defender->getName())); } // URL $page->set('attacker_id', $attacker->getId()); $page->set('defender_id', $defender->getId()); $page->set('date_value', date(DATETIME, $this->getBattleTime())); $page->set('toReturn', $text->getClickTo($text->get('toReturn'))); $showreport = true; if ($this->isDone() || $forceView) { $page->set('show_summary', true); $showreport = $bShowFight; if ($this->getVictory() < 0.01) { $page->set('victory_value', $text->get('defeated')); } else { $page->set('victory_value', Neuron_Core_Tools::putIntoText($text->get('victory_value'), array(floor($this->getVictory() * 100)))); } if (!$showreport) { $page->set('cur_tab', 'summary'); $page->set('attacking', $text->get('attacking')); $page->set('defending', $text->get('defending')); $page->set('stolen', $text->get('stolen')); $page->set('runes', $text->get('runes')); // Loop trough attackers $units = $this->getUnits($objVillage); self::printUnits($page, 'attacking', $units['attacking']); self::printUnits($page, 'defending', $units['defending']); // Resources if ($this->getStolenResources()) { $page->set('stolen_value', Dolumar_Battle_Battle::resourceToText($this->getStolenResources())); } foreach ($this->getStolenRunes() as $k => $v) { $page->addListValue('runes', array(ucfirst($text->get($k, $v > 1 ? 'runeDouble' : 'runeSingle', 'main')), $v)); } // Add special units $specialunits = $this->getSpecialUnits(); foreach ($specialunits as $k => $units) { foreach ($units as $v) { $page->addListValue($k . '_su', array('name' => $v->getDisplayName(), 'died' => !$v->isAlive())); } } } } if ($showreport) { $page->set('cur_tab', 'fightlog'); $fighttxt = $this->getFightlog($logid, $forceView); $page->set('report', $fighttxt); } return $page->parse('battle/report.tpl'); } else { return '<p class="false">' . $text->get('notFound') . '</p>'; } }
<?php $villageid = Neuron_Core_Tools::getInput('_GET', 'village', 'int'); $targetid = Neuron_Core_Tools::getInput('_GET', 'target', 'int'); $village = Dolumar_Players_Village::getVillage($villageid); $target = Dolumar_Players_Village::getVillage($targetid); if ($villageid && $targetid && $village && $target) { echo '<pre>'; $percentage = Dolumar_Battle_Battle::getMaxStolenRunesPercentage($target, true); echo '100% victory results in ' . $percentage . '% stolen runes.'; echo '</pre>'; echo '<pre>'; $clanlose = Dolumar_Battle_Battle::didClanAttackTargetEarlier($village, $target); if ($clanlose) { echo "Target clan will lose honour.\n"; } else { echo "Target clan will not lose honour.\n"; } echo '</pre>'; } else { echo '<p>Please provide village and target parameter</p>'; }