Merge remote-tracking branch 'origin/v0.2' into v0.2

This commit is contained in:
Jocy 2017-03-29 20:28:32 +02:00
commit b5d63d796d
10 changed files with 558 additions and 18 deletions

View File

@ -81,9 +81,24 @@ interface Callbacks {
const SM_ONPLAYERTHROWSOBJECT = "Shootmania.Event.OnPlayerThrowsObject";
const SM_ONPLAYERREQUESTACTIONCHANGE = "Shootmania.Event.OnPlayerRequestActionChange";
const TM_ONEVENTDEFAULT = "Trackmania.Event.Default";
// New TM Callbacks
const TM_ONEVENTDEFAULT = "Trackmania.Event.Default";
const TM_ONEVENTSTARTLINE = "Trackmania.Event.StartLine";
const TM_ONCOMMAND = "Trackmania.Event.OnCommand";
const TM_ONPLAYERADDED = "Trackmania.Event.OnPlayerAdded";
const TM_ONPLAYERREMOVED = "Trackmania.Event.OnPlayerRemoved";
const TM_ONWAYPOINT = "Trackmania.Event.WayPoint";
const TM_ONGIVEUP = "Trackmania.Event.GiveUp";
const TM_ONRESPAWN = "Trackmania.Event.Respawn";
const TM_ONSTUNT = "Trackmania.Event.Stunt";
const TM_ONSTARTCOUNTDOWN = "Trackmania.Event.StartCountdown";
const TM_SCORES = "Trackmania.Scores";
const TM_WARMUPSTART = "Trackmania.WarmUp.Start";
const TM_WARMUPSTARTROUND = "Trackmania.WarmUp.StartRound";
const TM_WARMUPENDROUND = "Trackmania.WarmUp.EndRound";
const TM_WARMUPEND = "Trackmania.WarmUp.End";
//ManiaControl Callbacks
/** BeginMap Callback: Map */
const BEGINMAP = 'Callbacks.BeginMap';

View File

@ -44,7 +44,6 @@ class LibXmlRpcCallbacks implements CallbackListener {
* @param mixed $data
*/
public function handleScriptCallback($name, $data) {
var_dump($name);
if (!$this->maniaControl->getCallbackManager()->callbackListeningExists($name)) {
//return; //Leave that disabled while testing/implementing Callbacks
}

View File

@ -20,12 +20,16 @@ class RecordCallback extends BaseCallback {
/*
* Public Properties
*/
public $isEndRace = null;
public $isEndLap = null;
public $time = null;
public $lapTime = null;
public $checkpoint = null;
public $lapCheckpoint = null;
public $lap = null;
public $blockId = null;
public $player = null;
public $racetime = null;
public $laptime = null;
public $stuntsscore = null;
public $checkpointinrace = null;
public $checkpointinlap = null;
public $isendrace = null;
public $isendlap = null;
public $blockid = null;
public $speed = null;
public $distance = null;
}

View File

@ -43,7 +43,6 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure {
$jsonObj = $this->getPlainJsonObject();
$this->time = $jsonObj->time;
$this->weapon = $jsonObj->weapon;
$this->damage = $jsonObj->damage; //TODO does only exist on onhit -> make baseclass
$this->shooterPosition = new Position();
$this->shooterPosition->setX($jsonObj->shooterposition->x);
@ -59,6 +58,10 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure {
$this->distance = $this->getPlainJsonObject()->distance;
}
if (property_exists($this->getPlainJsonObject(), 'damage')) {
$this->damage = $this->getPlainJsonObject()->damage;
}
$this->shooter = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->shooter);
$this->victim = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->victim);
}

View File

@ -0,0 +1,134 @@
<?php
namespace ManiaControl\Callbacks\Structures\TrackMania\Models;
use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait;
use ManiaControl\Players\Player;
/**
* PlayerScore Model
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @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;
private $matchPoints;
private $bestraceTime;
private $bestlapTime;
private $stuntScore;
/**
* 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;
}
/**
* Gets the bestRaceTime
*
* @param int $bestraceTime
*/
public function getbestraceTime(){
return $this->bestraceTime;
}
/**
* Gets the bestRaceTime
*
* @param int $bestraceTime
*/
public function getbestraceTime(){
return $this->bestraceTime;
}
/**
* Gets the bestlapTime
*
* @param int $bestlapTime
*/
public function getbestlapTime(){
return $this->bestlapTime;
}
/**
* Gets the StuntScore
*
* @param int $bestraceTime
*/
public function getstuntScore(){
return $this->stuntScore;
}
}

View File

