Пример #1
0
 public function run(array &$data)
 {
     $data['template'] = $this->getTemplate();
     $this->addCurrentGameInfo($data);
     $this->moveController = new SetShipsController(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId());
     // update moves
     if (isset($_POST['setship'])) {
         $this->setShip($data);
     }
     if (isset($_POST['fixate_start'])) {
         $this->fixateMove($data);
     }
     if (isset($_POST['delete'])) {
         $this->deleteMove($data);
     }
     // show already set ships
     $data['currentShips'] = array();
     $iterator = ModelSetShipsMove::getSetShipMovesForUser(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId());
     while ($iterator->hasNext()) {
         /** @var ModelSetShipsMove $move */
         $move = $iterator->next();
         $zShip = ModelInGameShip::getShipById(ModelGame::getCurrentGame()->getId(), $move->getIdZunit());
         $id_ship = $zShip->getIdUnit();
         $ship = ModelShip::getModelById($id_ship);
         $zAreaInPort = ModelGameArea::getGameArea(ModelGame::getCurrentGame()->getId(), $move->getIdZareaInPort());
         $zAreaAtSea = ModelGameArea::getGameArea(ModelGame::getCurrentGame()->getId(), $move->getIdZarea());
         $data['currentShips'][] = array('id' => $move->getId(), 'ship_type' => $ship->getName(), 'ship_name' => $zShip->getName(), 'zarea_in_port' => $zAreaInPort->getName() . ' ' . $zAreaInPort->getNumber(), 'zarea_at_sea' => $zAreaAtSea->getName() . ' ' . $zAreaAtSea->getNumber());
     }
     // show still available ships
     $data['availableShips'] = array();
     $stillAvailableShips = $this->moveController->getStillAvailableShips();
     foreach ($stillAvailableShips as $id_unit => $count) {
         if ($count <= 0) {
             continue;
         }
         $data['availableShips'][] = array('id' => $id_unit, 'count' => $count, 'name' => ModelShip::getModelById($id_unit)->getName());
     }
     // show available countries
     $data['availableZAreasInPort'] = array();
     $data['availableZAreasAtSea'] = array();
     $iterator = ModelGameArea::iterator(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId());
     while ($iterator->hasNext()) {
         /** @var ModelGameArea $zArea */
         $zArea = $iterator->next();
         $data['availableZAreasInPort'][] = array('id_zarea_in_port' => $zArea->getId(), 'name' => $zArea->getName(), 'number' => $zArea->getNumber());
     }
     $iterator = ModelArea::iterator(TYPE_SEA);
     while ($iterator->hasNext()) {
         /** @var ModelArea $area */
         $area = $iterator->next();
         $data['availableZAreasAtSea'][] = array('id_zarea_at_sea' => ModelGameArea::getGameAreaForArea(ModelGame::getCurrentGame()->getId(), $area->getId())->getId(), 'name' => $area->getName(), 'number' => $area->getNumber());
     }
     $this->checkFixate($data, PHASE_SETSHIPS);
     $this->checkCurrentPhase($data, PHASE_SETSHIPS);
 }
Пример #2
0
 /**
  * @param $id_user int
  * @param $id_game int
  * @return array (money => int, countries => int, resproduction => int, traderoutes => int, trproduction => int, combos => int, comboproduction => int, sum => int)
  * @throws NullPointerException
  */
 public static function getCurrentProductionForUserInGame($id_user, $id_game)
 {
     $id_user = (int) $id_user;
     $id_game = (int) $id_game;
     $output = array();
     // money on bank
     $ingame = ModelIsInGameInfo::getIsInGameInfo($id_user, $id_game);
     $output['money'] = $ingame->getMoney();
     $output['moneySpendable'] = min($output['money'], MAX_MONEY_SPENDABLE);
     // money from resources
     $output['countries'] = 0;
     $output['resproduction'] = 0;
     $combos = array();
     $combos[RESOURCE_OIL] = 0;
     $combos[RESOURCE_TRANSPORT] = 0;
     $combos[RESOURCE_INDUSTRY] = 0;
     $combos[RESOURCE_MINERALS] = 0;
     $combos[RESOURCE_POPULATION] = 0;
     $iter = ModelGameArea::iterator($id_user, $id_game);
     while ($iter->hasNext()) {
         $area = $iter->next();
         ++$output['countries'];
         $output['resproduction'] += $area->getProductivity();
         ++$combos[$area->getIdResource()];
     }
     // money from traderoutes
     $output['traderoutes'] = 0;
     $output['trproduction'] = 0;
     // money from combos
     $combo_count = $combos[RESOURCE_OIL];
     foreach ($combos as $res_count) {
         if ($res_count < $combo_count) {
             $combo_count = $res_count;
         }
     }
     $output['combos'] = $combo_count;
     $output['comboproduction'] = $combo_count * 4;
     // sum
     $output['sum'] = $output['moneySpendable'] + $output['resproduction'] + $output['trproduction'] + $output['comboproduction'];
     return $output;
 }
