Added PHPDoc comments to QueuePlugin + added (UNTESTED) Dynamic Pointlimit plugin

This commit is contained in:
Max Klaversma 2014-01-24 23:39:25 +01:00 committed by Steffen Schröder
parent dc37ccaf4a
commit 7bf223cd45
2 changed files with 207 additions and 0 deletions

View File

@ -0,0 +1,144 @@
<?php
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
/**
* Dynamic Pointlimit plugin
* Based on the Linearmode plugin for MPAseco by kremsy
*
* @author TheM
*/
class DynamicPointlimitPlugin implements CallbackListener, CommandListener, Plugin {
/**
* Constants
*/
const ID = 13;
const VERSION = 0.1;
const DYNPNT_MULTIPLIER = 'Pointlimit multiplier';
const DYNPNT_OFFSET = 'Pointlimit offset';
const DYNPNT_MIN = 'Minimum pointlimit';
const DYNPNT_MAX = 'Maximum pointlimit';
/**
* Private properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/**
* Load the plugin
*
* @param \ManiaControl\ManiaControl $maniaControl
* @throws Exception
* @return bool
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'changePointlimit');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'changePointlimit');
$this->maniaControl->settingManager->initSetting($this, self::DYNPNT_MULTIPLIER, 10);
$this->maniaControl->settingManager->initSetting($this, self::DYNPNT_OFFSET, 0);
$this->maniaControl->settingManager->initSetting($this, self::DYNPNT_MIN, 30);
$this->maniaControl->settingManager->initSetting($this, self::DYNPNT_MAX, 200);
if($this->maniaControl->server->titleId != 'SMStormRoyal@nadeolabs') {
$error = 'This plugin only supports Royal!';
throw new Exception($error);
}
}
/**
* Unload the plugin and its resources
*/
public function unload() {
$this->maniaControl->manialinkManager->unregisterManialinkPageAnswerListener($this);
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
$this->maniaControl = null;
}
/**
* Get plugin id
*
* @return int
*/
public static function getId() {
return self::ID;
}
/**
* Get Plugin Name
*
* @return string
*/
public static function getName() {
return 'Dynamic Pointlimit Plugin';
}
/**
* Get Plugin Version
*
* @return float
*/
public static function getVersion() {
return self::VERSION;
}
/**
* Get Plugin Author
*
* @return string
*/
public static function getAuthor() {
return 'TheM';
}
/**
* Get Plugin Description
*
* @return string
*/
public static function getDescription() {
return 'Plugin offers a dynamic pointlimit according to the amount of players on the server.';
}
/**
* Function called on player connect and disconnect, changing the pointlimit.
*
* @param array $callback
*/
public function changePointlimit(array $callback) {
$numberOfPlayers = 0;
$numberOfSpectators = 0;
/** @var Player $player */
foreach($this->maniaControl->playerManager->getPlayers() as $player) {
if($player->isSpectator) {
$numberOfSpectators++;
} else {
$numberOfPlayers++;
}
}
$pointlimit = ($numberOfPlayers * $this->maniaControl->settingManager->getSetting($this, self::DYNPNT_MULTIPLIER)) + $this->maniaControl->settingManager->getSetting($this, self::DYNPNT_OFFSET);
$min_value = $this->maniaControl->settingManager->getSetting($this, self::DYNPNT_MIN);
$max_value = $this->maniaControl->settingManager->getSetting($this, self::DYNPNT_MAX);
if($pointlimit < $min_value)
$pointlimit = $min_value;
if($pointlimit > $max_value)
$pointlimit = $max_value;
$this->maniaControl->client->setModeScriptSettings(array('S_MapPointsLimit' => $pointlimit));
}
}

View File

