shufflemapcommand

This commit is contained in:
kremsy 2014-01-11 16:34:05 +01:00 committed by Steffen Schröder
parent 0b6a8b3912
commit 85e5c543e1
2 changed files with 42 additions and 0 deletions

View File

@ -46,6 +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('shufflemaps', $this, 'command_ShuffleMap', true);
// Register for player chat commands
$this->maniaControl->commandManager->registerCommandListener(array('maps', 'list'), $this, 'command_List');
@ -109,6 +110,23 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->maniaControl->mapManager->removeMap($player, $map->uid);
}
/**
* Handle addmap command
*
* @param array $chatCallback
* @param \ManiaControl\Players\Player $player
*/
public function command_ShuffleMaps(array $chatCallback, Player $player) {
if(!$this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_SHUFFLE_MAPS)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
// add Map from Mania Exchange
$this->maniaControl->mapManager->shuffleMapList();
//TODO message
}
/**
* Handle addmap command
*

View File

@ -29,6 +29,7 @@ class MapManager implements CallbackListener {
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';
/**
* Public Properties
@ -68,6 +69,7 @@ class MapManager implements CallbackListener {
//Define Rights
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_ADD_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_REMOVE_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_SHUFFLE_MAPS, AuthenticationManager::AUTH_LEVEL_ADMIN);
}
/**
@ -156,6 +158,28 @@ class MapManager implements CallbackListener {
unset($this->maps[$uid]);
}
/**
* Shuffles the MapList
*
* @return bool
*/
public function shuffleMapList() {
if(!$this->maniaControl->client->query('GetMapList', 100, 0)) {
trigger_error("Couldn't fetch mapList. " . $this->maniaControl->getClientErrorText());
return false;
}
$mapList = $this->maniaControl->client->getResponse();
shuffle($mapList);
if(!$this->maniaControl->client->query('hooseNextChallengeLis', $mapList)) {
trigger_error("Couldn't shuffle mapList. " . $this->maniaControl->getClientErrorText());
return false;
}
return true;
}
/**
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps
*/