public function getDefenseSlots($amount = null) { $out = array(); for ($i = 1; $i <= $amount; $i++) { $out[$i] = Dolumar_Battle_Slot_Grass::getRandomSlot($i, $this); } return $out; }
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 parseSlot($slot) { if (!is_array($slot)) { $slotId = $slot; $oid = 0; } else { $slotId = $slot[0]; $oid = $slot[1]; } return Dolumar_Battle_Slot_Grass::getFromId($slotId, $oid); }
public function getDefenseSlots($amount = null) { if (!isset($amount) || $amount < 1) { $runes = $this->objProfile->resources->getTotalRunes(); $amount = 1 + ceil($runes / 75) * 2; } // Load the slots $db = Neuron_Core_Database::__getInstance(); $l = $db->select('villages_slots', array('*'), "vs_vid = " . $this->objProfile->getId()); $out = array(); foreach ($l as $v) { $out[$v['vs_slot']] = Dolumar_Battle_Slot_Grass::getFromId($v['vs_slotId'], $v['vs_slot'], $this->objProfile); } if (count($out) < $amount) { for ($i = 1; $i <= $amount; $i++) { if (!isset($out[$i])) { $out[$i] = Dolumar_Battle_Slot_Grass::getRandomSlot($i, $this->objProfile); $db->insert('villages_slots', array('vs_vid' => $this->objProfile->getId(), 'vs_slot' => $i, 'vs_slotId' => $out[$i]->getSlotId())); } } } while (count($out) > $amount) { array_pop($out); } return $out; }