コード例 #1
0
ファイル: Fleet.php プロジェクト: enriquesomolinos/Bengine
 /**
  * Main method of sending fleet via Ajax.
  *
  * @return Bengine_Game_Controller_Ajax_Fleet
  */
 protected function init()
 {
     Core::getLanguage()->load("Galaxy");
     $events = Game::getEH()->getOwnFleetEvents();
     if ($events !== false && Game::getResearch(14) + 1 <= count($events)) {
         Core::getLanguage()->load("mission");
         $this->display($this->format(Core::getLanguage()->getItem("NO_FREE_FLEET_SLOTS")));
     }
     $this->setIsAjax();
     Hook::event("AjaxSendFleet", array($this));
     return parent::init();
 }
コード例 #2
0
/**
 * Executes a formula.
 *
 * @param string $formula	Formular to execute
 * @param integer $basic	First number to replace
 * @param integer $level	Second number to replace
 *
 * @return integer	Result
 */
function parseFormula($formula, $basic, $level)
{
    Hook::event("ParseFormula", array(&$formula, &$basic, &$level));
    $formula = Str::replace("{level}", $level, $formula);
    $formula = Str::replace("{basic}", $basic, $formula);
    $formula = Str::replace("{temp}", Game::getPlanet()->getData("temperature"), $formula);
    $formula = preg_replace_callback("#\\{tech\\=([0-9]+)\\}#i", function ($matches) {
        return Game::getResearch($matches[1]);
    }, $formula);
    $formula = preg_replace_callback("#\\{building\\=([0-9]+)\\}#i", function ($matches) {
        return Game::getPlanet()->getBuilding($matches[1]);
    }, $formula);
    $result = 0;
    eval("\$result = " . $formula . ";");
    return (int) $result;
}
コード例 #3
0
ファイル: Mission.php プロジェクト: enriquesomolinos/Bengine
 /**
  * This starts the missions and shows a quick overview of the flight.
  *
  * @param integer $mode
  * @param integer $metal
  * @param integer $silicon
  * @param integer $hydrogen
  * @param integer $holdingTime
  * @throws Recipe_Exception_Generic
  * @return Bengine_Game_Controller_Mission
  */
 protected function sendFleet($mode, $metal, $silicon, $hydrogen, $holdingTime)
 {
     $this->noAction = true;
     $fleetEvents = Game::getEH()->getOwnFleetEvents();
     if ($fleetEvents && Game::getResearch(14) + 1 <= count(Game::getEH()->getOwnFleetEvents())) {
         throw new Recipe_Exception_Generic("Too many fleets on missions.");
     }
     $result = Core::getQuery()->select("temp_fleet", "data", "", Core::getDB()->quoteInto("planetid = ?", Core::getUser()->get("curplanet")));
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         $temp = unserialize($row["data"]);
         if (!in_array($mode, $temp["amissions"])) {
             Logger::dieMessage("UNKNOWN_MISSION");
         }
         $data["ships"] = $temp["ships"];
         $data["galaxy"] = $temp["galaxy"];
         $data["system"] = $temp["system"];
         $data["position"] = $temp["position"];
         $data["sgalaxy"] = Game::getPlanet()->getData("galaxy");
         $data["ssystem"] = Game::getPlanet()->getData("system");
         $data["sposition"] = Game::getPlanet()->getData("position");
         $data["maxspeed"] = $temp["maxspeed"];
         $distance = Game::getDistance($data["galaxy"], $data["system"], $data["position"]);
         $data["consumption"] = Game::getFlyConsumption($temp["consumption"], $distance, $temp["speed"]);
         if (Game::getPlanet()->getData("hydrogen") - $data["consumption"] < 0) {
             Logger::dieMessage("NOT_ENOUGH_FUEL");
         }
         if ($temp["capacity"] < $data["consumption"]) {
             Logger::dieMessage("NOT_ENOUGH_CAPACITY");
         }
         $data["metal"] = (int) abs($metal);
         $data["silicon"] = (int) abs($silicon);
         $data["hydrogen"] = (int) abs($hydrogen);
         if ($data["metal"] > Game::getPlanet()->getData("metal")) {
             $data["metal"] = _pos(Game::getPlanet()->getData("metal"));
         }
         if ($data["silicon"] > Game::getPlanet()->getData("silicon")) {
             $data["silicon"] = _pos(Game::getPlanet()->getData("silicon"));
         }
         if ($data["hydrogen"] > Game::getPlanet()->getData("hydrogen") - $data["consumption"]) {
             $data["hydrogen"] = _pos(Game::getPlanet()->getData("hydrogen") - $data["consumption"]);
         }
         if ($mode == 13) {
             $data["duration"] = _pos($holdingTime);
             if ($data["duration"] > 24) {
                 $data["duration"] = 24;
             }
             $data["duration"] *= 3600;
         }
         $capa = $temp["capacity"] - $data["consumption"] - $data["metal"] - $data["silicon"] - $data["hydrogen"];
         // Reduce used capacity automatically
         if ($capa < 0) {
             if ($capa + $data["hydrogen"] > 0) {
                 $data["hydrogen"] -= abs($capa);
             } else {
                 $capa += $data["hydrogen"];
                 $data["hydrogen"] = 0;
                 if ($capa + $data["silicon"] > 0 && $capa < 0) {
                     $data["silicon"] -= abs($capa);
                 } else {
                     if ($capa < 0) {
                         $capa += $data["silicon"];
                         $data["silicon"] = 0;
                         if ($capa + $data["metal"] && $capa < 0) {
                             $data["metal"] -= abs($capa);
                         } else {
                             if ($capa < 0) {
                                 $data["metal"] = 0;
                             }
                         }
                     }
                 }
             }
         }
         $data["capacity"] = $temp["capacity"] - $data["consumption"] - $data["metal"] - $data["silicon"] - $data["hydrogen"];
         if ($data["capacity"] < 0) {
             Logger::dieMessage("NOT_ENOUGH_CAPACITY");
         }
         // If mission is recycling, get just the capacity of the recyclers.
         if ($mode == 9 && $data["capacity"] > 0) {
             $_result = Core::getQuery()->select("ship_datasheet", "capicity", "", "unitid = '37'");
             // It is __capacity__ and not capicity
             $_row = $_result->fetchRow();
             $_result->closeCursor();
             $recCapa = $_row["capicity"] * $temp["ships"][37]["quantity"];
             if ($data["capacity"] >= $recCapa) {
                 $data["capacity"] = $recCapa;
             }
         }
         $time = Game::getFlyTime($distance, $data["maxspeed"], $temp["speed"]);
         $data["time"] = $time;
         if ($mode == 18) {
             $data["alliance_attack"] = $temp["alliance_attack"];
             $mainFleet = Game::getEH()->getMainFormationFleet($data["alliance_attack"]["eventid"]);
             $allFleets = Game::getEH()->getFormationFleets($data["alliance_attack"]["eventid"]);
             $numFleets = 1;
             $formationUser[$mainFleet->get("user")] = true;
             /* @var Bengine_Game_Model_Fleet $oneFleet */
             foreach ($allFleets as $oneFleet) {
                 $numFleets++;
                 $formationUser[$oneFleet->get("user")] = true;
             }
             unset($formationUser[Core::getUser()->get("userid")]);
             if ($numFleets >= Core::getOptions()->get("MAX_FORMATION_FLEETS")) {
                 Logger::dieMessage("MAX_FORMATION_FLEETS_EXCEEDED");
             }
             if (count($formationUser) >= Core::getOptions()->get("MAX_FORMATION_USER")) {
                 Logger::dieMessage("MAX_FORMATION_USER_EXCEEDED");
             }
             if ($data["time"] + TIME > ($mainFleet["time"] - TIME) * (1 + Core::getOptions()->get("MAX_FORMATION_DELAY")) + TIME) {
                 Logger::dieMessage("MAX_FORMATION_DELAY_EXCEEDED");
             }
         }
         Hook::event("SendFleet", array(&$data, &$time, &$temp, $distance));
         Core::getQuery()->delete("temp_fleet", "planetid = ?", null, null, array(Core::getUser()->get("curplanet")));
         $handler = Game::getEH()->addEvent($mode, $time + TIME, Core::getUser()->get("curplanet"), Core::getUser()->get("userid"), isset($temp["destination"]) ? $temp["destination"] : null, $data);
         Core::getTPL()->assign("mission", Game::getMissionName($mode));
         Core::getTPL()->assign("mode", $mode);
         Core::getTPL()->assign("distance", fNumber($distance));
         Core::getTPL()->assign("speed", fNumber($temp["maxspeed"]));
         Core::getTPL()->assign("consume", fNumber($data["consumption"]));
         Core::getTPL()->assign("start", Game::getPlanet()->getCoords(false));
         Core::getTPL()->assign("target", $data["galaxy"] . ":" . $data["system"] . ":" . $data["position"]);
         Core::getTPL()->assign("arrival", Date::timeToString(1, $handler->getFinishTime()));
         if ($returnTime = $handler->getReturnTime()) {
             Core::getTPL()->assign("return", Date::timeToString(1, $returnTime));
         }
         $fleet = array();
         foreach ($data["ships"] as $key => $value) {
             $fleet[$key]["name"] = Core::getLanguage()->getItem($value["name"]);
             $fleet[$key]["quantity"] = fNumber($value["quantity"]);
         }
         Core::getTPL()->addLoop("fleet", $fleet);
         $this->setTemplate("mission/step4");
     }
     return $this;
 }