@ -139,6 +139,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
return 'Plugin offers the known AutoQueue/SpecJam options.'; return 'Plugin offers the known AutoQueue/SpecJam options.';
} }
/**
* Function handling on the connection of a player.
*
* @param array $callback
*/
public function handlePlayerConnect(array $callback) { public function handlePlayerConnect(array $callback) {
$login = $callback[1]->login; $login = $callback[1]->login;
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
@ -156,6 +161,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
} }
/**
* Function handling on the disconnection of a player.
*
* @param array $callback
*/
public function handlePlayerDisconnect(array $callback) { public function handlePlayerDisconnect(array $callback) {
/** @var Player $player */ /** @var Player $player */
$player = $callback[1]; $player = $callback[1];
@ -166,6 +176,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->moveFirstPlayerToPlay(); $this->moveFirstPlayerToPlay();
} }
/**
* Function handling the change of player information.
*
* @param array $callback
*/
public function handlePlayerInfoChanged(array $callback) { public function handlePlayerInfoChanged(array $callback) {
$login = $callback[1][0]['Login']; $login = $callback[1][0]['Login'];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
@ -181,6 +196,9 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
} }
/**
* Function called on every second.
*/
public function handleEverySecond() { public function handleEverySecond() {
if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > count($this->maniaControl->playerManager->players)) { if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > count($this->maniaControl->playerManager->players)) {
$this->moveFirstPlayerToPlay(); $this->moveFirstPlayerToPlay();
@ -199,16 +217,31 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
} }
/**
* Function handling the click of the widget to add them to the queue.
*
* @param array $chatCallback
* @param Player $player
*/
public function handleManiaLinkAnswerAdd(array $chatCallback, Player $player) { public function handleManiaLinkAnswerAdd(array $chatCallback, Player $player) {
$this->addPlayerToQueue($player); $this->addPlayerToQueue($player);
} }
/**
* Function handling the click of the widget to remove them from the queue.
*
* @param array $chatCallback
* @param Player $player
*/
public function handleManiaLinkAnswerRemove(array $chatCallback, Player $player) { public function handleManiaLinkAnswerRemove(array $chatCallback, Player $player) {
$this->removePlayerFromQueue($player->login); $this->removePlayerFromQueue($player->login);
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
$this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff' . $player->nickname . '$> has left the queue!'); $this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff' . $player->nickname . '$> has left the queue!');
} }
/**
* Function used to move the first queued player to the
*/
private function moveFirstPlayerToPlay() { private function moveFirstPlayerToPlay() {
if(count($this->queue) > 0) { if(count($this->queue) > 0) {
$firstPlayer = $this->maniaControl->playerManager->getPlayer($this->queue[0]->login); $firstPlayer = $this->maniaControl->playerManager->getPlayer($this->queue[0]->login);
@ -216,6 +249,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
} }
/**
* Function to force a player to play status.
*
* @param Player $player
*/
private function forcePlayerToPlay(Player $player) { private function forcePlayerToPlay(Player $player) {
if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > count($this->maniaControl->playerManager->players)) { if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > count($this->maniaControl->playerManager->players)) {
$this->maniaControl->client->forceSpectator($player->login, 2); $this->maniaControl->client->forceSpectator($player->login, 2);
@ -229,6 +267,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
} }
/**
* Function adds a player to the queue.
*
* @param Player $player
*/
private function addPlayerToQueue(Player $player) { private function addPlayerToQueue(Player $player) {
if($this->maniaControl->settingManager->getSetting($this, self::QUEUE_MAX) > count($this->queue)) { if($this->maniaControl->settingManager->getSetting($this, self::QUEUE_MAX) > count($this->queue)) {
$this->queue[count($this->queue)] = $player; $this->queue[count($this->queue)] = $player;
@ -236,6 +279,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
} }
/**
* Function removes a player from the queue.
*
* @param $login
*/
private function removePlayerFromQueue($login) { private function removePlayerFromQueue($login) {
$count = 0; $count = 0;
$newQueue = array(); $newQueue = array();
@ -249,6 +297,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->queue = $newQueue; $this->queue = $newQueue;
} }
/**
* Function shows the join queue widget to a player.
*
* @param Player $player
*/
private function showJoinQueueWidget(Player $player) { private function showJoinQueueWidget(Player $player) {
$maniaLink = new ManiaLink(self::ML_ID); $maniaLink = new ManiaLink(self::ML_ID);
@ -332,6 +385,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'Queue'); $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'Queue');
} }
/**
* Function shows the "You got a free spot, enjoy playing!" widget.
*
* @param Player $player
*/
private function showPlayWidget(Player $player) { private function showPlayWidget(Player $player) {
$maniaLink = new ManiaLink(self::ML_ID); $maniaLink = new ManiaLink(self::ML_ID);
@ -370,6 +428,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->showPlay[$player->login] = array('time' => time(), 'player' => $player); $this->showPlay[$player->login] = array('time' => time(), 'player' => $player);
} }
/**
* Function hides the queue widget from the player.
*
* @param Player $player
*/
private function hideQueueWidget(Player $player) { private function hideQueueWidget(Player $player) {
$maniaLink = new ManiaLink(self::ML_ID); $maniaLink = new ManiaLink(self::ML_ID);
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'Queue'); $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'Queue');