2014-05-03 21:57:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace steeffeen;
|
|
|
|
|
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
2014-05-24 19:41:11 +02:00
|
|
|
use ManiaControl\Callbacks\Models\RecordCallback;
|
2014-05-03 23:49:58 +02:00
|
|
|
use ManiaControl\ManiaControl;
|
2014-05-03 21:57:38 +02:00
|
|
|
use ManiaControl\Plugins\Plugin;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin for the TM Game Mode 'Endurance' by TGYoshi
|
|
|
|
*
|
|
|
|
* @author steeffeen
|
|
|
|
*/
|
|
|
|
class EndurancePlugin implements CallbackListener, Plugin {
|
2014-05-03 23:49:58 +02:00
|
|
|
/*
|
2014-05-03 21:57:38 +02:00
|
|
|
* Constants
|
|
|
|
*/
|
2014-05-03 23:49:58 +02:00
|
|
|
const ID = 25;
|
|
|
|
const VERSION = 0.2;
|
|
|
|
const NAME = 'Endurance Plugin';
|
|
|
|
const AUTHOR = 'steeffeen';
|
2014-05-03 21:57:38 +02:00
|
|
|
const CB_CHECKPOINT = 'Endurance.Checkpoint';
|
2014-05-03 23:49:58 +02:00
|
|
|
|
2014-05-03 21:57:38 +02:00
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* Private Properties
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-05-03 23:49:58 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2014-05-03 21:57:38 +02:00
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public static function prepare(ManiaControl $maniaControl) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getId()
|
|
|
|
*/
|
|
|
|
public static function getId() {
|
|
|
|
return self::ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getName()
|
|
|
|
*/
|
|
|
|
public static function getName() {
|
2014-05-03 23:49:58 +02:00
|
|
|
return self::NAME;
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
|
|
|
*/
|
|
|
|
public static function getVersion() {
|
|
|
|
return self::VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
|
|
|
*/
|
|
|
|
public static function getAuthor() {
|
2014-05-03 23:49:58 +02:00
|
|
|
return self::AUTHOR;
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
|
|
|
*/
|
|
|
|
public static function getDescription() {
|
|
|
|
return "Plugin enabling Support for the TM Game Mode 'Endurance' by TGYoshi.";
|
|
|
|
}
|
|
|
|
|
2014-05-03 23:49:58 +02:00
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::load()
|
|
|
|
*/
|
|
|
|
public function load(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
|
|
|
// Register for callbacks
|
2014-05-24 19:41:11 +02:00
|
|
|
$this->maniaControl->callbackManager->registerScriptCallbackListener(self::CB_CHECKPOINT, $this, 'handleEnduranceCheckpointCallback');
|
2014-05-03 23:49:58 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
|
|
|
*/
|
|
|
|
public function unload() {
|
|
|
|
}
|
|
|
|
|
2014-05-03 21:57:38 +02:00
|
|
|
/**
|
2014-05-24 19:41:11 +02:00
|
|
|
* Handle Endurance Checkpoint Callback
|
2014-05-03 21:57:38 +02:00
|
|
|
*
|
2014-05-03 23:49:58 +02:00
|
|
|
* @param array $callback
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-05-24 19:41:11 +02:00
|
|
|
public function handleEnduranceCheckpointCallback(array $callback) {
|
2014-05-03 21:57:38 +02:00
|
|
|
$callbackData = json_decode($callback[1]);
|
2014-05-24 19:41:11 +02:00
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($callbackData->Login);
|
2014-05-03 21:57:38 +02:00
|
|
|
if (!$player) {
|
2014-05-24 19:41:11 +02:00
|
|
|
// Invalid player
|
2014-05-03 21:57:38 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-05-24 19:41:11 +02:00
|
|
|
|
|
|
|
// Build callback
|
|
|
|
$enduranceCallback = new RecordCallback();
|
|
|
|
$enduranceCallback->rawCallback = $callback;
|
|
|
|
$enduranceCallback->setPlayer($player);
|
|
|
|
$enduranceCallback->isEndLap = $callbackData->EndLap;
|
|
|
|
$enduranceCallback->isEndRace = $callbackData->EndRace;
|
|
|
|
$enduranceCallback->time = $callbackData->Time;
|
|
|
|
$enduranceCallback->lapTime = $callbackData->LapTime;
|
|
|
|
$enduranceCallback->checkpoint = $callbackData->Checkpoint;
|
|
|
|
$enduranceCallback->lapCheckpoint = $callbackData->CheckpointInLap;
|
|
|
|
|
|
|
|
if ($enduranceCallback->isEndLap) {
|
|
|
|
$enduranceCallback->name = $enduranceCallback::LAPFINISH;
|
|
|
|
} else if (($enduranceCallback->isEndRace)) {
|
|
|
|
$enduranceCallback->name = $enduranceCallback::FINISH;
|
|
|
|
} else {
|
|
|
|
$enduranceCallback->name = $enduranceCallback::CHECKPOINT;
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
2014-05-24 19:41:11 +02:00
|
|
|
|
|
|
|
$this->maniaControl->callbackManager->triggerCallback($enduranceCallback);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
}
|