本文整理汇总了PHP中Application::getModel方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::getModel方法的具体用法?PHP Application::getModel怎么用?PHP Application::getModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Application
的用法示例。
在下文中一共展示了Application::getModel方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUser
/**
* Retrieves the user model.
*
* @return Bengine_Game_Model_User
*/
public function getUser()
{
if (!$this->exists("user")) {
$this->set("user", Application::getModel("game/user")->load($this->getUserId()));
}
return $this->get("user");
}
示例2: _formatFeed
/**
* 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;
}
示例3: loadFile
/**
* Loads the event types from
*
* @return array The handlers
*/
protected static function loadFile()
{
if (empty(self::$handlers)) {
$types = Application::getModel("game/event_type")->getCollection();
foreach ($types as $handler) {
self::$handlers[$handler->get("code")] = $handler;
self::$handlers[$handler->getEventTypeId()] = $handler;
}
}
return self::$handlers;
}
示例4: _execute
/**
* Executes all events that are queued, but max 1000 events.
*
* @return Bengine_Game_Cronjob_EventExecution
*/
protected function _execute()
{
require_once "Bengine/Game.php";
$raceConditionKey = Str::substring(md5(microtime(true)), 0, 16);
/* @var Bengine_Game_Model_Collection_Event $collection */
$collection = Application::getModel("game/event")->getCollection();
$collection->addRaceConditionFilter($raceConditionKey, Core::getConfig()->get("CRONJOB_MAX_EVENT_EXECUTION"));
$collection->executeAll();
if ($collection->count() > 0) {
Core::getQuery()->delete("events", "prev_rc = ?", null, null, array($raceConditionKey));
}
return $this;
}
示例5: userAction
/**
* @var int $user
* @return Bengine_Game_Controller_Achievements
*/
public function userAction($user)
{
Core::getLanguage()->load(array("Achievements"));
$user = Application::getModel("game/user")->load((int) $user);
/* @var Bengine_Game_Model_Collection_Achievement $achievements */
$achievements = Application::getCollection("game/achievement");
$achievements->addUserJoin($user->get("userid"), true)->addDefaultSorting();
$this->view->addLoop("achievements", $achievements);
$this->view->assign("user", $user);
$this->language->assign("leftXP", $user->getLeftXPForNextLevel());
$this->language->assign("nextLevel", $user->get("level") + 1);
$this->language->assign("xp", $user->get("xp"));
$this->language->assign("level", $user->get("level"));
$this->language->assign("achievementUser", Link::get("game/" . SID . "/Profile/Page/" . $user->get("userid"), $user->get("username")));
}
示例6: getModel
/**
* Returns an empty model of this collection.
*
* @return Recipe_Model_Abstract
*/
public function getModel()
{
return Application::getModel($this->getModelName());
}
示例7: getHomePlanet
/**
* Returns the home planet model.
*
* @return Bengine_Game_Model_Planet
*/
public function getHomePlanet()
{
if (!$this->exists("home_planet")) {
$this->set("home_planet", Application::getModel("game/planet")->load($this->getHp()));
}
return $this->get("home_planet");
}
示例8: sendBack
/**
* Sends a fleet back to its original planet.
*
* @param array $data Data array
* @param integer|boolean $time Time [optional]
* @param integer|boolean $startPlanet Start planet id [optional]
* @param integer|boolean $destinationPlanet Destination planet id [optional]
*
* @return Bengine_Game_EventHandler_Handler_Abstract
*/
protected function sendBack(array $data = null, $time = false, $startPlanet = false, $destinationPlanet = false)
{
$event = $this->getEvent();
if (is_null($data)) {
$data = $event->getData();
}
$data["oldmode"] = $event->getMode();
if (count($data["ships"]) == 0) {
return $this;
}
$time = $time === false ? TIME + (TIME - $event->getStart()) : (int) $time;
$startPlanet = $startPlanet === false ? $event->getDestination() : $startPlanet;
$destinationPlanet = $destinationPlanet === false ? $event->getPlanetid() : $destinationPlanet;
$rEvent = Application::getModel("game/event");
$rEvent->setMode(self::RETURN_EVENT_ID)->setTime($time)->setPlanetid($startPlanet)->setDestination($destinationPlanet)->setUser($event->getUserid())->set("data", $data);
$rEvent->save();
return $this;
}
示例9: finish
/**
* Makes final calculations and sends the fleet back.
*
* @param integer $result Assault result
*
* @return Bengine_Game_Assault_Participant
*/
public function finish($result)
{
// Update units after battle.
if (($result == 0 || $result == 1) && $this->mode == 1 || ($result == 1 || $result == 2) && $this->mode == 0) {
$this->data["ships"] = array();
$metal = 0;
$silicon = 0;
$hydrogen = 0;
$result = Core::getQuery()->select("assaultparticipant ap", array("f2a.unitid", "f2a.quantity", "b.name", "ap.haul_metal", "ap.haul_silicon", "ap.haul_hydrogen"), "LEFT JOIN " . PREFIX . "fleet2assault f2a ON (ap.participantid = f2a.participantid) LEFT JOIN " . PREFIX . "construction b ON (b.buildingid = f2a.unitid)", Core::getDB()->quoteInto("f2a.participantid = ?", $this->participantid));
foreach ($result->fetchAll() as $row) {
if ($row["quantity"] > 0) {
$id = $row["unitid"];
$this->data["ships"][$id]["id"] = $row["unitid"];
$this->data["ships"][$id]["quantity"] = $row["quantity"];
$this->data["ships"][$id]["name"] = $row["name"];
}
$metal = $row["haul_metal"];
$silicon = $row["haul_silicon"];
$hydrogen = $row["haul_hydrogen"];
}
$result->closeCursor();
$this->data["metal"] += $metal;
$this->data["silicon"] += $silicon;
$this->data["hydrogen"] += $hydrogen;
$this->data["oldmode"] = 10;
if (count($this->data["ships"]) > 0 && $this->mode == 1) {
$event = Application::getModel("game/event");
$event->setMode(20)->setTime($this->data["time"] + $this->time)->setUserid($this->userid)->setPlanetid($this->location)->setDestination($this->planetid)->setData($this->data);
$event->save();
} else {
if ($this->mode == 0 && $this->eventid > 0) {
if (count($this->data["ships"]) > 0) {
Core::getQuery()->update("events", array("data" => serialize($this->data)), "eventid = ?", array($this->eventid));
} else {
Core::getQuery()->delete("events", "eventid = ?", null, null, array($this->eventid));
}
}
}
}
return $this;
}
示例10: _execute
/**
* (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;
}
示例11: getBuilding
/**
* @param string $name
* @return Bengine_Game_Model_Construction
*/
public function getBuilding($name)
{
$this->getBuildings();
return isset($this->buildings[$name]) ? $this->buildings[$name] : Application::getModel("game/construction");
}
示例12: send
/**
* (non-PHPdoc)
* @see app/code/Bengine/Model/Bengine_Game_Model_Abstract#_beforeSave()
* TODO
*/
public function send()
{
if (!$this->getReceiver() || !$this->getMode() || !$this->getMessage() || !$this->getSubject()) {
throw new Recipe_Exception_Generic("Missing required data to send message.");
}
if (is_null($this->getRead())) {
$this->setRead(0);
}
if (!$this->getTime()) {
$this->setTime(TIME);
}
if ($this->getSender() && $this->getSendToOutbox()) {
$message = Application::getModel("game/message");
$message->setReceiver($this->getSender())->setMode(self::OUTBOX_FOLDER_ID)->setMessage($this->getMessage())->setSender($this->getReceiver())->setSubject($this->getSubject())->setSendToOutbox(false);
$message->save();
}
$this->save();
return $this;
}
示例13: getUser
/**
* Loads the user data to output.
*
* @throws Recipe_Exception_Generic
* @return Bengine_Game_Model_User
*/
public function getUser()
{
if ($this->_user === null) {
$this->_user = Application::getModel("game/user")->load($this->getUserId());
if (!$this->_user->getUserid()) {
throw new Recipe_Exception_Generic("Unkown user signature.");
}
}
return $this->_user;
}