Пример #1
0
 /**
  * Test GameSettings
  */
 public function testGameSettings()
 {
     $settings = ["setting1" => "value1", "setting2" => "value2"];
     $gameSettings = new GameSettings($settings);
     $this->assertEquals($settings['setting1'], $gameSettings->get("setting1"));
     $this->assertTrue($gameSettings->has("setting1"));
     $this->assertFalse($gameSettings->has("setting3"));
     $this->assertEquals($settings, $gameSettings->all());
 }
Пример #2
0
 /**
  * Performs post analyze actions.
  *
  * @return void
  */
 protected function postAnalyze()
 {
     if (!$this->gameSettings->isScenario()) {
         $lines = explode("\n", $this->gameInfo->objectivesString);
         // get map
         if (!$this->isMgx || $this->gameSettings->mapId == Map::CUSTOM) {
             if (count($lines) > 2) {
                 $this->gameSettings->map = ltrim(strstr($lines[2], ': '), ': ');
                 if (!$this->isMgx) {
                     $map_found = false;
                     //TODO get map from localized map strings
                 }
             }
         }
     }
     $this->buildTeams();
     // fix: player could click age advance, but game finished before reaching specific age
     foreach ($this->players as $player) {
         if ($player->feudalTime > $this->gameInfo->playTime) {
             $player->feudalTime = 0;
         }
         if ($player->castleTime > $this->gameInfo->playTime) {
             $player->castleTime = 0;
         }
         if ($player->imperialTime > $this->gameInfo->playTime) {
             $player->imperialTime = 0;
         }
     }
     //TODO: otestovat, ci je to OK
     //units pole
     if (!empty($this->ingameChat)) {
         usort($this->ingameChat, array('RecAnalyst\\RecAnalyst', 'chatMessagesCompare'));
     }
     if (!empty($this->buildings)) {
         ksort($this->buildings);
     }
     // we sort gaia objects, so we can draw first ciffs than relics,
     // this ensures that relics will overlap cliffs and not vice versa
     usort($this->gaiaObjects, array('RecAnalyst\\RecAnalyst', 'gaiaObjectsCompare'));
     // UserPatch population limits
     if ($this->gameInfo->isUserPatch) {
         $this->gameSettings->popLimit = 25 * $this->gameSettings->popLimit;
     }
 }
Пример #3
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($new = false)
 {
     if ($new === true) {
         $model = new Games();
     } else {
         $model = $this->loadModel($_GET['id']);
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Games'])) {
         $model->attributes = $_POST['Games'];
         if ($model->save()) {
             $this->redirect(array('index'));
         } else {
             $this->addFlashMessage($model->errors, 'error');
         }
     }
     if (isset($_POST['setting'])) {
         $var = $_POST;
         extract($var);
         $connection = Yii::app()->db;
         $sql = "UPDATE crzsettings SET value='{$get_more_than_bet_freq}' where name='get_more_than_bet_freq'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$max_part_of_bank_at_once}' where name='max_part_of_bank_at_once'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$max_gain_at_once}' where name='max_gain_at_once'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$max_gain_in_double}' where name='max_gain_in_double'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$max_gain_on_rope}' where name='max_gain_on_rope'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$max_super_prize}' where name='max_super_prize'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$bonus_freq}' where name='bonus_freq'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$banana_freq}' where name='banana_freq'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$bonus_min}' where name='bonus_min'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$bonus_max}' where name='bonus_max'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$double_freq}' where name='double_freq'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$bonus2_50}' where name='bonus2_50'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$bonus2_100}' where name='bonus2_100'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$bonus2_150}' where name='bonus2_150'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$bonus2_200}' where name='bonus2_200'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         $sql = "UPDATE crzsettings SET value='{$bonus2_250}' where name='bonus2_250'";
         $command = $connection->createCommand($sql);
         $rowCount = $command->execute();
         for ($i = 1; $i <= 9; $i++) {
             for ($j = 1; $j < 4; $j++) {
                 if (isset(${'wl' . "{$i}" . "{$j}"})) {
                     $per = ${'wl' . "{$i}" . "{$j}"};
                     $sql = "UPDATE crzsettings SET value='" . $per . "' where name='wl,{$i},{$j}'";
                     $command = $connection->createCommand($sql);
                     $rowCount = $command->execute();
                     if (isset(Yii::app()->session["wl" . "{$i}" . "{$j}"])) {
                         unset(Yii::app()->session["wl" . "{$i}" . "{$j}"]);
                     }
                 }
             }
         }
         $this->refresh();
     }
     if (isset($_POST['GameSettings'])) {
         $vars = $_POST['GameSettings'];
         if (!empty($vars)) {
             foreach ($vars as $key => $val) {
                 $gs = GameSettings::model()->find(array('condition' => 'game_id=:game_id and name=:name', 'params' => array(':game_id' => $model->id, ':name' => $key)));
                 if ($gs) {
                     $gs->value = $val;
                     $gs->save();
                 }
             }
         }
         $this->refresh();
     }
     $this->render('update', array('model' => $model));
 }
Пример #4
0
 /**
  * Performs post analyze actions.
  *
  * @return void
  */
 protected function postAnalyze()
 {
     if (!$this->gameSettings->isScenario()) {
         $lines = explode("\n", $this->gameInfo->objectivesString);
         // get map
         if (!$this->isMgx || $this->gameSettings->mapId == Map::CUSTOM) {
             if (count($lines) > 2) {
                 $this->gameSettings->map = ltrim(strstr($lines[2], ': '), ': ');
                 if (!$this->isMgx) {
                     $map_found = false;
                     //TODO get map from localized map strings
                 }
             }
         }
     }
     $this->buildTeams();
     // fix: player could click age advance, but game finished before reaching specific age
     foreach ($this->players as $player) {
         if ($player->feudalTime > $this->gameInfo->playTime) {
             $player->feudalTime = 0;
         }
         if ($player->castleTime > $this->gameInfo->playTime) {
             $player->castleTime = 0;
         }
         if ($player->imperialTime > $this->gameInfo->playTime) {
             $player->imperialTime = 0;
         }
     }
     if (!empty($this->ingameChat)) {
         $compareTime = function ($a, $b) {
             return $a->time - $b->time;
         };
         usort($this->ingameChat, $compareTime);
     }
     if (!empty($this->buildings)) {
         ksort($this->buildings);
     }
     // we sort gaia objects, so we can draw first ciffs than relics,
     // this ensures that relics will overlap cliffs and not vice versa
     usort($this->gaiaObjects, function ($item1, $item2) {
         // relics show on top of everything else
         if ($item1->id === Unit::RELIC && $item2->id !== Unit::RELIC) {
             return 1;
         }
         // cliffs show below everything else
         if (in_array($item1->id, RecAnalystConst::$CLIFF_UNITS) && !in_array($item2->id, RecAnalystConst::$CLIFF_UNITS)) {
             return -1;
         }
         if ($item2->id === Unit::RELIC && $item1->id !== Unit::RELIC) {
             return -1;
         }
         if (in_array($item2->id, RecAnalystConst::$CLIFF_UNITS) && !in_array($item1->id, RecAnalystConst::$CLIFF_UNITS)) {
             return 1;
         }
         return 0;
     });
     // UserPatch supports pop limits of up to 1000, so that won't normally fit in a byte.
     // Instead it stores N so that the pop limit is 25*N.
     if ($this->gameInfo->isUserPatch) {
         $this->gameSettings->popLimit = 25 * $this->gameSettings->popLimit;
     }
 }