updated pause / warmup systems in mc
This commit is contained in:
parent
65f179e7a2
commit
cffbc6cd89
@ -212,10 +212,10 @@ class ModeScriptEventManager implements UsageInformationAble {
|
||||
* Extend the duration of any ongoing warmup.
|
||||
*
|
||||
* @api
|
||||
* @param $milisec < the duration of the extension in milliseconds.
|
||||
* @param $seconds < the duration of the extension in seconds.
|
||||
*/
|
||||
public function extendManiaPlanetWarmup($milisec) {
|
||||
$this->maniaControl->getClient()->triggerModeScriptEvent('Maniaplanet.WarmUp.Extend', array($milisec));
|
||||
public function extendManiaPlanetWarmup($seconds) {
|
||||
$this->maniaControl->getClient()->triggerModeScriptEvent('Maniaplanet.WarmUp.Extend', array($seconds * 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace ManiaControl\Script;
|
||||
|
||||
use ManiaControl\Callbacks\Structures\Common\StatusCallbackStructure;
|
||||
use ManiaControl\Callbacks\Structures\ManiaPlanet\ModeUseTeamsStructure;
|
||||
use ManiaControl\General\UsageInformationAble;
|
||||
use ManiaControl\General\UsageInformationTrait;
|
||||
@ -12,6 +13,7 @@ use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
||||
/**
|
||||
* Manager for Game Mode Script related Stuff
|
||||
*
|
||||
* @api
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2017 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
@ -19,12 +21,16 @@ use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
||||
class ScriptManager implements UsageInformationAble {
|
||||
use UsageInformationTrait;
|
||||
|
||||
//TODO add CB to MC Website
|
||||
const CB_PAUSE_STATUS_CHANGED = "ManiaControl.ScriptManager.PauseStatusChanged";
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
private $isScriptMode = null;
|
||||
private $maniaControl = null;
|
||||
private $isScriptMode = null;
|
||||
private $modeUsesPause = false;
|
||||
|
||||
/**
|
||||
* Construct a new script manager instance
|
||||
@ -69,13 +75,53 @@ class ScriptManager implements UsageInformationAble {
|
||||
}
|
||||
});
|
||||
|
||||
//Checks if the Mode Uses Pause
|
||||
$this->checkIfTheModeUsesPause();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Mode Uses Pause Async
|
||||
*/
|
||||
private function checkIfTheModeUsesPause() {
|
||||
try {
|
||||
$scriptInfos = $this->maniaControl->getClient()->getModeScriptInfo();
|
||||
|
||||
foreach ($scriptInfos->commandDescs as $param) { //TODO Mp3, can be removed later
|
||||
if ($param->name === "Command_ForceWarmUp" || $param->name === "Command_SetPause") {
|
||||
$this->setPauseStatus(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (GameModeException $e) {
|
||||
}
|
||||
|
||||
//Checks if the Script has implemented the Pause Feature and Sets the Information
|
||||
$this->maniaControl->getModeScriptEventManager()->getPauseStatus()->setCallable(function (StatusCallbackStructure $structure) {
|
||||
if ($structure->isAvailable()) {
|
||||
$this->setPauseStatus(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the New Pause Status
|
||||
*
|
||||
* @param boolean $status
|
||||
*/
|
||||
private function setPauseStatus($status) {
|
||||
$status = (boolean) $status;
|
||||
if ($this->modeUsesPause != $status) {
|
||||
$this->modeUsesPause = $status;
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_PAUSE_STATUS_CHANGED, $status);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the Server is running in Script Mode
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function isScriptMode() {
|
||||
@ -85,4 +131,24 @@ class ScriptManager implements UsageInformationAble {
|
||||
}
|
||||
return $this->isScriptMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Mode Can be Forced to a Pause
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function modeUsesPause() {
|
||||
return $this->modeUsesPause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Mode is in TeamMode
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function modeIsTeamMode() {
|
||||
return $this->maniaControl->getServer()->isTeamMode();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\Callbacks\Structures\Common\StatusCallbackStructure;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\Logger;
|
||||
@ -38,9 +39,6 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
|
||||
const SETTING_PERMISSION_SHOW_SYSTEMINFO = 'Show SystemInfo';
|
||||
const SETTING_PERMISSION_SHUTDOWN_SERVER = 'Shutdown Server';
|
||||
const SETTING_PERMISSION_CHANGE_SERVERSETTINGS = 'Change ServerSettings';
|
||||
const COMMAND_EXTEND_WARMUP = 'WarmUp_Extend';
|
||||
const COMMAND_FORCE_WARMUP = 'Command_ForceWarmUp';
|
||||
const COMMAND_SET_PAUSE = 'Command_SetPause';
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
@ -61,7 +59,7 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
|
||||
// Callbacks
|
||||
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'each5Seconds', 5000);
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::WARMUPSTATUS, $this, 'handleWarmUpStatus');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_WARMUP_STATUS, $this, 'handleWarmUpStatus');
|
||||
|
||||
// Chat commands
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('setservername', $this, 'commandSetServerName', true, 'Sets the ServerName.');
|
||||
@ -92,8 +90,6 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
|
||||
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CANCEL_VOTE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_HANDLE_WARMUP, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||
|
||||
$this->handleWarmUpStatus(true); //TODO dynamic
|
||||
|
||||
$this->updateCancelVoteMenuItem();
|
||||
$this->updateWarmUpMenuItems();
|
||||
}
|
||||
@ -112,21 +108,8 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
|
||||
* Manage the WarmUp related menu items
|
||||
*/
|
||||
private function updateWarmUpMenuItems() {
|
||||
$pauseExists = false;
|
||||
try {
|
||||
$scriptInfos = $this->maniaControl->getClient()->getModeScriptInfo();
|
||||
foreach ($scriptInfos->commandDescs as $param) {
|
||||
if ($param->name === self::COMMAND_FORCE_WARMUP || $param->name === self::COMMAND_SET_PAUSE) {
|
||||
$pauseExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->maniaControl->getClient()->triggerModeScriptEvent("WarmUp_GetStatus");
|
||||
} catch (GameModeException $e) {
|
||||
}
|
||||
|
||||
// Add pause menu item
|
||||
if ($pauseExists) {
|
||||
if ($this->maniaControl->getServer()->getScriptManager()->modeUsesPause()) {
|
||||
$itemQuad = new Quad_Icons128x32_1();
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch);
|
||||
$itemQuad->setAction(self::ACTION_SET_PAUSE);
|
||||
@ -140,8 +123,8 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
|
||||
*
|
||||
* @param $warmupEnabled
|
||||
*/
|
||||
public function handleWarmUpStatus($warmupEnabled) {
|
||||
if ($warmupEnabled) {
|
||||
public function handleWarmUpStatus(StatusCallbackStructure $structure) {
|
||||
if ($structure->isAvailable()) {
|
||||
// Extend WarmUp menu item
|
||||
$itemQuad = new Quad_BgRaceScore2();
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_SendScore);
|
||||
@ -193,11 +176,10 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->maniaControl->getClient()->triggerModeScriptEvent('WarmUp_Extend', '10');
|
||||
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' extended the WarmUp by 10 seconds!');
|
||||
} catch (GameModeException $e) {
|
||||
}
|
||||
//TODO command paprameter for seconds
|
||||
$this->maniaControl->getModeScriptEventManager()->extendManiaPlanetWarmup(10);
|
||||
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' extended the WarmUp by 10 seconds!');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -212,13 +194,8 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->maniaControl->getClient()->triggerModeScriptEvent('WarmUp_Stop', ''); //TODO remove
|
||||
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' stopped the WarmUp!');
|
||||
} catch (GameModeException $e) {
|
||||
}
|
||||
|
||||
$this->maniaControl->getModeScriptEventManager()->stopManiaPlanetWarmup();
|
||||
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' stopped the WarmUp!');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -249,6 +226,11 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
|
||||
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceEndRound' => true));
|
||||
} catch (GameModeException $ex) {
|
||||
}
|
||||
|
||||
//TODO verify if not everything is replaced through the new pause
|
||||
$this->maniaControl->getModeScriptEventManager()->startPause();
|
||||
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -487,6 +487,8 @@ class Server implements CallbackListener, CommandListener, UsageInformationAble
|
||||
/**
|
||||
* Check if the Server Runs a Team-Based Mode
|
||||
*
|
||||
* @deprecated
|
||||
* @see ScriptManager::modeIsTeamMode()
|
||||
* @return bool
|
||||
*/
|
||||
public function isTeamMode() {
|
||||
|
@ -26,6 +26,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use ManiaControl\Script\ScriptManager;
|
||||
use ManiaControl\Server\Commands;
|
||||
use ManiaControl\Server\Server;
|
||||
use ManiaControl\Utils\ColorUtil;
|
||||
@ -146,6 +147,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(self::CB_CUSTOM_VOTE_FINISHED, $this, 'handleVoteFinished');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'constructMenu');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(ScriptManager::CB_PAUSE_STATUS_CHANGED, $this, 'constructMenu');
|
||||
|
||||
// Settings
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_ICON_POSX, 156.);
|
||||
@ -224,26 +226,11 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
|
||||
$itemQuad->setAction(self::ACTION_START_VOTE . 'restartmap');
|
||||
$this->addVoteMenuItem($itemQuad, 5, 'Vote for Restart-Map');
|
||||
|
||||
//Check if Pause exists in current GameMode
|
||||
try {
|
||||
$scriptInfos = $this->maniaControl->getClient()->getModeScriptInfo();
|
||||
|
||||
$pauseExists = false;
|
||||
foreach ($scriptInfos->commandDescs as $param) {
|
||||
if ($param->name === "Command_ForceWarmUp" || $param->name === "Command_SetPause") {
|
||||
$pauseExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Menu Pause
|
||||
if ($pauseExists) {
|
||||
$itemQuad = new Quad_Icons128x32_1();
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch);
|
||||
$itemQuad->setAction(self::ACTION_START_VOTE . 'pausegame');
|
||||
$this->addVoteMenuItem($itemQuad, 10, 'Vote for a pause of Current Game');
|
||||
}
|
||||
} catch (GameModeException $e) {
|
||||
if ($this->maniaControl->getServer()->getScriptManager()->modeUsesPause()) {
|
||||
$itemQuad = new Quad_Icons128x32_1();
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch);
|
||||
$itemQuad->setAction(self::ACTION_START_VOTE . 'pausegame');
|
||||
$this->addVoteMenuItem($itemQuad, 10, 'Vote for a pause of Current Game');
|
||||
}
|
||||
|
||||
//Menu SkipMap
|
||||
@ -252,7 +239,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
|
||||
$itemQuad->setAction(self::ACTION_START_VOTE . 'skipmap');
|
||||
$this->addVoteMenuItem($itemQuad, 15, 'Vote for a Map Skip');
|
||||
|
||||
if ($this->maniaControl->getServer()->isTeamMode()) {
|
||||
if ($this->maniaControl->getServer()->getScriptManager()->modeIsTeamMode()) {
|
||||
//Menu TeamBalance
|
||||
$itemQuad = new Quad_Icons128x32_1();
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team);
|
||||
@ -551,15 +538,9 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
|
||||
} catch (GameModeException $ex) {
|
||||
}
|
||||
|
||||
try {
|
||||
//Chase and Combo?
|
||||
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_SetPause' => true));
|
||||
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!');
|
||||
|
||||
//Especially for chase, force end of the round to reach a draw
|
||||
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceEndRound' => true));
|
||||
} catch (GameModeException $ex) {
|
||||
}
|
||||
//TODO verify if not everything is replaced through the new pause
|
||||
$this->maniaControl->getModeScriptEventManager()->startPause();
|
||||
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!');
|
||||
break;
|
||||
case 'replay':
|
||||
$this->maniaControl->getMapManager()->getMapQueue()->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->getMapManager()->getCurrentMap());
|
||||
|
Loading…
Reference in New Issue
Block a user