@ -0,0 +1,93 @@
<?php
namespace ManiaControl\Callbacks\Structures\TrackMania\Models;
use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait;
/**
* TeamScore Model
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @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;
private $mapPoints;
private $matchPoints;
/**
* @return mixed
*/
public function getId() {
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id) {
$this->id = $id;
}
/**
* @return mixed
*/
public function getName() {
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name) {
$this->name = $name;
}
/**
* @return mixed
*/
public function getRoundPoints() {
return $this->roundPoints;
}
/**
* @param mixed $roundPoints
*/
public function setRoundPoints($roundPoints) {
$this->roundPoints = $roundPoints;
}
/**
* @return mixed
*/
public function getMapPoints() {
return $this->mapPoints;
}
/**
* @param mixed $mapPoints
*/
public function setMapPoints($mapPoints) {
$this->mapPoints = $mapPoints;
}
/**
* @return mixed
*/
public function getMatchPoints() {
return $this->matchPoints;
}
/**
* @param mixed $matchPoints
*/
public function setMatchPoints($matchPoints) {
$this->matchPoints = $matchPoints;
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace ManiaControl\Callbacks\Structures\TrackMania;
use ManiaControl\Callbacks\Structures\BaseStructure;
use ManiaControl\ManiaControl;
/**
* Structure Class for the EventStartLine 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 OnEventStartLineStructure extends BaseStructure {
private $time;
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()->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;
}
}

View File

@ -0,0 +1,92 @@
<?php
namespace ManiaControl\Callbacks\Structures\TrackMania;
use ManiaControl\Callbacks\Structures\BaseStructure;
use ManiaControl\Callbacks\Models\RecordCallback;
use ManiaControl\ManiaControl;
use ManiaControl\Utils\Formatter;
/**
* Structure Class for the Default Event 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 OnEventWayPointStructure extends BaseStructure {
private $time;
private $player;
private $racetime;
private $laptime;
private $stuntsscore;
private $checkpointinrace;
private $checkpointinlap;
private $isendrace;
private $isendlap;
private $blockid;
private $speed;
private $distance;
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$this->time = $this->getPlainJsonObject()->time;
$this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login);
$this->racetime = (int) $this->getPlainJsonObject()->racetime;
$this->laptime = (int) $this->getPlainJsonObject()->laptime;
$this->stuntsscore = $this->getPlainJsonObject()->stuntsscore;
$this->checkpointinrace = (int) $this->getPlainJsonObject()->checkpointinrace;
$this->checkpointinlap = (int) $this->getPlainJsonObject()->checkpointinlap;
$this->isendrace = $this->getPlainJsonObject()->isendrace;
$this->isendlap = $this->getPlainJsonObject()->isendlap;
$this->blockid = $this->getPlainJsonObject()->blockid;
$this->speed = $this->getPlainJsonObject()->speed;
$this->distance = $this->getPlainJsonObject()->distance;
// Build callback
$wayPointCallback = new RecordCallback();
$wayPointCallback->rawCallback = $data;
$wayPointCallback->setPlayer($this->player);
$wayPointCallback->blockId = $this->blockid;
$wayPointCallback->time = $this->racetime;
$wayPointCallback->checkpoint = $this->checkpointinrace;
$wayPointCallback->isEndRace = Formatter::parseBoolean($this->isendrace);
$wayPointCallback->lapTime = $this->laptime;
$wayPointCallback->lapCheckpoint = $this->checkpointinlap;
$wayPointCallback->lap = 0;
$wayPointCallback->isEndLap = Formatter::parseBoolean($this->isendlap);
if ($wayPointCallback->checkpoint > 0) {
$currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
$wayPointCallback->lap += $wayPointCallback->checkpoint / $currentMap->nbCheckpoints;
}
if ($wayPointCallback->isEndRace) {
$wayPointCallback->name = $wayPointCallback::FINISH;
} else if ($wayPointCallback->isEndLap) {
$wayPointCallback->name = $wayPointCallback::LAPFINISH;
} else {
$wayPointCallback->name = $wayPointCallback::CHECKPOINT;
}
$this->maniaControl->getCallbackManager()->triggerCallback($wayPointCallback);
}
/**
* 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;
}
}

View File

@ -0,0 +1,125 @@
<?php
namespace ManiaControl\Callbacks\Structures\TrackMania;
use ManiaControl\Callbacks\Structures\BaseStructure;
use ManiaControl\Callbacks\Structures\TrackMania\Models\PlayerScore;
use ManiaControl\Callbacks\Structures\TrackMania\Models\TeamScore;
use ManiaControl\ManiaControl;
/**
* Structure Class for the OnScores 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 OnScoresStructure extends BaseStructure {
private $responseId;
private $section;
private $useTeams;
private $winnerTeam;
private $winnerPlayer;
private $teamScores = array();
private $playerScores = array();
//TODO test
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$jsonObj = $this->getPlainJsonObject();
$this->responseId = $jsonObj->responseId;
$this->section = $jsonObj->section;
$this->useTeams = $jsonObj->useTeams;
$this->winnerTeam = $jsonObj->winnerTeam;
$this->winnerPlayer = $this->maniaControl->getPlayerManager()->getPlayer($jsonObj->winnerplayer);
foreach ($jsonObj->teams as $team) {
$teamScore = new TeamScore();
$teamScore->setId($team->id);
$teamScore->setName($team->name);
$teamScore->setRoundPoints($team->roundpoints);
$teamScore->setMatchPoints($team->matchpoints);
$teamScore->setMapPoints($team->mappoints);
$this->teamScores[$team->id] = $teamScore; //TODO verify that different teams have different ids
}
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;
}
}
/**
* Get the Winner Player Object
*
* @return \ManiaControl\Players\Player
*/
public function getWinnerPlayer() {
return $this->winnerPlayer;
}
/**
* Get the Response Id
*
* @return string
*/
public function getResponseId() {
return $this->responseId;
}
/**
* < Current progress of the match. Can be "" | "EndRound" | "EndMap" | "EndMatch"
*
* @return string
*/
public function getSection() {
return $this->section;
}
/**
* Returns if the GameMode uses Teams or not
*
* @return boolean
*/
public function getUseTeams() {
return $this->useTeams;
}
/**
* Get the Winner Team Id
*
* @return int
*/
public function getWinnerTeamId() {
return $this->winnerTeam;
}
/**
* Returns the TeamScores
*
* @return TeamScore[]
*/
public function getTeamScores() {
return $this->teamScores;
}
/**
* Get the Player Scores
*
* @return PlayerScore[]
*/
public function getPlayerScores() {
return $this->playerScores;
}
}

