callback improvements, new structures for shootmania callbacks

This commit is contained in:
kremsy 2014-10-10 16:19:46 +02:00
parent 1feeb768b2
commit 27efcabb6e
6 changed files with 120 additions and 6 deletions

View File

@ -84,12 +84,19 @@ interface Callbacks {
/** Returns if the GameMode has Warmup activated, returned after param1 Scores */ //returned after TODO
const WARMUPSTATUS = 'Callbacks.WarmupStatus';
/** OnShoot Callback: Player, WeaponNumber (see Weapons Structure) */
const ONSHOOT = 'Callbacks.OnShoot';
/** OnShoot Callback: PlayerHitStructure */
/** OnHit Callback: PlayerHitStructure */
const ONHIT = 'Callbacks.OnHit';
/** OnNearMiss Callback: NearMissStructure */
const ONNEARMISS = 'Callbacks.OnNearMiss';
/** OnArmorEmpty Callback: ArmorEmptyStructure */
const ONARMOREMPTY = 'Callbacks.OnArmorEmpty';
/** OnCapture Callback: CaptureStructure */
const ONCAPTURE = 'Callbacks.OnCapture';
/** OnPlayerRequestRespawn Callback: Player */
const ONPLAYERREQUESTRESPAWN = 'Callbacks.OnPlayerRequestRespawn';
/*
* TrackMania Callbacks

View File

@ -2,6 +2,9 @@
namespace ManiaControl\Callbacks;
use ManiaControl\Callbacks\Structures\ArmorEmptyStructure;
use ManiaControl\Callbacks\Structures\CaptureStructure;
use ManiaControl\Callbacks\Structures\NearMissStructure;
use ManiaControl\Callbacks\Structures\PlayerHitStructure;
use ManiaControl\ManiaControl;
@ -115,13 +118,26 @@ class LibXmlRpcCallbacks implements CallbackListener {
case 'LibXmlRpc_OnStunt':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONSTUNT, $data);
break;
case 'LibXmlRpc_OnShoot': //TODO testing
case 'LibXmlRpc_OnShoot':
$player = $this->maniaControl->getPlayerManager()->getPlayer($data[0]);
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONSHOOT, $player, $data[1]);
break;
case 'LibXmlRpc_OnHit':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONHIT, new PlayerHitStructure($this->maniaControl, $data));
break;
case 'LibXmlRpc_OnNearMiss':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONHIT, new NearMissStructure($this->maniaControl, $data));
break;
case 'LibXmlRpc_OnArmorEmpty':
$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));
break;
case 'LibXmlRpc_OnPlayerRequestRespawn':
$player = $this->maniaControl->getPlayerManager()->getPlayer($data[0]);
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONARMOREMPTY, $player);
break;
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace ManiaControl\Callbacks\Structures;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
class ArmorEmptyStructure {
private $shooter;
private $victim;
private $damage;
private $shooterPoints;
private $weapon;
/** @var ManiaControl $maniaControl */
private $maniaControl;
public function __construct(ManiaControl $maniaControl, $data) {
$this->shooter = $data[0];
$this->victim = $data[1];
$this->damage = $data[2];
$this->weapon = $data[3];
$this->shooterPoints = $data[4];
}
/**
* @return Player
*/
public function getShooter() {
$shooter = $this->maniaControl->getPlayerManager()->getPlayer($this->shooter);
return $shooter;
}
/**
* @return Player
*/
public function getVictim() {
$victim = $this->maniaControl->getPlayerManager()->getPlayer($this->victim);
return $victim;
}
/**
* @return int
*/
public function getDamage() {
return $this->damage;
}
/**
* @return int
*/
public function getShooterPoints() {
return $this->shooterPoints;
}
/**
* @return int
*/
public function getWeapon() { //TODO any way of returning type "Weapon?"
return $this->weapon;
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace ManiaControl\Callbacks\Structures;
use ManiaControl\Players\Player;
class CaptureStructure {
private $playerArray;
public function __construct($maniaControl, $data) {
$this->playerArray = $data;
}
/**
* @return mixed
*/
public function getLoginArray() {
return $this->playerArray;
}
/**
* @return Player[]
*/
public function getPlayerArray() {
//TODO build array with player objects
return $this->playerArray;
}
}

View File

@ -23,7 +23,7 @@ class NearMissStructure {
}
/**
* @return Player
* @return Player|null
*/
public function getShooter() {
$shooter = $this->maniaControl->getPlayerManager()->getPlayer($this->shooter);
@ -31,7 +31,7 @@ class NearMissStructure {
}
/**
* @return Player
* @return Player|null
*/
public function getVictim() {
$victim = $this->maniaControl->getPlayerManager()->getPlayer($this->victim);

View File

@ -24,7 +24,7 @@ class PlayerHitStructure {
}
/**
* @return Player
* @return Player|null
*/
public function getShooter() {
$shooter = $this->maniaControl->getPlayerManager()->getPlayer($this->shooter);
@ -32,7 +32,7 @@ class PlayerHitStructure {
}
/**
* @return Player
* @return Player|null
*/
public function getVictim() {
$victim = $this->maniaControl->getPlayerManager()->getPlayer($this->victim);