public function respond()
 {
     $c = $this->get_controller();
     if (!$c->_prep()) {
         $c->forward('index', 'index', NULL, array('error' => 'problem loading game'));
     } elseif (!$c->view->player_group) {
         $params = array('error' => 'Cannot load group');
         $c->forward('run', NULL, NULL, $params);
     }
     $ord = new Ultimatum_Model_Ultplayergrouporders();
     $ord->player_group = $c->view->player_group->identity();
     $ord->type = 'attack';
     if ($c->_getParam('repeat')) {
         $ord->repeat = 'iterate';
         $ord->iterations = min(1, (int) $c->_getParam('repeat_count'));
     }
     $ord->target = $c->_getParam('target');
     $ord->save();
     $attack = new Ultimatum_Model_Ultplayergrouporderattacks();
     $attack->order_id = $ord->identity();
     $attack->reduceprop = $c->_getParam('reduceprop');
     $attack->reduceprop_property = (int) $c->_getParam('reduceprop_property');
     $attack->reduceprop_strength = (int) $c->_getParam('reduceprop_strength');
     $attack->loss = $c->_getParam('loss');
     // $attack->loss_count = $c->_getParam('loss_strength_count');
     $attack->loss_strength = $c->_getParam('loss_strength');
     $attack->loss_strength_count = $c->_getParam('loss_strength_count');
     $attack->payoff = $c->_getParam('payoff');
     $attack->payoff_count = $c->_getParam('payoff_count');
     $attack->save();
     $params = array('message' => 'Scheduled attack');
     $c->forward('run', NULL, NULL, $params);
 }
 /**
  *
  * @return Ultimatum_Model_Ultplayergrouporders
  */
 public static function getInstance()
 {
     if ($pReload || is_null(self::$_Instance)) {
         // process
         self::$_Instance = new self();
     }
     return self::$_Instance;
 }
 function order($pReload = FALSE)
 {
     if ($pReload || is_null($this->_order)) {
         $value = Ultimatum_Model_Ultplayergrouporders::getInstance()->get($this->order_id);
         // process
         $this->_order = $value;
     }
     return $this->_order;
 }
 /**
  * @return void
  */
 public function save()
 {
     $mode = $this->mode->get_value();
     if ($mode == 'replace') {
         Ultimatum_Model_Ultplayergrouporders::clear_orders($this->player_group->get_value());
     }
     return parent::save();
     // magic delegates to the domain object.
 }
 /**
  * @return Ultimatum_Model_Ultplayergrouporders[]
  */
 public function pending_orders()
 {
     $orders = Ultimatum_Model_Ultplayergrouporders::getInstance();
     try {
         $sql = sprintf('SELECT po.id FROM %s po ', $orders->table()->tableName());
         $sql .= sprintf(' LEFT JOIN %s pg ON pg.id = po.player_group ', Ultimatum_Model_Ultgamegroups::getInstance()->table()->tableName());
         $sql .= sprintf(' WHERE po.target = %s ', $this->get_group()->identity());
         $sql .= sprintf(' AND pg.player = %s', $this->player);
         $sql .= ' AND po.active > 0;';
         error_log(__METHOD__ . ': finding orders; sql = ' . $sql);
         $out = $orders->find_from_sql($sql, FALSE);
     } catch (Exception $e) {
         error_log(__METHOD__ . ': error on sql ' . $sql);
         $out = array();
     }
     return $out;
 }
Example #6
0
 /**
  *
  * @param <type> $pType
  * @param <type> $pTarget
  * @return
  */
 public function pending_orders($pType = NULL, $pTarget = NULL)
 {
     $params = array('commander' => $this->identity(), 'active' => 1);
     $out = Ultimatum_Model_Ultplayergrouporders::getInstance()->find($params, 'given_at');
     return $out;
 }
 public function cancelorderAction()
 {
     if (!$this->_prep()) {
         $this->_forward('index', 'index', NULL, array('error' => 'problem loading game'));
     }
     $order = $this->_getParam("order", NULL);
     $po = Ultimatum_Model_Ultplayergrouporders::getInstance()->get($order);
     if (!$po->player_group()->player()->identity() == $this->view->player->identity()) {
         $params = array('error' => 'cannot cancel order ' . $order . ': doesn\'t refer to one of your groups');
     } else {
         $po->cancel();
         $params = array('message' => 'Cancelled order ' . $po);
     }
     $this->_forward('run', NULL, NULL, $params);
 }
 /**
  *
  * @return array
  */
 public function pending_orders()
 {
     $po = Ultimatum_Model_Ultplayergrouporders::getInstance();
     $select = $po->table()->select()->where('active = ?', 1)->where('player_group = ?', $this->identity())->where('status = ?', Ultimatum_Model_Ultplayergrouporders::STATUS_PENDIONG)->orWhere('status = ?', Ultimatum_Model_Ultplayergrouporders::STATUS_EXECUTING);
     return $po->find($select, 'series');
 }