Exemple #1
0
 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;
 }
Exemple #2
0
 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');
     }
 }
Exemple #3
0
 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;
 }
Exemple #4
0
 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;
     }
 }
Exemple #5
0
 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);
     }
 }