From 5f7eff0660aecc3eb71d5f4daf1842bd5d22753c Mon Sep 17 00:00:00 2001 From: kremsy Date: Sat, 20 Dec 2014 18:43:51 +0100 Subject: [PATCH] callback improvements --- core/Callbacks/Callbacks.php | 6 +++ core/Callbacks/LibXmlRpcCallbacks.php | 8 ++- core/Callbacks/ShootManiaCallbacks.php | 7 +++ .../Structures/EliteBeginTurnStructure.php | 52 +++++++++++++++++++ core/Callbacks/Structures/VictoryTypes.php | 17 ++++++ 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 core/Callbacks/Structures/EliteBeginTurnStructure.php create mode 100644 core/Callbacks/Structures/VictoryTypes.php diff --git a/core/Callbacks/Callbacks.php b/core/Callbacks/Callbacks.php index 18d7dcd4..8ee9e493 100644 --- a/core/Callbacks/Callbacks.php +++ b/core/Callbacks/Callbacks.php @@ -98,6 +98,11 @@ interface Callbacks { /** OnPlayerRequestRespawn Callback: Player */ const ONPLAYERREQUESTRESPAWN = 'Callbacks.OnPlayerRequestRespawn'; + /** Elite OnBeginTurn Callback: EliteBeginTurnStructure */ + const ELITE_ONBEGINTURN = "Callbacks.EliteOnBeginTurn"; + /** Elite OnEndTurn Callback: integer (VictoryTypes) */ + const ELITE_ONENDTURN = "Callbacks.EliteOnEndTurn"; + /* * TrackMania Callbacks */ @@ -111,4 +116,5 @@ interface Callbacks { const ONRESPAWN = 'Callbacks.OnRespawn'; /** OnStunt Callback */ const ONSTUNT = 'Callbacks.OnStunt'; + } diff --git a/core/Callbacks/LibXmlRpcCallbacks.php b/core/Callbacks/LibXmlRpcCallbacks.php index 472b76b3..c02eecc0 100644 --- a/core/Callbacks/LibXmlRpcCallbacks.php +++ b/core/Callbacks/LibXmlRpcCallbacks.php @@ -61,6 +61,9 @@ class LibXmlRpcCallbacks implements CallbackListener { case 'LibXmlRpc_BeginTurn': $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINTURN, $data[0]); break; + case 'LibXmlRpc_BeginRound': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINROUND, $data[0]); + break; case 'LibXmlRpc_BeginPlaying': $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINPLAYING); break; @@ -71,6 +74,7 @@ class LibXmlRpcCallbacks implements CallbackListener { $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDTURN, $data[0]); break; case 'LibXmlRpc_EndRound': + var_dump("test"); $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDROUND, $data[0]); break; case 'LibXmlRpc_EndSubmatch': @@ -131,11 +135,11 @@ class LibXmlRpcCallbacks implements CallbackListener { $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONARMOREMPTY, new ArmorEmptyStructure($this->maniaControl, $data)); break; case 'LibXmlRpc_OnCapture': - $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONARMOREMPTY, new CaptureStructure($this->maniaControl, $data)); + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONCAPTURE, new CaptureStructure($this->maniaControl, $data)); break; case 'LibXmlRpc_OnPlayerRequestRespawn': $player = $this->maniaControl->getPlayerManager()->getPlayer($data[0]); - $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONARMOREMPTY, $player); + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONPLAYERREQUESTRESPAWN, $player); break; } } diff --git a/core/Callbacks/ShootManiaCallbacks.php b/core/Callbacks/ShootManiaCallbacks.php index bd371fec..d493ab75 100644 --- a/core/Callbacks/ShootManiaCallbacks.php +++ b/core/Callbacks/ShootManiaCallbacks.php @@ -3,6 +3,7 @@ namespace ManiaControl\Callbacks; use ManiaControl\Callbacks\Models\RecordCallback; +use ManiaControl\Callbacks\Structures\EliteBeginTurnStructure; use ManiaControl\ManiaControl; /** @@ -60,6 +61,12 @@ class ShootManiaCallbacks implements CallbackListener { case 'WarmUp_Status': $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::WARMUPSTATUS, $data[0]); break; + 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; case self::CB_TIMEATTACK_ONCHECKPOINT: $this->handleTimeAttackOnCheckpoint($name, $data); break; diff --git a/core/Callbacks/Structures/EliteBeginTurnStructure.php b/core/Callbacks/Structures/EliteBeginTurnStructure.php new file mode 100644 index 00000000..ffe5f787 --- /dev/null +++ b/core/Callbacks/Structures/EliteBeginTurnStructure.php @@ -0,0 +1,52 @@ +maniaControl = $maniaControl; + $this->attackerLogin = $data[0]; + $this->defenderLogins = $data[1]; + } + + /** + * Get the attacker + * + * @return Player + */ + public function getAttacker() { + return $this->maniaControl->getPlayerManager()->getPlayer($this->attackerLogin); + } + + /** + * Get the defenders as an Player Array + * + * @return Player[] + */ + public function getDefenders() { + $defenders = array(); + foreach (explode(";", $this->defenderLogins) as $defenderLogin) { + $defenders[] = $this->maniaControl->getPlayerManager()->getPlayer($defenderLogin); + } + + return $defenders; + } +} diff --git a/core/Callbacks/Structures/VictoryTypes.php b/core/Callbacks/Structures/VictoryTypes.php new file mode 100644 index 00000000..5c3cd754 --- /dev/null +++ b/core/Callbacks/Structures/VictoryTypes.php @@ -0,0 +1,17 @@ + + * @copyright 2014 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +interface VictoryTypes { + const TIME_LIMIT = 1; + const CAPTURE = 2; + const ATTACKER_ELIMINATED = 3; + const DEFENDERS_ELIMINATED = 4; +}