Пример #1
0
 /**
  * Renvoie le Hexa lié
  * @return Hexa
  */
 public function getHexaInfrastructure()
 {
     return HexaStore::getById(InfrastructureStore::getById($this->getIdInfrastructure())->getIdHexa());
 }
Пример #2
0
 function supprimerInfra()
 {
     $ret = array('error' => 0, 'errorMsg' => '');
     if (!isset($_POST['idInfra'])) {
         $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;
     }
     $infra = InfrastructureStore::getById($_POST['idInfra']);
     if (is_null($infra)) {
         $ret['error'] = 2;
         $ret['errorMsg'] = 'Infrastructure inexistante';
         echo json_encode($ret);
         exit;
     }
     if (!$infra->destructiblePar(SessionBusiness::getCookieSession()->getJoueur())) {
         $ret['error'] = 3;
         $ret['errorMsg'] = 'Cette infrasctructure n\'est pas destructible par ce joueur';
         echo json_encode($ret);
         exit;
     }
     $ret['idInfra'] = $infra->getId();
     if ($infra->getEnConstruction() == -1) {
         if (SessionBusiness::getCookieSession()->getJoueur()->getTresor() < $infra->getPrix()) {
             $ret['error'] = 6;
             $ret['errorMsg'] = 'Pas assez d\'or';
             echo json_encode($ret);
             exit;
         }
         SessionBusiness::getCookieSession()->getJoueur()->varTresor(-$infra->getPrix());
         SessionBusiness::getCookieSession()->getJoueur()->save();
         $infra->setEnConstruction(0);
         $infra->save();
     } elseif ($infra->getEnConstruction() == 1) {
         SessionBusiness::getCookieSession()->getJoueur()->varTresor($infra->getPrix());
         SessionBusiness::getCookieSession()->getJoueur()->save();
         $infra->delete();
     } elseif ($infra->getEnConstruction() == 0) {
         $infra->setEnConstruction(-1);
         $infra->save();
     }
     $ret['montantTresor'] = SessionBusiness::getCookieSession()->getJoueur()->getTresor();
     echo json_encode($ret);
 }
Пример #3
0
 /**
  * Renvoie l'infrastructure pont entre les 2 hexas de la riviere
  * @return Infrastructure
  */
 public function getPont()
 {
     return InfrastructureStore::getByHexas($this->getHexa1(), $this->getHexa2());
 }
Пример #4
0
 /**
  * Renvoie les ponts des rivières de la collection
  * @return InfrastructureCollection
  */
 public function getPonts()
 {
     if (is_null($this->cachePonts)) {
         $this->cachePonts = new InfrastructureCollection();
         foreach ($this as $riviere) {
             /** @var Riviere $riviere */
             if (InfrastructureStore::existsByHexas($riviere->getHexa1(), $riviere->getHexa2())) {
                 $this->cachePonts->ajout(InfrastructureStore::getByHexas($riviere->getHexa1(), $riviere->getHexa2()));
             }
         }
     }
     return $this->cachePonts;
 }
 /**
  * Met les Infrastructures de la collection dans le InfrastructureStore
  * Vérifie si le Infrastructure était déjà storé, dans ce cas, remplace le Infrastructure concerné par celui du InfrastructureStore
  */
 public function store()
 {
     $replaces = array();
     foreach ($this as $offset => $infrastructure) {
         /** @var Infrastructure $infrastructure */
         if (InfrastructureStore::exists($infrastructure->getId())) {
             $replaces[$offset] = $infrastructure;
         } else {
             InfrastructureStore::store($infrastructure);
         }
     }
     unset($offset);
     foreach ($replaces as $offset => $infrastructure) {
         $this->offsetSet($offset, InfrastructureStore::getById($infrastructure->getId()));
     }
 }