performed code formatting

This commit is contained in:
Steffen Schröder
2014-08-05 02:17:41 +02:00
parent 98b5f132dc
commit 28d2c08936
66 changed files with 4054 additions and 1901 deletions

View File

@ -100,22 +100,32 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$this->initTables();
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MIN_HITS_RATIO_RANKING, 100);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MIN_HITS_POINTS_RANKING, 15);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MIN_HITS_RATIO_RANKING, 100);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MIN_HITS_POINTS_RANKING, 15);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MIN_REQUIRED_RECORDS, 3);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAX_STORED_RECORDS, 50);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MIN_REQUIRED_RECORDS, 3);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MAX_STORED_RECORDS, 50);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_RANKING_TYPE, $this->getRankingsTypeArray());
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_RANKING_TYPE, $this->getRankingsTypeArray());
// Callbacks
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleEndMap');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleEndMap');
// Commands
$this->maniaControl->getCommandManager()->registerCommandListener('rank', $this, 'command_showRank', false, 'Shows your current ServerRank.');
$this->maniaControl->getCommandManager()->registerCommandListener('nextrank', $this, 'command_nextRank', false, 'Shows the person in front of you in the ServerRanking.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('topranks', 'top100'), $this, 'command_topRanks', false, 'Shows an overview of the best-ranked 100 players.');
$this->maniaControl->getCommandManager()
->registerCommandListener('rank', $this, 'command_showRank', false, 'Shows your current ServerRank.');
$this->maniaControl->getCommandManager()
->registerCommandListener('nextrank', $this, 'command_nextRank', false, 'Shows the person in front of you in the ServerRanking.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('topranks', 'top100'), $this, 'command_topRanks', false, 'Shows an overview of the best-ranked 100 players.');
// TODO: only update records count
$this->resetRanks();
@ -128,10 +138,12 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
* @return array[]
*/
private function getRankingsTypeArray() {
$script = $this->maniaControl->getClient()->getScriptName();
$script = $this->maniaControl->getClient()
->getScriptName();
if ($this->maniaControl->getMapManager()->getCurrentMap()
->getGame() === 'tm'
if ($this->maniaControl->getMapManager()
->getCurrentMap()
->getGame() === 'tm'
) {
//TODO also add obstacle here as default
return array(self::RANKING_TYPE_RECORDS, self::RANKING_TYPE_POINTS, self::RANKING_TYPE_RATIOS);
@ -146,7 +158,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
* Create necessary database tables
*/
private function initTables() {
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RANK . "` (
`PlayerIndex` int(11) NOT NULL,
`Rank` int(11) NOT NULL,
@ -164,7 +177,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
* Resets and rebuilds the Ranking
*/
private function resetRanks() {
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
// Erase old Average Data
$query = "TRUNCATE TABLE `" . self::TABLE_RANK . "`;";
@ -173,15 +187,20 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
trigger_error($mysqli->error);
}
$type = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_RANKING_TYPE);
$type = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_RANKING_TYPE);
switch ($type) {
case self::RANKING_TYPE_RATIOS:
$minHits = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_RATIO_RANKING);
$minHits = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_HITS_RATIO_RANKING);
$hits = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
$killDeathRatios = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticManager::SPECIAL_STAT_KD_RATIO);
$accuracies = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticManager::SPECIAL_STAT_LASER_ACC);
$hits = $this->maniaControl->getStatisticManager()
->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
$killDeathRatios = $this->maniaControl->getStatisticManager()
->getStatsRanking(StatisticManager::SPECIAL_STAT_KD_RATIO);
$accuracies = $this->maniaControl->getStatisticManager()
->getStatsRanking(StatisticManager::SPECIAL_STAT_LASER_ACC);
$ranks = array();
foreach ($hits as $login => $hitCount) {
@ -195,19 +214,24 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
break;
case self::RANKING_TYPE_POINTS:
$minHits = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_POINTS_RANKING);
$ranks = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
$minHits = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_HITS_POINTS_RANKING);
$ranks = $this->maniaControl->getStatisticManager()
->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
break;
case self::RANKING_TYPE_RECORDS:
// TODO: verify workable status
/** @var LocalRecordsPlugin $localRecordsPlugin */
$localRecordsPlugin = $this->maniaControl->getPluginManager()->getPlugin(__NAMESPACE__ . '\LocalRecordsPlugin');
$localRecordsPlugin = $this->maniaControl->getPluginManager()
->getPlugin(__NAMESPACE__ . '\LocalRecordsPlugin');
if (!$localRecordsPlugin) {
return;
}
$requiredRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_REQUIRED_RECORDS);
$maxRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAX_STORED_RECORDS);
$requiredRecords = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_REQUIRED_RECORDS);
$maxRecords = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAX_STORED_RECORDS);
$query = "SELECT `playerIndex`, COUNT(*) AS `Cnt`
FROM `" . LocalRecordsPlugin::TABLE_RECORDS . "`
@ -221,7 +245,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
}
$result->free_result();
$maps = $this->maniaControl->getMapManager()->getMaps();
$maps = $this->maniaControl->getMapManager()
->getMaps();
foreach ($maps as $map) {
$records = $localRecordsPlugin->getLocalRecords($map, $maxRecords);
@ -296,14 +321,17 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
public function showRank(Player $player) {
$rankObj = $this->getRank($player);
$type = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_RANKING_TYPE);
$type = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_RANKING_TYPE);
$message = '';
if ($rankObj) {
switch ($type) {
case self::RANKING_TYPE_RATIOS:
$killDeathRatio = $this->maniaControl->getStatisticManager()->getStatisticData(StatisticManager::SPECIAL_STAT_KD_RATIO, $player->index);
$accuracy = $this->maniaControl->getStatisticManager()->getStatisticData(StatisticManager::SPECIAL_STAT_LASER_ACC, $player->index);
$killDeathRatio = $this->maniaControl->getStatisticManager()
->getStatisticData(StatisticManager::SPECIAL_STAT_KD_RATIO, $player->index);
$accuracy = $this->maniaControl->getStatisticManager()
->getStatisticData(StatisticManager::SPECIAL_STAT_LASER_ACC, $player->index);
$message = '$0f3Your Server rank is $<$ff3' . $rankObj->rank . '$> / $<$fff' . $this->recordCount . '$> (K/D: $<$fff' . round($killDeathRatio, 2) . '$> Acc: $<$fff' . round($accuracy * 100) . '%$>)';
break;
case self::RANKING_TYPE_POINTS:
@ -315,19 +343,23 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
} else {
switch ($type) {
case self::RANKING_TYPE_RATIOS:
$minHits = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_RATIO_RANKING);
$minHits = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_HITS_RATIO_RANKING);
$message = '$0f3 You must make $<$fff' . $minHits . '$> Hits on this server before receiving a rank...';
break;
case self::RANKING_TYPE_POINTS:
$minPoints = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_POINTS_RANKING);
$minPoints = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_HITS_POINTS_RANKING);
$message = '$0f3 You must make $<$fff' . $minPoints . '$> Hits on this server before receiving a rank...';
break;
case self::RANKING_TYPE_RECORDS:
$minRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_REQUIRED_RECORDS);
$minRecords = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_REQUIRED_RECORDS);
$message = '$0f3 You need $<$fff' . $minRecords . '$> Records on this server before receiving a rank...';
}
}
$this->maniaControl->getChat()->sendChat($message, $player);
$this->maniaControl->getChat()
->sendChat($message, $player);
}
/**
@ -338,7 +370,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
*/
private function getRank(Player $player) {
//TODO setting global from db or local
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_RANK . "`
WHERE `PlayerIndex` = {$player->index};";
@ -371,12 +404,14 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
if ($rankObject->rank > 1) {
$nextRank = $this->getNextRank($player);
$nextPlayer = $this->maniaControl->getPlayerManager()->getPlayerByIndex($nextRank->playerIndex);
$nextPlayer = $this->maniaControl->getPlayerManager()
->getPlayerByIndex($nextRank->playerIndex);
$message = '$0f3The next better ranked player is $fff' . $nextPlayer->nickname;
} else {
$message = '$0f3No better ranked player :-)';
}
$this->maniaControl->getChat()->sendChat($message, $player);
$this->maniaControl->getChat()
->sendChat($message, $player);
return true;
}
@ -394,7 +429,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
}
$nextRank = $rankObject->rank - 1;
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_RANK . "`
WHERE `Rank` = {$nextRank};";
$result = $mysqli->query($query);
@ -418,7 +454,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
public function handleEndMap() {
$this->resetRanks();
foreach ($this->maniaControl->getPlayerManager()->getPlayers() as $player) {
foreach ($this->maniaControl->getPlayerManager()
->getPlayers() as $player) {
if ($player->isFakePlayer()) {
continue;
}
@ -427,7 +464,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
}
// Trigger callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_RANK_BUILT);
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_RANK_BUILT);
}
/**
@ -449,7 +487,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
public function command_nextRank(array $chatCallback, Player $player) {
if (!$this->showNextRank($player)) {
$message = '$0f3You need to have a ServerRank first!';
$this->maniaControl->getChat()->sendChat($message, $player);
$this->maniaControl->getChat()
->sendChat($message, $player);
}
}
@ -471,15 +510,20 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
private function showTopRanksList(Player $player) {
$query = "SELECT * FROM `" . self::TABLE_RANK . "`
ORDER BY `Rank` ASC LIMIT 0, 100;";
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$result = $mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
return;
}
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
$width = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
// create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -488,7 +532,9 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$script->addFeature($paging);
// Main frame
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
$frame = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultListFrame($script, $paging);
$maniaLink->add($frame);
// Start offsets
@ -496,7 +542,9 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$posY = $height / 2;
//Predefine description Label
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
$descriptionLabel = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
// Headline
@ -504,7 +552,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$frame->add($headFrame);
$headFrame->setY($posY - 5);
$array = array('$oRank' => $posX + 5, '$oNickname' => $posX + 18, '$oAverage' => $posX + 70);
$this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
$this->maniaControl->getManialinkManager()
->labelLine($headFrame, $array);
$index = 1;
$posY -= 10;
@ -530,16 +579,19 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$lineQuad->setZ(0.001);
}
$playerObject = $this->maniaControl->getPlayerManager()->getPlayerByIndex($rankedPlayer->PlayerIndex);
$playerObject = $this->maniaControl->getPlayerManager()
->getPlayerByIndex($rankedPlayer->PlayerIndex);
$array = array($rankedPlayer->Rank => $posX + 5, $playerObject->nickname => $posX + 18, (string)round($rankedPlayer->Avg, 2) => $posX + 70);
$this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array);
$this->maniaControl->getManialinkManager()
->labelLine($playerFrame, $array);
$posY -= 4;
$index++;
}
// Render and display xml
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'TopRanks');
$this->maniaControl->getManialinkManager()
->displayWidget($maniaLink, $player, 'TopRanks');
}
}