View File

@ -4,6 +4,10 @@ namespace ManiaControl\Callbacks;
use ManiaControl\Callbacks\Models\RecordCallback;
use ManiaControl\Callbacks\Structures\TrackMania\OnDefaultEventStructure;
use ManiaControl\Callbacks\Structures\TrackMania\OnEventStartLineStructure;
use ManiaControl\Callbacks\Structures\TrackMania\OnCommandStructure;
use ManiaControl\Callbacks\Structures\TrackMania\OnScoresStructure;
use ManiaControl\Callbacks\Structures\TrackMania\OnEventWayPointStructure;
use ManiaControl\ManiaControl;
use ManiaControl\Utils\Formatter;
@ -21,6 +25,7 @@ class TrackManiaCallbacks implements CallbackListener {
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/**
* Create a new TrackMania Callbacks Instance
*
@ -32,12 +37,6 @@ class TrackManiaCallbacks implements CallbackListener {
// Register for script callbacks
$callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks');
// Register for callbacks
$callbackManager->registerCallbackListener(Callbacks::ONWAYPOINT, $this, 'handleOnWayPointCallback');
$callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpointCallback');
$callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinishCallback');
}
/**
@ -52,9 +51,41 @@ class TrackManiaCallbacks implements CallbackListener {
}
switch ($name) {
//MP4 New Callbacks
case Callbacks::TM_SCORES:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_SCORES, new OnScoresStructure($this->maniaControl, $data));
break;
case Callbacks::TM_ONEVENTDEFAULT:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONEVENTDEFAULT, new OnDefaultEventStructure($this->maniaControl, $data));
break;
case Callbacks::TM_ONEVENTSTARTLINE:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONEVENTSTARTLINE, new OnEventStartLineStructure($this->maniaControl, $data));
break;
case Callbacks::TM_ONCOMMAND:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONCOMMAND, new OnCommandStructure($this->maniaControl, $data));
break;
case Callbacks::TM_ONPLAYERADDED:
break;
case Callbacks::TM_ONPLAYERREMOVED:
break;
case Callbacks::TM_ONWAYPOINT:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONWAYPOINT, new OnEventWayPointStructure($this->maniaControl, $data));
break;
case Callbacks:: TM_ONGIVEUP:
break;
case Callbacks::TM_ONRESPAWN:
break;
case Callbacks::TM_ONSTUNT:
break;
case Callbacks::TM_ONSTARTCOUNTDOWN:
break;
case Callbacks::TM_WARMUPSTART:
break;
case Callbacks::TM_WARMUPSTARTROUND:
break;
case Callbacks::TM_WARMUPENDROUND:
break;
case Callbacks::TM_WARMUPEND:
break;
}
}