added some callbacks

This commit is contained in:
kremsy 2017-03-25 11:53:55 +01:00
parent f15dab5d42
commit bd2c5a8c9c
7 changed files with 256 additions and 20 deletions

View File

@ -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";

View File

@ -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]);

View File

@ -0,0 +1,73 @@
<?php
/**
* Created by PhpStorm.
* User: Lukas
* Date: 25. Mär. 2017
* Time: 11:37
*/
namespace ManiaControl\Callbacks\Structures\ShootMania;
class Landmark {
private $tag = "";
private $order = 0;
private $id = "";
private $position = null;
/**
* @return mixed
*/
public function getTag() {
return $this->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;
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace ManiaControl\Callbacks\Structures\ShootMania;
class Position {
private $x = 0;
private $y = 0;
private $z = 0;
/**
* @return int
*/
public function getX() {
return $this->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;
}
}

View File

@ -0,0 +1,86 @@
<?php
namespace ManiaControl\Callbacks\Structures\ShootMania;
use ManiaControl\Callbacks\Structures\BaseStructure;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
/**
* Structure Class for the OnCapture Structure Callback
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @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;
}
}

View File

@ -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();

View File

@ -1,9 +0,0 @@
<?php
namespace ManiaControl\Callbacks\Structures\ShootMania;
class Position {
//TODO x y z positions
}