improved trackmania callbacks
added legacy trackmania callbacks
This commit is contained in:
parent
1c78afc63b
commit
cf345dfdc3
@ -17,6 +17,7 @@ abstract class BaseCallback {
|
|||||||
*/
|
*/
|
||||||
public $name = null;
|
public $name = null;
|
||||||
public $rawCallback = null;
|
public $rawCallback = null;
|
||||||
|
public $isLegacyCallback = null;
|
||||||
|
|
||||||
public $pid = null;
|
public $pid = null;
|
||||||
public $login = null;
|
public $login = null;
|
||||||
|
@ -26,5 +26,6 @@ class RecordCallback extends BaseCallback {
|
|||||||
public $lapTime = null;
|
public $lapTime = null;
|
||||||
public $checkpoint = null;
|
public $checkpoint = null;
|
||||||
public $lapCheckpoint = null;
|
public $lapCheckpoint = null;
|
||||||
|
public $lap = null;
|
||||||
public $blockId = null;
|
public $blockId = null;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ class TrackManiaCallbacks implements CallbackListener {
|
|||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$callbackManager->registerCallbackListener(Callbacks::ONWAYPOINT, $this, 'handleOnWayPointCallback');
|
$callbackManager->registerCallbackListener(Callbacks::ONWAYPOINT, $this, 'handleOnWayPointCallback');
|
||||||
|
$callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpointCallback');
|
||||||
|
$callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinishCallback');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,25 +46,83 @@ class TrackManiaCallbacks implements CallbackListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build callback
|
// Build callback
|
||||||
$checkpointCallback = new RecordCallback();
|
$wayPointCallback = new RecordCallback();
|
||||||
$checkpointCallback->rawCallback = $callback;
|
$wayPointCallback->rawCallback = $callback;
|
||||||
$checkpointCallback->setPlayer($player);
|
$wayPointCallback->setPlayer($player);
|
||||||
$checkpointCallback->blockId = $callback[1];
|
$wayPointCallback->blockId = $callback[1];
|
||||||
$checkpointCallback->time = (int)$callback[2];
|
$wayPointCallback->time = (int)$callback[2];
|
||||||
$checkpointCallback->checkpoint = (int)$callback[3];
|
$wayPointCallback->checkpoint = (int)$callback[3];
|
||||||
$checkpointCallback->isEndRace = (bool)$callback[4];
|
$wayPointCallback->isEndRace = (bool)$callback[4];
|
||||||
$checkpointCallback->lapTime = (int)$callback[5];
|
$wayPointCallback->lapTime = (int)$callback[5];
|
||||||
$checkpointCallback->lapCheckpoint = (int)$callback[6];
|
$wayPointCallback->lapCheckpoint = (int)$callback[6];
|
||||||
$checkpointCallback->isEndLap = (bool)$callback[7];
|
$wayPointCallback->lap = 0;
|
||||||
|
$wayPointCallback->isEndLap = (bool)$callback[7];
|
||||||
|
|
||||||
if ($checkpointCallback->isEndRace) {
|
if ($wayPointCallback->checkpoint > 0) {
|
||||||
$checkpointCallback->name = $checkpointCallback::FINISH;
|
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
||||||
} else if ($checkpointCallback->isEndLap) {
|
$wayPointCallback->lap += $wayPointCallback->checkpoint / $currentMap->nbCheckpoints;
|
||||||
$checkpointCallback->name = $checkpointCallback::LAPFINISH;
|
}
|
||||||
|
|
||||||
|
if ($wayPointCallback->isEndRace) {
|
||||||
|
$wayPointCallback->name = $wayPointCallback::FINISH;
|
||||||
|
} else if ($wayPointCallback->isEndLap) {
|
||||||
|
$wayPointCallback->name = $wayPointCallback::LAPFINISH;
|
||||||
} else {
|
} else {
|
||||||
|
$wayPointCallback->name = $wayPointCallback::CHECKPOINT;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback($wayPointCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Hard-Coded Player Checkpoint Callback
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function handlePlayerCheckpointCallback(array $callback) {
|
||||||
|
$data = $callback[1];
|
||||||
|
$login = $data[1];
|
||||||
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
if (!$player) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$checkpointCallback = new RecordCallback();
|
||||||
$checkpointCallback->name = $checkpointCallback::CHECKPOINT;
|
$checkpointCallback->name = $checkpointCallback::CHECKPOINT;
|
||||||
|
$checkpointCallback->isLegacyCallback = true;
|
||||||
|
$checkpointCallback->setPlayer($player);
|
||||||
|
$checkpointCallback->time = (int)$data[2];
|
||||||
|
$checkpointCallback->lap = (int)$data[3];
|
||||||
|
$checkpointCallback->checkpoint = (int)$data[4];
|
||||||
|
$checkpointCallback->lapCheckpoint = $checkpointCallback->checkpoint;
|
||||||
|
|
||||||
|
if ($checkpointCallback->lap > 0) {
|
||||||
|
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
||||||
|
$checkpointCallback->lapCheckpoint -= $checkpointCallback->lap * $currentMap->nbCheckpoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback($checkpointCallback);
|
$this->maniaControl->callbackManager->triggerCallback($checkpointCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Hard-Coded Player Finish Callback
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function handlePlayerFinishCallback(array $callback) {
|
||||||
|
$data = $callback[1];
|
||||||
|
$login = $data[1];
|
||||||
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
if (!$player) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$finishCallback = new RecordCallback();
|
||||||
|
$finishCallback->name = $finishCallback::FINISH;
|
||||||
|
$finishCallback->isLegacyCallback = true;
|
||||||
|
$finishCallback->setPlayer($player);
|
||||||
|
$finishCallback->time = (int)$data[2];
|
||||||
|
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback($finishCallback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user