public static function setGameDetails(Game $game) { self::$logItem->setTurn($game->getTurn()); self::$logItem->setPhase($game->getPhase()->getName()); if ($game->getCurrentAction()) { $action = $game->getCurrentAction(); self::$logItem->setActionDetails($action->getDetails()); if ($action->getActionDie()) { self::$logItem->setActionDie($action->getActionDie()->getDetails()); } } }
public function setNextAction(Game $game) { $nA = new Action($this->getNextAction()); $game->setCurrentAction($nA); }
/** * Set game * * @param \Meldon\WotRBundle\Entity\Game $game * @return Nation */ public function setGame(\Meldon\WotRBundle\Entity\Game $game = null) { $this->game = $game; $game->addNation($this); return $this; }
/** * Set game * * @param Game $game * @return Log */ public function setGame(Game $game = null) { $this->game = $game; $game->setLog($this); return $this; }
/** * Set game * * @param \Meldon\WotRBundle\Entity\Game $game * @return DecisionStack */ public function setGame(\Meldon\WotRBundle\Entity\Game $game = null) { $this->game = $game; $game->setDecisionStack($this); return $this; }
/** * @Route("/wotr/ajax/units/{id}") * @ParamConverter("post", class="WotRBundle:Game", options={"repository_method" = "getCurrentGame"}) * @param Game $game * @param Request $request * @return JsonResponse|Response */ public function ajaxUnitsAction(Game $game, Request $request) { if ($request->isXMLHttpRequest()) { $units = $game->getUnits(); $outputArr = array(); /** @var Unit $u */ foreach ($units as $u) { if ($u->getLocation()) { $outputArr[$u->getId()] = array('unitName' => $u->getName(), 'loc' => $u->getLocation()->getId(), 'sideId' => $u->getSide()->getId()); } } $response = new JsonResponse(); $response->setData(array('data' => $outputArr)); return $response; } return new Response('This is not ajax!', 400); $unitTable = 'units'; $request = new Request(); switch ($request->getProperty('request')) { case 'units': $sql = "SELECT {$unitTable}.id, loc, unit.name as unitName, unitType.name as type, " . "nation.side_id as sideId, nation.name as nation FROM {$unitTable} " . "LEFT JOIN unit ON unit_id = unit.id " . "LEFT JOIN nation ON nation_id = nation.id " . "LEFT JOIN unitType on unitType_id = unitType.id " . "WHERE loc != 0 " . "ORDER BY {$unitTable}.loc"; $unitsQ = DBP::query($sql); $outputArr = array(); foreach ($unitsQ->rows as $unit) { $outputArr[$unit->id] = array('unitName' => $unit->unitName, 'loc' => $unit->loc, 'type' => $unit->type, 'nation' => $unit->nation, 'sideId' => $unit->sideId); } echo json_encode($outputArr); break; case 'recruitable': $sql = "SELECT {$unitTable}.id, IF( ISNULL(unit.name),CONCAT(nation.name, ' ', unitType.name, ' (', COUNT({$unitTable}.id), ' remaining)'),unit.name) AS unitName " . "FROM {$unitTable} " . "LEFT JOIN unit ON {$unitTable}.unit_id = unit.id " . "LEFT JOIN nation ON nation.id = nation_id " . "LEFT JOIN unitType ON unitType.id = unitType_id " . "WHERE loc = 0 AND ( side_id = 2 || casualty != 1 ) AND unit.unitType_id <= 4 " . "GROUP BY CONCAT(nation.name, ' ', unitType.name) " . "UNION ALL " . "SELECT {$unitTable}.id, unit.name AS unitName FROM {$unitTable} " . "LEFT JOIN unit ON {$unitTable}.unit_id = unit.id " . "LEFT JOIN nation ON nation.id = nation_id " . "LEFT JOIN unitType ON unitType.id = unitType_id " . "WHERE loc = 0 AND casualty != 1 AND unit.unitType_id >= 5 " . "ORDER BY id"; $units = DBP::query($sql, NULL, NULL, 'keyPair'); echo json_encode($units->rows); break; case 'recruit': $unitID = $request->getProperty('unit'); $regionID = $request->getProperty('region'); if ($regionID && $unitID) { $sql = "UPDATE {$unitTable} SET loc = ? WHERE id = ?"; $pA = array($regionID, $unitID); DBP::query($sql, $pA); echo "Unit recruited."; } else { echo "Please select a unit to recruit."; } break; case 'move': $unitIDs = $request->getProperty('selectedUnits'); $dest = $request->getProperty('dest'); if (is_array($unitIDs)) { $qMarks = str_repeat('?,', count($unitIDs) - 1) . '?'; $sql = "UPDATE {$unitTable} SET loc = ? WHERE id IN ({$qMarks})"; array_unshift($unitIDs, $dest); DBP::query($sql, $unitIDs); echo "Units moved"; } else { echo "Please select units to move"; } break; case 'remove': $unitIDs = $request->getProperty('selectedUnits'); $casualty = $request->getProperty('casualty'); if (is_array($unitIDs)) { $qMarks = str_repeat('?,', count($unitIDs) - 1) . '?'; $sql = "UPDATE {$unitTable} SET loc = 0, casualty = ? WHERE id IN ({$qMarks})"; array_unshift($unitIDs, $casualty); DBP::query($sql, $unitIDs); echo "Units removed"; } else { echo "Please select units to remove"; } break; case 'reduce': $unitIDs = $request->getProperty('selectedUnits'); $regionID = $request->getProperty('region'); $return = ''; foreach ($unitIDs as $unitID) { $sql = "SELECT nation_id FROM {$unitTable} " . "LEFT JOIN unit ON {$unitTable}.unit_id = unit.id " . "WHERE {$unitTable}.id = ?"; $result = DBP::query($sql, array($unitID)); $nation = $result->nation_id; $sql = "SELECT {$unitTable}.id, casualty FROM {$unitTable} " . "LEFT JOIN unit ON {$unitTable}.unit_id = unit.id " . "WHERE nation_id = ? AND loc = 0 AND unitType_id = 1 " . "ORDER BY casualty DESC"; $regulars = DBP::query($sql, array($nation)); if ($regulars->getRows()) { $sql = "UPDATE {$unitTable} SET loc = 0, casualty = 1 WHERE id = ?"; $pA = array($unitID); DBP::query($sql, $pA); $sql = "UPDATE {$unitTable} SET loc = ?, casualty = 0 WHERE id = ?"; $pA = array($regionID, $regulars->id); DBP::query($sql, $pA); $return = 'Elite reduced'; } else { $return = 'No regular to reduce elite'; } } echo $return; } }
/** * Set game * * @param \Meldon\WotRBundle\Entity\Game $game * @return Fellowship */ public function setGame(\Meldon\WotRBundle\Entity\Game $game = null) { $this->game = $game; $game->setFellowship($this); return $this; }