From d6995f211d33035323ed1daf5786706a49cf329a Mon Sep 17 00:00:00 2001 From: kremsy Date: Sat, 25 Mar 2017 20:19:45 +0100 Subject: [PATCH] callback implementation --- core/Callbacks/Callbacks.php | 22 ++--- core/Callbacks/LibXmlRpcCallbacks.php | 2 +- core/Callbacks/ShootManiaCallbacks.php | 22 ++++- .../Structures/ShootMania/Models/Landmark.php | 6 -- .../ShootMania/Models/PlayerScore.php | 8 +- .../Structures/ShootMania/Models/Position.php | 2 +- .../ShootMania/Models/TeamScore.php | 8 +- .../Structures/ShootMania/Models/Weapons.php | 17 ++++ .../ShootMania/OnCommandStructure.php | 57 ++++++++++++ .../ShootMania/OnCustomEventStructure.php | 14 +++ ...ucture.php => OnDefaultEventStructure.php} | 2 +- .../ShootMania/OnFallDamageStructure.php | 50 +++++++++++ .../OnPlayerRequestRespawnStructure.php | 50 +++++++++++ .../ShootMania/OnShootStructure.php | 8 +- .../ShootMania/OnShotDenyStructure.php | 88 +++++++++++++++++++ .../TrackMania/OnCommandStructure.php | 57 ++++++++++++ .../OnDefaultEventStructure.php} | 4 +- core/Callbacks/TrackManiaCallbacks.php | 8 +- 18 files changed, 380 insertions(+), 45 deletions(-) create mode 100644 core/Callbacks/Structures/ShootMania/Models/Weapons.php create mode 100644 core/Callbacks/Structures/ShootMania/OnCommandStructure.php create mode 100644 core/Callbacks/Structures/ShootMania/OnCustomEventStructure.php rename core/Callbacks/Structures/ShootMania/{DefaultEventStructure.php => OnDefaultEventStructure.php} (93%) create mode 100644 core/Callbacks/Structures/ShootMania/OnFallDamageStructure.php create mode 100644 core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php create mode 100644 core/Callbacks/Structures/ShootMania/OnShotDenyStructure.php create mode 100644 core/Callbacks/Structures/TrackMania/OnCommandStructure.php rename core/Callbacks/Structures/{Trackmania/DefaultEventStructure.php => TrackMania/OnDefaultEventStructure.php} (87%) diff --git a/core/Callbacks/Callbacks.php b/core/Callbacks/Callbacks.php index b74f331f..b997a1f9 100644 --- a/core/Callbacks/Callbacks.php +++ b/core/Callbacks/Callbacks.php @@ -63,17 +63,17 @@ interface Callbacks { const SM_SCORES = "Shootmania.Scores"; - const SM_EVENTDEFAULT = "Shootmania.Event.Default"; - const SM_ONSHOOT = "Shootmania.Event.OnShoot"; - const SM_ONHIT = "Shootmania.Event.OnHit"; - const SM_ONNEARMISS = "Shootmania.Event.OnNearMiss"; - const SM_ONARMOREMPTY = "Shootmania.Event.OnArmorEmpty"; - const SM_ONCAPTURE = "Shootmania.Event.OnCapture"; - const SM_ONSHOTDENY = "Shootmania.Event.OnShotDeny"; - const SM_ONFALLDAMAGE = "Shootmania.Event.OnFallDamage"; - const SM_ONCOMMAND = "Shootmania.Event.OnCommand"; + const SM_ONEVENTDEFAULT = "Shootmania.Event.Default"; + const SM_ONSHOOT = "Shootmania.Event.OnShoot"; + const SM_ONHIT = "Shootmania.Event.OnHit"; + const SM_ONNEARMISS = "Shootmania.Event.OnNearMiss"; + const SM_ONARMOREMPTY = "Shootmania.Event.OnArmorEmpty"; + const SM_ONCAPTURE = "Shootmania.Event.OnCapture"; + const SM_ONSHOTDENY = "Shootmania.Event.OnShotDeny"; + const SM_ONFALLDAMAGE = "Shootmania.Event.OnFallDamage"; + const SM_ONCOMMAND = "Shootmania.Event.OnCommand"; //Shootmania.Event.OnPlayerRemoved Shootmania.Event.OnPlayerAdded not needed yet - const SM_ONPLAYERREQUESTRESAWPN = "Shootmania.Event.OnPlayerRequestRespawn"; + const SM_ONPLAYERREQUESTRESPAWN = "Shootmania.Event.OnPlayerRequestRespawn"; const SM_ONACTIONCUSTOMEVENT = "Shootmania.Event.OnActionCustomEvent"; const SM_ONACTIONEVENT = "Shootmania.Event.OnActionEvent"; const SM_ONPLAYERTOUCHESOBJECT = "Shootmania.Event.OnPlayerTouchesObject"; @@ -82,7 +82,7 @@ interface Callbacks { const SM_ONPLAYERREQUESTACTIONCHANGE = "Shootmania.Event.OnPlayerRequestActionChange"; - const TM_EVENTDEFAULT = "Trackmania.Event.Default"; + const TM_ONEVENTDEFAULT = "Trackmania.Event.Default"; //ManiaControl Callbacks /** BeginMap Callback: Map */ diff --git a/core/Callbacks/LibXmlRpcCallbacks.php b/core/Callbacks/LibXmlRpcCallbacks.php index a5dbdc19..5f2adfc7 100644 --- a/core/Callbacks/LibXmlRpcCallbacks.php +++ b/core/Callbacks/LibXmlRpcCallbacks.php @@ -46,7 +46,7 @@ class LibXmlRpcCallbacks implements CallbackListener { public function handleScriptCallback($name, $data) { var_dump($name); if (!$this->maniaControl->getCallbackManager()->callbackListeningExists($name)) { - return; + //return; //Leave that disabled while testing/implementing Callbacks } switch ($name) { //New callbacks diff --git a/core/Callbacks/ShootManiaCallbacks.php b/core/Callbacks/ShootManiaCallbacks.php index 547dc125..4a7f2d21 100644 --- a/core/Callbacks/ShootManiaCallbacks.php +++ b/core/Callbacks/ShootManiaCallbacks.php @@ -4,10 +4,13 @@ namespace ManiaControl\Callbacks; use ManiaControl\Callbacks\Models\RecordCallback; use ManiaControl\Callbacks\Structures\EliteBeginTurnStructure; -use ManiaControl\Callbacks\Structures\ShootMania\DefaultEventStructure; 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\OnPlayerRequestRespawnStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnShootStructure; +use ManiaControl\Callbacks\Structures\ShootMania\OnShotDenyStructure; use ManiaControl\ManiaControl; /** @@ -53,12 +56,12 @@ class ShootManiaCallbacks implements CallbackListener { */ public function handleScriptCallbacks($name, $data) { if (!$this->maniaControl->getCallbackManager()->callbackListeningExists($name)) { - return; + //return; //Leave that disabled while testing/implementing Callbacks } switch ($name) { //MP4 New Callbacks - case Callbacks::SM_EVENTDEFAULT: - $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_EVENTDEFAULT, new DefaultEventStructure($this->maniaControl, $data)); + case Callbacks::SM_ONEVENTDEFAULT: + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONEVENTDEFAULT, new OnDefaultEventStructure($this->maniaControl, $data)); break; case Callbacks::SM_ONSHOOT: $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONSHOOT, new OnShootStructure($this->maniaControl, $data)); @@ -75,6 +78,17 @@ class ShootManiaCallbacks implements CallbackListener { case Callbacks::SM_ONCAPTURE: $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONCAPTURE, new OnCaptureStructure($this->maniaControl, $data)); break; + 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: + break; //Old Callbacks case 'LibXmlRpc_Rankings': $this->maniaControl->getServer()->getRankingManager()->updateRankings($data[0]); diff --git a/core/Callbacks/Structures/ShootMania/Models/Landmark.php b/core/Callbacks/Structures/ShootMania/Models/Landmark.php index 81e0f2b3..bcf87d87 100644 --- a/core/Callbacks/Structures/ShootMania/Models/Landmark.php +++ b/core/Callbacks/Structures/ShootMania/Models/Landmark.php @@ -1,10 +1,4 @@ + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +interface Weapons { + const LASER = 1; + const ROCKET = 2; + const NUCLEUS = 3; + const ARROW = 5; +} diff --git a/core/Callbacks/Structures/ShootMania/OnCommandStructure.php b/core/Callbacks/Structures/ShootMania/OnCommandStructure.php new file mode 100644 index 00000000..5140daaf --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/OnCommandStructure.php @@ -0,0 +1,57 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnCommandStructure extends BaseStructure { + public $time; + public $name; + public $value; + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->time = $this->getPlainJsonObject()->time; + $this->name = $this->getPlainJsonObject()->name; + $this->value = $this->getPlainJsonObject()->value; + } + + /** Dumps the Object with some Information */ + public function dump() { + parent::dump(); + var_dump("With getShooter() you get a Player Object"); + } + + /** + * @return int + */ + public function getTime() { + return $this->time; + } + + /** + * @return mixed + */ + public function getName() { + return $this->name; + } + + /** + * @return \ManiaControl\Players\Player + */ + public function getValue() { + return $this->value; + } + + +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnCustomEventStructure.php b/core/Callbacks/Structures/ShootMania/OnCustomEventStructure.php new file mode 100644 index 00000000..7137f8d6 --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/OnCustomEventStructure.php @@ -0,0 +1,14 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnFallDamageStructure extends BaseStructure { + public $time; + /** + * @var Player $shooter + */ + private $victim; + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->time = $this->getPlainJsonObject()->time; + $this->victim = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->victim); + } + + /** + * @return int + */ + public function getTime() { + return $this->time; + } + + /** + * @return Player + */ + public function getVictim() { + return $this->victim; + } + + /** Dumps the Object with some Information */ + public function dump() { + parent::dump(); + var_dump("With getVictim() you get a Player Object"); + } +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php b/core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php new file mode 100644 index 00000000..dcf98c07 --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php @@ -0,0 +1,50 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnPlayerRequestRespawnStructure extends BaseStructure { + public $time; + /** + * @var Player $shooter + */ + 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()->victim); + } + + /** + * @return int + */ + public function getTime() { + return $this->time; + } + + /** + * @return Player + */ + public function getPlayer() { + return $this->player; + } + + /** Dumps the Object with some Information */ + public function dump() { + parent::dump(); + var_dump("With getPlayer() you get a Player Object"); + } +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnShootStructure.php b/core/Callbacks/Structures/ShootMania/OnShootStructure.php index 2f2e9dcc..2b3b69c5 100644 --- a/core/Callbacks/Structures/ShootMania/OnShootStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnShootStructure.php @@ -7,6 +7,13 @@ use ManiaControl\Callbacks\Structures\BaseStructure; use ManiaControl\ManiaControl; use ManiaControl\Players\Player; +/** + * Structure Class for the OnShoot Structure Callback + * + * @author ManiaControl Team + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ class OnShootStructure extends BaseStructure { public $time; public $weapon; @@ -15,7 +22,6 @@ class OnShootStructure extends BaseStructure { */ private $shooter; - //TODO test public function __construct(ManiaControl $maniaControl, $data) { parent::__construct($maniaControl, $data); diff --git a/core/Callbacks/Structures/ShootMania/OnShotDenyStructure.php b/core/Callbacks/Structures/ShootMania/OnShotDenyStructure.php new file mode 100644 index 00000000..6b496d9d --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/OnShotDenyStructure.php @@ -0,0 +1,88 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnShotDenyStructure extends BaseStructure { + public $time; + public $shooterWeapon; + public $victimWeapon; + + protected $shooter; + protected $victim; + + /** + * Construct a new On Hit Structure + * + * @param ManiaControl $maniaControl + * @param array $data + */ + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $jsonObj = $this->getPlainJsonObject(); + $this->time = $jsonObj->time; + $this->shooterWeapon = $jsonObj->victim; + $this->victimWeapon = $jsonObj->damage; + + $this->shooter = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->shooter); + $this->victim = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->victim); + } + + /** Dumps the Object with some Information */ + public function dump() { + parent::dump(); + var_dump("With getShooter() you get a Player Object"); + var_dump("With getVictim() you get a Player Object"); + } + + /** + * @return int + */ + public function getTime() { + return $this->time; + } + + + /** + * @return Player + */ + public function getShooter() { + return $this->shooter; + } + + /** + * @return Player + */ + public function getVictim() { + return $this->victim; + } + + /** + * @return mixed + */ + public function getShooterWeapon() { + return $this->shooterWeapon; + } + + /** + * @return mixed + */ + public function getVictimWeapon() { + return $this->victimWeapon; + } + + +} \ No newline at end of file diff --git a/core/Callbacks/Structures/TrackMania/OnCommandStructure.php b/core/Callbacks/Structures/TrackMania/OnCommandStructure.php new file mode 100644 index 00000000..dd8fc655 --- /dev/null +++ b/core/Callbacks/Structures/TrackMania/OnCommandStructure.php @@ -0,0 +1,57 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnCommandStructure extends BaseStructure { + public $time; + public $name; + public $value; + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->time = $this->getPlainJsonObject()->time; + $this->name = $this->getPlainJsonObject()->name; + $this->value = $this->getPlainJsonObject()->value; + } + + /** Dumps the Object with some Information */ + public function dump() { + parent::dump(); + var_dump("With getShooter() you get a Player Object"); + } + + /** + * @return int + */ + public function getTime() { + return $this->time; + } + + /** + * @return mixed + */ + public function getName() { + return $this->name; + } + + /** + * @return \ManiaControl\Players\Player + */ + public function getValue() { + return $this->value; + } + + +} \ No newline at end of file diff --git a/core/Callbacks/Structures/Trackmania/DefaultEventStructure.php b/core/Callbacks/Structures/TrackMania/OnDefaultEventStructure.php similarity index 87% rename from core/Callbacks/Structures/Trackmania/DefaultEventStructure.php rename to core/Callbacks/Structures/TrackMania/OnDefaultEventStructure.php index 80d63848..0d4abec8 100644 --- a/core/Callbacks/Structures/Trackmania/DefaultEventStructure.php +++ b/core/Callbacks/Structures/TrackMania/OnDefaultEventStructure.php @@ -1,6 +1,6 @@ maniaControl->getCallbackManager()->callbackListeningExists($name)) { - return; + //return; //Leave that disabled while testing/implementing Callbacks } switch ($name) { //MP4 New Callbacks - case Callbacks::TM_EVENTDEFAULT: - $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_EVENTDEFAULT, new DefaultEventStructure($this->maniaControl, $data)); + case Callbacks::TM_ONEVENTDEFAULT: + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONEVENTDEFAULT, new OnDefaultEventStructure($this->maniaControl, $data)); break; } }