From 8afdfeb4503925a5a768ee5bb0d9a02379498fe0 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sat, 11 Jan 2014 17:06:32 +0100 Subject: [PATCH] shufflemap list --- application/core/Maps/MapCommands.php | 2 +- application/core/Maps/MapManager.php | 30 +++++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/application/core/Maps/MapCommands.php b/application/core/Maps/MapCommands.php index 6d7a18f0..a402d34a 100644 --- a/application/core/Maps/MapCommands.php +++ b/application/core/Maps/MapCommands.php @@ -46,7 +46,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb $this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap', true); $this->maniaControl->commandManager->registerCommandListener('addmap', $this, 'command_AddMap', true); $this->maniaControl->commandManager->registerCommandListener(array('removemap', 'removethis', 'erasemap', 'erasethis'), $this, 'command_RemoveMap', true); - $this->maniaControl->commandManager->registerCommandListener(array('shufflemaps', 'shuffle'), $this, 'command_ShuffleMap', true); + $this->maniaControl->commandManager->registerCommandListener(array('shufflemaps', 'shuffle'), $this, 'command_ShuffleMaps', true); // Register for player chat commands $this->maniaControl->commandManager->registerCommandListener(array('maps', 'list'), $this, 'command_List'); diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index 1f6a795d..6816c7fc 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -23,12 +23,12 @@ class MapManager implements CallbackListener { /** * Constants */ - const TABLE_MAPS = 'mc_maps'; - const CB_BEGINMAP = 'MapManager.BeginMap'; - const CB_MAPS_UPDATED = 'MapManager.MapsUpdated'; - const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated'; - const SETTING_PERMISSION_ADD_MAP = 'Add Maps'; - const SETTING_PERMISSION_REMOVE_MAP = 'Remove Maps'; + const TABLE_MAPS = 'mc_maps'; + const CB_BEGINMAP = 'MapManager.BeginMap'; + const CB_MAPS_UPDATED = 'MapManager.MapsUpdated'; + const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated'; + const SETTING_PERMISSION_ADD_MAP = 'Add Maps'; + const SETTING_PERMISSION_REMOVE_MAP = 'Remove Maps'; const SETTING_PERMISSION_SHUFFLE_MAPS = 'Shuffle Maps'; /** @@ -164,18 +164,22 @@ class MapManager implements CallbackListener { * @return bool */ public function shuffleMapList() { - if(!$this->maniaControl->client->query('GetMapList', 100, 0)) { - trigger_error("Couldn't fetch mapList. " . $this->maniaControl->getClientErrorText()); - return false; + shuffle($this->maps); + + $mapArray = array(); + + foreach($this->maps as $map) { + /** @var Map $map */ + $mapArray[] = $map->fileName; } - $mapList = $this->maniaControl->client->getResponse(); - shuffle($mapList); - - if(!$this->maniaControl->client->query('ChooseNextChallengeList', $mapList)) { + if(!$this->maniaControl->client->query('ChooseNextMapList', $mapArray)) { trigger_error("Couldn't shuffle mapList. " . $this->maniaControl->getClientErrorText()); return false; } + + $this->fetchCurrentMap(); + return true; }