/** * Index action. * * @return Bengine_Game_Controller_Friends */ protected function indexAction() { Core::getLanguage()->load(array("Statistics", "Buddylist")); if ($this->isPost()) { if ($this->getParam("delete")) { $this->remove($this->getParam("remove", array())); } if ($this->getParam("accept")) { $this->acceptRequest($this->getParam("relid")); } } $bl = array(); $select = array("b.relid", "b.friend1", "b.friend2", "b.accepted", "u1.username as user1", "u1.points as points1", "u1.last as lastlogin1", "u2.points as points2", "u2.username as user2", "u2.last as lastlogin2", "a1.tag as ally1", "a1.aid as allyid1", "a2.tag as ally2", "a2.aid as allyid2", "g1.galaxy as gala1", "g1.system as sys1", "g1.position as pos1", "g2.galaxy as gala2", "g2.system as sys2", "g2.position as pos2"); $joins = "LEFT JOIN " . PREFIX . "user u1 ON (u1.userid = b.friend1)"; $joins .= "LEFT JOIN " . PREFIX . "user u2 ON (u2.userid = b.friend2)"; $joins .= "LEFT JOIN " . PREFIX . "galaxy g1 ON (g1.planetid = u1.hp)"; $joins .= "LEFT JOIN " . PREFIX . "galaxy g2 ON (g2.planetid = u2.hp)"; $joins .= "LEFT JOIN " . PREFIX . "user2ally u2a1 ON (u2a1.userid = b.friend1)"; $joins .= "LEFT JOIN " . PREFIX . "user2ally u2a2 ON (u2a2.userid = b.friend2)"; $joins .= "LEFT JOIN " . PREFIX . "alliance a1 ON (a1.aid = u2a1.aid)"; $joins .= "LEFT JOIN " . PREFIX . "alliance a2 ON (a2.aid = u2a2.aid)"; $result = Core::getQuery()->select("buddylist b", $select, $joins, Core::getDB()->quoteInto("b.friend1 = ? OR b.friend2 = ?", Core::getUser()->get("userid")), "u1.points DESC, u2.points DESC, u1.username ASC, u2.username ASC"); foreach ($result->fetchAll() as $row) { Hook::event("ShowBuddyFirst", array(&$row)); if ($row["friend1"] == Core::getUser()->get("userid")) { if ($row["lastlogin2"] > TIME - 900) { $status = Image::getImage("on.gif", getTimeTerm(TIME - $row["lastlogin2"])); } else { $status = Image::getImage("off.gif", getTimeTerm(TIME - $row["lastlogin2"])); } $username = Link::get("game/" . SID . "/MSG/Write/" . rawurlencode($row["user2"]), Image::getImage("pm.gif", Core::getLanguage()->getItem("WRITE_MESSAGE"))) . " " . Link::get("game/" . SID . "/Profile/Page/" . $row["friend2"], $row["user2"]); $points = $row["points2"]; $position = getCoordLink($row["gala2"], $row["sys2"], $row["pos2"]); $ally = Link::get("game/" . SID . "/Alliance/Page/" . $row["allyid2"], $row["ally2"]); } else { if ($row["lastlogin1"] > TIME - 900) { $status = Image::getImage("on.gif", getTimeTerm(TIME - $row["lastlogin1"])); } else { $status = Image::getImage("off.gif", getTimeTerm(TIME - $row["lastlogin1"])); } $username = Link::get("game/" . SID . "/MSG/Write/" . rawurlencode($row["user1"]), Image::getImage("pm.gif", Core::getLanguage()->getItem("WRITE_MESSAGE"))) . " " . Link::get("game/" . SID . "/Profile/Page/" . $row["friend1"], $row["user1"]); $points = $row["points1"]; $position = getCoordLink($row["gala1"], $row["sys1"], $row["pos1"]); $ally = Link::get("game/" . SID . "/Alliance/Page/" . $row["allyid1"], $row["ally1"]); } $bl[$row["relid"]]["f1"] = $row["friend1"]; $bl[$row["relid"]]["f2"] = $row["friend2"]; $bl[$row["relid"]]["relid"] = $row["relid"]; $bl[$row["relid"]]["username"] = $username; $bl[$row["relid"]]["accepted"] = $row["accepted"]; $bl[$row["relid"]]["points"] = fNumber($points); $bl[$row["relid"]]["status"] = $status; $bl[$row["relid"]]["position"] = $position; $bl[$row["relid"]]["ally"] = $ally; Hook::event("ShowBuddyLast", array($row, &$bl)); } $result->closeCursor(); Core::getTPL()->addLoop("buddylist", $bl); return $this; }
/** * Alliance page action. * * @return Bengine_Comm_Controller_Alliance */ public function pageAction() { Core::getLanguage()->load("Alliance"); Core::getTPL()->clearHTMLHeaderFiles(); Core::getTPL()->addHTMLHeaderFile("game.css", "css"); Core::getTPL()->addHTMLHeaderFile("lib/jquery.js", "js"); $tag = $this->getParam("1"); $fNumber = array("member", "points", "rpoints", "fpoints", "dpoints"); $attr = array("a.aid", "a.name", "a.tag", "a.logo", "a.textextern", "a.homepage", "a.showhomepage", "COUNT(u2a.userid) AS member", "SUM(u.points) AS points", "SUM(u.rpoints) AS rpoints", "SUM(u.fpoints) AS fpoints", "SUM(u.dpoints) AS dpoints"); $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.aid = a.aid) "; $joins .= "LEFT JOIN " . PREFIX . "user u ON (u2a.userid = u.userid) "; $result = Core::getQuery()->select("alliance a", $attr, $joins, Core::getDB()->quoteInto("tag = ?", $tag), "", 1, "a.aid"); $row = $result->fetchRow(); if ($row) { foreach ($fNumber as $field) { $row[$field] = fNumber($row[$field]); } $parser = new Bengine_Game_Alliance_Page_Parser($row["aid"]); if (Str::length(strip_tags($row["textextern"])) > 0) { $row["textextern"] = $parser->startParser($row["textextern"]); } else { $row["textextern"] = Core::getLang()->get("WELCOME"); } $row["homepage"] = $row["homepage"] != "" ? Link::get($row["homepage"], $row["homepage"], $row["homepage"]) : ""; $row["logo"] = $row["logo"] != "" ? Image::getImage($row["logo"], "") : ""; Hook::event("ShowPublicAlliancePage", array(&$row)); $this->assign($row); $this->setIsAjax(); } else { $this->setNoDisplay(true); } return $this; }
/** * Renders the signature image. * * @return Bengine_Comm_Controller_Signature */ protected function _render() { Core::getLang()->load("Signature"); $config = $this->getConfig(); $imageConfig = $config["image"]; $user = $this->getUser(); $img = imagecreatefrompng(AD . "img/" . $imageConfig["background"]); if ($imageConfig["stats"]["show"]) { $result = Core::getQuery()->select("user", array("userid")); $totalUser = fNumber($result->rowCount()); $this->_addParamToImage($img, "stats", Core::getLang()->get("RANK") . " " . $user->getFormattedRank() . "/" . $totalUser); } if ($imageConfig["planets"]["show"]) { $result = Core::getQuery()->select("planet", array("planetid"), "", Core::getDB()->quoteInto("userid = ? AND ismoon = 0", $user->getUserid())); $planets = Core::getLang()->get("NUMBER_OF_COLONY") . " " . fNumber($result->rowCount() - 1); $this->_addParamToImage($img, "planets", $planets); } $this->_addParamToImage($img, "username", $user->getUsername()); $this->_addParamToImage($img, "gameName", Core::getConfig()->get("pagetitle")); $this->_addParamToImage($img, "planet", $user->getHomePlanet()->getPlanetname() . " [" . $user->getHomePlanet()->getCoords(false) . "]"); $this->_addParamToImage($img, "points", Core::getLang()->get("POINTS") . " " . $user->getFormattedPoints()); if ($user->getAid()) { $this->_addParamToImage($img, "alliance", Core::getLang()->get("ALLIANCE") . " " . $user->getAlliance()->getTag()); } imagepng($img, $this->getCachePath() . DIRECTORY_SEPARATOR . $this->getUserId() . self::IMAGE_FILE_EXTENSION, $imageConfig["quality"]); imagedestroy($img); return $this; }
/** * Returns the formatted capacity of the unit. * * @return string */ public function getFormattedCapacity() { $capacity = $this->get("capicity"); if ($this->getQty() > 0) { $capacity *= $this->getQty(); } return fNumber($capacity); }
/** * Formats the message for news feeds. * * @param Bengine_Game_Model_Message $message * * @return Bengine_Game_MessageFolder_Combat */ protected function _formatFeed(Bengine_Game_Model_Message $message) { $assaultId = (int) $message->get("message"); $assault = Application::getModel("game/assault")->load($assaultId); $link = BASE_URL . Core::getLang()->getOpt("langcode") . "/combat/report/" . $assaultId . "/" . $assault->get("key"); $gentime = $assault->get("gentime") / 1000; $text = Core::getLanguage()->getItem("ASSAULT_REPORT") . " (A: " . fNumber($assault->get("lostunits_attacker")) . ", D: " . fNumber($assault->get("lostunits_defender")) . ") " . $gentime . "s"; $subject = Core::getLang()->get($message->get("subject")) . ": " . $assault->get("planetname") . " [" . $assault->getCoords(false) . "]"; $message->set(array("message" => $text, "subject" => $subject, "link" => $link)); return $this; }
/** * Index action. * * @return Bengine_Game_Controller_Statistics */ protected function indexAction() { Hook::event("StatisticsStart"); $this->loadTotalUnits(Bengine_Game_Controller_Shipyard::FLEET_CONSTRUCTION_TYPE); $this->loadTotalUnits(Bengine_Game_Controller_Shipyard::DEFENSE_CONSTRUCTION_TYPE); $statistics = array("totalMetal" => $this->fetchTotalMetal(), "totalSilicon" => $this->fetchTotalSilicon(), "totalHydrogen" => $this->fetchTotalHydrogen(), "totalPlayers" => fNumber($this->fetchTotalPlayers()), "totalPlanets" => fNumber($this->fetchTotalPlanets()), "totalMoons" => fNumber($this->fetchTotalPlanets(1)), "totalOnline" => fNumber($this->fetchOnlinePlayers()), "totalDebrisFields" => fNumber($this->fetchDebrisFields()), "totalRecentAssaults" => fNumber($this->fetchRecentAssaults())); $totalRessources = $statistics["totalSilicon"] + $statistics["totalHydrogen"] + $statistics["totalMetal"]; $statistics["percentMetal"] = fNumber($statistics["totalMetal"] / $totalRessources * 100, 2); $statistics["percentSilicon"] = fNumber($statistics["totalSilicon"] / $totalRessources * 100, 2); $statistics["percentHydrogen"] = fNumber($statistics["totalHydrogen"] / $totalRessources * 100, 2); $statistics["totalMetal"] = fNumber($statistics["totalMetal"] / 1000000, 2); $statistics["totalSilicon"] = fNumber($statistics["totalSilicon"] / 1000000, 2); $statistics["totalHydrogen"] = fNumber($statistics["totalHydrogen"] / 1000000, 2); Hook::event("StatisticsFinished", array(&$statistics)); Core::getTPL()->assign($statistics); Core::getTPL()->addLoop("ships", $this->unitCount); return $this; }
/** * Shows alliance ranking. * * @param integer $type Type of ranking (Fleet, Research, Points) * @param integer $pos Position to start ranking * * @return Bengine_Game_Controller_Ranking */ protected function allianceRanking($type, $pos) { $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.aid = a.aid)"; $joins .= "LEFT JOIN " . PREFIX . "user u ON (u.userid = u2a.userid)"; $result = Core::getQuery()->select("alliance a", "SUM(u." . $type . ") AS points", $joins, "a.aid > '0'", "", "", "a.aid", "HAVING points >= (points)"); $oPos = $result->rowCount(); $oPos = $oPos <= 0 ? 1 : $oPos; $oPos = ceil($oPos / Core::getOptions()->get("USER_PER_PAGE")); $result->closeCursor(); $result = Core::getQuery()->select("alliance", "aid", "", "aid > '0'"); $pages = ceil($result->rowCount() / Core::getOptions()->get("USER_PER_PAGE")); $result->closeCursor(); if (!is_numeric($pos)) { $pos = $oPos; } else { if ($pos > $pages) { $pos = $pages; } else { if ($pos < 1) { $pos = 1; } } } $ranks = ""; for ($i = 0; $i < $pages; $i++) { $n = $i * Core::getOptions()->get("USER_PER_PAGE") + 1; if ($i + 1 == $pos) { $s = 1; } else { $s = 0; } if ($i + 1 == $oPos) { $c = "ownPosition"; } else { $c = ""; } $ranks .= createOption($i + 1, fNumber($n) . " - " . fNumber($n + Core::getOptions()->get("USER_PER_PAGE") - 1), $s, $c); } Core::getTPL()->assign("rankingSel", $ranks); $order = $this->average ? "average" : "points"; $rank = abs(($pos - 1) * Core::getOptions()->get("USER_PER_PAGE")); $max = Core::getOptions()->get("USER_PER_PAGE"); $select = array("a.aid", "a.name", "a.tag", "a.showhomepage", "a.homepage", "a.open", "COUNT(u2a.userid) AS members", "FLOOR(SUM(u." . $type . ")) AS points", "AVG(u." . $type . ") AS average"); $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON u2a.aid = a.aid "; $joins .= "LEFT JOIN " . PREFIX . "user u ON u2a.userid = u.userid "; $result = Core::getQuery()->select("alliance a", $select, $joins, "a.aid > '0'", $order . " DESC, members DESC, a.tag ASC", $rank . ", " . $max, "a.aid"); $AllianceList = new Bengine_Game_Alliance_List($result, $rank); Hook::event("ShowRankingAlliance", array($AllianceList)); Core::getTPL()->addLoop("ranking", $AllianceList->getArray()); $this->setTemplate("ranking/ally"); return $this; }
/** * Shows the editing form. * * @return Bengine_Game_Controller_Unit */ protected function editAction() { Core::getUser()->checkPermissions("CAN_EDIT_CONSTRUCTIONS"); if ($this->isPost()) { if ($this->getParam("saveunit")) { $this->saveConstruction($this->id, $this->getParam("name_id"), $this->getParam("name"), $this->getParam("allow_on_moon"), $this->getParam("desc"), $this->getParam("full_desc"), $this->getParam("basic_metal"), $this->getParam("basic_silicon"), $this->getParam("basic_hydrogen"), $this->getParam("basic_energy"), $this->getParam("capicity"), $this->getParam("speed"), $this->getParam("consume"), $this->getParam("attack"), $this->getParam("shield"), $this->getParam("baseEngine"), $this->getParam("extentedEngine"), $this->getParam("extentedEngineLevel"), $this->getParam("extentedEngineSpeed"), $this->getParam("del_rf"), $this->getParam("rf_new"), $this->getParam("rf_new_value")); } if ($this->getParam("addreq")) { $this->addRequirement($this->getParam("level"), $this->getParam("needs")); } } $languageid = Core::getLang()->getOpt("languageid"); $select = array("c.name AS name_id", "c.allow_on_moon", "p.content AS name", "c.basic_metal", "c.basic_silicon", "c.basic_hydrogen", "c.basic_energy", "sds.unitid", "sds.capicity AS capacity", "sds.speed", "sds.consume", "sds.attack", "sds.shield"); $joins = "LEFT JOIN " . PREFIX . "phrases p ON (p.title = c.name)"; $joins .= "LEFT JOIN " . PREFIX . "ship_datasheet sds ON (sds.unitid = c.buildingid)"; $where = Core::getDB()->quoteInto("c.buildingid = ? AND p.languageid = ?", array($this->id, $languageid)); $result = Core::getQuery()->select("construction c", $select, $joins, $where); if ($row = $result->fetchRow()) { $result->closeCursor(); Hook::event("EditUnitDataLoaded", array(&$row)); Core::getTPL()->assign($row); Core::getTPL()->assign("shell", fNumber(($row["basic_metal"] + $row["basic_silicon"]) / 10)); $where = Core::getDB()->quoteInto("languageid = ? AND title = ?", array($languageid, $row["name_id"] . "_DESC")); $result = Core::getQuery()->select("phrases", "content", "", $where); $_row = $result->fetchRow(); $result->closeCursor(); Core::getTPL()->assign("description", Str::replace("<br />", "", $_row["content"])); $where = Core::getDB()->quoteInto("languageid = ? AND title = ?", array($languageid, $row["name_id"] . "_FULL_DESC")); $result = Core::getQuery()->select("phrases", "content", "", $where); $_row = $result->fetchRow(); $result->closeCursor(); Core::getTPL()->assign("full_description", Str::replace("<br />", "", $_row["content"])); // Engine selection Core::getTPL()->assign("extentedEngine", $this->getEnginesList(0)); Core::getTPL()->assign("extentedEngineLevel", 0); Core::getTPL()->assign("extentedEngineSpeed", ""); $engines = array(); $result = Core::getQuery()->select("ship2engine s2e", array("s2e.engineid", "s2e.level", "s2e.base_speed", "s2e.base"), "", Core::getDB()->quoteInto("s2e.unitid = ?", $this->id)); foreach ($result->fetchAll() as $_row) { if ($_row["base"] == 1) { Core::getTPL()->assign("baseEngine", $this->getEnginesList($_row["engineid"])); } else { Core::getTPL()->assign("extentedEngine", $this->getEnginesList($_row["engineid"])); Core::getTPL()->assign("extentedEngineLevel", $_row["level"]); Core::getTPL()->assign("extentedEngineSpeed", $_row["base_speed"]); } } $req = array(); $i = 0; $where = Core::getDB()->quoteInto("r.buildingid = ? AND p.languageid = ?", array($this->id, $languageid)); $result = Core::getQuery()->select("requirements r", array("r.requirementid", "r.needs", "r.level", "p.content"), "LEFT JOIN " . PREFIX . "construction b ON (b.buildingid = r.needs) LEFT JOIN " . PREFIX . "phrases p ON (p.title = b.name)", $where); foreach ($result->fetchAll() as $row) { $req[$i]["delete"] = Link::get("game/" . SID . "/Unit/DeleteRequirement/" . $this->id . "/" . $row["requirementid"], "[" . Core::getLanguage()->getItem("DELETE") . "]"); $req[$i]["name"] = Link::get("game/" . SID . "/Unit/Edit/" . $row["needs"], $row["content"]); $req[$i]["level"] = $row["level"]; $i++; } $result->closeCursor(); Core::getTPL()->addLoop("requirements", $req); $const = array(); $i = 0; $where = Core::getDB()->quoteInto("(b.mode = '1' OR b.mode = '2' OR b.mode = '5') AND p.languageid = ?", $languageid); $result = Core::getQuery()->select("construction b", array("b.buildingid", "p.content"), "LEFT JOIN " . PREFIX . "phrases p ON (p.title = b.name)", $where, "p.content ASC"); foreach ($result->fetchAll() as $row) { $const[$i]["name"] = $row["content"]; $const[$i]["id"] = $row["buildingid"]; $i++; } $result->closeCursor(); Core::getTPL()->addLoop("constructions", $const); Core::getTPL()->addLoop("rapidfire", $this->getRapidFire()); Core::getTPL()->assign("rfSelect", $this->getShipSelect()); } return $this; }
/** * Select the ships for jump. * * @param array $ships * * @return Bengine_Game_Controller_Mission */ protected function starGateJump($ships) { $this->noAction = true; $data = array(); Core::getQuery()->delete("temp_fleet", "planetid = ?", null, null, array(Core::getUser()->get("curplanet"))); $select = array("u2s.unitid", "u2s.quantity", "d.capicity", "d.speed", "d.consume", "b.name"); $joins = "LEFT JOIN " . PREFIX . "construction b ON (b.buildingid = u2s.unitid)"; $joins .= "LEFT JOIN " . PREFIX . "ship_datasheet d ON (d.unitid = u2s.unitid)"; $result = Core::getQuery()->select("unit2shipyard u2s", $select, $joins, Core::getDB()->quoteInto("b.mode = '3' AND u2s.planetid = ?", Core::getUser()->get("curplanet"))); foreach ($result->fetchAll() as $row) { $id = $row["unitid"]; if (isset($ships[$id])) { $quantity = _pos($ships[$id]); if ($quantity > $row["quantity"]) { $quantity = $row["quantity"]; } if ($quantity > 0) { $data["ships"][$id]["quantity"] = $quantity; $data["ships"][$id]["name"] = $row["name"]; } } } $result->closeCursor(); $result = Core::getQuery()->select("stargate_jump", "time", "", Core::getDB()->quoteInto("planetid = ?", Core::getUser()->get("curplanet")), "time DESC"); $row = $result->fetchRow(); $result->closeCursor(); $requiredReloadTime = (int) Core::getConfig()->get("STAR_GATE_RELOAD_TIME") * 60; $reloadTime = $row["time"] + $requiredReloadTime; if (count($data) > 0 && $reloadTime < TIME) { $moons = array(); $select = new Recipe_Database_Select(); $select->from(array("p" => "planet"))->attributes(array("p" => array("planetid", "planetname"), "g" => array("galaxy", "system", "position"), "sj" => array("time"))); $select->join(array("b2p" => "building2planet"), array("b2p" => "planetid", "p" => "planetid"))->join(array("g" => "galaxy"), array("g" => "moonid", "p" => "planetid"))->join(array("sj" => "stargate_jump"), array("sj" => "planetid", "p" => "planetid"))->where(array("p" => "userid"), Core::getUser()->get("userid"))->where(array("p" => "ismoon"), 1)->where(array("p" => "planetid", "!="), Core::getUser()->get("curplanet"))->where(array("b2p" => "buildingid"), 56)->where("IFNULL(sj.time, 0) + ? < UNIX_TIMESTAMP()", $requiredReloadTime)->group(array("p" => "planetid"))->order(array("g" => "galaxy"))->order(array("g" => "system"))->order(array("g" => "position")); $result = $select->getStatement(); foreach ($result->fetchAll() as $row) { $moons[] = $row; $data["moons"][] = $row["planetid"]; } $result->closeCursor(); Hook::event("ShowStarGates", array(&$moons, &$data)); Core::getTPL()->addLoop("moons", $moons); $data = serialize($data); Core::getQuery()->insert("temp_fleet", array("planetid" => Core::getUser()->get("curplanet"), "data" => $data)); $this->setTemplate("mission/stargatejump"); } else { if ($reloadTime < TIME) { $reloadTime = TIME; } Core::getLanguage()->assign("reloadTime", fNumber(($reloadTime - TIME) / 60), 2); Logger::addMessage("RELOADING_STAR_GATE"); } return $this; }
/** * Returns the rank for this user as a formatted number. * * @return string */ public function getFormattedRank() { return fNumber($this->getRank()); }
/** * Generates a list of alliance member. * * @param string $showPoints Show points of members * @param string $order List order * * @return string Formatted list */ protected function replaceMember($showPoints, $order) { $this->loadMember($order); $showPoints = $this->term($showPoints); $out = ""; foreach ($this->member as $member) { $out .= $member["username"]; if ($showPoints) { $out .= " - " . fNumber($member["points"]); } $out .= "<br/>"; } $out = Str::substring($out, 0, -5); return $out; }
/** * Shows all building information. * * @param integer $id * @throws Recipe_Exception_Generic * @return Bengine_Game_Controller_Constructions */ protected function infoAction($id) { $select = array("name", "demolish", "basic_metal", "basic_silicon", "basic_hydrogen", "basic_energy", "prod_metal", "prod_silicon", "prod_hydrogen", "prod_energy", "special", "cons_metal", "cons_silicon", "cons_hydrogen", "cons_energy", "charge_metal", "charge_silicon", "charge_hydrogen", "charge_energy"); $result = Core::getQuery()->select("construction", $select, "", Core::getDB()->quoteInto("buildingid = ? AND (mode = '1' OR mode = '2' OR mode = '5')", $id)); if ($row = $result->fetchRow()) { $result->closeCursor(); Core::getLanguage()->load("info,Resource"); Hook::event("BuildingInfoBefore", array(&$row)); // Assign general building data Core::getTPL()->assign("buildingName", Core::getLanguage()->getItem($row["name"])); Core::getTPL()->assign("buildingDesc", Core::getLanguage()->getItem($row["name"] . "_FULL_DESC")); Core::getTPL()->assign("buildingImage", Image::getImage("buildings/" . $row["name"] . ".gif", Core::getLanguage()->getItem($row["name"]), null, null, "leftImage")); Core::getTPL()->assign("edit", Link::get("game/" . SID . "/Construction_Edit/Index/" . $id, "[" . Core::getLanguage()->getItem("EDIT") . "]")); // Production and consumption of the building $prodFormula = false; if (!empty($row["prod_metal"])) { $prodFormula = $row["prod_metal"]; $baseCost = $row["basic_metal"]; } else { if (!empty($row["prod_silicon"])) { $prodFormula = $row["prod_silicon"]; $baseCost = $row["basic_metal"]; } else { if (!empty($row["prod_hydrogen"])) { $prodFormula = $row["prod_hydrogen"]; $baseCost = $row["basic_hydrogen"]; } else { if (!empty($row["prod_energy"])) { $prodFormula = $row["prod_energy"]; $baseCost = $row["basic_energy"]; } else { if (!empty($row["special"])) { $prodFormula = $row["special"]; $baseCost = 0; } } } } } $consFormula = false; if (!empty($row["cons_metal"])) { $consFormula = $row["cons_metal"]; } else { if (!empty($row["cons_silicon"])) { $consFormula = $row["cons_silicon"]; } else { if (!empty($row["cons_hydrogen"])) { $consFormula = $row["cons_hydrogen"]; } else { if (!empty($row["cons_energy"])) { $consFormula = $row["cons_energy"]; } } } } // Production and consumption chart $chartType = false; if ($prodFormula != false || $consFormula != false) { $chart = array(); $chartType = "cons_chart"; if ($prodFormula && $consFormula) { $chartType = "prod_and_cons_chart"; } else { if ($prodFormula) { $chartType = "prod_chart"; } } if (Game::getPlanet()->getBuilding($id) - 7 < 0) { $start = 7; } else { $start = Game::getPlanet()->getBuilding($id); } $productionFactor = (double) Core::getConfig()->get("PRODUCTION_FACTOR"); if (!empty($row["prod_energy"])) { $productionFactor = 1; } $currentProduction = 0; if ($prodFormula) { $currentProduction = parseFormula($prodFormula, $baseCost, Game::getPlanet()->getBuilding($id)) * $productionFactor; } $currentConsumption = 0; if ($consFormula) { $currentConsumption = parseFormula($consFormula, 0, Game::getPlanet()->getBuilding($id)); } for ($i = $start - 7; $i <= Game::getPlanet()->getBuilding($id) + 7; $i++) { $chart[$i]["level"] = $i; $chart[$i]["s_prod"] = $prodFormula ? parseFormula($prodFormula, $baseCost, $i) * $productionFactor : 0; $chart[$i]["s_diffProd"] = $prodFormula ? $chart[$i]["s_prod"] - $currentProduction : 0; $chart[$i]["s_cons"] = $consFormula ? parseFormula($consFormula, 0, $i) : 0; $chart[$i]["s_diffCons"] = $consFormula ? $currentConsumption - $chart[$i]["s_cons"] : 0; $chart[$i]["prod"] = fNumber($chart[$i]["s_prod"]); $chart[$i]["diffProd"] = fNumber($chart[$i]["s_diffProd"]); $chart[$i]["cons"] = fNumber($chart[$i]["s_cons"]); $chart[$i]["diffCons"] = fNumber($chart[$i]["s_diffCons"]); } Hook::event("BuildingInfoProduction", array(&$chart)); Core::getTPL()->addLoop("chart", $chart); } if ($chartType) { Core::getTPL()->assign("chartType", "game/constructions/" . $chartType); } // Show demolish function $factor = floatval($row["demolish"]); if (Game::getPlanet()->getBuilding($id) > 0 && $factor > 0.0) { Core::getTPL()->assign("buildingLevel", Game::getPlanet()->getBuilding($id)); Core::getTPL()->assign("demolish", true); $metal = ""; $_metal = 0; $silicon = ""; $_silicon = 0; $hydrogen = ""; $_hydrogen = 0; if ($row["basic_metal"] > 0) { $_metal = 1 / $factor * parseFormula($row["charge_metal"], $row["basic_metal"], Game::getPlanet()->getBuilding($id)); $metal = Core::getLanguage()->getItem("METAL") . ": " . fNumber($_metal); } Core::getTPL()->assign("metal", $metal); if ($row["basic_silicon"] > 0) { $_silicon = 1 / $factor * parseFormula($row["charge_silicon"], $row["basic_silicon"], Game::getPlanet()->getBuilding($id)); $silicon = Core::getLanguage()->getItem("SILICON") . ": " . fNumber($_silicon); } Core::getTPL()->assign("silicon", $silicon); if ($row["basic_hydrogen"] > 0) { $_hydrogen = 1 / $factor * parseFormula($row["charge_hydrogen"], $row["basic_hydrogen"], Game::getPlanet()->getBuilding($id)); $hydrogen = Core::getLanguage()->getItem("HYDROGEN") . ": " . fNumber($_hydrogen); } Core::getTPL()->assign("hydrogen", $hydrogen); $time = getBuildTime($_metal, $_silicon, self::BUILDING_CONSTRUCTION_TYPE); Core::getTPL()->assign("dimolishTime", getTimeTerm($time)); $showLink = Game::getPlanet()->getData("metal") >= $_metal && Game::getPlanet()->getData("silicon") >= $_silicon && Game::getPlanet()->getData("hydrogen") >= $_hydrogen; if ($id == 12 && Game::getEH()->getResearchEvent()) { $showLink = false; } $shipyardSize = Game::getEH()->getShipyardEvents()->getCalculatedSize(); if (($id == 8 || $id == 7) && $shipyardSize > 0) { $showLink = false; } Core::getTPL()->assign("showLink", $showLink && !$this->event && !Core::getUser()->get("umode")); Core::getTPL()->assign("demolishNow", Link::get("game/" . SID . "/Constructions/Demolish/{$id}", Core::getLanguage()->getItem("DEMOLISH_NOW"))); } else { Core::getTPL()->assign("demolish", false); } Hook::event("BuildingInfoAfter", array(&$row)); } else { $result->closeCursor(); throw new Recipe_Exception_Generic("Unkown building. You'd better don't manipulate the URL. We see everything ;)"); } return $this; }
/** * Fetches the alliance rank from database. * * @param int $aid * @param string $pointType * * @return integer */ protected function getAllianceRank($aid, $pointType) { if (!in_array($pointType, array("points", "fpoints", "dpoints", "rpoints"))) { throw new Recipe_Exception_Generic("Unknown point type supplied."); } $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.aid = a.aid)"; $joins .= "LEFT JOIN " . PREFIX . "user u ON (u.userid = u2a.userid)"; $subselect = "(SELECT SUM(u." . $pointType . ") FROM " . PREFIX . "user2ally u2a LEFT JOIN " . PREFIX . "user u ON (u.userid = u2a.userid) WHERE u2a.aid = ?)"; $result = Core::getQuery()->select("alliance a", "a.aid", $joins, "", "", "", "u2a.aid", "HAVING SUM(u." . $pointType . ") >= " . $subselect, array($aid)); $rank = fNumber($result->rowCount()); $result->closeCursor(); return $rank; }
/** * Index action. * * @return Bengine_Game_Controller_Galaxy */ protected function indexAction() { if ($this->isPost()) { $this->setCoordinatesByPost($this->getParam("galaxy"), $this->getParam("system"), $this->getParam("submittype")); } $this->validateInputs()->subtractHydrogen(); // Star surveillance $canMonitorActivity = false; if (Game::getPlanet()->getBuilding("STAR_SURVEILLANCE") > 0) { $range = pow(Game::getPlanet()->getBuilding("STAR_SURVEILLANCE"), 2) - 1; $diff = abs(Game::getPlanet()->getData("system") - $this->system); if ($this->galaxy == Game::getPlanet()->getData("galaxy") && $range >= $diff) { $canMonitorActivity = true; } } Core::getTPL()->assign("canMonitorActivity", $canMonitorActivity); // Images $rockimg = Image::getImage("rocket.gif", Core::getLanguage()->getItem("ROCKET_ATTACK")); // Get sunsystem data $select = array("g.planetid", "g.position", "g.destroyed", "g.metal", "g.silicon", "g.moonid", "p.picture", "p.planetname", "p.last as planetactivity", "u.username", "u.usertitle", "u.userid", "u.points", "u.last as useractivity", "u.umode", "u.level", "m.planetid AS moon", "m.picture AS moonpic", "m.planetname AS moonname", "m.diameter AS moonsize", "m.temperature", "m.last as moonactivity", "a.tag", "a.name", "a.showmember", "a.homepage", "a.showhomepage", "u2a.aid", "b.to"); $joins = "LEFT JOIN " . PREFIX . "planet p ON (p.planetid = g.planetid)"; $joins .= "LEFT JOIN " . PREFIX . "user u ON (u.userid = p.userid)"; $joins .= "LEFT JOIN " . PREFIX . "planet m ON (m.planetid = g.moonid)"; $joins .= "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.userid = u.userid)"; $joins .= "LEFT JOIN " . PREFIX . "alliance a ON (a.aid = u2a.aid)"; $joins .= "LEFT JOIN " . PREFIX . "ban_u b ON (b.userid = u.userid AND b.to > '" . TIME . "')"; $where = Core::getDB()->quoteInto("g.galaxy = ? AND g.system = ?", array($this->galaxy, $this->system)); $result = Core::getQuery()->select("galaxy g", $select, $joins, $where); $UserList = new Bengine_Game_User_List(); $UserList->setKey("position"); $UserList->setNewbieProtection(true); $UserList->setFetchRank(true); $UserList->setTagAsLink(false); $UserList->load($result); $sys = $UserList->getArray(); Hook::event("SolarSystemDataBefore", array($this, &$sys)); for ($i = 1; $i <= 15; $i++) { if (isset($sys[$i]) && !$sys[$i]["destroyed"]) { $sys[$i]["systempos"] = $i; if ($sys[$i]["tag"] != "") { $sys[$i]["allydesc"] = sprintf(Core::getLanguage()->getItem("GALAXY_ALLY_HEADLINE"), $sys[$i]["tag"], $sys[$i]["alliance_rank"]); } $sys[$i]["metal"] = fNumber($sys[$i]["metal"]); $sys[$i]["silicon"] = fNumber($sys[$i]["silicon"]); $sys[$i]["picture"] = Image::getImage("planets/small/s_" . $sys[$i]["picture"] . Core::getConfig()->get("PLANET_IMG_EXT"), $sys[$i]["planetname"], 30, 30); $sys[$i]["picture"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["picture"]); $sys[$i]["planetname"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["planetname"]); $sys[$i]["moonpicture"] = $sys[$i]["moonpic"] != "" ? Image::getImage("planets/small/s_" . $sys[$i]["moonpic"] . Core::getConfig()->get("PLANET_IMG_EXT"), $sys[$i]["moonname"], 22, 22) : ""; $sys[$i]["moon"] = sprintf(Core::getLanguage()->getItem("MOON_DESC"), $sys[$i]["moonname"]); $sys[$i]["moonsize"] = fNumber($sys[$i]["moonsize"]); $sys[$i]["moontemp"] = fNumber($sys[$i]["temperature"]); if ($sys[$i]["moonactivity"] > $sys[$i]["planetactivity"]) { $activity = $sys[$i]["moonactivity"]; } else { $activity = $sys[$i]["planetactivity"]; } if ($activity > TIME - 900 && $sys[$i]["userid"] != Core::getUser()->get("userid")) { $sys[$i]["activity"] = "(*)"; } else { if ($activity > TIME - 3600 && $sys[$i]["userid"] != Core::getUser()->get("userid")) { $sys[$i]["activity"] = "(" . floor((TIME - $activity) / 60) . " min)"; } else { $sys[$i]["activity"] = ""; } } if (Game::getPlanet()->getBuilding("ROCKET_STATION") > 3 && $sys[$i]["userid"] != Core::getUser()->get("userid") && $this->inMissileRange()) { $sys[$i]["rocketattack"] = Link::get("game/" . SID . "/RocketAttack/Index/" . $sys[$i]["planetid"], $rockimg); $sys[$i]["moonrocket"] = "<tr><td colspan=\"3\" class=\"center\">" . Link::get("game/" . SID . "/RocketAttack/Index/" . $sys[$i]["moonid"] . "/1", Core::getLanguage()->getItem("ROCKET_ATTACK")) . "</td></tr>"; } else { $sys[$i]["rocketattack"] = ""; $sys[$i]["moonrocket"] = ""; } $sys[$i]["allypage"] = Str::replace("\"", "", Link::get("game/" . SID . "/Alliance/Page/" . $sys[$i]["aid"], Core::getLanguage()->getItem("ALLIANCE_PAGE"), 1)); if (($sys[$i]["showhomepage"] || $sys[$i]["aid"] == Core::getUser()->get("aid")) && $sys[$i]["homepage"] != "") { $sys[$i]["homepage"] = "<tr><td>" . Str::replace("'", "\\'", Link::get($sys[$i]["homepage"], Core::getLanguage()->getItem("HOMEPAGE"), 2)) . "</td></tr>"; } else { $sys[$i]["homepage"] = ""; } if ($sys[$i]["showmember"]) { $sys[$i]["memberlist"] = "<tr><td>" . Str::replace("\"", "", Link::get("game/" . SID . "/Alliance/Memberlist/" . $sys[$i]["aid"], Core::getLanguage()->getItem("SHOW_MEMBERLIST"), 3)) . "</td></tr>"; } $sys[$i]["debris"] = Image::getImage("debris.jpg", "", 25, 25); } else { if (empty($sys[$i]["destroyed"])) { $sys[$i] = array(); $sys[$i]["destroyed"] = false; $sys[$i]["metal"] = 0; $sys[$i]["silicon"] = 0; $sys[$i]["debris"] = ""; $sys[$i]["picture"] = ""; $sys[$i]["planetname"] = ""; $sys[$i]["planetid"] = ""; } else { $sys[$i]["metal"] = fNumber($sys[$i]["metal"]); $sys[$i]["silicon"] = fNumber($sys[$i]["silicon"]); $sys[$i]["debris"] = Image::getImage("debris.jpg", "", 25, 25); $sys[$i]["picture"] = Image::getImage("planets/small/s_" . $sys[$i]["picture"] . Core::getConfig()->get("PLANET_IMG_EXT"), $sys[$i]["planetname"], 30, 30); $sys[$i]["picture"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["picture"]); $sys[$i]["planetname"] = Core::getLanguage()->getItem("DESTROYED_PLANET"); $sys[$i]["planetname"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["planetname"]); } $sys[$i]["systempos"] = $i; $sys[$i]["userid"] = null; $sys[$i]["moon"] = ""; $sys[$i]["moonid"] = ""; $sys[$i]["username"] = ""; $sys[$i]["alliance"] = ""; $sys[$i]["activity"] = ""; $sys[$i]["moonpicture"] = ""; $sys[$i]["user_status_long"] = ""; } } ksort($sys); Hook::event("SolarSystemDataAfter", array($this, &$sys)); Core::getTPL()->assign("sendesp", Image::getImage("esp.gif", Core::getLanguage()->getItem("SEND_ESPIONAGE_PROBE"))); Core::getTPL()->assign("monitorfleet", Image::getImage("binocular.gif", Core::getLanguage()->getItem("MONITOR_FLEET_ACTIVITY"))); Core::getTPL()->assign("moon", Str::replace("\"", "", Image::getImage("planets/mond" . Core::getConfig()->get("PLANET_IMG_EXT"), Core::getLanguage()->getItem("MOON"), 75, 75))); Core::getTPL()->addLoop("sunsystem", $sys); Core::getTPL()->assign("debris", Str::replace("\"", "", Image::getImage("debris.jpg", Core::getLanguage()->getItem("DEBRIS"), 75, 75))); Core::getTPL()->assign("galaxy", $this->galaxy); Core::getTPL()->assign("system", $this->system); return $this; }
/** * Loads all production and consumption data of all available buildings. * * @return Bengine_Game_Controller_Resource */ protected function loadBuildingData() { $where = "c.prod_metal != '' OR c.prod_silicon != '' OR c.prod_hydrogen != '' OR c.prod_energy != '' OR c.cons_metal != '' OR c.cons_silicon != '' OR c.cons_hydrogen != '' OR c.cons_energy != ''"; $result = Core::getQuery()->select("construction c", array("c.buildingid", "c.name"), "", $where, "c.display_order ASC, c.buildingid ASC"); foreach ($result->fetchAll() as $row) { $id = $row["buildingid"]; $this->data[$id]["id"] = $id; $this->data[$id]["name"] = Core::getLang()->getItem($row["name"]); $this->data[$id]["level"] = Game::getPlanet()->getBuilding($id); $this->data[$id]["factor"] = Game::getPlanet()->getBuildingFactor($id); $this->data[$id]["metal"] = fNumber(Game::getPlanet()->getBuildingProd("metal", $id)); $this->data[$id]["silicon"] = fNumber(Game::getPlanet()->getBuildingProd("silicon", $id)); $this->data[$id]["hydrogen"] = fNumber(Game::getPlanet()->getBuildingProd("hydrogen", $id)); $this->data[$id]["energy"] = fNumber(Game::getPlanet()->getBuildingProd("energy", $id)); $this->data[$id]["metalCons"] = fNumber(Game::getPlanet()->getBuildingCons("metal", $id)); $this->data[$id]["siliconCons"] = fNumber(Game::getPlanet()->getBuildingCons("silicon", $id)); $this->data[$id]["hydrogenCons"] = fNumber(Game::getPlanet()->getBuildingCons("hydrogen", $id)); $this->data[$id]["energyCons"] = fNumber(Game::getPlanet()->getBuildingCons("energy", $id)); } return $this; }
/** * (non-PHPdoc) * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_execute($event, $data) */ protected function _execute(Bengine_Game_Model_Event $event, array $data) { Core::getLanguage()->load(array("info", "AutoMessages")); Hook::event("EhMissileAttackStart", array($event, &$data, $this)); $attackingRockets = $data["rockets"]; $primaryTarget = $data["primary_target"]; $attack = $data["attack"]; $def = array(); $destroyed = array(); // Load shelltech for defender $_result = Core::getQuery()->select("research2user", "level", "", Core::getDB()->quoteInto("userid = ? AND buildingid = '17'", $event["destination_user_id"])); $_row = $_result->fetchRow(); $_result->closeCursor(); $shell = (int) $_row["level"]; // Load defending units $where = Core::getDB()->quoteInto("b.mode = '4' AND u2s.planetid = ?", $event["destination"]); $_result = Core::getQuery()->select("unit2shipyard u2s", array("u2s.unitid", "u2s.quantity", "b.name", "basic_metal", "basic_silicon", "basic_hydrogen"), "LEFT JOIN " . PREFIX . "construction b ON (b.buildingid = u2s.unitid)", $where, "b.display_order ASC, b.buildingid ASC"); foreach ($_result->fetchAll() as $_row) { $def[$_row["unitid"]] = $_row; $def[$_row["unitid"]]["name"] = Core::getLanguage()->getItem($_row["name"]); $def[$_row["unitid"]]["shell"] = ($_row["basic_metal"] + $_row["basic_silicon"]) / 10; $def[$_row["unitid"]]["shell"] = floor($def[$_row["unitid"]]["shell"] * (1 + $shell / 10)); } $_result->closeCursor(); // Load guntech for attacker $_result = Core::getQuery()->select("research2user", "level", "", Core::getDB()->quoteInto("userid = ? AND buildingid = '15'", $event["userid"])); $_row = $_result->fetchRow(); $_result->closeCursor(); $gun = (int) $_row["level"]; Hook::event("EhMissileAttackLoaded", array($event, &$_row, &$data, &$def, &$attack, &$shell, &$gun, &$primaryTarget)); if (!array_key_exists($primaryTarget, $def)) { $primaryTarget = 0; } // Start attack $pointsLost = 0; if (count($def) > 0) { if (isset($def[51])) { $attackingRockets -= $def[51]["quantity"]; $destroyed[51] = $attackingRockets > 0 ? $def[51]["quantity"] : $data["rockets"]; $pointsLost += $destroyed[51] * $def[51]["basic_metal"]; $pointsLost += $destroyed[51] * $def[51]["basic_silicon"]; $pointsLost += $destroyed[51] * $def[51]["basic_hydrogen"]; if ($def[51]["quantity"] - $destroyed[51] <= 0) { Core::getQuery()->delete("unit2shipyard", "unitid = ? AND planetid = ?", null, null, array(51, $event["destination"])); } else { Core::getDB()->query("UPDATE " . PREFIX . "unit2shipyard SET quantity = quantity - ? WHERE unitid = ? AND planetid = ?", array($destroyed[51], 51, $event["destination"])); } } if ($attackingRockets > 0) { $damage = floor($attackingRockets * ($attack * (1 + $gun / 10))); if ($primaryTarget > 0) { if (!isset($destroyed[$primaryTarget])) { $destroyed[$primaryTarget] = 0; } if ($damage > $def[$primaryTarget]["shell"] * $def[$primaryTarget]["quantity"]) { $destroyed[$primaryTarget] += $def[$primaryTarget]["quantity"]; $damage -= $def[$primaryTarget]["shell"] * $destroyed[$primaryTarget]; } else { $destroyed[$primaryTarget] += floor($damage / $def[$primaryTarget]["shell"]); $damage -= $destroyed[$primaryTarget] * $def[$primaryTarget]["shell"]; } if ($def[$primaryTarget]["quantity"] - $destroyed[$primaryTarget] <= 0) { Core::getQuery()->delete("unit2shipyard", "unitid = ? AND planetid = ?", null, null, array($primaryTarget, $event["destination"])); } else { Core::getDB()->query("UPDATE " . PREFIX . "unit2shipyard SET quantity = quantity - ? WHERE unitid = ? AND planetid = ?", array($destroyed[$primaryTarget], $primaryTarget, $event["destination"])); } $pointsLost += $destroyed[$primaryTarget] * $def[$primaryTarget]["basic_metal"]; $pointsLost += $destroyed[$primaryTarget] * $def[$primaryTarget]["basic_silicon"]; $pointsLost += $destroyed[$primaryTarget] * $def[$primaryTarget]["basic_hydrogen"]; } foreach ($def as $key => $value) { if (!isset($destroyed[$key])) { $destroyed[$key] = 0; } if ($key == 51 || $key == $primaryTarget || $key == 52) { continue; } if ($damage > $value["shell"] * $value["quantity"]) { $destroyed[$key] += $value["quantity"]; $damage -= $value["shell"] * $destroyed[$key]; } else { $destroyed[$key] += floor($damage / $value["shell"]); $damage -= $destroyed[$key] * $value["shell"]; } if ($value["quantity"] - $destroyed[$key] <= 0) { Core::getQuery()->delete("unit2shipyard", "unitid = ? AND planetid = ?", null, null, array($key, $event["destination"])); } else { Core::getDB()->query("UPDATE " . PREFIX . "unit2shipyard SET quantity = quantity - ? WHERE unitid = ? AND planetid = ?", array($destroyed[$key], $key, $event["destination"])); } $pointsLost += $destroyed[$key] * $value["basic_metal"]; $pointsLost += $destroyed[$key] * $value["basic_silicon"]; $pointsLost += $destroyed[$key] * $value["basic_hydrogen"]; } } } // Generate report Hook::event("EhMissileAttackGenerateReport", array($event, &$_row, &$data, &$pointsLost, &$destroyed, &$def)); Core::getLanguage()->assign("planet", $data["planetname"]); Core::getLanguage()->assign("coords", getCoordLink($data["galaxy"], $data["system"], $data["position"], true)); $report = "<table class=\"ntable\" style=\"width: 400px;\">"; $report .= "<tr><th colspan=\"4\">" . Core::getLanguage()->getItem("ROCKET_ATTACK_REPORT_HEADLINE") . "</th></tr>"; $i = 0; foreach ($def as $key => $_def) { if ($i % 2 == 0) { $report .= "<tr>"; } if (!isset($destroyed[$key])) { $destroyed[$key] = 0; } $quantity = $_def["quantity"] - $destroyed[$key]; $dest = $destroyed[$key] > 0 ? " (-" . $destroyed[$key] . ")" : ""; $report .= "<td>" . $_def["name"] . "</td><td>" . $quantity . $dest . "</td>"; if (count($_def) == $i + 1 && $i % 2 == 0) { $report .= "<td></td><td></td></tr>"; } if ($i % 2 == 1) { $report .= "</tr>"; } $i++; } $report .= "</table>"; Core::getLanguage()->assign("rockets", $data["rockets"]); Core::getLanguage()->assign("attacker", $event["username"]); Core::getLanguage()->assign("defender", $event["destination_username"]); Core::getLanguage()->assign("lostunits", fNumber($pointsLost)); // Send report $message = Core::getLanguage()->getItem("ROCKET_ATTACK_MSG_ATTACKER") . $report; Hook::event("EhMissileAttackReportGeneratedAttacker", array($event, &$_row, &$data, &$message)); Core::getQuery()->insert("message", array("mode" => 3, "time" => TIME, "sender" => null, "receiver" => $event["userid"], "message" => $message, "subject" => Core::getLanguage()->getItem("ROCKET_ATTACK_SUBJECT"), "read" => 0)); $message = Core::getLanguage()->getItem("ROCKET_ATTACK_MSG_DEFENDER") . $report; Hook::event("EhMissileAttactReportGeneratedDefender", array($event, &$_row, &$data, &$message)); Core::getQuery()->insert("message", array("mode" => 3, "time" => TIME, "sender" => null, "receiver" => $event["destination_user_id"], "message" => $message, "subject" => Core::getLanguage()->getItem("ROCKET_ATTACK_SUBJECT"), "read" => 0)); // Update points for defender $pointsLost /= 1000; Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points - ? WHERE userid = ?", array($pointsLost, $event["destination_user_id"])); // Update points for attacker $points = $data["rockets"] * $data["basic_metal"] + $data["rockets"] * $data["basic_silicon"] + $data["rockets"] * $data["basic_hydrogen"]; $points /= 1000; Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points - ?, dpoints = dpoints - ? WHERE userid = ?", array($points, array_sum($destroyed), $event["userid"])); return $this; }
/** * Deletes messages. * * @param integer $folder Folder id * @param integer $option Mode to delete content * @param array $msgs Messages * * @return Bengine_Game_Controller_MSG */ protected function deleteMessages($folder, $option, array $msgs) { $pagination = $this->getPagination($folder); $deltime = 604800; if (is_numeric(Core::getOptions()->get("DEL_MESSAGE_DAYS")) && Core::getOptions()->get("DEL_MESSAGE_DAYS") > 0) { $deltime = (int) Core::getOptions()->get("DEL_MESSAGE_DAYS") * 86400; } $deltime = TIME - $deltime; Core::getQuery()->delete("message", "time <= ?", null, null, array($deltime)); switch ($option) { case 1: foreach ($msgs as $msgid) { Core::getQuery()->delete("message", "msgid = ? AND receiver = ?", null, null, array($msgid, Core::getUser()->get("userid"))); } break; case 2: $where = Core::getDB()->quoteInto("receiver = ? AND mode = ?", array(Core::getUser()->get("userid"), $folder)); $result = Core::getQuery()->select("message", "msgid", "", $where, "time DESC", $pagination->getStart() . ", " . Core::getOptions()->get("MAX_PMS")); foreach ($result->fetchAll() as $row) { if (!in_array($row["msgid"], $msgs)) { Core::getQuery()->delete("message", "msgid = ?", null, null, array($row["msgid"])); } } $result->closeCursor(); break; case 3: $where = Core::getDB()->quoteInto("receiver = ? AND mode = ?", array(Core::getUser()->get("userid"), $folder)); $result = Core::getQuery()->select("message", array("msgid"), "", $where, "time DESC", $pagination->getStart() . ", " . Core::getOptions()->get("MAX_PMS")); foreach ($result->fetchAll() as $row) { Core::getQuery()->delete("message", "msgid = ?", null, null, array($row["msgid"])); } break; case 4: Core::getQuery()->delete("message", "receiver = ? AND mode = ?", null, null, array(Core::getUser()->get("userid"), $folder)); break; case 5: $reports = array(); $modId = Game::getRandomModerator(); foreach ($msgs as $msgid) { $where = Core::getDB()->quoteInto("m.msgid = ? AND m.receiver = ?", array($msgid, Core::getUser()->get("userid"))); $result = Core::getQuery()->select("message m", array("m.sender", "m.mode", "m.message", "m.time", "u.username"), "LEFT JOIN " . PREFIX . "user u ON (u.userid = m.sender)", $where); if ($row = $result->fetchRow()) { if (($row["sender"] > 0 || $row["mode"] == 5) && $row["sender"] != $modId) { $reports[] = $row; } } } if (count($reports) > 0) { Core::getLang()->assign("reportSender", Core::getUser()->get("username")); foreach ($reports as $report) { Core::getLang()->assign("reportMessage", $report["message"]); Core::getLang()->assign("reportUser", $report["username"]); Core::getLang()->assign("reportSendTime", Date::timeToString(1, $report["time"], "", false)); if ($report["mode"] == 5) { $assault = Game::getModel("game/assault")->load((int) $report["message"]); $url = BASE_URL . Core::getLang()->getOpt("langcode") . "/combat/report/" . $assault->get("assaultid") . "/" . $assault->get("key"); $gentime = $assault->get("gentime") / 1000; $label = Core::getLanguage()->getItem("ASSAULT_REPORT") . " (A: " . fNumber($assault->get("lostunits_attacker")) . ", D: " . fNumber($assault->get("lostunits_defender")) . ") " . $gentime . "s"; Core::getLang()->assign("reportLink", "<span class=\"assault-report\" onclick=\"window.open('" . $url . "')\">" . $label . "</span>"); $message = Core::getDB()->escape(Core::getLang()->get("MODERATOR_REPORT_COMBAT")); } else { richText($message = Core::getLang()->get("MODERATOR_REPORT_MESSAGE")); } $subject = Core::getLang()->get("MODERATOR_REPORT_SUBJECT"); $spec = array("sender" => null, "mode" => 1, "subject" => $subject, "message" => $message, "receiver" => $modId, "time" => TIME, "read" => 0); Core::getQuery()->insert("message", $spec); } Logger::addMessage("MESSAGES_REPORTED", "success"); } break; } return $this; }
/** * Fetches the user rank from database. * * @param integer $points * @param string $username * @param string $pointType * @throws Recipe_Exception_Generic * @return integer */ protected function getUserRank($points, $username, $pointType) { if ($pointType != "points" && $pointType != "fpoints" && $pointType != "rpoints") { throw new Recipe_Exception_Generic("Unknown point type supplied."); } $where = "(`username` < ? AND `{$pointType}` >= {points}) OR `{$pointType}` > {points}"; $where = str_replace("{points}", (double) $points, $where); $result = Core::getQuery()->select("user", array("COUNT(`userid`)+1 AS rank"), "", $where, "", 1, "", "", array($username)); $rank = fNumber($result->fetchColumn()); $result->closeCursor(); return $rank; }
/** * Returns the number of occupied fields. * * @param boolean $formatted * * @return integer */ public function getFields($formatted = false) { $this->getBuildings(); if ($formatted) { return fNumber($this->fields); } return $this->fields; }
/** * Generates message for an asteroid event. * * @return Bengine_Game_AutoMsg */ protected function asteroid() { $msg = Core::getLanguage()->getItem("ASTEROID_IMPACT"); $coordinates = getCoordLink($this->data["galaxy"], $this->data["system"], $this->data["position"], true); $msg = sprintf($msg, $this->data["planet"], $coordinates, fNumber($this->data["metal"]), fNumber($this->data["silicon"])); Hook::event("AutoMsgAsteroid", array($this, &$msg)); $this->sendMsg(Core::getLanguage()->getItem("ASTEROID_IMPACT_SUBJECT"), $msg); return $this; }
/** * Allows the user to write a global mail to all alliance member. * * @param string $reply * @return Bengine_Game_Controller_Alliance */ protected function globalMailAction($reply) { $result = Core::getQuery()->select("user2ally u2a", array("a.founder", "ar.CAN_WRITE_GLOBAL_MAILS"), "LEFT JOIN " . PREFIX . "alliance a ON (a.aid = u2a.aid) LEFT JOIN " . PREFIX . "allyrank ar ON (ar.rankid = u2a.rank)", Core::getDB()->quoteInto("u2a.userid = ?", Core::getUser()->get("userid"))); if ($row = $result->fetchRow()) { $result->closeCursor(); if ($row["CAN_WRITE_GLOBAL_MAILS"] || $row["founder"] == Core::getUser()->get("userid")) { Core::getLanguage()->load("Message"); if ($this->isPost()) { $message = richtext($this->getParam("message")); $length = Str::length(strip_tags($message)); $subject = Str::validateXHTML(trim($this->getParam("subject"))); $receiver = $this->getParam("receiver"); if ($length > 2 && $length <= Core::getOptions()->get("MAX_PM_LENGTH") && Str::length($subject) > 0 && Str::length($subject) < 101) { Hook::event("SendGlobalMail", array($subject, &$message)); if ($receiver == "foo") { $where = Core::getDB()->quoteInto("aid = ?", $this->aid); } else { $where = Core::getDB()->quoteInto("rank = ? AND aid = ?", array($receiver, $this->aid)); } $_result = Core::getQuery()->select("user2ally", "userid", "", $where); foreach ($_result->fetchAll() as $_row) { Core::getQuery()->insert("message", array("mode" => 6, "time" => TIME, "sender" => Core::getUser()->get("userid"), "receiver" => $_row["userid"], "message" => $message, "subject" => $subject, "read" => $_row["userid"] == Core::getUser()->get("userid") ? 1 : 0)); } $_result->closeCursor(); Logger::addMessage("SENT_SUCCESSFUL", "success"); } else { if ($length < 3) { Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_SHORT")); } if ($length > Core::getOptions()->get("MAX_PM_LENGTH")) { Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_LONG")); } if (Str::length($subject) == 0) { Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_SHORT")); } if (Str::length($subject) > 100) { Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_LONG")); } Core::getTPL()->assign("subject", $this->getParam("subject"))->assign("message", $this->getParam("message")); } } else { if ($reply) { $reply = preg_replace("#((RE|FW):\\s)+#is", "\\1", $reply); Core::getTPL()->assign("subject", $reply); } } $ranks = Core::getQuery()->select("allyrank", array("rankid", "name"), "", Core::getDB()->quoteInto("aid = ?", $this->aid)); Core::getTPL()->assign("maxpmlength", fNumber(Core::getOptions()->get("MAX_PM_LENGTH"))); Core::getTPL()->addLoop("ranks", $ranks); } else { Logger::dieMessage("MISSING_RIGHTS_FOR_GLOBAL_MAIL", "warning"); } } else { Logger::dieMessage("MISSING_RIGHTS_FOR_GLOBAL_MAIL", "warning"); } return $this; }
/** * Returns the formatted quantity. * * @return string */ public function getFormattedQty() { return fNumber($this->get("quantity")); }
/** * Parses an event. * * @param Bengine_Game_Model_Event $f * * @return array Parsed event data */ protected function parseEvent(Bengine_Game_Model_Event $f) { if ($f->getCode() == "game/alliedFleet" && $f->getUserid() != Core::getUser()->get("userid")) { return false; // Hide foreign formations } $event = array(); $event["time_r"] = $f->getTimeLeft(); $event["time"] = $f->getFormattedTimeLeft(); $event["eventid"] = $f->getEventid(); $event["time_finished"] = Date::timeToString(1, $f->getTime()); $event["raw_coordinates"] = $f->getDestinationCoords(false); Core::getLanguage()->assign("rockets", $f->getData("rockets", 0)); Core::getLanguage()->assign("planet", !$f->getData("oldmode") || $f->getData("oldmode") != 9 ? $f->getPlanetname() : Core::getLanguage()->getItem("DEBRIS")); // TODO: Old mode should be translated to code Core::getLanguage()->assign("coords", $f->getPlanetCoords()); Core::getLanguage()->assign("target", $f->getCode() != "game/recycling" ? $f->getDestinationPlanetname() : Core::getLanguage()->getItem("DEBRIS")); Core::getLanguage()->assign("targetcoords", $f->getDestinationCoords()); Core::getLanguage()->assign("metal", fNumber($f->getData("metal", 0))); Core::getLanguage()->assign("silicon", fNumber($f->getData("silicon", 0))); Core::getLanguage()->assign("hydrogen", fNumber($f->getData("hydrogen", 0))); Core::getLanguage()->assign("username", $f->getUsername()); Core::getLanguage()->assign("message", Link::get("game/" . SID . "/MSG/Write/" . rawurlencode($f->getUsername()), Image::getImage("pm.gif", Core::getLanguage()->getItem("WRITE_MESSAGE")))); Core::getLanguage()->assign("mission", $f->getCode() == "game/return" ? $f->getOrgModeName() : $f->getModeName()); Core::getLanguage()->assign("fleet", $f->getFleetString()); $event["class"] = $f->getCssClass(); if ($f->getCode() == "game/allianceAttack") { if ($f->getUserid() == Core::getUser()->get("userid")) { $event["message"] = Core::getLanguage()->getItem("FLEET_MESSAGE_OWN"); } else { $event["message"] = Core::getLanguage()->getItem("FLEET_MESSAGE_OTHER"); } $allyFleets = Game::getEH()->getFormationFleets($f->getEventid()); foreach ($allyFleets as $af) { $coords = $af->getPlanetCoords(); $msg = Core::getLanguage()->getItem("FLEET_MESSAGE_FORMATION"); $msg = sprintf($msg, $af->getUsername(), $af->getPlanetname(), $coords, $af->getFleetString()); $event["message"] .= $msg; } } else { if ($f->getCode() == "game/alliedFleet") { $mainFleet = Game::getModel("game/event")->load($f->getParentId()); if ($mainFleet->getUsierid() == Core::getUser()->get("userid")) { return false; } $event["message"] = Core::getLanguage()->getItem("FLEET_MESSAGE_OWN"); $allyFleets = Game::getEH()->getFormationFleets($mainFleet->getEventid()); $allyFleets->add($mainFleet); foreach ($allyFleets as $af) { if ($af->getUserid() == Core::getUser()->get("userid")) { continue; } $coords = $af->getPlanetCoords(); $msg = Core::getLanguage()->getItem("FLEET_MESSAGE_FORMATION"); $msg = sprintf($msg, $af->getUsername(), $af->getPlanetname(), $coords, $af->getFleetString()); $event["message"] .= $msg; } } else { if ($f->getCode() == "game/holding" && $f->getUserid() == Core::getUser()->get("userid")) { $event["message"] = Core::getLanguage()->getItem("FLEET_MESSAGE_HOLDING_1"); } else { if ($f->getCode() == "game/holding") { $event["message"] = Core::getLanguage()->getItem("FLEET_MESSAGE_HOLDING_2"); } else { if ($f->getCode() == "game/return" && $f->getUserid() == Core::getUser()->get("userid")) { $event["message"] = Core::getLanguage()->getItem("FLEET_MESSAGE_RETURN"); } else { if ($f->getUserid() == Core::getUser()->get("userid") && $f->getCode() == "game/missileAttack") { $event["message"] = Core::getLanguage()->getItem("FLEET_MESSAGE_ROCKET_ATTACK"); } else { if ($f->getCode() == "game/missileAttack") { $event["message"] = Core::getLanguage()->getItem("FLEET_MESSAGE_ROCKET_ATTACK_FOREIGN"); } else { if ($f->getUserid() == Core::getUser()->get("userid")) { $event["message"] = Core::getLanguage()->getItem("FLEET_MESSAGE_OWN"); } else { $event["message"] = Core::getLanguage()->getItem("FLEET_MESSAGE_OTHER"); } } } } } } } } return $event; }
/** * Returns the formatted fleet quantity. * * @return string */ public function getFormattedFleetQuantity() { return fNumber($this->getFleetQuantity()); }
/** * Changes the ships against resources. * * @return Bengine_Game_Controller_Shipyard */ protected function changeAction() { if (!Core::getConfig()->get("SCRAP_MERCHANT_RATE")) { $this->redirect("game/" . SID . "/Shipyard"); } Core::getLanguage()->load(array("info", "buildings")); $selUnits = Core::getRequest()->getPOST("unit"); /* @var Bengine_Game_Model_Collection_Fleet $availUnits */ $availUnits = Application::getCollection("game/fleet", "game/unit"); $availUnits->addPlanetFilter(Core::getUser()->get("curplanet")); $metalCredit = 0; $siliconCredit = 0; $hydrogenCredit = 0; $totalQty = 0; $realUnits = array(); $rate = (double) Core::getConfig()->get("SCRAP_MERCHANT_RATE"); /* @var Bengine_Game_Model_Unit $unit */ foreach ($availUnits as $unit) { $unitId = $unit->getUnitid(); if (isset($selUnits[$unitId]) && $selUnits[$unitId] > 0) { $qty = _pos((int) $selUnits[$unitId]); $qty = min($qty, $unit->getQty()); $metalCredit += $qty * $unit->get("basic_metal"); $siliconCredit += $qty * $unit->get("basic_silicon"); $hydrogenCredit += $qty * $unit->get("basic_hydrogen"); $totalQty += $qty; $realUnits[(int) $unitId] = $qty; } } $points = ($metalCredit + $siliconCredit + $hydrogenCredit) / 1000; $metalCredit = floor($metalCredit * $rate); $siliconCredit = floor($siliconCredit * $rate); $hydrogenCredit = floor($hydrogenCredit * $rate); Core::getLang()->assign(array("metalCredit" => fNumber($metalCredit), "siliconCredit" => fNumber($siliconCredit), "hydrogenCredit" => fNumber($hydrogenCredit), "totalQty" => fNumber($totalQty))); if (Core::getRequest()->getPOST("verify") == "yes") { /* @var Bengine_Game_Model_Unit $unit */ foreach ($availUnits as $unit) { $unitId = (int) $unit->getUnitid(); if (isset($realUnits[$unitId])) { $qty = $realUnits[$unitId]; if ($unit->getQty() <= $qty) { Core::getQuery()->delete("unit2shipyard", "`unitid` = ? AND `planetid` = ?", null, null, array($unitId, Core::getUser()->get("curplanet"))); } else { $sql = "UPDATE `" . PREFIX . "unit2shipyard` SET `quantity` = `quantity` - ? WHERE `unitid` = ? AND `planetid` = ?"; Core::getDatabase()->query($sql, array($qty, $unitId, Core::getUser()->get("curplanet"))); } } } $sql = "UPDATE `" . PREFIX . "planet` SET `metal` = `metal` + ?, `silicon` = `silicon` + ?, `hydrogen` = `hydrogen` + ? WHERE `planetid` = ?"; Core::getDatabase()->query($sql, array($metalCredit, $siliconCredit, $hydrogenCredit, Core::getUser()->get("curplanet"))); $sql = "UPDATE `" . PREFIX . "user` SET `points` = `points` - ? WHERE `userid` = ?"; Core::getDatabase()->query($sql, array($points, Core::getUser()->get("userid"))); $this->redirect("game/" . SID . "/Shipyard"); } $this->setTemplate("shipyard/change"); $this->assign("units", $realUnits); return $this; }
/** * Returns the number of occupied fields. * * @param boolean $formatted Format the number * * @return integer Fields */ public function getFields($formatted = false) { $fields = array_sum($this->building) / 2 - $this->getBuilding(self::SOLAR_SAT_ID); if ($formatted) { return fNumber($fields); } return $fields; }