本文整理汇总了PHP中Game::getModel方法的典型用法代码示例。如果您正苦于以下问题:PHP Game::getModel方法的具体用法?PHP Game::getModel怎么用?PHP Game::getModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game
的用法示例。
在下文中一共展示了Game::getModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _match
/**
* @return bool
*/
protected function _match()
{
if ($this->getUser()->get("hp") == Core::getUser()->get("curplanet")) {
return Game::getPlanet()->getData("planetname") != Core::getLang()->get("HOME_PLANET");
}
$planet = Game::getModel("game/planet")->load($this->getUser()->get("hp"));
return $planet->get("planetname") != Core::getLang()->get("HOME_PLANET");
}
示例2: _remove
/**
* (non-PHPdoc)
* @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_remove($event, $data)
*/
protected function _remove(Bengine_Game_Model_Event $event, array $data)
{
$_event = Game::getModel("game/event")->load($event->getId());
if (!$_event->getId()) {
return false;
}
$this->addResourceToPlanet($data);
return $this;
}
示例3: 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;
}
示例4: _match
/**
* @return bool
*/
protected function _match()
{
Core::getLanguage()->load(array("Profile"));
$userId = $this->getUser()->get("userid");
/* @var Bengine_Game_Model_Profile $avatar */
$avatar = Game::getModel("game/profile")->loadByCode("AVATAR", $userId);
/* @var Bengine_Game_Model_Profile $about */
$about = Game::getModel("game/profile")->loadByCode("ABOUT_ME", $userId);
if ($avatar->get("data") != "" && strip_tags($about->get("data")) != "" && $about->get("data") != Core::getLang()->get("DEFAULT_ABOUT_ME")) {
return true;
}
return false;
}
示例5: indexAction
/**
* Index action.
*
* @return Bengine_Game_Controller_Mission
*/
protected function indexAction()
{
if (!$this->noAction) {
$fleetEvents = Game::getEH()->getOwnFleetEvents();
$fleetEvents = !is_array($fleetEvents) ? array() : $fleetEvents;
Hook::event("ShowAllMissions", array(&$fleetEvents));
Core::getTPL()->addLoop("missions", $fleetEvents);
Core::getQuery()->delete("temp_fleet", "planetid = ?", null, null, array(Core::getUser()->get("curplanet")));
/* @var Bengine_Game_Model_Collection_Fleet $fleet */
$fleet = Game::getModel("game/fleet")->getCollection();
$fleet->addTypeFilter(3);
$fleet->addPlanetFilter(Core::getUser()->get("curplanet"));
Hook::event("MissionFlettList", array($fleet));
Core::getTPL()->addLoop("fleet", $fleet);
$canSendFleet = false;
if (empty($fleetEvents) || Game::getResearch(14) + 1 > count($fleetEvents)) {
$canSendFleet = true;
}
Core::getTPL()->assign("canSendFleet", $canSendFleet);
}
return $this;
}
示例6: proceedBan
/**
* Bans an user.
*
* @param integer $ban
* @param integer $timeEnd
* @param string $reason
* @param boolean $forceUmode
*
* @return Bengine_Game_Controller_Moderator
*/
protected function proceedBan($ban, $timeEnd, $reason, $forceUmode)
{
$to = TIME + $ban * $timeEnd;
if ($to > 9999999999) {
$to = 9999999999;
}
Hook::event("BanUser", array(&$to, $reason, $forceUmode));
$spec = array("userid" => $this->userid, "from" => TIME, "to" => $to, "reason" => $reason, "modid" => Core::getUser()->get("userid"));
Core::getQuery()->insert("ban_u", $spec);
if ($forceUmode) {
Core::getQuery()->update("user", array("umode" => 1), "userid = ?", array($this->userid));
setProdOfUser($this->userid, 0);
}
Core::getQuery()->update("sessions", array("logged" => 0), "userid = ?", array($this->userid));
$user = Game::getModel("game/user")->load($this->userid);
Core::getTemplate()->assign("banReason", $reason);
Core::getLang()->assign("banDate", Date::timeToString(1, $to, "", 0));
Core::getLang()->assign("username", $user->get("username"));
$template = new Recipe_Email_Template("ban_notification");
$mail = new Email(array($user->get("email") => $user->get("username")), Core::getLanguage()->getItem("BAN_NOTIFICATION_MAIL_SUBJECT"));
$template->send($mail);
return $this;
}
示例7: cancelAction
/**
* @return Bengine_Game_Controller_Shipyard
*/
protected function cancelAction()
{
$events = Core::getRequest()->getPOST("shipyard_events");
foreach ($events as $eventId) {
$event = Game::getModel("game/event")->load((int) $eventId);
if ($event->get("userid") == Core::getUser()->get("userid")) {
Game::getEH()->removeEvent($event);
}
}
$this->redirect("game/" . SID . "/" . Core::getRequest()->getGET("controller"));
return $this;
}
示例8: 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;
}
示例9: parseEvent
/**
* 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;
}
示例10: init
/**
* Shows the fleet events of the stated planet.
* Firstly, check for validation (Range, consumption, ...)
*
* @return Bengine_Game_Controller_MonitorPlanet
*/
protected function init()
{
$this->planetid = Core::getRequest()->getGET("1");
$this->planetData = Game::getModel("game/planet")->load($this->planetid);
return parent::init();
}
示例11: add
/**
* Adds an event.
*
* @param integer $mode Mode id
* @param integer $time Time when event will be triggered
* @param integer $planetid Planet where event has been triggered
* @param integer $userid User ID
* @param integer $destination Destination planet (just for fleet events)
* @param array $data Event-related data
*
* @return Bengine_Game_EventHandler_Handler_Abstract
*/
public function add($mode, $time, $planetid, $userid, $destination, array $data)
{
$event = Game::getModel("game/event");
$this->setEvent($event);
$event->setMode($mode)->setTime($time)->setPlanetid($planetid)->setUser($userid)->setDestination($destination)->set("data", $data);
$rollback = $this->_add($event, $event->getData());
Hook::event("EhAddEvent", array($event));
if ($rollback !== false) {
$event->save();
}
return $this;
}
示例12: acceptRequest
/**
* Accepts a buddylist request.
*
* @param int $relid
*
* @return Bengine_Game_Controller_Friends
*/
protected function acceptRequest($relid)
{
if (!empty($relid) && is_numeric($relid)) {
Hook::event("AcceptBuddyListRequest", array($relid));
$where = "relid = ? AND friend2 = ?";
Core::getQuery()->update("buddylist", array("accepted" => 1), $where, array($relid, Core::getUser()->get("userid")));
$where = Core::getDB()->quoteInto($where, array($relid, Core::getUser()->get("userid")));
$result = Core::getQuery()->select("buddylist", array("friend1"), "", $where);
if ($friend = $result->fetchColumn()) {
/* @var Bengine_Game_Model_Message $pm */
$pm = Game::getModel("game/message");
$pm->set("receiver", $friend)->set("mode", Bengine_Game_Model_Message::USER_FOLDER_ID)->set("subject", Core::getLang()->get("FRIEND_REQUEST_ACCEPTED"))->set("message", Core::getLang()->get("FRIEND_REQUEST_ACCEPTED_MESSAGE"));
$pm->send();
}
}
return $this->redirect("game/" . SID . "/Friends");
}
示例13: deleteMessages
/**
* 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;
}
示例14: saveAboutAction
/**
* Saves the about me text.
*
* @param integer $user_id
*
* @return Bengine_Game_Controller_Profile
*/
protected function saveAboutAction($user_id)
{
if (!$user_id) {
$user_id = Core::getUser()->get("userid");
}
if ($user_id != Core::getUser()->get("userid")) {
Core::getUser()->checkPermissions(array("CAN_EDIT_PROFILES"));
}
$this->setNoDisplay();
if ($this->isPost()) {
$aboutText = $this->getParam("text");
$about = Game::getModel("game/profile")->loadByCode("ABOUT_ME", $user_id);
if (!$about->getUserId()) {
$about->setIsNew(true);
}
$about->setData($aboutText)->setUserId($user_id);
if ($about->getFieldObject()->validate()) {
$about->save();
} else {
echo implode("\n", $about->getFieldObject()->getErrors());
}
}
return $this;
}
示例15: getMainFormationFleet
/**
* Loads the main fleet of an alliance attack.
*
* @param integer $eventid
*
* @return Bengine_Game_Model_Event
*/
public function getMainFormationFleet($eventid)
{
return Game::getModel("game/event")->load($eventid);
}