Пример #3
0
 public function getUserInfo($ingame)
 {
     $user = ModelUser::getUser($ingame->getIdUser());
     // money on bank
     $money = $ingame->getMoney();
     // money from resources
     $resproduction = 0;
     $combos = array();
     $combos[RESOURCE_OIL] = 0;
     $combos[RESOURCE_TRANSPORT] = 0;
     $combos[RESOURCE_INDUSTRY] = 0;
     $combos[RESOURCE_MINERALS] = 0;
     $combos[RESOURCE_POPULATION] = 0;
     $iter = ModelGameArea::iterator($user->getId(), ModelGame::getCurrentGame()->getId());
     while ($iter->hasNext()) {
         $area = $iter->next();
         $resproduction += $area->getProductivity();
         $combos[$area->getIdResource()]++;
     }
     // money from traderoutes
     $traderoutes = 0;
     // money from combos
     $combo_count = $combos[RESOURCE_OIL];
     foreach ($combos as $res) {
         if ($res < $combo_count) {
             $combo_count = $res;
         }
     }
     $combo_money = $combo_count * 4;
     // sum
     $sum = $money + $resproduction + $traderoutes + $combo_money;
     $userData = array();
     $userData['login'] = $user->getLogin();
     $userData['money'] = $money;
     $userData['resproduction'] = $resproduction;
     $userData['trproduction'] = $traderoutes;
     $userData['comboproduction'] = $combo_money;
     $userData['sum'] = $sum;
     return $userData;
 }
Пример #4
0
 /**
  * run the game logic
  *
  * @throws LogicException
  * @return void
  */
 public function run()
 {
     if (!$this->checkIfValid()) {
         throw new LogicException('Game ' . $this->id_game . ' not valid for processing.');
     }
     $this->startProcessing();
     try {
         // run through moves for each user
         $iter = ModelSelectStartMove::iterator($this->id_game);
         while ($iter->hasNext()) {
             // areas to select for user
             $selectStartMove = $iter->next();
             $regions_selected = $selectStartMove->getRegions();
             // array(int option_number => array(int id_zarea))
             $id_user = $selectStartMove->getIdUser();
             /* @var $iigi ModelIsInGameInfo */
             $iigi = ModelIsInGameInfo::getIsInGameInfo($id_user, $this->id_game);
             $id_set = $iigi->getIdStartingSet();
             foreach ($regions_selected as $option_number => $areas) {
                 $regions = ModelStartRegion::getRegionsForSetAndOption($id_set, $option_number);
                 // array(int id_area => ModelStartRegion)
                 foreach ($areas as $id_zarea) {
                     $gameArea = ModelGameArea::getGameArea($this->id_game, $id_zarea);
                     $id_area = $gameArea->getIdArea();
                     /* @var $region ModelStartRegion */
                     $region = $regions[$id_area];
                     $id_option = $region->getIdOptionType();
                     $unit_count = ModelOptionType::getOptionType($id_option)->getUnits();
                     // set user for game area
                     $gameArea->setIdUser($id_user);
                     // create units for user
                     $iterUnits = ModelLandUnit::iterator();
                     while ($iterUnits->hasNext()) {
                         $landUnit = $iterUnits->next();
                         $id_unit = $landUnit->getId();
                         $inGameLandUnit = ModelInGameLandUnit::getModelByIdZAreaUserUnit($this->id_game, $id_zarea, $id_user, $id_unit);
                         $inGameLandUnit->setCount($unit_count);
                     }
                 }
             }
         }
         // add units to all empty game-areas
         $iter = ModelGameArea::iterator(NEUTRAL_COUNTRY, $this->id_game);
         while ($iter->hasNext()) {
             /* @var $gameArea ModelGameArea */
             $gameArea = $iter->next();
             if ($gameArea->getIdType() !== TYPE_LAND) {
                 continue;
             }
             $count = $gameArea->getProductivity();
             if ($gameArea->getIdResource() === RESOURCE_OIL) {
                 ++$count;
             }
             $iterUnits = ModelLandUnit::iterator();
             while ($iterUnits->hasNext()) {
                 $landUnit = $iterUnits->next();
                 $id_unit = $landUnit->getId();
                 $inGameLandUnit = ModelInGameLandUnit::getModelByIdZAreaUserUnit($this->id_game, $gameArea->getId(), NEUTRAL_COUNTRY, $id_unit);
                 $inGameLandUnit->setCount($count);
             }
         }
         $this->finishProcessing();
     } catch (\Exception $ex) {
         $this->logger->fatal($ex);
         $this->rollback();
     }
 }