From 498237491fe42d72bd2c49913eff1833d216073d Mon Sep 17 00:00:00 2001 From: W1lla van den Munckhof Date: Wed, 29 Mar 2017 13:28:32 +0200 Subject: [PATCH 1/2] First Batch TM Callbacks Gonna work on the others --- core/Callbacks/Callbacks.php | 21 ++- core/Callbacks/LibXmlRpcCallbacks.php | 1 - core/Callbacks/Models/RecordCallback.php | 18 ++- .../TrackMania/Models/PlayerScore.php | 134 ++++++++++++++++++ .../TrackMania/Models/TeamScore.php | 93 ++++++++++++ .../TrackMania/OnEventStartLineStructure.php | 44 ++++++ .../TrackMania/OnEventWayPointStructure.php | 92 ++++++++++++ .../TrackMania/OnScoresStructure.php | 125 ++++++++++++++++ core/Callbacks/TrackManiaCallbacks.php | 43 +++++- 9 files changed, 554 insertions(+), 17 deletions(-) create mode 100644 core/Callbacks/Structures/TrackMania/Models/PlayerScore.php create mode 100644 core/Callbacks/Structures/TrackMania/Models/TeamScore.php create mode 100644 core/Callbacks/Structures/TrackMania/OnEventStartLineStructure.php create mode 100644 core/Callbacks/Structures/TrackMania/OnEventWayPointStructure.php create mode 100644 core/Callbacks/Structures/TrackMania/OnScoresStructure.php diff --git a/core/Callbacks/Callbacks.php b/core/Callbacks/Callbacks.php index b997a1f9..82a0c142 100644 --- a/core/Callbacks/Callbacks.php +++ b/core/Callbacks/Callbacks.php @@ -81,9 +81,24 @@ interface Callbacks { const SM_ONPLAYERTHROWSOBJECT = "Shootmania.Event.OnPlayerThrowsObject"; const SM_ONPLAYERREQUESTACTIONCHANGE = "Shootmania.Event.OnPlayerRequestActionChange"; - - const TM_ONEVENTDEFAULT = "Trackmania.Event.Default"; - + // New TM Callbacks + + const TM_ONEVENTDEFAULT = "Trackmania.Event.Default"; + const TM_ONEVENTSTARTLINE = "Trackmania.Event.StartLine"; + const TM_ONCOMMAND = "Trackmania.Event.OnCommand"; + const TM_ONPLAYERADDED = "Trackmania.Event.OnPlayerAdded"; + const TM_ONPLAYERREMOVED = "Trackmania.Event.OnPlayerRemoved"; + const TM_ONWAYPOINT = "Trackmania.Event.WayPoint"; + const TM_ONGIVEUP = "Trackmania.Event.GiveUp"; + const TM_ONRESPAWN = "Trackmania.Event.Respawn"; + const TM_ONSTUNT = "Trackmania.Event.Stunt"; + const TM_ONSTARTCOUNTDOWN = "Trackmania.Event.StartCountdown"; + const TM_SCORES = "Trackmania.Scores"; + const TM_WARMUPSTART = "Trackmania.WarmUp.Start"; + const TM_WARMUPSTARTROUND = "Trackmania.WarmUp.StartRound"; + const TM_WARMUPENDROUND = "Trackmania.WarmUp.EndRound"; + const TM_WARMUPEND = "Trackmania.WarmUp.End"; + //ManiaControl Callbacks /** BeginMap Callback: Map */ const BEGINMAP = 'Callbacks.BeginMap'; diff --git a/core/Callbacks/LibXmlRpcCallbacks.php b/core/Callbacks/LibXmlRpcCallbacks.php index 5f2adfc7..caf6242b 100644 --- a/core/Callbacks/LibXmlRpcCallbacks.php +++ b/core/Callbacks/LibXmlRpcCallbacks.php @@ -44,7 +44,6 @@ class LibXmlRpcCallbacks implements CallbackListener { * @param mixed $data */ public function handleScriptCallback($name, $data) { - var_dump($name); if (!$this->maniaControl->getCallbackManager()->callbackListeningExists($name)) { //return; //Leave that disabled while testing/implementing Callbacks } diff --git a/core/Callbacks/Models/RecordCallback.php b/core/Callbacks/Models/RecordCallback.php index 371489b2..4c5815fa 100644 --- a/core/Callbacks/Models/RecordCallback.php +++ b/core/Callbacks/Models/RecordCallback.php @@ -20,12 +20,16 @@ class RecordCallback extends BaseCallback { /* * Public Properties */ - public $isEndRace = null; - public $isEndLap = null; public $time = null; - public $lapTime = null; - public $checkpoint = null; - public $lapCheckpoint = null; - public $lap = null; - public $blockId = null; + public $player = null; + public $racetime = null; + public $laptime = null; + public $stuntsscore = null; + public $checkpointinrace = null; + public $checkpointinlap = null; + public $isendrace = null; + public $isendlap = null; + public $blockid = null; + public $speed = null; + public $distance = null; } diff --git a/core/Callbacks/Structures/TrackMania/Models/PlayerScore.php b/core/Callbacks/Structures/TrackMania/Models/PlayerScore.php new file mode 100644 index 00000000..7de096fb --- /dev/null +++ b/core/Callbacks/Structures/TrackMania/Models/PlayerScore.php @@ -0,0 +1,134 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class PlayerScore implements UsageInformationAble { + use UsageInformationTrait; + + private $player; + private $rank; + private $roundPoints; + private $mapPoints; + private $matchPoints; + private $bestraceTime; + private $bestlapTime; + private $stuntScore; + + /** + * Returns the Player + * + * @return Player + */ + public function getPlayer() { + return $this->player; + } + + /** + * @param \ManiaControl\Players\Player $player + */ + public function setPlayer(Player $player) { + $this->player = $player; + } + + /** + * Returns the Rank + * + * @return int + */ + public function getRank() { + return $this->rank; + } + + /** + * Sets the Rank + * + * @param int $rank + */ + public function setRank($rank) { + $this->rank = $rank; + } + + /** + * Gets the Round Points + * + * @return int + */ + public function getRoundPoints() { + return $this->roundPoints; + } + + /** + * Sets the RoundPoints + * + * @param int $roundPoints + */ + public function setRoundPoints($roundPoints) { + $this->roundPoints = $roundPoints; + } + + /** + * Gets the Map Points + * + * @return int + */ + public function getMapPoints() { + return $this->mapPoints; + } + + /** + * Sets the Map Points + * + * @param int $mapPoints + */ + public function setMapPoints($mapPoints) { + $this->mapPoints = $mapPoints; + } + + /** + * Gets the bestRaceTime + * + * @param int $bestraceTime + */ + public function getbestraceTime(){ + return $this->bestraceTime; + } + + /** + * Gets the bestRaceTime + * + * @param int $bestraceTime + */ + public function getbestraceTime(){ + return $this->bestraceTime; + } + + /** + * Gets the bestlapTime + * + * @param int $bestlapTime + */ + public function getbestlapTime(){ + return $this->bestlapTime; + } + + /** + * Gets the StuntScore + * + * @param int $bestraceTime + */ + public function getstuntScore(){ + return $this->stuntScore; + } + +} \ No newline at end of file diff --git a/core/Callbacks/Structures/TrackMania/Models/TeamScore.php b/core/Callbacks/Structures/TrackMania/Models/TeamScore.php new file mode 100644 index 00000000..07fe30a3 --- /dev/null +++ b/core/Callbacks/Structures/TrackMania/Models/TeamScore.php @@ -0,0 +1,93 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class TeamScore implements UsageInformationAble { + use UsageInformationTrait; + + private $id; + private $name; + private $roundPoints; + private $mapPoints; + private $matchPoints; + + /** + * @return mixed + */ + public function getId() { + return $this->id; + } + + /** + * @param mixed $id + */ + public function setId($id) { + $this->id = $id; + } + + /** + * @return mixed + */ + public function getName() { + return $this->name; + } + + /** + * @param mixed $name + */ + public function setName($name) { + $this->name = $name; + } + + /** + * @return mixed + */ + public function getRoundPoints() { + return $this->roundPoints; + } + + /** + * @param mixed $roundPoints + */ + public function setRoundPoints($roundPoints) { + $this->roundPoints = $roundPoints; + } + + /** + * @return mixed + */ + public function getMapPoints() { + return $this->mapPoints; + } + + /** + * @param mixed $mapPoints + */ + public function setMapPoints($mapPoints) { + $this->mapPoints = $mapPoints; + } + + /** + * @return mixed + */ + public function getMatchPoints() { + return $this->matchPoints; + } + + /** + * @param mixed $matchPoints + */ + public function setMatchPoints($matchPoints) { + $this->matchPoints = $matchPoints; + } +} \ No newline at end of file diff --git a/core/Callbacks/Structures/TrackMania/OnEventStartLineStructure.php b/core/Callbacks/Structures/TrackMania/OnEventStartLineStructure.php new file mode 100644 index 00000000..0532b73f --- /dev/null +++ b/core/Callbacks/Structures/TrackMania/OnEventStartLineStructure.php @@ -0,0 +1,44 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnEventStartLineStructure extends BaseStructure { + private $time; + private $player; + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->time = $this->getPlainJsonObject()->time; + $this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login); + } + + /** + * Returns Server time when the event occured + * + * @return int + */ + public function getTime() { + return $this->time; + } + + /** + * < player who triggered the action + * + * @return \ManiaControl\Players\Player + */ + public function getPlayer() { + return $this->player; + } +} \ No newline at end of file diff --git a/core/Callbacks/Structures/TrackMania/OnEventWayPointStructure.php b/core/Callbacks/Structures/TrackMania/OnEventWayPointStructure.php new file mode 100644 index 00000000..0aac25eb --- /dev/null +++ b/core/Callbacks/Structures/TrackMania/OnEventWayPointStructure.php @@ -0,0 +1,92 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnEventWayPointStructure extends BaseStructure { + private $time; + private $player; + private $racetime; + private $laptime; + private $stuntsscore; + private $checkpointinrace; + private $checkpointinlap; + private $isendrace; + private $isendlap; + private $blockid; + private $speed; + private $distance; + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->time = $this->getPlainJsonObject()->time; + $this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login); + $this->racetime = (int) $this->getPlainJsonObject()->racetime; + $this->laptime = (int) $this->getPlainJsonObject()->laptime; + $this->stuntsscore = $this->getPlainJsonObject()->stuntsscore; + $this->checkpointinrace = (int) $this->getPlainJsonObject()->checkpointinrace; + $this->checkpointinlap = (int) $this->getPlainJsonObject()->checkpointinlap; + $this->isendrace = $this->getPlainJsonObject()->isendrace; + $this->isendlap = $this->getPlainJsonObject()->isendlap; + $this->blockid = $this->getPlainJsonObject()->blockid; + $this->speed = $this->getPlainJsonObject()->speed; + $this->distance = $this->getPlainJsonObject()->distance; + + // Build callback + $wayPointCallback = new RecordCallback(); + $wayPointCallback->rawCallback = $data; + $wayPointCallback->setPlayer($this->player); + $wayPointCallback->blockId = $this->blockid; + $wayPointCallback->time = $this->racetime; + $wayPointCallback->checkpoint = $this->checkpointinrace; + $wayPointCallback->isEndRace = Formatter::parseBoolean($this->isendrace); + $wayPointCallback->lapTime = $this->laptime; + $wayPointCallback->lapCheckpoint = $this->checkpointinlap; + $wayPointCallback->lap = 0; + $wayPointCallback->isEndLap = Formatter::parseBoolean($this->isendlap); + if ($wayPointCallback->checkpoint > 0) { + $currentMap = $this->maniaControl->getMapManager()->getCurrentMap(); + $wayPointCallback->lap += $wayPointCallback->checkpoint / $currentMap->nbCheckpoints; + } + if ($wayPointCallback->isEndRace) { + $wayPointCallback->name = $wayPointCallback::FINISH; + } else if ($wayPointCallback->isEndLap) { + $wayPointCallback->name = $wayPointCallback::LAPFINISH; + } else { + $wayPointCallback->name = $wayPointCallback::CHECKPOINT; + } + $this->maniaControl->getCallbackManager()->triggerCallback($wayPointCallback); + } + + /** + * Returns Server time when the event occured + * + * @return int + */ + public function getTime() { + return $this->time; + } + + /** + * < player who triggered the action + * + * @return \ManiaControl\Players\Player + */ + public function getPlayer() { + return $this->player; + } + +} \ No newline at end of file diff --git a/core/Callbacks/Structures/TrackMania/OnScoresStructure.php b/core/Callbacks/Structures/TrackMania/OnScoresStructure.php new file mode 100644 index 00000000..fafcdf1f --- /dev/null +++ b/core/Callbacks/Structures/TrackMania/OnScoresStructure.php @@ -0,0 +1,125 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnScoresStructure extends BaseStructure { + private $responseId; + private $section; + private $useTeams; + private $winnerTeam; + private $winnerPlayer; + private $teamScores = array(); + private $playerScores = array(); + + //TODO test + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $jsonObj = $this->getPlainJsonObject(); + + $this->responseId = $jsonObj->responseId; + $this->section = $jsonObj->section; + $this->useTeams = $jsonObj->useTeams; + $this->winnerTeam = $jsonObj->winnerTeam; + + $this->winnerPlayer = $this->maniaControl->getPlayerManager()->getPlayer($jsonObj->winnerplayer); + + foreach ($jsonObj->teams as $team) { + $teamScore = new TeamScore(); + $teamScore->setId($team->id); + $teamScore->setName($team->name); + $teamScore->setRoundPoints($team->roundpoints); + $teamScore->setMatchPoints($team->matchpoints); + $teamScore->setMapPoints($team->mappoints); + + $this->teamScores[$team->id] = $teamScore; //TODO verify that different teams have different ids + } + + foreach ($jsonObj->players as $jsonPlayer) { + $playerScore = new PlayerScore(); + $playerScore->setPlayer($this->maniaControl->getPlayerManager()->getPlayer($jsonPlayer->login)); + $playerScore->setRank($jsonPlayer->rank); + $playerScore->setRoundPoints($jsonPlayer->roundpoints); + $playerScore->setMapPoints($jsonPlayer->mappoints); + + $this->playerScores[$jsonPlayer->login] = $playerScore; + } + + } + + /** + * Get the Winner Player Object + * + * @return \ManiaControl\Players\Player + */ + public function getWinnerPlayer() { + return $this->winnerPlayer; + } + + /** + * Get the Response Id + * + * @return string + */ + public function getResponseId() { + return $this->responseId; + } + + /** + * < Current progress of the match. Can be "" | "EndRound" | "EndMap" | "EndMatch" + * + * @return string + */ + public function getSection() { + return $this->section; + } + + /** + * Returns if the GameMode uses Teams or not + * + * @return boolean + */ + public function getUseTeams() { + return $this->useTeams; + } + + /** + * Get the Winner Team Id + * + * @return int + */ + public function getWinnerTeamId() { + return $this->winnerTeam; + } + + /** + * Returns the TeamScores + * + * @return TeamScore[] + */ + public function getTeamScores() { + return $this->teamScores; + } + + /** + * Get the Player Scores + * + * @return PlayerScore[] + */ + public function getPlayerScores() { + return $this->playerScores; + } +} \ No newline at end of file diff --git a/core/Callbacks/TrackManiaCallbacks.php b/core/Callbacks/TrackManiaCallbacks.php index 8c5090ef..298bbe2e 100644 --- a/core/Callbacks/TrackManiaCallbacks.php +++ b/core/Callbacks/TrackManiaCallbacks.php @@ -4,6 +4,10 @@ namespace ManiaControl\Callbacks; use ManiaControl\Callbacks\Models\RecordCallback; use ManiaControl\Callbacks\Structures\TrackMania\OnDefaultEventStructure; +use ManiaControl\Callbacks\Structures\TrackMania\OnEventStartLineStructure; +use ManiaControl\Callbacks\Structures\TrackMania\OnCommandStructure; +use ManiaControl\Callbacks\Structures\TrackMania\OnScoresStructure; +use ManiaControl\Callbacks\Structures\TrackMania\OnEventWayPointStructure; use ManiaControl\ManiaControl; use ManiaControl\Utils\Formatter; @@ -21,6 +25,7 @@ class TrackManiaCallbacks implements CallbackListener { /** @var ManiaControl $maniaControl */ private $maniaControl = null; + /** * Create a new TrackMania Callbacks Instance * @@ -32,12 +37,6 @@ class TrackManiaCallbacks implements CallbackListener { // Register for script callbacks $callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks'); - - - // Register for callbacks - $callbackManager->registerCallbackListener(Callbacks::ONWAYPOINT, $this, 'handleOnWayPointCallback'); - $callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpointCallback'); - $callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinishCallback'); } /** @@ -52,9 +51,41 @@ class TrackManiaCallbacks implements CallbackListener { } switch ($name) { //MP4 New Callbacks + case Callbacks::TM_SCORES: + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_SCORES, new OnScoresStructure($this->maniaControl, $data)); + break; case Callbacks::TM_ONEVENTDEFAULT: $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONEVENTDEFAULT, new OnDefaultEventStructure($this->maniaControl, $data)); break; + case Callbacks::TM_ONEVENTSTARTLINE: + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONEVENTSTARTLINE, new OnEventStartLineStructure($this->maniaControl, $data)); + break; + case Callbacks::TM_ONCOMMAND: + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONCOMMAND, new OnCommandStructure($this->maniaControl, $data)); + break; + case Callbacks::TM_ONPLAYERADDED: + break; + case Callbacks::TM_ONPLAYERREMOVED: + break; + case Callbacks::TM_ONWAYPOINT: + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONWAYPOINT, new OnEventWayPointStructure($this->maniaControl, $data)); + break; + case Callbacks:: TM_ONGIVEUP: + break; + case Callbacks::TM_ONRESPAWN: + break; + case Callbacks::TM_ONSTUNT: + break; + case Callbacks::TM_ONSTARTCOUNTDOWN: + break; + case Callbacks::TM_WARMUPSTART: + break; + case Callbacks::TM_WARMUPSTARTROUND: + break; + case Callbacks::TM_WARMUPENDROUND: + break; + case Callbacks::TM_WARMUPEND: + break; } } From 4e546f64041708e5b73dc81e9aabe95d9cc9b81a Mon Sep 17 00:00:00 2001 From: kremsy Date: Wed, 29 Mar 2017 18:29:02 +0200 Subject: [PATCH 2/2] cb fix --- .../ShootMania/OnHitNearMissArmorEmptyStructure.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/Callbacks/Structures/ShootMania/OnHitNearMissArmorEmptyStructure.php b/core/Callbacks/Structures/ShootMania/OnHitNearMissArmorEmptyStructure.php index 740e9c6b..f0b56e2c 100644 --- a/core/Callbacks/Structures/ShootMania/OnHitNearMissArmorEmptyStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnHitNearMissArmorEmptyStructure.php @@ -43,7 +43,6 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure { $jsonObj = $this->getPlainJsonObject(); $this->time = $jsonObj->time; $this->weapon = $jsonObj->weapon; - $this->damage = $jsonObj->damage; //TODO does only exist on onhit -> make baseclass $this->shooterPosition = new Position(); $this->shooterPosition->setX($jsonObj->shooterposition->x); @@ -59,6 +58,10 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure { $this->distance = $this->getPlainJsonObject()->distance; } + if (property_exists($this->getPlainJsonObject(), 'damage')) { + $this->damage = $this->getPlainJsonObject()->damage; + } + $this->shooter = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->shooter); $this->victim = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->victim); }