public static function getUnitStatsHTML($objUnit) { $page = new Neuron_Core_Template(); // Ugly, but easy ;) Dolumar_Units_Unit::printStatNames($page); // Ugly again, but easy (again) $v = array(); $v['stats'] = $objUnit->getStats(); $page->set('unit', $v); return $page->parse('units/stats.phpt'); }
public function canEquip(Dolumar_Units_Unit $unit) { return $this->checkRace($unit->getVillage()->getRace()); }
private function loadUnits() { if (!is_array($this->aUnits)) { $db = Neuron_Core_Database::__getInstance(); $l = $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\tsquad_units su\n\t\t\t\tLEFT JOIN\n\t\t\t\t\tunits u ON u.unitId = su.u_id\n\t\t\t\tWHERE\n\t\t\t\t\tsu.s_id = '" . $this->getId() . "'\n\t\t\t")); // Load thze items $items = $db->getDataFromQuery($db->customQuery("\n\t\t\t\tSELECT\n\t\t\t\t\tsquad_equipment.*\n\t\t\t\tFROM\n\t\t\t\t\tsquad_equipment\n\t\t\t\tWHERE\n\t\t\t\t\tsquad_equipment.s_id = '" . $this->getId() . "'\n\t\t\t")); $critItems = array(); foreach ($items as $v) { if (!isset($critItems[$v['u_id']])) { $critItems[$v['u_id']] = array(); } $critItems[$v['u_id']][] = Dolumar_Players_Equipment::getFromId($v['e_id']); } $o = array(); foreach ($l as $v) { $i = $v['unitId']; $o[$i] = Dolumar_Units_Unit::getUnitFromName($v['unitName'], $this->getVillage()->getRace(), $this->getVillage()); $isMoving = $this->isMoving(); $o[$i]->addAmount($v['s_amount'], $isMoving ? 0 : $v['s_amount'], $v['s_amount']); $o[$i]->setSquad($this); // Set slot ID $o[$i]->setDefaultSlot($v['s_slotId'], $v['s_priority']); if (isset($critItems[$v['u_id']])) { foreach ($critItems[$v['u_id']] as $v) { $o[$i]->addEquipment($v); } } // Don't see why this would be required, but just to be sure... // $o[$i]->getStats (); } $this->aUnits = $o; } }
private function getSpeedUpTraining($data) { $text = Neuron_Core_Text::getInstance(); $inputData = $this->getInputData(); $village = isset($data['village']) ? $data['village'] : null; $unit = isset($data['unit']) ? $data['unit'] : null; $id = isset($data['order']) ? $data['order'] : null; $village = Dolumar_Players_Village::getFromId($village); $troop = Dolumar_Units_Unit::getFromId($unit); $order = $village->units->getTrainingStatus($id); if (!$troop || !$id || !$village || !$order) { return '<p>Order not found.</p>'; } $price = PREMIUM_SPEEDUP_TRAINING_PRICE; $unit = PREMIUM_SPEEDUP_TRAINING_UNIT; if (isset($inputData['duration'])) { $selected = abs(intval($inputData['duration'])); $desc = Neuron_Core_Tools::putIntoText($text->get('confdesc_training', 'speedup', 'statusbar'), array('unit' => $troop->getName(), 'amount' => Neuron_Core_Tools::getDurationText($selected * $unit))); return $this->getConfirm($price, $unit, $selected, $desc); } $time = $order['timeLeft']; return $this->getSpeedUpHTML('training', $time, $price, $unit); }
private function getUnitLog($row) { $objVillage = Dolumar_Players_Village::getVillage($row['l_vid']); $unitname = !empty($row['unitName']) ? $row['unitName'] : $row['l_subId']; $objUnit = Dolumar_Units_Unit::getUnitFromName($unitname, $objVillage->getRace(), $objVillage); if ($objUnit) { $unitname = $objUnit->getName(); } return array('unit' => $unitname, 'amount' => $row['lt_amount']); }
private function getFrontageMultiplier(Dolumar_Units_Unit $unit) { $frontage = $unit->getStat('frontage'); $amount = $unit->getAmount() - $unit->getKillUnitsQue(); if ($amount < $frontage * 10) { return 1; } else { $multiplier = floor(pow(2, 1 + log(ceil($amount / ($frontage * 10)), 2))); return $multiplier; } }
public function getGuards() { $a = array(); $a[0] = Dolumar_Units_Unit::getUnitFromName('Guards', $this->getVillage()->getRace(), $this->getVillage()); $a[0]->addAmount(10, 10, 10); return $a; }
public function simulate() { $input = $this->getInputData(); //return '<pre>' . print_r ($input, true) . '</pre>'; $slots = array(); // Collect thze slots foreach (array('att', 'def') as $side) { $units = array(); $hasnext = true; $counter = 1; while ($hasnext) { $dummy = new Dolumar_Players_DummyVillage(); $unit = isset($input['slot_' . $side . '_unit_' . $counter]) ? $input['slot_' . $side . '_unit_' . $counter] : false; $slot = isset($input['slot_' . $side . '_slot_' . $counter]) ? $input['slot_' . $side . '_slot_' . $counter] : false; $amount = isset($input['slot_' . $side . '_amount_' . $counter]) ? $input['slot_' . $side . '_amount_' . $counter] : false; if ($unit === false || $slot === false || $amount === false) { $hasnext = false; break; } if (!isset($slots[$counter])) { $slots[$counter] = Dolumar_Battle_Slot_Grass::getFromId($slot, $counter, $dummy); } $unitdata = explode('_', $unit); if (count($unitdata) == 2) { $race = Dolumar_Races_Race::getFromId($unitdata[0]); //echo $race->getName () . "\n"; $unitobj = Dolumar_Units_Unit::getUnitFromId($unitdata[1], $race, $dummy); //echo $unitobj->getName () . "\n"; $unitobj->addAmount($amount, $amount, $amount); $unitobj->setBattleSlot($slots[$counter]); $units[$counter] = $unitobj; } $counter++; } ${$side} = $units; } //return print_r ($att, true) . ' ' . print_r ($def, true); $logger = new Dolumar_Battle_Logger(); // __construct ($objAttVil, $objDefVil, $objAttUnits, $objDefUnits, $slots, $specialUnits, $objLogger) $fight = new Dolumar_Battle_Fight($dummy, $dummy, $att, $def, $slots, array(), $logger); $result = $fight->getResult(); $out = '<p>Fight result: ' . ceil($result * 100) . '%</p>'; $report = Dolumar_Battle_SimulatorReport::getFromLogger($logger); $out .= $this->showReport($report); // Set the request data $this->updateRequestData(array('report' => $report->serialize())); // We puts the report in thze session //$_SESSION['tmp_report'] = $report; // NEVER DO THAT AGAIN! return $out; }
private function getCheckedAvailableUnits() { // Loop trough units $units = array(); foreach ($this->getAvailableUnits() as $v) { // Get the unit $unit = Dolumar_Units_Unit::getUnitFromName($v, $this->getVillage()->getRace(), $this->getVillage()); if ($unit->canTrainUnit()) { $units[] = $unit; } } return $units; }
private function killUnits(Dolumar_Units_Unit $v, $amount, &$died) { $sumcons = 0; foreach ($v->getConsumption() as $vv) { $sumcons += $vv; } // Kill half the amount that is required to even out the consumption $tokill = ceil($amount * (1 - min(1, $this->shortagefactor)) * 0.5); if ($tokill > 0) { $uid = $v->getId(); if (!isset($died[$uid])) { $died[$uid] = array('unit' => $v, 'died' => 0); } $died[$uid]['died'] += $tokill; $this->objMember->removeUnits($v, $tokill); } }
private function getAddSquad() { $input = $this->getInputData(); if (isset($input['squadName']) && Neuron_Core_Tools::checkInput($input['squadName'], 'unitname') && isset($input['squadUnit'])) { // Check if unit type exists $unit = Dolumar_Units_Unit::getUnitFromId($input['squadUnit'], $this->village->getRace(), $this->village); if ($unit) { // Add the squad $objSquad = $this->village->addSquad($input['squadName'], $input['squadUnit']); if ($objSquad) { return $this->getAddUnits($objSquad); } else { return $this->getOverview(); } } else { $this->alert('Invalid unit type: ' . $input['squadUnit']); } } else { $text = Neuron_Core_Text::__getInstance(); $text->setFile('squads'); $text->setSection('addSquad'); $page = new Neuron_Core_Template(); if (isset($input['squadName'])) { $page->set('warning', $text->get('squadNameSyntax')); } $page->set('title', $text->get('title')); $page->set('name', $text->get('name')); $page->set('submit', $text->get('submit')); $page->set('toReturn', $text->getClickTo($text->get('toReturn'))); // Load all units $units = $this->village->getMyUnits(); foreach ($units as $unit) { if ($unit->getSquadlessAmount() > 0) { $page->addListValue('units', array('name' => $unit->getName(), 'id' => $unit->getUnitId())); } } return $page->parse('squads/add.tpl'); } }
private function executeTrainQueue($data) { $unit = Dolumar_Units_Unit::getUnitFromId($data['unit'], $this->village->getRace(), $this->village); $amount = $data['amount']; $building = $data['building']; $building = Dolumar_Buildings_Building::getFromId($building); $building->setVillage($this->village); if ($building && $unit) { if ($building->doTrainUnits($unit, $amount)) { echo "Training " . $unit->getName() . "\n"; return true; } else { echo "No training units: " . $building->getTrainError() . "\n"; return false; } } else { return true; } }
public function removeUnits(Dolumar_Units_Unit $unit, $arAmount) { $db = Neuron_Core_Database::__getInstance(); $amount = $arAmount; // Remove items foreach ($unit->getEquipment() as $v) { $this->removeEquipment($v, $arAmount); } $unitid = $unit->getUnitId(); $vid = $this->getId(); // Lock the table $db->customQuery('LOCK TABLES villages_units WRITE'); // Select my units $units = $db->select('villages_units', array('amount', 'killedAmount', 'uid'), "vid = '" . $vid . "' AND unitId = '" . $unitid . "'", 'endTraining ASC'); $removeWhere = ""; $removes = 0; reset($units); foreach ($units as $v) { if ($amount > 0) { $actAmount = $v['amount'] - $v['killedAmount']; if ($actAmount - $amount <= 0) { $removeWhere .= "uid = '{$v['uid']}' OR "; $removes++; } else { // withdraw $db->update('villages_units', array('killedAmount' => '++' . $amount), "uid = '{$v['uid']}'"); } $amount -= $actAmount; } else { break; } } // Remove them if ($removes > 0) { $removeWhere = substr($removeWhere, 0, -4); $db->remove('villages_units', $removeWhere); } $db->customQuery('UNLOCK TABLES'); // Now remove the units from the class $unit->removeAmount($arAmount); // Now remove them from squads etc $unit->onKillUnits($arAmount); }
public function getUnits($objVillage = null) { $this->loadData(); // Fetch attackers & defenders $log = explode('&', $this->data['fightLog']); $units = array(); $units['attacking'] = explode(';', $log[0]); if (isset($log[1])) { $units['defending'] = explode(';', $log[1]); } else { $units['defending'] = array(); } // Loop trough units $out = array(); // Filter for defender (info) $disabled = array(); /* if ( !( $this->fullReport || ( is_object ($objVillage) && $objVillage->getId () == $this->getDefender ()->getId () ) || $this->getVictory () > 0.1 ) ) { $disabled['defending'] = true; } */ foreach ($units as $teamKey => $team) { $out[$teamKey] = array(); $distinct = array(); if (isset($disabled[$teamKey])) { $out[$teamKey] = false; } else { foreach ($team as $v) { $l = explode(':', $v); if (count($l) >= 4) { $vil = Dolumar_Players_Village::getVillage($l[1]); //$race = $vil->getRace (); $race = Dolumar_Races_Race::getFromId($l[2]); $key = $l[0] . '_' . $race->getName(); $log = $key . ": "; if (!isset($distinct[$key])) { $distinct[$key] = count($out[$teamKey]); $unit = Dolumar_Units_Unit::getUnitFromId($l[0], $race, $vil); $out[$teamKey][$distinct[$key]] = array('unit' => $unit, 'amount' => $l[3], 'died' => $l[4]); $log .= "init"; } else { $out[$teamKey][$distinct[$key]]['amount'] += $l[3]; $out[$teamKey][$distinct[$key]]['died'] += $l[4]; $log .= "update"; } } } } } return $out; }
private function getUnitStats() { $html = ""; foreach (Dolumar_Races_Race::getRaceObjects() as $race) { $html .= '<div style="width: 450px; float: left; margin: 0px 0px 0px 0px;">'; $html .= '<h2>' . $race->getDisplayName() . '</h2>'; $units = Dolumar_Units_Unit::getAllUnits($race); $page = new Neuron_Core_Template(); $page->set('showConsumption', true); $page->set('showCost', true); $page->set('showSpeed', true); Dolumar_Units_Unit::printStatNames($page); foreach ($units as $v) { $data = array('name' => $v->getName(), 'stats' => $v->getStats(), 'available' => $v->getAvailableAmount(), 'total' => $v->getTotalAmount(), 'consumption' => Dolumar_Tools::resourceToText($v->getConsumption()), 'cost' => Dolumar_Tools::resourceToText($v->getTrainingCost()), 'type' => $v->getAttackType_text(), 'image' => $v->getImageUrl()); $page->addListValue('units', $data); } $html .= $page->parse('structure/unitstats.phpt'); $html .= '</div>'; } return $html; }
private function loadTroopCounters($vilsId) { $db = Neuron_Core_Database::__getInstance(); $t = $db->select('villages_units', array('*'), "endTraining > '" . time() . "' {$vilsId}"); $text = Neuron_Core_Text::getInstance(); $text->setSection('status', 'statusbar'); foreach ($t as $v) { $village = Dolumar_Players_Village::getVillage($v['vid']); $troop = Dolumar_Units_Unit::getUnitFromId($v['unitId'], $village->getRace(), $village); $speedUp = null; if ($this->canSpeedUp('training')) { $speedUp = array('type' => 'training', 'village' => $village->getId(), 'order' => $v['uid'], 'unit' => $troop->getId()); } $txt = Neuron_Core_Tools::putIntoText($text->get('training'), array('unit' => $troop->getName($v['amount'] > 1), 'amount' => $v['amount'])); $this->addCounter($v['endTraining'], $village, $txt, 'training', false, $speedUp); } }