From bd2c5a8c9c1d5b98383e9afc76144bedc66e66d8 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sat, 25 Mar 2017 11:53:55 +0100 Subject: [PATCH] added some callbacks --- core/Callbacks/Callbacks.php | 2 + core/Callbacks/ShootManiaCallbacks.php | 16 +++- .../Structures/ShootMania/Models/Landmark.php | 73 ++++++++++++++++ .../Structures/ShootMania/Models/Position.php | 53 ++++++++++++ .../ShootMania/OnCaptureStructure.php | 86 +++++++++++++++++++ ...p => OnHitNearMissArmorEmptyStructure.php} | 37 ++++++-- .../Structures/ShootMania/Position.php | 9 -- 7 files changed, 256 insertions(+), 20 deletions(-) create mode 100644 core/Callbacks/Structures/ShootMania/Models/Landmark.php create mode 100644 core/Callbacks/Structures/ShootMania/Models/Position.php create mode 100644 core/Callbacks/Structures/ShootMania/OnCaptureStructure.php rename core/Callbacks/Structures/ShootMania/{OnHitStructure.php => OnHitNearMissArmorEmptyStructure.php} (65%) delete mode 100644 core/Callbacks/Structures/ShootMania/Position.php diff --git a/core/Callbacks/Callbacks.php b/core/Callbacks/Callbacks.php index 3fddc9e2..95b89745 100644 --- a/core/Callbacks/Callbacks.php +++ b/core/Callbacks/Callbacks.php @@ -60,6 +60,8 @@ interface Callbacks { const MP_PODIUMSTART = 'Callbacks.ManiaPlanetPodiumStart'; const MP_PODIUMEND = 'Callbacks.ManiaPlanetPodiumEnd'; + const SM_SCORES = "Shootmania.Scores"; + const SM_EVENTDEFAULT = "Shootmania.Event.Default"; const SM_ONSHOOT = "Shootmania.Event.OnShoot"; const SM_ONHIT = "Shootmania.Event.OnHit"; diff --git a/core/Callbacks/ShootManiaCallbacks.php b/core/Callbacks/ShootManiaCallbacks.php index 4ed857b8..535069a7 100644 --- a/core/Callbacks/ShootManiaCallbacks.php +++ b/core/Callbacks/ShootManiaCallbacks.php @@ -5,7 +5,8 @@ namespace ManiaControl\Callbacks; use ManiaControl\Callbacks\Models\RecordCallback; use ManiaControl\Callbacks\Structures\EliteBeginTurnStructure; use ManiaControl\Callbacks\Structures\ShootMania\DefaultEventStructure; -use ManiaControl\Callbacks\Structures\ShootMania\OnHitStructure; +use ManiaControl\Callbacks\Structures\ShootMania\OnCaptureStructure; +use ManiaControl\Callbacks\Structures\ShootMania\OnHitNearMissArmorEmptyStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnShootStructure; use ManiaControl\ManiaControl; @@ -60,9 +61,18 @@ class ShootManiaCallbacks implements CallbackListener { $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)); + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONHIT, new OnHitNearMissArmorEmptyStructure($this->maniaControl, $data)); + break; + case Callbacks::SM_ONNEARMISS: + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONNEARMISS, new OnHitNearMissArmorEmptyStructure($this->maniaControl, $data)); + break; + case Callbacks::SM_ONARMOREMPTY: + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONARMOREMPTY, new OnHitNearMissArmorEmptyStructure($this->maniaControl, $data)); + break; + case Callbacks::SM_ONCAPTURE: + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONCAPTURE, new OnCaptureStructure($this->maniaControl, $data)); + break; 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 new file mode 100644 index 00000000..ae61ad1e --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/Models/Landmark.php @@ -0,0 +1,73 @@ +tag; + } + + /** + * @param mixed $tag + */ + public function setTag($tag) { + $this->tag = $tag; + } + + /** + * @return mixed + */ + public function getOrder() { + return $this->order; + } + + /** + * @param mixed $order + */ + public function setOrder($order) { + $this->order = $order; + } + + /** + * @return mixed + */ + public function getId() { + return $this->id; + } + + /** + * @param mixed $id + */ + public function setId($id) { + $this->id = $id; + } + + /** + * @return mixed + */ + public function getPosition() { + return $this->position; + } + + /** + * @param mixed $position + */ + public function setPosition(Position $position) { + $this->position = $position; + } +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/Models/Position.php b/core/Callbacks/Structures/ShootMania/Models/Position.php new file mode 100644 index 00000000..155410a7 --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/Models/Position.php @@ -0,0 +1,53 @@ +x; + } + + /** + * @param int $x + */ + public function setX($x) { + $this->x = $x; + } + + /** + * @return int + */ + public function getZ() { + return $this->z; + } + + /** + * @param int $z + */ + public function setZ($z) { + $this->z = $z; + } + + /** + * @return int + */ + public function getY() { + return $this->y; + } + + /** + * @param int $y + */ + public function setY($y) { + $this->y = $y; + } +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnCaptureStructure.php b/core/Callbacks/Structures/ShootMania/OnCaptureStructure.php new file mode 100644 index 00000000..799a86f7 --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/OnCaptureStructure.php @@ -0,0 +1,86 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnCaptureStructure extends BaseStructure { + + public $time; + public $landMark; + + private $playerArray = array(); + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $jsonObj = $this->getPlainJsonObject(); + + $this->time = $jsonObj->time; + $this->playerArray = $jsonObj->players; + + $this->landMark = new Landmark(); + $this->landMark->setTag($jsonObj->landmark->tag); + $this->landMark->setOrder($jsonObj->landmark->tag); + $this->landMark->setId($jsonObj->landmark->tag); + + $position = new Position(); + $position->setX($jsonObj->landmark->position->x); + $position->setY($jsonObj->landmark->position->y); + $position->setZ($jsonObj->landmark->position->z); + + $this->landMark->setPosition($position); + + $this->shooter = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->shooter); + } + + + /** + * Get the logins + * + * @return array + */ + public function getLoginArray() { + return $this->playerArray; + } + + /** + * Get the players + * + * @return Player[] + */ + public function getPlayerArray() { + $playerArray = array(); + foreach ($this->playerArray as $login) { + $player = $this->maniaControl->getPlayerManager()->getPlayer($login); + if ($player) { + $playerArray[$login] = $player; + } + } + return $playerArray; + } + + /** + * @return LandMark + */ + public function getLandMark() { + return $this->landMark; + } + + /** + * @param mixed $landMark + */ + public function setLandMark(Landmark $landMark) { + $this->landMark = $landMark; + } +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnHitStructure.php b/core/Callbacks/Structures/ShootMania/OnHitNearMissArmorEmptyStructure.php similarity index 65% rename from core/Callbacks/Structures/ShootMania/OnHitStructure.php rename to core/Callbacks/Structures/ShootMania/OnHitNearMissArmorEmptyStructure.php index 666f5aa8..92e18693 100644 --- a/core/Callbacks/Structures/ShootMania/OnHitStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnHitNearMissArmorEmptyStructure.php @@ -15,12 +15,13 @@ use ManiaControl\Players\Player; * @copyright 2014-2017 ManiaControl Team * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -class OnHitStructure extends BaseStructure { +class OnHitNearMissArmorEmptyStructure extends BaseStructure { public $time; public $weapon; public $damage; public $shooterPosition; public $victimPosition; + public $distance = 0; //Note no distance on the OnHit and ArmorEmpty yet protected $shooter; protected $victim; @@ -38,11 +39,24 @@ class OnHitStructure extends BaseStructure { public function __construct(ManiaControl $maniaControl, $data) { parent::__construct($maniaControl, $data); - $this->time = $this->getPlainJsonObject()->time; - $this->weapon = $this->getPlainJsonObject()->weapon; - $this->damage = $this->getPlainJsonObject()->damage; - $this->shooterPosition = $this->getPlainJsonObject()->shooterPosition; - $this->victimPosition = $this->getPlainJsonObject()->victimPosition; + $jsonObj = $this->getPlainJsonObject(); + $this->time = $jsonObj->time; + $this->weapon = $jsonObj->weapon; + $this->damage = $jsonObj->damage; + + $this->shooterPosition = new Position(); + $this->shooterPosition->setX($jsonObj->shooterposition->x); + $this->shooterPosition->setY($jsonObj->shooterposition->y); + $this->shooterPosition->setZ($jsonObj->shooterposition->z); + + $this->victimPosition = new Position(); + $this->victimPosition->setX($jsonObj->victimposition->x); + $this->victimPosition->setY($jsonObj->victimposition->y); + $this->victimPosition->setZ($jsonObj->victimposition->z); + + if (property_exists($this->getPlainJsonObject(), 'distance')) { + $this->distance = $this->getPlainJsonObject()->distance; + } $this->shooter = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->shooter); $this->victim = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->victim); @@ -72,7 +86,7 @@ class OnHitStructure extends BaseStructure { /** * TODO Position Object * - * @return Object + * @return Position */ public function getShooterPosition() { return $this->shooterPosition; @@ -81,7 +95,7 @@ class OnHitStructure extends BaseStructure { /** * TODO Position Object * - * @return Object + * @return Position */ public function getVictimPosition() { return $this->victimPosition; @@ -101,6 +115,13 @@ class OnHitStructure extends BaseStructure { return $this->victim; } + /** + * @return mixed + */ + public function getDistance() { + return $this->distance; + } + /** Dumps the Object with some Information */ public function dump() { parent::dump(); diff --git a/core/Callbacks/Structures/ShootMania/Position.php b/core/Callbacks/Structures/ShootMania/Position.php deleted file mode 100644 index 85df4951..00000000 --- a/core/Callbacks/Structures/ShootMania/Position.php +++ /dev/null @@ -1,9 +0,0 @@ -