TrackManiaControl/core/Callbacks/ShootManiaCallbacks.php

243 lines
11 KiB
PHP
Raw Normal View History

<?php
namespace ManiaControl\Callbacks;
use ManiaControl\Callbacks\Models\RecordCallback;
2014-12-20 18:43:51 +01:00
use ManiaControl\Callbacks\Structures\EliteBeginTurnStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnActionCustomEventStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnActionEvent;
use ManiaControl\Callbacks\Structures\ShootMania\OnArmorEmptyStructure;
2017-03-25 11:53:55 +01:00
use ManiaControl\Callbacks\Structures\ShootMania\OnCaptureStructure;
2017-03-25 20:19:45 +01:00
use ManiaControl\Callbacks\Structures\ShootMania\OnCommandStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnDefaultEventStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnEliteEndTurnStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnEliteStartTurnStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnHitStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnJoustReloadStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnJoustRoundResultsStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnJoustSelectedPlayersStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnNearMissStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerObjectStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerRequestActionChange;
2017-03-25 20:19:45 +01:00
use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerRequestRespawnStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerTriggersSectorStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnRoyalPlayerSpawnStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnRoyalPointsStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnRoyalRoundWinnerStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnScoresStructure;
2017-03-24 22:49:43 +01:00
use ManiaControl\Callbacks\Structures\ShootMania\OnShootStructure;
2017-03-25 20:19:45 +01:00
use ManiaControl\Callbacks\Structures\ShootMania\OnShotDenyStructure;
use ManiaControl\Callbacks\Structures\ShootMania\StatusCallbackStructure;
use ManiaControl\ManiaControl;
/**
* Class handling and parsing ShootMania Callbacks
*
2014-05-02 17:50:30 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
2017-02-04 11:49:23 +01:00
* @copyright 2014-2017 ManiaControl Team
2014-04-24 21:55:47 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ShootManiaCallbacks implements CallbackListener {
/*
* Constants
*/
const CB_TIMEATTACK_ONSTART = 'TimeAttack_OnStart';
const CB_TIMEATTACK_ONRESTART = 'TimeAttack_OnRestart';
const CB_TIMEATTACK_ONCHECKPOINT = 'TimeAttack_OnCheckpoint';
const CB_TIMEATTACK_ONFINISH = 'TimeAttack_OnFinish';
2014-04-24 21:55:47 +02:00
/*
* Private properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/**
* Create a new ShootMania Callbacks Instance
*
2014-05-02 17:50:30 +02:00
* @param ManiaControl $maniaControl
* @param CallbackManager $callbackManager
*/
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
$this->maniaControl = $maniaControl;
2014-04-24 21:55:47 +02:00
// Register for script callbacks
2014-04-24 23:11:09 +02:00
$callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks');
}
2014-04-24 23:11:09 +02:00
/**
* Handle Script Callbacks
*
2014-05-02 17:50:30 +02:00
* @param string $name
* @param mixed $data
2014-04-24 23:11:09 +02:00
*/
public function handleScriptCallbacks($name, $data) {
if (!$this->maniaControl->getCallbackManager()->callbackListeningExists($name)) {
2017-03-25 20:19:45 +01:00
//return; //Leave that disabled while testing/implementing Callbacks
}
2014-05-02 17:50:30 +02:00
switch ($name) {
2017-03-24 22:49:43 +01:00
//MP4 New Callbacks
case Callbacks::SM_SCORES:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_SCORES, new OnScoresStructure($this->maniaControl, $data));
break;
case Callbacks::SM_UIPROPERTIES:
//TODO
break;
2017-03-25 20:19:45 +01:00
case Callbacks::SM_ONEVENTDEFAULT:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONEVENTDEFAULT, new OnDefaultEventStructure($this->maniaControl, $data));
2017-03-24 22:49:43 +01:00
break;
case Callbacks::SM_ONSHOOT:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONSHOOT, new OnShootStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONHIT:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONHIT, new OnHitStructure($this->maniaControl, $data));
2017-03-25 11:53:55 +01:00
break;
case Callbacks::SM_ONNEARMISS:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONNEARMISS, new OnNearMissStructure($this->maniaControl, $data));
2017-03-25 11:53:55 +01:00
break;
case Callbacks::SM_ONARMOREMPTY:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONARMOREMPTY, new OnArmorEmptyStructure($this->maniaControl, $data));
2017-03-25 11:53:55 +01:00
break;
case Callbacks::SM_ONCAPTURE:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONCAPTURE, new OnCaptureStructure($this->maniaControl, $data));
break;
2017-03-25 20:19:45 +01:00
case Callbacks::SM_ONSHOTDENY:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONSHOTDENY, new OnShotDenyStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONCOMMAND:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONCOMMAND, new OnCommandStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONPLAYERREQUESTRESPAWN:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONPLAYERREQUESTRESPAWN, new OnPlayerRequestRespawnStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONACTIONCUSTOMEVENT:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONACTIONCUSTOMEVENT, new OnActionCustomEventStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONACTIONEVENT:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONACTIONEVENT, new OnActionEvent($this->maniaControl, $data));
break;
case Callbacks::SM_ONPLAYERTOUCHESOBJECT:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONPLAYERTOUCHESOBJECT, new OnPlayerObjectStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONPLAYERTRIGGERSSECTOR:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONPLAYERTRIGGERSSECTOR, new OnPlayerTriggersSectorStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONPLAYERTHROWSOBJECT:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONPLAYERTHROWSOBJECT, new OnPlayerObjectStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONPLAYERREQUESTACTIONCHANGE:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONPLAYERREQUESTACTIONCHANGE, new OnPlayerRequestActionChange($this->maniaControl, $data));
2017-03-25 20:19:45 +01:00
break;
case Callbacks::SM_COMBO_PAUSESTATUS:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_COMBO_PAUSESTATUS, new StatusCallbackStructure($this->maniaControl, $data));
2017-04-07 17:28:04 +02:00
break;
case Callbacks::SM_ELITE_STARTTURN:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ELITE_STARTTURN, new OnEliteStartTurnStructure($this->maniaControl, $data));
2017-04-07 17:28:04 +02:00
break;
case Callbacks::SM_ELITE_ENDTURN:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ELITE_ENDTURN, new OnEliteEndTurnStructure($this->maniaControl, $data));
2017-04-07 17:28:04 +02:00
break;
case Callbacks::SM_JOUST_ONRELOAD:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_JOUST_ONRELOAD, new OnJoustReloadStructure($this->maniaControl, $data));
2017-04-07 17:28:04 +02:00
break;
case Callbacks::SM_JOUST_SELECTEDPLAYERS:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_JOUST_SELECTEDPLAYERS, new OnJoustSelectedPlayersStructure($this->maniaControl, $data));
2017-04-07 17:28:04 +02:00
break;
case Callbacks::SM_JOUST_ROUNDRESULT:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_JOUST_ROUNDRESULT, new OnJoustRoundResultsStructure($this->maniaControl, $data));
2017-04-07 17:28:04 +02:00
break;
case Callbacks::SM_ROYAL_POINTS:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ROYAL_POINTS, new OnRoyalPointsStructure($this->maniaControl, $data));
2017-04-07 17:28:04 +02:00
break;
case Callbacks::SM_ROYAL_PLAYERSPAWN:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ROYAL_PLAYERSPAWN, new OnRoyalPlayerSpawnStructure($this->maniaControl, $data));
2017-04-07 17:28:04 +02:00
break;
case Callbacks::SM_ROYAL_ROUNDWINNER:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ROYAL_ROUNDWINNER, new OnRoyalRoundWinnerStructure($this->maniaControl, $data));
2017-04-07 17:28:04 +02:00
break;
2017-03-24 22:49:43 +01:00
//Old Callbacks
2014-04-24 23:11:09 +02:00
case 'LibXmlRpc_Rankings':
2014-08-13 11:05:52 +02:00
$this->maniaControl->getServer()->getRankingManager()->updateRankings($data[0]);
2014-04-24 23:11:09 +02:00
break;
case 'LibAFK_IsAFK':
$this->triggerAfkStatus($data[0]);
break;
case 'WarmUp_Status':
2014-08-13 11:05:52 +02:00
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::WARMUPSTATUS, $data[0]);
break;
2014-12-20 18:43:51 +01:00
case 'Elite_BeginTurn':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ELITE_ONBEGINTURN, new EliteBeginTurnStructure($this->maniaControl, $data));
break;
case 'Elite_EndTurn':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ELITE_ONENDTURN, $data[0]);
break;
2017-02-04 11:41:31 +01:00
case 'Joust_SelectedPlayers':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::JOUST_SELECTEDPLAYERS, $data);
break;
case self::CB_TIMEATTACK_ONCHECKPOINT:
$this->handleTimeAttackOnCheckpoint($name, $data);
break;
case self::CB_TIMEATTACK_ONFINISH:
$this->handleTimeAttackOnFinish($name, $data);
break;
2014-04-24 23:11:09 +02:00
}
}
/**
* Triggers the AFK Status of an Player
*
2014-05-02 17:50:30 +02:00
* @param string $login
2014-04-24 23:11:09 +02:00
*/
private function triggerAfkStatus($login) {
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::AFKSTATUS, $player);
2014-04-24 23:11:09 +02:00
}
/**
* Handle TimeAttack OnCheckpoint Callback
*
* @param string $name
* @param array $data
*/
public function handleTimeAttackOnCheckpoint($name, array $data) {
$login = $data[0];
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if (!$player) {
return;
}
// Trigger checkpoint callback
$checkpointCallback = new RecordCallback();
$checkpointCallback->rawCallback = array($name, $data);
$checkpointCallback->name = $checkpointCallback::CHECKPOINT;
$checkpointCallback->setPlayer($player);
2017-02-04 11:41:31 +01:00
$checkpointCallback->time = (int) $data[1];
2014-08-13 11:05:52 +02:00
$this->maniaControl->getCallbackManager()->triggerCallback($checkpointCallback);
}
/**
* Handle TimeAttack OnFinish Callback
*
* @param string $name
* @param array $data
*/
public function handleTimeAttackOnFinish($name, array $data) {
$login = $data[0];
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if (!$player) {
return;
}
// Trigger finish callback
$finishCallback = new RecordCallback();
$finishCallback->rawCallback = array($name, $data);
$finishCallback->name = $finishCallback::FINISH;
$finishCallback->setPlayer($player);
2017-02-04 11:41:31 +01:00
$finishCallback->time = (int) $data[1];
2014-08-13 11:05:52 +02:00
$this->maniaControl->getCallbackManager()->triggerCallback($finishCallback);
}
}