/**
  * checks if production is valid, takes in consideration all other moves for this phase/user that are not flagged as deleted
  *
  * @param ModelProductionMove $move
  * @return void
  * @throws ControllerException $ex
  */
 public function validateProductionMove(ModelProductionMove $move)
 {
     // 1. check if zarea belongs to user
     $gameArea = ModelGameArea::getGameArea($move->getIdGame(), $move->getIdZArea());
     if ($move->getIdUser() !== $gameArea->getIdUser()) {
         throw new ControllerException('Area doesn\'t belong to the user.');
     }
     // 2. check if user has enough res left
     // 2.a check cost of previous productions
     $current_costs = $move->getCost();
     $moves = ModelProductionMove::iterator($move->getIdUser(), $move->getIdGame(), $move->getRound());
     while ($moves->hasNext()) {
         /* @var $move ModelProductionMove */
         $move_tmp = $moves->next();
         if ($move_tmp === $move) {
             continue;
         }
         $current_costs += $move_tmp->getCost();
     }
     // 2.b get available res
     $current_production = UserViewHelper::getCurrentProductionForUserInGame($move->getIdUser(), $move->getIdGame());
     if ($current_production['sum'] - $current_costs < 0) {
         throw new ControllerException('Insufficient funds!');
     }
 }
Ejemplo n.º 2
0
 private function executeProduction(ModelProductionMove $move)
 {
     $id_user = $move->getIdUser();
     $id_zarea = $move->getIdZArea();
     foreach ($move->getUnits() as $id_unit => $count) {
         $inGameLandUnits = ModelInGameLandUnit::getModelByIdZAreaUserUnit($this->id_game, $id_zarea, $id_user, $id_unit);
         $inGameLandUnits->addCount($count);
     }
     if (!isset($this->spent_production[$id_user])) {
         $this->spent_production[$id_user] = 0;
     }
     $this->spent_production[$id_user] += $move->getCost();
 }