playedtime stat (only elite yet)
This commit is contained in:
parent
e72e1e24c8
commit
a6e7ac785e
@ -22,6 +22,7 @@ class StatisticCollector implements CallbackListener {
|
|||||||
/*
|
/*
|
||||||
* Statistics
|
* Statistics
|
||||||
*/
|
*/
|
||||||
|
const STAT_PLAYTIME = 'Play Time';
|
||||||
const STAT_ON_SHOOT = 'Shots';
|
const STAT_ON_SHOOT = 'Shots';
|
||||||
const STAT_ON_NEARMISS = 'Near Misses';
|
const STAT_ON_NEARMISS = 'Near Misses';
|
||||||
const STAT_ON_CAPTURE = 'Captures';
|
const STAT_ON_CAPTURE = 'Captures';
|
||||||
@ -44,7 +45,7 @@ class StatisticCollector implements CallbackListener {
|
|||||||
*
|
*
|
||||||
* @param \ManiaControl\ManiaControl $maniaControl
|
* @param \ManiaControl\ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) { //TODO Stat player playtime without spec and warmup
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
//Register Callbacks
|
//Register Callbacks
|
||||||
@ -66,6 +67,7 @@ class StatisticCollector implements CallbackListener {
|
|||||||
*/
|
*/
|
||||||
public function onInit(array $callback) {
|
public function onInit(array $callback) {
|
||||||
//Define Stats MetaData
|
//Define Stats MetaData
|
||||||
|
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYTIME, StatisticManager::STAT_TYPE_TIME);
|
||||||
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_ON_SHOOT);
|
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_ON_SHOOT);
|
||||||
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_ON_NEARMISS);
|
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_ON_NEARMISS);
|
||||||
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_ON_CAPTURE);
|
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_ON_CAPTURE);
|
||||||
@ -125,7 +127,6 @@ class StatisticCollector implements CallbackListener {
|
|||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handleCallbacks(array $callback) {
|
public function handleCallbacks(array $callback) {
|
||||||
|
|
||||||
//Check if Stat Collecting is enabled
|
//Check if Stat Collecting is enabled
|
||||||
if(!$this->maniaControl->settingManager->getSetting($this, self::SETTING_COLLECT_STATS_ENABLED)) {
|
if(!$this->maniaControl->settingManager->getSetting($this, self::SETTING_COLLECT_STATS_ENABLED)) {
|
||||||
return;
|
return;
|
||||||
@ -157,15 +158,18 @@ class StatisticCollector implements CallbackListener {
|
|||||||
$logins = explode(';', $logins);
|
$logins = explode(';', $logins);
|
||||||
foreach($logins as $login) {
|
foreach($logins as $login) {
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
if (!$player) continue;
|
if(!$player) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_CAPTURE, $player);
|
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_CAPTURE, $player);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'LibXmlRpc_OnArmorEmpty':
|
case 'LibXmlRpc_OnArmorEmpty':
|
||||||
$shooter = $this->maniaControl->playerManager->getPlayer($callback[1][1][0]);
|
$shooter = $this->maniaControl->playerManager->getPlayer($callback[1][1][0]);
|
||||||
$victim = $this->maniaControl->playerManager->getPlayer($callback[1][1][1]);
|
$victim = $this->maniaControl->playerManager->getPlayer($callback[1][1][1]);
|
||||||
if($shooter != null)
|
if($shooter != null) {
|
||||||
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_KILL, $shooter);
|
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_KILL, $shooter);
|
||||||
|
}
|
||||||
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_DEATH, $victim);
|
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_DEATH, $victim);
|
||||||
break;
|
break;
|
||||||
case 'LibXmlRpc_OnPlayerRequestRespawn':
|
case 'LibXmlRpc_OnPlayerRequestRespawn':
|
||||||
@ -198,14 +202,24 @@ class StatisticCollector implements CallbackListener {
|
|||||||
$victim = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Victim->Login);
|
$victim = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Victim->Login);
|
||||||
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_DEATH, $victim);
|
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_DEATH, $victim);
|
||||||
$shooter = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Shooter->Login);
|
$shooter = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Shooter->Login);
|
||||||
if($shooter != null)
|
if($shooter != null) {
|
||||||
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_KILL, $shooter);
|
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_KILL, $shooter);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'OnRequestRespawn':
|
case 'OnRequestRespawn':
|
||||||
$paramsObject = json_decode($callback[1][1]);
|
$paramsObject = json_decode($callback[1][1]);
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Player->Login);
|
$player = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Player->Login);
|
||||||
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
|
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
|
||||||
break;
|
break;
|
||||||
|
case 'EndTurn': //TODO make it for other modes working
|
||||||
|
$paramsObject = json_decode($callback[1][1]);
|
||||||
|
$durationTime = (int)(($paramsObject->EndTime - $paramsObject->StartTime) / 1000);
|
||||||
|
$scoresTable = $paramsObject->ScoresTable;
|
||||||
|
foreach($scoresTable as $score) {
|
||||||
|
$player = $this->maniaControl->playerManager->getPlayer($score->Login);
|
||||||
|
$this->maniaControl->statisticManager->insertStat(self::STAT_PLAYTIME, $player, -1, $durationTime);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user