public function groupresizeAction()
 {
     $game_id = $this->_getParam("game_id", NULL);
     $group_id = $this->_getParam("group_id", NULL);
     $size = (int) $this->_getParam('size');
     $mode = $this->_getParam('mode');
     $game = Ultimatum_Model_Ultgames::getInstance()->get($game_id);
     $group = Ultimatum_Model_Ultgroups::getInstance()->get($group_id);
     $sizer = new Ultimatum_Model_Ultplayergroupsize();
     $sizer->group_id = $group_id;
     $sizer->game = $game_id;
     $sizer->turn = $game->turn();
     switch ($mode) {
         case 'relative':
             if ($size) {
                 $sizer->size = $size;
                 $sizer->save();
                 $m_key = 'message';
                 $message = 'Sice changed by ' . $size;
             } else {
                 $m_key = 'error';
                 $message = 'No Size Change Made';
             }
             break;
         case 'absolute':
             $current = $group->size_in_game($game_id);
             if ($current != $size) {
                 $size -= $current;
                 $sizer->size = $size;
                 $sizer->save();
                 $m_key = 'message';
                 $message = 'Size changed to ' . $size;
             } else {
                 $m_key = 'error';
                 $message = 'No Size Change Made';
             }
             break;
     }
     $params = array('id' => $group_id, 'game' => $game_id, $m_key => $message);
     $this->_forward('gamegroupview', NULL, NULL, $params);
 }
 /**
  *
  * @return void
  */
 public function _prep()
 {
     $user = Model_Users::current_user();
     if (!$user) {
         $params = array('error' => 'You must be logged in to run a game. ');
         $this->_forward('index', 'index', NULL, $params);
         return FALSE;
     }
     $game_id = $this->_getParam('game');
     // either actively select game or reactivate last played game
     if ($game_id) {
         $game = Ultimatum_Model_Ultgames::getInstance()->get($game_id);
         $player = Ultimatum_Model_Ultplayers::for_user_game($user, $game)->activate();
     } else {
         $player = Ultimatum_Model_Ultplayers::user_active_player($user);
         if (!$player) {
             $params = array('error' => 'cannot find active game');
             $this->_forward('index', 'index', NULL, $params);
             return FALSE;
         }
         $game = $player->get_game();
     }
     // at this point the player and game objects should be set.
     if (!$player) {
         $params = array('errror' => 'You are not a player in game ' . $id);
         $this->_forward('index', 'index', NULL, $params);
         return FALSE;
     }
     $this->view->game = $game;
     $game->activate();
     $this->view->player = $player;
     // there may or may not be a player group specified by paramerters.
     // player_group refers to the group indirectly by the game group id.
     // group refers to the group id directly.
     if ($player_group = $this->_getParam('player_group')) {
         $this->view->player_group = Ultimatum_Model_Ultgamegroups::getInstance()->get($player_group);
     } elseif ($group = $this->_getParam("group", NULL)) {
         $this->view->player_group = $player->player_group($group);
     }
     // there may or may not be a target.
     // the target id is the group id NOT the game group id.
     if ($target = $this->_getParam('target')) {
         $this->view->target = $target_obj = Ultimatum_Model_Ultgroups::getInstance()->get($target);
         $this->view->target_scan = $player->get_scan($target);
     }
     return TRUE;
 }
示例#3
0
 /**
  *
  * @param boolean $pReload
  * @return Ultimatum_Model_Ultgames
  */
 function get_game($pReload = FALSE)
 {
     if ($pReload || is_null($this->_game)) {
         // process
         $this->_game = Ultimatum_Model_Ultgames::getInstance()->get($this->game);
     }
     return $this->_game;
 }
 /**
  * This method is a bit more "expansive" than as_game_group
  * as it allows a game group object to autospawn if $pGreat = TRUE.
  * @param  $pGroup
  * @return Ultimatum_Model_Ultgamegroups
  */
 public function group_for_game($pGroup, $pGame = NULL, $pCreate = FALSE)
 {
     $pGroup = Zupal_Domain_Abstract::_as($pGroup, 'Ultimatum_Model_Ultgroups', TRUE);
     $pGame = $pGame ? Zupal_Domain_Abstract::_as($pGame, 'Ultimatum_Model_Ultgames', TRUE) : Ultimatum_Model_Ultgames::getInstance()->get_active_id();
     $params = array('group' => $pGroup, 'game' => $pGame);
     $gfg = $this->findOne($params);
     if (!$gfg && $pCreate) {
         $gfg = new self();
         $gfg->group = $pGroup;
         $gfg->game = $pGame;
         $gfg->save();
     }
     return $gfg;
 }