コード例 #4
0
ファイル: Research.php プロジェクト: enriquesomolinos/Bengine
 /**
  * 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;
 }
コード例 #5
0
ファイル: Techtree.php プロジェクト: enriquesomolinos/Bengine
 /**
  * Index action.
  *
  * @return Bengine_Game_Controller_Techtree
  */
 protected function indexAction()
 {
     $reqs = Game::getAllRequirements();
     $cons = array();
     $research = array();
     $ships = array();
     $def = array();
     $moon = array();
     $result = Core::getQuery()->select("construction", array("buildingid", "mode", "name"), "ORDER BY display_order ASC, buildingid ASC");
     foreach ($result->fetchAll() as $row) {
         Hook::event("LoadTechtree", array(&$row));
         $bid = $row["buildingid"];
         $requirements = "";
         if (!isset($reqs[$bid])) {
             $reqs[$bid] = array();
         }
         foreach ($reqs[$bid] as $r) {
             $buffer = Core::getLanguage()->getItem($r["name"]) . " (" . Core::getLanguage()->getItem("LEVEL") . " " . $r["level"] . ")</span><br />";
             $rLevel = 0;
             if ($r["mode"] == 1 || $r["mode"] == 5) {
                 $rLevel = Game::getPlanet()->getBuilding($r["needs"]);
             } else {
                 if ($r["mode"] == 2) {
                     $rLevel = Game::getResearch($r["needs"]);
                 }
             }
             if ($rLevel >= $r["level"]) {
                 $requirements .= "<span class=\"true\">" . $buffer;
             } else {
                 $requirements .= "<span class=\"false\">" . $buffer;
             }
         }
         $name = Core::getLanguage()->getItem($row["name"]);
         switch ($row["mode"]) {
             case 1:
                 $cons[$bid]["name"] = Link::get("game/" . SID . "/Constructions/Info/" . $row["buildingid"], $name);
                 $cons[$bid]["requirements"] = $requirements;
                 break;
             case 2:
                 $research[$bid]["name"] = Link::get("game/" . SID . "/Constructions/Info/" . $row["buildingid"], $name);
                 $research[$bid]["requirements"] = $requirements;
                 break;
             case 3:
                 $ships[$bid]["name"] = Link::get("game/" . SID . "/Unit/Info/" . $row["buildingid"], $name);
                 $ships[$bid]["requirements"] = $requirements;
                 break;
             case 4:
                 $def[$bid]["name"] = Link::get("game/" . SID . "/Unit/Info/" . $row["buildingid"], $name);
                 $def[$bid]["requirements"] = $requirements;
                 break;
             case 5:
                 $moon[$bid]["name"] = Link::get("game/" . SID . "/Constructions/Info/" . $row["buildingid"], $name);
                 $moon[$bid]["requirements"] = $requirements;
                 break;
         }
     }
     $result->closeCursor();
     Hook::event("ShowLoadedTechtree", array(&$cons, &$research, &$ships, &$def, &$moon, &$moon));
     Core::getTPL()->addLoop("construction", $cons);
     Core::getTPL()->addLoop("research", $research);
     Core::getTPL()->addLoop("shipyard", $ships);
     Core::getTPL()->addLoop("defense", $def);
     Core::getTPL()->addLoop("moon", $moon);
     return $this;
 }