本文整理汇总了PHP中Game::canBuild方法的典型用法代码示例。如果您正苦于以下问题:PHP Game::canBuild方法的具体用法?PHP Game::canBuild怎么用?PHP Game::canBuild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game
的用法示例。
在下文中一共展示了Game::canBuild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upgradeAction
/**
* Check for sufficient resources and start research upgrade.
*
* @param integer $id Building id to upgrade
* @throws Recipe_Exception_Generic
* @return Bengine_Game_Controller_Research
*/
protected function upgradeAction($id)
{
// Check events
if ($this->event != false || Core::getUser()->get("umode")) {
$this->redirect("game/" . SID . "/Research");
}
// Check for requirements
if (!Game::canBuild($id) || !Game::getPlanet()->getBuilding("RESEARCH_LAB")) {
throw new Recipe_Exception_Generic("You do not fulfil the requirements to research this.");
}
// Check if research labor is not in progress
if (!Game::getEH()->canReasearch()) {
throw new Recipe_Exception_Generic("Research labor in progress.");
}
/* @var Bengine_Game_Model_Construction $construction */
$construction = Game::getModel("game/construction");
$construction->load($id);
if (!$construction->getId()) {
throw new Recipe_Exception_Generic("Unkown research :(");
}
if ($construction->get("mode") != self::RESEARCH_CONSTRUCTION_TYPE) {
throw new Recipe_Exception_Generic("Research not allowed.");
}
if (Game::getPlanet()->getData("ismoon") && !$construction->get("allow_on_moon")) {
throw new Recipe_Exception_Generic("Research not allowed.");
}
Hook::event("UpgradeResearchFirst", array($construction));
// Get required resources
$level = Game::getResearch($id);
if ($level > 0) {
$level = $level + 1;
} else {
$level = 1;
}
$this->setRequieredResources($level, $construction);
// Check resources
if ($this->checkResources()) {
$data["metal"] = $this->requiredMetal;
$data["silicon"] = $this->requiredSilicon;
$data["hydrogen"] = $this->requiredHydrogen;
$data["energy"] = $this->requiredEnergy;
$time = getBuildTime($data["metal"], $data["silicon"], self::RESEARCH_CONSTRUCTION_TYPE);
$data["level"] = $level;
$data["buildingid"] = $id;
$data["buildingname"] = $construction->get("name");
Hook::event("UpgradeResearchLast", array($construction, &$data, &$time));
Game::getEH()->addEvent(3, $time + TIME, Core::getUser()->get("curplanet"), Core::getUser()->get("userid"), null, $data);
$this->redirect("game/" . SID . "/Research");
} else {
Logger::dieMessage("INSUFFICIENT_RESOURCES");
}
return $this;
}
示例2: orderAction
/**
* Starts an event for building units.
*
* @throws Recipe_Exception_Generic
* @return Bengine_Game_Controller_Shipyard
*/
protected function orderAction()
{
if (Core::getUser()->get("umode") || Game::isDbLocked()) {
$this->redirect("game/" . SID . "/" . Core::getRequest()->getGET("controller"));
}
if (!$this->canBuildUnits) {
throw new Recipe_Exception_Generic("Shipyard or nano factory in progress.");
}
$post = Core::getRequest()->getPOST();
/* @var Bengine_Game_Model_Collection_Construction $collection */
$collection = Application::getCollection("game/construction", "game/unit");
$collection->addTypeFilter($this->mode, Game::getPlanet()->getData("ismoon"))->addShipyardJoin(Core::getUser()->get("curplanet"));
foreach ($collection as $construction) {
/* @var Bengine_Game_Model_Unit $construction */
$id = $construction->getId();
if (isset($post[$id]) && $post[$id] > 0) {
// Check for requirements
if (!Game::canBuild($id)) {
throw new Recipe_Exception_Generic("You cannot build this.");
}
$quantity = _pos($post[$id]);
if ($quantity > Core::getConfig()->get("SHIPYARD_MAX_UNITS_PER_ORDER")) {
$quantity = (int) Core::getConfig()->get("SHIPYARD_MAX_UNITS_PER_ORDER");
}
Hook::event("UnitOrderStart", array($construction, &$quantity));
if ($id == 49 || $id == 50) {
$where = Core::getDB()->quoteInto("unitid = ? AND planetid = ?", array($id, Core::getUser()->get("curplanet")));
$_result = Core::getQuery()->select("unit2shipyard", "quantity", "", $where);
if ($_result->rowCount() > 0) {
throw new Recipe_Exception_Generic("You cannot build this.");
}
$_result->closeCursor();
if (Game::getEH()->hasSmallShieldDome() && $id == 49) {
throw new Recipe_Exception_Generic("You cannot build this.");
}
if (Game::getEH()->hasLargeShieldDome() && $id == 50) {
throw new Recipe_Exception_Generic("You cannot build this.");
}
$quantity = 1;
// Make sure that shields cannot be build twice
}
if ($id == 51 || $id == 52) {
$maxsize = Game::getRocketStationSize();
// Check max. size
if (!$this->canBuildRockets) {
continue;
}
// Decrease quantity, if necessary
if ($id == 52) {
$quantity *= 2;
}
if ($quantity > $maxsize - $this->existingRockets) {
$quantity = $maxsize - $this->existingRockets;
}
if ($id == 52) {
$quantity = floor($quantity / 2);
}
}
// Check resources
$quantity = $this->checkResourceForQuantity($quantity, $construction);
// make event
if ($quantity > 0) {
$latest = TIME;
$existingEvents = Game::getEH()->getShipyardEvents();
foreach ($existingEvents as $existingEvent) {
if ($existingEvent->getData("finished") > $latest) {
$latest = $existingEvent->getData("finished");
}
}
$time = getBuildTime($construction->get("basic_metal"), $construction->get("basic_silicon"), $this->mode);
$data["one"] = $time;
$data["quantity"] = $quantity;
$data["finished"] = $time * $quantity + $latest;
$data["mission"] = $construction->get("name");
$data["buildingid"] = $id;
$data["metal"] = $construction->get("basic_metal");
$data["silicon"] = $construction->get("basic_silicon");
$data["hydrogen"] = $construction->get("basic_hydrogen");
$data["points"] = ($construction->get("basic_metal") + $construction->get("basic_silicon") + $construction->get("basic_hydrogen")) / 1000;
$mode = $this->mode == self::FLEET_CONSTRUCTION_TYPE ? 4 : 5;
Hook::event("UnitOrderLast", array($construction, $quantity, $mode, &$time, &$latest, &$data));
Game::getEH()->addEvent($mode, $time + $latest, Core::getUser()->get("curplanet"), Core::getUser()->get("userid"), null, $data);
}
}
}
$this->redirect("game/" . SID . "/" . Core::getRequest()->getGET("controller"));
return $this;
}
示例3: upgradeAction
/**
* Check for sufficient resources and start to upgrade building.
*
* @param integer $id Building id to upgrade
* @throws Recipe_Exception_Generic
* @return Bengine_Game_Controller_Constructions
*/
protected function upgradeAction($id)
{
// Check events
if ($this->event != false || Core::getUser()->get("umode")) {
$this->redirect("game/" . SID . "/Constructions");
}
if ($id == 12 && Game::getEH()->getResearchEvent()) {
throw new Recipe_Exception_Generic("Do not mess with the url.");
}
$shipyardSize = Game::getEH()->getShipyardEvents()->getCalculatedSize();
if (($id == 8 || $id == 7) && $shipyardSize > 0) {
throw new Recipe_Exception_Generic("Do not mess with the url.");
}
// Check fields
if (!Game::getPlanet()->planetFree()) {
Logger::dieMessage("PLANET_FULLY_DEVELOPED");
}
// Check for requirements
if (!Game::canBuild($id)) {
throw new Recipe_Exception_Generic("You do not fulfil the requirements to build this.");
}
// Load building data
Core::getLanguage()->load(array("info", "buildings"));
$isMoon = Game::getPlanet()->getData("ismoon");
/* @var Bengine_Game_Model_Construction $construction */
$construction = Game::getModel("game/construction");
$construction->load($id);
if (!$construction->getId()) {
throw new Recipe_Exception_Generic("Unkown building :(");
}
$mode = $construction->get("mode");
if ($isMoon && $mode != self::MOON_CONSTRUCTION_TYPE) {
if ($mode == self::BUILDING_CONSTRUCTION_TYPE && !$construction->get("allow_on_moon")) {
throw new Recipe_Exception_Generic("Building not allowed.");
}
}
if (!$isMoon && $mode != self::BUILDING_CONSTRUCTION_TYPE) {
throw new Recipe_Exception_Generic("Building not allowed.");
}
Hook::event("UpgradeBuildingFirst", array($construction));
// Get required resources
$level = Game::getPlanet()->getBuilding($id);
if ($level > 0) {
$level = $level + 1;
} else {
$level = 1;
}
$this->setRequieredResources($level, $construction);
// Check resources
if ($this->checkResources()) {
$data["metal"] = $this->requiredMetal;
$data["silicon"] = $this->requiredSilicon;
$data["hydrogen"] = $this->requiredHydrogen;
$data["energy"] = $this->requiredEnergy;
$time = getBuildTime($data["metal"], $data["silicon"], self::BUILDING_CONSTRUCTION_TYPE);
$data["level"] = $level;
$data["buildingid"] = $id;
$data["buildingname"] = $construction->get("name");
Hook::event("UpgradeBuildingLast", array($construction, &$data, &$time));
Game::getEH()->addEvent(1, $time + TIME, Core::getUser()->get("curplanet"), Core::getUser()->get("userid"), null, $data);
$this->redirect("game/" . SID . "/Constructions");
} else {
Logger::dieMessage("INSUFFICIENT_RESOURCES");
}
return $this;
}