2014-03-19 21:58:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Callbacks;
|
|
|
|
|
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class handling and parsing ShootMania Callbacks
|
|
|
|
*
|
2014-04-24 21:55:47 +02:00
|
|
|
* @author steeffeen
|
2014-04-12 12:14:37 +02:00
|
|
|
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
2014-04-24 21:55:47 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-03-19 21:58:11 +01:00
|
|
|
*/
|
|
|
|
class ShootManiaCallbacks implements CallbackListener {
|
|
|
|
/*
|
|
|
|
* Constants
|
|
|
|
*/
|
2014-04-24 21:55:47 +02:00
|
|
|
const SCB_TIMEATTACK_ONSTART = 'TimeAttack_OnStart';
|
|
|
|
const SCB_TIMEATTACK_ONRESTART = 'TimeAttack_OnRestart';
|
2014-03-19 21:58:11 +01:00
|
|
|
const SCB_TIMEATTACK_ONCHECKPOINT = 'TimeAttack_OnCheckpoint';
|
2014-04-24 21:55:47 +02:00
|
|
|
const SCB_TIMEATTACK_ONFINISH = 'TimeAttack_OnFinish';
|
|
|
|
|
2014-03-19 21:58:11 +01:00
|
|
|
/*
|
2014-04-12 12:14:37 +02:00
|
|
|
* Private Properties
|
2014-03-19 21:58:11 +01:00
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new ShootMania Callbacks Instance
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-04-24 21:55:47 +02:00
|
|
|
|
2014-03-19 21:58:11 +01:00
|
|
|
// Register for script callbacks
|
|
|
|
$callbackManager->registerScriptCallbackListener(self::SCB_TIMEATTACK_ONCHECKPOINT, $this, 'callback_TimeAttack_OnCheckpoint');
|
|
|
|
$callbackManager->registerScriptCallbackListener(self::SCB_TIMEATTACK_ONFINISH, $this, 'callback_TimeAttack_OnFinish');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle TimeAttack OnCheckpoint Script Callback
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function callback_TimeAttack_OnCheckpoint(array $callback) {
|
2014-04-24 21:55:47 +02:00
|
|
|
$login = $callback[1][0];
|
|
|
|
$time = (int)$callback[1][1];
|
2014-03-19 21:58:11 +01:00
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
|
|
if (!$player || $time <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Trigger trackmania player checkpoint callback
|
|
|
|
$checkpointCallback = array($player->pid, $player->login, $time, 0, 0);
|
2014-04-24 21:55:47 +02:00
|
|
|
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT, array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
|
2014-03-19 21:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle TimeAttack OnFinish Script Callback
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function callback_TimeAttack_OnFinish(array $callback) {
|
2014-04-24 21:55:47 +02:00
|
|
|
$login = $callback[1][0];
|
|
|
|
$time = (int)$callback[1][1];
|
2014-03-19 21:58:11 +01:00
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
|
|
if (!$player || $time <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Trigger trackmania player finish callback
|
|
|
|
$finishCallback = array($player->pid, $player->login, $time);
|
2014-04-24 21:55:47 +02:00
|
|
|
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH, array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
|
2014-03-19 21:58:11 +01:00
|
|
|
}
|
|
|
|
}
|