Ejemplo n.º 1
0
 /**
  * @return void
  */
 public function main()
 {
     $ret = array('error' => 0, 'errorMsg' => '');
     while (true) {
         if (is_null($this->getHttp()->getPost('idCentre')) || is_null($this->getHttp()->getPost('largeur')) || is_null($this->getHttp()->getPost('hauteur'))) {
             $ret['error'] = 1;
             $ret['errorMsg'] = "Données manquantes";
             break;
         }
         $token = null;
         if (!is_null($this->getHttp()->getCookie('token'))) {
             $token = $this->getHttp()->getCookie('token');
         } elseif ($this->getHttp()->getGet('token')) {
             $token = $this->getHttp()->getGet('token');
         } elseif ($this->getHttp()->getPost('token')) {
             $token = $this->getHttp()->getPost('token');
         }
         if (is_null($token)) {
             $ret['error'] = 2;
             $ret['errorMsg'] = "Pas de token de session";
             break;
         }
         $session = SessionStore::getByToken($token);
         $carte = new Carte($session->getPartie(), HexaStore::getById($this->getHttp()->getPost('idCentre')), $session->getJoueur(), $this->getHttp()->getPost('largeur'), $this->getHttp()->getPost('hauteur'));
         $this->output($carte->getJson());
         break;
     }
 }
Ejemplo n.º 2
0
 /**
  * Renvoie le Hexa lié
  * @return Hexa
  */
 public function getHexaInfrastructure()
 {
     return HexaStore::getById(InfrastructureStore::getById($this->getIdInfrastructure())->getIdHexa());
 }
Ejemplo n.º 3
0
 /**
  * Renvoie le Hexa lié
  * @return Hexa
  */
 public function getHexa()
 {
     return HexaStore::getById(QgStore::getById($this->getIdQg())->getIdHexa());
 }
Ejemplo n.º 4
0
 /**
  * Crée la végétation
  */
 public function genererVegetation()
 {
     // Germes
     mt_srand($this->getRandForet());
     $germesIds = array();
     for ($i = 1; $i <= $this->getNbGermesForet(); $i++) {
         do {
             $id = mt_rand($this->getIdHexaMini(), $this->getIdHexaMini() + $this->getLargeur() * $this->getHauteur() - 1);
         } while (in_array($id, $germesIds) && HexaStore::getById($id)->getAltitude() < 4);
         $germesIds[] = $id;
     }
     foreach ($germesIds as $id) {
         $germe = new GermeForet(HexaStore::getById($id), mt_rand(13, 15), mt_rand($this->getCoefGaussMinGermesForet(), $this->getCoefGaussMaxGermesForet()));
         $germe->generer();
     }
     // Supprimer la végétation des mers
     foreach ($this->getHexas() as $hexa) {
         /** @var Hexa $hexa */
         if ($hexa->getAltitude() < 4) {
             $hexa->setVegetation(0);
         }
     }
     // Adapter la végétation à l'altitude
     foreach ($this->getHexas() as $hexa) {
         /** @var Hexa $hexa */
         if ($hexa->getAltitude() >= 12) {
             $hexa->setVegetation(max(0, $hexa->getVegetation() - 4));
         }
     }
     // Influence des rivières sur la végétation
     foreach ($this->getHexas() as $hexa) {
         /** @var Hexa $hexa */
         if ($hexa->getRivieres()->count() > 0) {
             $hexa->setVegetation(min(15, $hexa->getVegetation() + 1.5));
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @return Hexa
  */
 public function getCapitale()
 {
     return HexaStore::getById($this->getIdCapitale());
 }
Ejemplo n.º 6
0
 public function construireUnite()
 {
     $ret = array('error' => 0, 'errorMsg' => '');
     if (!isset($_POST['idHexa']) || !isset($_POST['idTypeUnite']) || !isset($_POST['cadreId'])) {
         $ret['error'] = 1;
         $ret['errorMsg'] = 'Champs manquants';
         echo json_encode($ret);
         exit;
     }
     if (!$this->checkDroit(Droit::LOGGE_PARTIE)) {
         $ret['error'] = 2;
         $ret['errorMsg'] = 'Pas le droit';
         echo json_encode($ret);
         exit;
     }
     $hexa = HexaStore::getById($_POST['idHexa']);
     if (is_null($hexa)) {
         $ret['error'] = 3;
         $ret['errorMsg'] = 'Hexa inexistant';
         echo json_encode($ret);
         exit;
     }
     $ret['idHexa'] = $hexa->getId();
     $ret['cadreId'] = $_POST['cadreId'];
     if (!$hexa->peutConstruireBatiment(SessionBusiness::getCookieSession()->getJoueur())) {
         $ret['error'] = 4;
         $ret['errorMsg'] = 'Pas le droit de construire cette unité';
         echo json_encode($ret);
         exit;
     }
     $liste = $hexa->listeUnitesAConstruire();
     if (!$liste->typeExists($_POST['idTypeUnite'])) {
         $ret['error'] = 5;
         $ret['errorMsg'] = "Ce type d'unité n'est pas constructible";
         echo json_encode($ret);
         exit;
     }
     foreach ($liste as $unite) {
         /** @var Unite $unite */
         if ($unite->getIdType() == $_POST['idTypeUnite']) {
             if (SessionBusiness::getCookieSession()->getJoueur()->getTresor() < $unite->getPrix()) {
                 $ret['error'] = 6;
                 $ret['errorMsg'] = 'Pas assez d\'or';
                 echo json_encode($ret);
                 exit;
             }
             $unite->setEnConstruction(1);
             $unite->save();
             SessionBusiness::getCookieSession()->getJoueur()->varTresor(-$unite->getPrix());
             SessionBusiness::getCookieSession()->getJoueur()->save();
             $ret['idUnite'] = $unite->getId();
         }
     }
     $this->data['unite'] = $unite;
     $ret['html'] = $this->fetch('elements/cadres/uniteEnconstruction.php');
     $ret['montantTresor'] = SessionBusiness::getCookieSession()->getJoueur()->getTresor();
     echo json_encode($ret);
 }
Ejemplo n.º 7
0
 /**
  * Renvoie le Partie lié
  * @return Partie
  */
 public function getPartie()
 {
     return PartieStore::getById(HexaStore::getById($this->getIdHexa())->getIdPartie());
 }
Ejemplo n.º 8
0
 /**
  * Renvoie le Joueur lié
  * @return Joueur
  */
 public function getJoueurTerritoire()
 {
     return JoueurStore::getById(HexaStore::getById($this->getIdHexa())->getIdTerritoire());
 }
Ejemplo n.º 9
0
 /**
  * Renvoie le Hexa lié
  * @return Hexa
  */
 public function getHexa2()
 {
     return HexaStore::getById($this->getIdHexa2());
 }
Ejemplo n.º 10
0
 /**
  * Range les Qgs dans les caches Qgs des hexas concernés
  * @return void
  */
 public function distribuerDansHexas()
 {
     foreach ($this as $qg) {
         /** @var Qg $qg */
         HexaStore::getById($qg->getIdHexa())->addQgCache($qg);
     }
 }