From 5a7ee1c9bec90c1be95440cf9e8ec13b790a9f9c Mon Sep 17 00:00:00 2001 From: kremsy Date: Mon, 27 Mar 2017 22:21:59 +0200 Subject: [PATCH] finished first version of shootmania callbacks --- core/Callbacks/ShootManiaCallbacks.php | 21 +++++ .../Structures/ShootMania/Models/Landmark.php | 14 ++- .../ShootMania/Models/PlayerScore.php | 89 +++++++++++++++++- .../Structures/ShootMania/Models/Position.php | 15 ++- .../ShootMania/Models/TeamScore.php | 15 ++- .../OnActionCustomEventStructure.php | 91 +++++++++++++++++++ .../Structures/ShootMania/OnActionEvent.php | 58 ++++++++++++ .../ShootMania/OnCustomEventStructure.php | 14 --- .../ShootMania/OnPlayerObjectStructure.php | 80 ++++++++++++++++ .../OnPlayerRequestActionChange.php | 58 ++++++++++++ .../OnPlayerRequestRespawnStructure.php | 1 - .../OnPlayerTriggersSectorStructure.php | 59 ++++++++++++ .../ShootMania/OnScoresStructure.php | 25 +++-- 13 files changed, 510 insertions(+), 30 deletions(-) create mode 100644 core/Callbacks/Structures/ShootMania/OnActionCustomEventStructure.php create mode 100644 core/Callbacks/Structures/ShootMania/OnActionEvent.php delete mode 100644 core/Callbacks/Structures/ShootMania/OnCustomEventStructure.php create mode 100644 core/Callbacks/Structures/ShootMania/OnPlayerObjectStructure.php create mode 100644 core/Callbacks/Structures/ShootMania/OnPlayerRequestActionChange.php create mode 100644 core/Callbacks/Structures/ShootMania/OnPlayerTriggersSectorStructure.php diff --git a/core/Callbacks/ShootManiaCallbacks.php b/core/Callbacks/ShootManiaCallbacks.php index 4a7f2d21..3062f4db 100644 --- a/core/Callbacks/ShootManiaCallbacks.php +++ b/core/Callbacks/ShootManiaCallbacks.php @@ -4,11 +4,16 @@ namespace ManiaControl\Callbacks; use ManiaControl\Callbacks\Models\RecordCallback; use ManiaControl\Callbacks\Structures\EliteBeginTurnStructure; +use ManiaControl\Callbacks\Structures\ShootMania\OnActionCustomEventStructure; +use ManiaControl\Callbacks\Structures\ShootMania\OnActionEvent; use ManiaControl\Callbacks\Structures\ShootMania\OnCaptureStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnCommandStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnDefaultEventStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnHitNearMissArmorEmptyStructure; +use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerObjectStructure; +use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerRequestActionChange; use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerRequestRespawnStructure; +use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerTriggersSectorStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnShootStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnShotDenyStructure; use ManiaControl\ManiaControl; @@ -88,6 +93,22 @@ class ShootManiaCallbacks implements CallbackListener { $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)); break; //Old Callbacks case 'LibXmlRpc_Rankings': diff --git a/core/Callbacks/Structures/ShootMania/Models/Landmark.php b/core/Callbacks/Structures/ShootMania/Models/Landmark.php index af562863..79c0847e 100644 --- a/core/Callbacks/Structures/ShootMania/Models/Landmark.php +++ b/core/Callbacks/Structures/ShootMania/Models/Landmark.php @@ -3,7 +3,19 @@ namespace ManiaControl\Callbacks\Structures\ShootMania\Models; -class Landmark { +use ManiaControl\General\UsageInformationAble; +use ManiaControl\General\UsageInformationTrait; + +/** + * Landmark Model + * + * @author ManiaControl Team + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class Landmark implements UsageInformationAble { + use UsageInformationTrait; + private $tag = ""; private $order = 0; private $id = ""; diff --git a/core/Callbacks/Structures/ShootMania/Models/PlayerScore.php b/core/Callbacks/Structures/ShootMania/Models/PlayerScore.php index 7e4aeedf..8e695dbc 100644 --- a/core/Callbacks/Structures/ShootMania/Models/PlayerScore.php +++ b/core/Callbacks/Structures/ShootMania/Models/PlayerScore.php @@ -2,7 +2,92 @@ namespace ManiaControl\Callbacks\Structures\ShootMania\Models; -//TODO describtion -class PlayerScore { +use ManiaControl\General\UsageInformationAble; +use ManiaControl\General\UsageInformationTrait; +use ManiaControl\Players\Player; +/** + * PlayerScore Model + * + * @author ManiaControl Team + * @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; + + /** + * 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; + } } \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/Models/Position.php b/core/Callbacks/Structures/ShootMania/Models/Position.php index 7fa88c3c..0fe28187 100644 --- a/core/Callbacks/Structures/ShootMania/Models/Position.php +++ b/core/Callbacks/Structures/ShootMania/Models/Position.php @@ -3,8 +3,19 @@ namespace ManiaControl\Callbacks\Structures\ShootMania\Models; -//TODO describtion -class Position { +use ManiaControl\General\UsageInformationAble; +use ManiaControl\General\UsageInformationTrait; + +/** + * Position Model + * + * @author ManiaControl Team + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class Position implements UsageInformationAble { + use UsageInformationTrait; + private $x = 0; private $y = 0; private $z = 0; diff --git a/core/Callbacks/Structures/ShootMania/Models/TeamScore.php b/core/Callbacks/Structures/ShootMania/Models/TeamScore.php index a300aea0..b1557bb5 100644 --- a/core/Callbacks/Structures/ShootMania/Models/TeamScore.php +++ b/core/Callbacks/Structures/ShootMania/Models/TeamScore.php @@ -2,8 +2,19 @@ namespace ManiaControl\Callbacks\Structures\ShootMania\Models; -//TODO describtion -class TeamScore { +use ManiaControl\General\UsageInformationAble; +use ManiaControl\General\UsageInformationTrait; + +/** + * TeamScore Model + * + * @author ManiaControl Team + * @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; diff --git a/core/Callbacks/Structures/ShootMania/OnActionCustomEventStructure.php b/core/Callbacks/Structures/ShootMania/OnActionCustomEventStructure.php new file mode 100644 index 00000000..25a28022 --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/OnActionCustomEventStructure.php @@ -0,0 +1,91 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnActionCustomEventStructure extends BaseStructure { + private $time; + private $actionId; + private $shooter; + private $victim; + private $param1; + private $param2 = array(); + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->time = $this->getPlainJsonObject()->time; + $this->actionId = $this->getPlainJsonObject()->actionid; + + $this->victim = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->victim); + $this->shooter = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->shooter); + + $this->param1 = $this->getPlainJsonObject()->param1; + $this->param2 = $this->getPlainJsonObject()->param2; + } + + /** + * Returns Server time when the event occured + * + * @return int + */ + public function getTime() { + return $this->time; + } + + /** + * < Id of the action that triggered the event + * + * @return string + */ + public function getActionId() { + return $this->actionId; + } + + /** + * < Login of the player who shot if any + * + * @return \ManiaControl\Players\Player + */ + public function getShooter() { + return $this->shooter; + } + + /** + * < player who got hit if any + * + * @return \ManiaControl\Players\Player + */ + public function getVictim() { + return $this->victim; + } + + /** + * < First custom param of the event + * + * @return string + */ + public function getParam1() { + return $this->param1; + } + + /** + * < Second custom param of the event + * + * @return array + */ + public function getParam2() { + return $this->param2; + } + +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnActionEvent.php b/core/Callbacks/Structures/ShootMania/OnActionEvent.php new file mode 100644 index 00000000..badad2f0 --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/OnActionEvent.php @@ -0,0 +1,58 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnActionEvent extends BaseStructure { + private $time; + private $player; + private $actionInput; + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->time = $this->getPlainJsonObject()->time; + $this->actionInput = $this->getPlainJsonObject()->actioninput; + + $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; + } + + /** + * < The input pressed to trigger the action + * + * @return string + */ + public function getActionInput() { + return $this->actionInput; + } + + +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnCustomEventStructure.php b/core/Callbacks/Structures/ShootMania/OnCustomEventStructure.php deleted file mode 100644 index 7137f8d6..00000000 --- a/core/Callbacks/Structures/ShootMania/OnCustomEventStructure.php +++ /dev/null @@ -1,14 +0,0 @@ - + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnPlayerObjectStructure extends BaseStructure { + private $time; + private $player; + private $objectId; + private $modelId; + private $modelName; + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->time = $this->getPlainJsonObject()->time; + $this->objectId = $this->getPlainJsonObject()->objectid; + $this->modelId = $this->getPlainJsonObject()->modelid; + $this->modelName = $this->getPlainJsonObject()->modelname; + + $this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login); + } + + /** + * Returns Server time when the event occured + * + * @return int + */ + public function getTime() { + return $this->time; + } + + /** + * < Login of the player who touched the object + * + * @return \ManiaControl\Players\Player + */ + public function getPlayer() { + return $this->player; + } + + /** + * < The id of the object + * + * @return string + */ + public function getObjectId() { + return $this->objectId; + } + + /** + * < The id of the object model + * + * @return string + */ + public function getModelId() { + return $this->modelId; + } + + /** + * < The name of the object model + * + * @return string + */ + public function getModelName() { + return $this->modelName; + } + + +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnPlayerRequestActionChange.php b/core/Callbacks/Structures/ShootMania/OnPlayerRequestActionChange.php new file mode 100644 index 00000000..8e0e8a28 --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/OnPlayerRequestActionChange.php @@ -0,0 +1,58 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnPlayerRequestActionChange extends BaseStructure { + private $time; + private $player; + private $actionChange; + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->time = $this->getPlainJsonObject()->time; + $this->actionChange = $this->getPlainJsonObject()->actionChange; + + $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 requested a new action + * + * @return \ManiaControl\Players\Player + */ + public function getPlayer() { + return $this->player; + } + + /** + * < Can be -1 (request previous action) or 1 (request next action) + * + * @return string + */ + public function getActionChange() { + return $this->actionChange; + } + + +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php b/core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php index 4419e9c5..a9ea16a3 100644 --- a/core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php @@ -27,7 +27,6 @@ class OnPlayerRequestRespawnStructure extends BaseStructure { $this->time = $this->getPlainJsonObject()->time; $this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login); - $this->getUsage(); } /** diff --git a/core/Callbacks/Structures/ShootMania/OnPlayerTriggersSectorStructure.php b/core/Callbacks/Structures/ShootMania/OnPlayerTriggersSectorStructure.php new file mode 100644 index 00000000..8f9b9824 --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/OnPlayerTriggersSectorStructure.php @@ -0,0 +1,59 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnPlayerTriggersSectorStructure extends BaseStructure { + private $time; + private $player; + private $sectorId; + + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->time = $this->getPlainJsonObject()->time; + $this->sectorId = $this->getPlainJsonObject()->sectorid; + + $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 touched the object + * + * @return \ManiaControl\Players\Player + */ + public function getPlayer() { + return $this->player; + } + + /** + * < Id of the triggered sector + * + * @return string + */ + public function getSectorId() { + return $this->sectorId; + } + + +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnScoresStructure.php b/core/Callbacks/Structures/ShootMania/OnScoresStructure.php index 5f171665..a759d015 100644 --- a/core/Callbacks/Structures/ShootMania/OnScoresStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnScoresStructure.php @@ -4,6 +4,7 @@ namespace ManiaControl\Callbacks\Structures\ShootMania; use ManiaControl\Callbacks\Structures\BaseStructure; +use ManiaControl\Callbacks\Structures\ShootMania\Models\PlayerScore; use ManiaControl\Callbacks\Structures\ShootMania\Models\TeamScore; use ManiaControl\ManiaControl; @@ -20,8 +21,8 @@ class OnScoresStructure extends BaseStructure { private $useTeams; private $winnerTeam; private $winnerPlayer; - private $teamScores = array(); - private $players; //TODO implement + private $teamScores = array(); + private $playerScores = array(); //TODO test public function __construct(ManiaControl $maniaControl, $data) { @@ -47,7 +48,16 @@ class OnScoresStructure extends BaseStructure { $this->teamScores[$team->id] = $teamScore; //TODO verify that different teams have different ids } - //TODO implement player + 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; + } + } /** @@ -105,12 +115,11 @@ class OnScoresStructure extends BaseStructure { } /** - * Get The Player Scores + * Get the Player Scores * - * @return mixed + * @return PlayerScore[] */ - public function getPlayers() { - //TODO proper implementation - return $this->players; + public function getPlayerScores() { + return $this->playerScores; } } \ No newline at end of file