Exemplo n.º 1
0
 /**
  * Combat report action.
  *
  * @return Bengine_Comm_Controller_Combat
  */
 public function reportAction()
 {
     if (!defined("SID")) {
         define("SID", "");
     }
     Core::getLanguage()->load(array("info", "AssaultReport"));
     Core::getTPL()->clearHTMLHeaderFiles();
     Core::getTPL()->addHTMLHeaderFile("game.css", "css");
     Core::getTPL()->addHTMLHeaderFile("lib/jquery.js", "js");
     $select = new Recipe_Database_Select();
     $select->from(array("a" => "assault"))->join(array("p" => "planet"), "p.planetid = a.planetid")->attributes(array("a" => array("report"), "p" => array("planetname")))->where(array("a" => "assaultid"), $this->getParam("1"))->where(array("a" => "key"), $this->getParam("2"));
     $result = $select->getStatement();
     $row = $result->fetchRow();
     if ($row) {
         $report = $row["report"];
         $report = preg_replace_callback("/\\{lang}([^\"]+)\\{\\/lang}/siU", function ($matches) {
             return Core::getLanguage()->getItem($matches[1]);
         }, $report);
         $report = preg_replace_callback("/\\{embedded\\[([^\"]+)]}(.*)\\{\\/embedded}/siU", function ($matches) {
             return sprintf(Core::getLanguage()->getItem($matches[1]), $matches[2]);
         }, $report);
         Hook::event("ShowCombatReport", array(&$report, &$row));
         $this->assign("report", $report);
         $this->assign("planetName", $row["planetname"]);
         $this->setIsAjax();
     } else {
         $this->setNoDisplay(true);
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Sends the reminder mails.
  *
  * @return Bengine_Game_Cronjob_Reminder
  */
 protected function sendReminders()
 {
     $time = TIME - Core::getConfig()->get("REMINDER_MAIL_TIME") * 86400;
     $select = new Recipe_Database_Select();
     $select->from("user")->attributes(array("username", "email", "last"))->where("last < ?", $time);
     $result = $select->getStatement();
     Core::getLang()->load(array("Registration"));
     foreach ($result->fetchAll() as $row) {
         Core::getLang()->assign("username", $row["username"]);
         Core::getLang()->assign("reminderLast", Date::timeToString(2, $row["last"]));
         $template = new Recipe_Email_Template("reminder");
         $mail = new Email(array($row["email"] => $row["username"]), Core::getLang()->get("REMINDER_MAIL_SUBJECT"));
         $template->send($mail);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * (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)
 {
     Hook::event("EbUpgradeResearch", array($event, &$data, $this));
     $points = ($data["metal"] + $data["silicon"] + $data["hydrogen"]) / 1000;
     $select = new Recipe_Database_Select();
     $select->from("research2user")->attributes(array("level"))->where("buildingid = ?", $data["buildingid"])->where("userid = ?", $event->getUserid());
     if ($row = $select->getStatement()->fetchRow()) {
         Core::getQuery()->update("research2user", array("level" => $data["level"]), "buildingid = ? AND userid = ?", array($data["buildingid"], $event->getUserid()));
         Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points + ?, rpoints = rpoints + '1' WHERE userid = ?", array($points, $event->getUserid()));
     } else {
         if ($data["level"] == 1) {
             Core::getQuery()->insert("research2user", array("buildingid" => $data["buildingid"], "userid" => $event->getUserid(), "level" => 1));
             Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points + ?, rpoints = rpoints + '1' WHERE userid = ?", array($points, $event->getUserid()));
         }
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * (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)
 {
     Hook::event("EhMoonDestruction", array($event, &$data, $this));
     // Start normal combat
     $assault = new Bengine_Game_Assault($event->getDestination(), $event->getDestinationUserId(), $event);
     $assault->addParticipant(1, $event->getUserid(), $event->getPlanetid(), $event->getTime(), $data);
     $assault->startAssault($data["galaxy"], $data["system"], $data["position"]);
     if ($assault->getData("result") == 1 || $assault->getData("result") == 0) {
         Core::getLanguage()->load("AutoMessages");
         $defenders = $assault->getDefenders();
         while ($defenders->next()) {
             $participant = $this->defenders->current();
             if ($participant instanceof Bengine_Game_Assault_Participant) {
                 $participant->finish($assault->getData("result"));
             }
         }
         $assault->updateMainDefender($assault->getData("lostunits_defender"));
         $attacker = $assault->getAttackers()->getFirst();
         $select = new Recipe_Database_Select();
         $select->from(array("f2a" => "fleet2assault"))->join(array("c" => "construction"), array("c" => "buildingid", "f2a" => "unitid"))->attributes(array("f2a" => array("unitid", "quantity"), "c" => array("basic_metal", "basic_silicon", "basic_hydrogen")))->where("f2a.participantid = ?", $attacker->getParticipantId());
         $result = $select->getStatement();
         $fleet = array();
         foreach ($result->fetchAll() as $row) {
             $fleet[$row["unitid"]] = $row;
         }
         $rips = isset($fleet[self::DEATH_STAR_CONSTRUCTION_ID]["quantity"]) ? $fleet[self::DEATH_STAR_CONSTRUCTION_ID]["quantity"] : 0;
         $result->closeCursor();
         $moon = $event->getDestinationPlanet();
         $message = "";
         // Chance to destroy the moon
         $diameter = min($moon->getDiameter(), 9999);
         $md = max(floor((100 - sqrt($diameter)) * sqrt($rips)), 1);
         $rand = mt_rand(0, 100);
         Core::getLang()->assign("moonName", $moon->getPlanetname());
         Core::getLang()->assign("moonCoords", $moon->getCoords(true, true));
         if ($rand <= $md) {
             $message = Core::getLang()->get("MD_MOON_DESTROYED");
             Core::getQuery()->update("events", array("planetid" => null), "planetid = ?", array($moon->getId()));
             $sql = "UPDATE `" . PREFIX . "events` e, `" . PREFIX . "galaxy` g SET e.`destination` = g.`planetid` WHERE g.`moonid` = ? AND e.`destination` = ?";
             Core::getDB()->query($sql, array($moon->getId(), $moon->getId()));
             deletePlanet($moon->getId(), $moon->getUserid(), 1);
         } else {
             $message = Core::getLang()->get("MD_MOON_SURVIVE");
         }
         // Chance of fleet destruction
         $fd = floor(sqrt($diameter) / 2);
         $rand = mt_rand(0, 100);
         if ($rand <= $fd) {
             $points = 0;
             foreach ($fleet as $ship) {
                 $points += $ship["quantity"] * ($ship["basic_metal"] + $ship["basic_silicon"] + $ship["basic_hydrogen"]);
             }
             Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points - ? WHERE userid = ?", array($points / 1000, $event->getUserid()));
             $message .= "<br/><br/>" . Core::getLang()->get("MD_FLEET_DESTROYED");
         } else {
             $attacker->finish($assault->getData("result"));
         }
         $msgAttacker = Application::getModel("game/message");
         $msgAttacker->setReceiver($event->getDestinationUserId())->setMode(Bengine_Game_Model_Message::FLEET_REPORTS_FOLDER_ID)->setSubject(Core::getLang()->get("MD_SUBJECT"))->setMessage($message)->setSendToOutbox(false);
         $msgDefender = clone $msgAttacker;
         $msgDefender->setReceiver($event->getUserid());
         $msgAttacker->send();
         $msgDefender->send();
     } else {
         $assault->finish();
     }
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Loads all total units.
  *
  * @param integer $mode
  * @return Bengine_Game_Controller_Statistics
  */
 protected function loadTotalUnits($mode)
 {
     $select = new Recipe_Database_Select();
     $select->from(array("c" => "construction"));
     $select->attributes(array("c" => array("name"), "s" => array("total" => new Recipe_Database_Expr("SUM(s.quantity)"))));
     $select->join(array("s" => "unit2shipyard"), array("s" => "unitid", "c" => "buildingid"))->group(array("c" => "buildingid"))->where(array("c" => "mode"), $mode)->order(array("c" => "display_order"), "ASC")->order(array("c" => "buildingid"), "ASC");
     $result = $select->getStatement();
     foreach ($result->fetchAll() as $row) {
         $this->unitCount[$mode][$row["name"]] = $row["total"];
     }
     $result->closeCursor();
     return $this;
 }