コード例 #1
0
ファイル: Battle.php プロジェクト: Toxicat/dolumar
 public static function fight(Dolumar_Underworld_Models_Army $attacker, Dolumar_Underworld_Models_Army $target)
 {
     $dummy = new Dolumar_Players_DummyVillage();
     $slots = $target->getSlots();
     $attUnits = $attacker->getUnits($slots);
     $defUnits = $target->getUnits($slots);
     $logger = new Dolumar_Battle_Logger();
     $fight = new Dolumar_Battle_Fight($dummy, $dummy, $attUnits, $defUnits, $slots, array(), $logger);
     $fight->getResult();
     $report = Dolumar_Underworld_Models_Report::getFromLogger($logger);
     // No need to duplicate the report anymore
     //$report = Dolumar_Battle_Report::unserialize ($report->serialize ());
     // Create battle
     $battle = new Dolumar_Underworld_Models_Battle(null);
     $battle->setReport($report);
     $battle->setAttacker($attacker);
     $battle->setDefender($target);
     $battle->setStartdate(NOW);
     $battle->setEnddate(NOW + $report->getDuration());
     // Kill kill kill kill kill the units
     $fight->killUnits($fight);
     return $battle;
 }
コード例 #2
0
$village2 = new Dolumar_Players_DummyVillage();
$slots = $village1->getAttackSlots($village2);
$attacking = array();
$defending = array();
$logger = new Dolumar_Battle_Logger();
foreach ($slots as $k => $v) {
    $tmp = new Dolumar_Units_Archers($village1);
    $tmp->setBattleSlot($v);
    $tmp->addAmount(5000, 5000, 5000);
    $attacking[$k] = $tmp;
    $tmp = new Dolumar_Units_Archers($village2);
    $tmp->setBattleSlot($v);
    $tmp->addAmount(5000, 5000, 5000);
    $defending[$k] = $tmp;
}
// Let's do the fight
$fight = new Dolumar_Battle_Fight($village1, $village2, $attacking, $defending, $slots, array(), $logger);
echo '<h2>Combat result</h2>';
echo $fight->getResult();
echo '<h2>Debugger</h2>';
echo '<pre>' . $logger->getDebugLog() . '</pre>';
unset($fight);
unset($village1);
unset($village2);
unset($attacking);
unset($defending);
unset($logger);
echo '<h2>Profiler</h2>';
$profiler = Neuron_Profiler_Profiler::getInstance();
//$profiler->stop ();
echo '<pre>' . $profiler . '</pre>';
コード例 #3
0
ファイル: Simulator.php プロジェクト: Toxicat/dolumar
 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;
 }