shufflemap list

This commit is contained in:
kremsy 2014-01-11 17:06:32 +01:00 committed by Steffen Schröder
parent 7bc09fca3b
commit 8afdfeb450
2 changed files with 18 additions and 14 deletions

View File

@ -46,7 +46,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap', true); $this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap', true);
$this->maniaControl->commandManager->registerCommandListener('addmap', $this, 'command_AddMap', 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('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 // Register for player chat commands
$this->maniaControl->commandManager->registerCommandListener(array('maps', 'list'), $this, 'command_List'); $this->maniaControl->commandManager->registerCommandListener(array('maps', 'list'), $this, 'command_List');

View File

@ -23,12 +23,12 @@ class MapManager implements CallbackListener {
/** /**
* Constants * Constants
*/ */
const TABLE_MAPS = 'mc_maps'; const TABLE_MAPS = 'mc_maps';
const CB_BEGINMAP = 'MapManager.BeginMap'; const CB_BEGINMAP = 'MapManager.BeginMap';
const CB_MAPS_UPDATED = 'MapManager.MapsUpdated'; const CB_MAPS_UPDATED = 'MapManager.MapsUpdated';
const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated'; const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated';
const SETTING_PERMISSION_ADD_MAP = 'Add Maps'; const SETTING_PERMISSION_ADD_MAP = 'Add Maps';
const SETTING_PERMISSION_REMOVE_MAP = 'Remove Maps'; const SETTING_PERMISSION_REMOVE_MAP = 'Remove Maps';
const SETTING_PERMISSION_SHUFFLE_MAPS = 'Shuffle Maps'; const SETTING_PERMISSION_SHUFFLE_MAPS = 'Shuffle Maps';
/** /**
@ -164,18 +164,22 @@ class MapManager implements CallbackListener {
* @return bool * @return bool
*/ */
public function shuffleMapList() { public function shuffleMapList() {
if(!$this->maniaControl->client->query('GetMapList', 100, 0)) { shuffle($this->maps);
trigger_error("Couldn't fetch mapList. " . $this->maniaControl->getClientErrorText());
return false; $mapArray = array();
foreach($this->maps as $map) {
/** @var Map $map */
$mapArray[] = $map->fileName;
} }
$mapList = $this->maniaControl->client->getResponse(); if(!$this->maniaControl->client->query('ChooseNextMapList', $mapArray)) {
shuffle($mapList);
if(!$this->maniaControl->client->query('ChooseNextChallengeList', $mapList)) {
trigger_error("Couldn't shuffle mapList. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't shuffle mapList. " . $this->maniaControl->getClientErrorText());
return false; return false;
} }
$this->fetchCurrentMap();
return true; return true;
} }