/** * Déroule le combat * @return void */ public function run() { while (!$this->termine) { $this->tour++; if ($this->getAttaquants()->getNbMaxToursDeCombat() != 0 && $this->tour > $this->getAttaquants()->getNbMaxToursDeCombat()) { break; } Log::getInstance()->debug(array('msg' => 'combatRun', $this->debug())); $this->testMoral(); if ($this->termine) { break; } $this->tour(); } foreach ($this->attaquants as $qg) { IndexPositions::reindexQg($qg); } foreach ($this->defenseurs as $qg) { IndexPositions::reindexQg($qg); } }
/** * Résoud les déplacements des Qgs et les combats * @return void */ public function resolve() { Log::getInstance()->debug(array('msg' => 'qgsAvantDeplacement', 'qgs' => $this->qgs->debug())); $intercepteurs = new QgCollection(); foreach ($this->qgs as $qg) { $qg->getMission()->beforeDeplacements(); } foreach ($this->qgs->getByMission() as $idTypeMission => $qgs) { if (in_array($idTypeMission, Missions::missionsInterception())) { $intercepteurs = $qgs; } if (!in_array($idTypeMission, Missions::missionsDeplacement())) { continue; } $maxVitesse = $qgs->maxVitesse(true); for ($pas = 1; $pas <= $maxVitesse; $pas++) { Log::getInstance()->debug(array('msg' => 'pas', 'idTypeMission' => $idTypeMission, 'pas' => $pas)); /* * Pas et interceptions */ foreach ($qgs as $qg) { /** @var Qg $qg */ $qg->getMission()->pas($maxVitesse); /* * Zones d'interception */ if ($qg->getMission()->isInterceptable() && IndexPositions::getIntercepteursOnSamePosition($qg)->count()) { foreach (IndexPositions::getIntercepteursOnSamePosition($qg) as $intercepteur) { if ($qg->getJoueur()->isEnnemi($intercepteur->getJoueur())) { /** @var Interception $mission */ $mission = $intercepteur->getMission(); $mission->getCiblesPotentielles()->ajout($qg); } } } } /* * Interceptions (combat) */ $interceptions = new CombatCollection(); foreach ($intercepteurs as $intercepteur) { /** @var Qg $intercepteur */ $mission = $intercepteur->getMission(); /** @var Interception $mission */ $combat = $mission->createCombat(); if (!is_null($combat)) { $interceptions->ajout($combat); } } $interceptions->run(); /* * Combats */ $this->combatsAFaire()->run(); } /* * Stacks à gérer en fin de déplacements */ $recul = true; while ($recul) { $recul = false; foreach (IndexPositions::getStacks() as $stack) { foreach ($stack->qgsQuiDoiventBouger() as $qg) { /** @var Qg $qg */ $qg->getMission()->recul(); } $recul = true; } IndexPositions::reset(); foreach ($this->qgs as $qg) { IndexPositions::reindexQg($qg); } $this->combatsAFaire()->run(); } } foreach ($this->qgs as $qg) { $qg->getMission()->afterDeplacements(); } Log::getInstance()->debug(array('msg' => 'qgsApresDeplacement', 'qgs' => $this->qgs->debug())); }
/** * Fait faire un pas au qg * @param $maxVitesse */ public function pas($maxVitesse) { if ($this->modeTrajectoire) { $this->mvtDepensePartiel += $this->getQg()->getMvtTotal() / $maxVitesse; $coutProchaineCase = $this->getQg()->getCoutDeplacement($this->getPosition(), $this->nextTraj->getHexa()); if ($this->mvtDepensePartiel >= $coutProchaineCase || $this->mvtDepenseTotal < $this->getQg()->getMvtTotal() && $this->mvtDepenseTotal + $coutProchaineCase >= $maxVitesse) { // Avancement d'une case $this->historiquePositions->ajout($this->nextTraj->getHexa()); $nextTraj = $this->getQg()->getTrajs()->getByOrdre($this->nextTraj->getOrdre() + 1); if (!is_null($nextTraj)) { $this->nextTraj = $nextTraj; } else { $this->modeTrajectoire = false; } $this->incrMvtDepensePartiel(-1 * $coutProchaineCase); $this->incrMvtDepenseTotal($coutProchaineCase); IndexPositions::reindexQg($this->getQg()); $this->auMoinsUnDeplacementFait = true; } } }