TrackManiaControl/core/Statistics/StatisticCollector.php

574 lines
22 KiB
PHP
Raw Permalink Normal View History

2013-12-31 21:41:52 +01:00
<?php
namespace ManiaControl\Statistics;
2013-12-31 21:41:52 +01:00
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
use ManiaControl\Callbacks\Structures\ManiaPlanet\StartEndStructure;
2017-03-31 22:07:00 +02:00
use ManiaControl\Callbacks\Structures\ShootMania\Models\Weapons;
use ManiaControl\Callbacks\Structures\ShootMania\OnArmorEmptyStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnCaptureStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnHitStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnNearMissStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerRequestRespawnStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnShootStructure;
2013-12-31 21:41:52 +01:00
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
2014-03-02 10:27:55 +01:00
use ManiaControl\Players\PlayerManager;
2013-12-31 21:41:52 +01:00
/**
* Statistic Collector Class
*
2014-05-02 17:50:30 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
2020-01-22 10:39:35 +01:00
* @copyright 2014-2020 ManiaControl Team
2014-05-02 17:50:30 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
2017-03-31 22:07:00 +02:00
class StatisticCollector implements CallbackListener { //TODO remove old callbacks later
/*
2013-12-31 21:41:52 +01:00
* Constants
*/
const SETTING_COLLECT_STATS_ENABLED = 'Collect Stats Enabled';
2014-05-13 18:26:38 +02:00
const SETTING_COLLECT_STATS_MINPLAYERS = 'Minimum Player Count for Collecting Stats';
const SETTING_ON_SHOOT_PRESTORE = 'Prestore Shots before Insert into Database';
2013-12-31 21:41:52 +01:00
/*
* Statistics
*/
2014-01-11 18:24:44 +01:00
const STAT_PLAYTIME = 'Play Time';
2014-02-06 21:18:25 +01:00
const STAT_MAP_WINS = 'Map Wins';
2014-01-04 00:11:12 +01:00
const STAT_ON_SHOOT = 'Shots';
2014-01-03 18:37:51 +01:00
const STAT_ON_NEARMISS = 'Near Misses';
const STAT_ON_CAPTURE = 'Captures';
const STAT_ON_HIT = 'Hits';
const STAT_ON_GOT_HIT = 'Got Hits';
const STAT_ON_DEATH = 'Deaths';
const STAT_ON_PLAYER_REQUEST_RESPAWN = 'Respawns';
const STAT_ON_KILL = 'Kills';
const STAT_LASER_SHOT = 'Laser Shots';
2014-01-28 22:27:33 +01:00
const STAT_LASER_HIT = 'Laser Hits';
const STAT_ROCKET_SHOT = 'Rocket Shots';
2014-01-28 22:27:33 +01:00
const STAT_ROCKET_HIT = 'Rocket Hits';
const STAT_ARROW_SHOT = 'Arrow Shots';
2014-01-28 22:27:33 +01:00
const STAT_ARROW_HIT = 'Arrow Hits';
const STAT_NUCLEUS_SHOT = 'Nucleus Shots';
2014-01-28 22:27:33 +01:00
const STAT_NUCLEUS_HIT = 'Nucleus Hits';
2014-01-03 19:14:07 +01:00
const SPECIAL_STAT_KILL_DEATH_RATIO = 'Kill / Death';
/*
* Private properties
2013-12-31 21:41:52 +01:00
*/
/** @var ManiaControl $maniaControl */
2013-12-31 21:41:52 +01:00
private $maniaControl = null;
private $onShootArray = array();
2014-01-02 13:35:52 +01:00
private $startPlayLoopTime = -1;
2013-12-31 21:41:52 +01:00
/**
* Construct a new statistic collector instance
2013-12-31 21:41:52 +01:00
*
* @param ManiaControl $maniaControl
2013-12-31 21:41:52 +01:00
*/
2014-03-01 11:11:50 +01:00
public function __construct(ManiaControl $maniaControl) {
2013-12-31 21:41:52 +01:00
$this->maniaControl = $maniaControl;
// Callbacks
2014-08-13 11:05:52 +02:00
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACK, $this, 'handleCallbacks');
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACKARRAY, $this, 'handleCallbacks');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'onPlayerDisconnect');
2013-12-31 21:41:52 +01:00
2017-03-31 22:07:00 +02:00
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::SM_ONHIT, $this, 'onHitCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::SM_ONSHOOT, $this, 'onShootCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::SM_ONNEARMISS, $this, 'onNearMissCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::SM_ONCAPTURE, $this, 'onCaptureCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_STARTPLAYLOOP, $this, 'onStartPlayLoop');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_ENDPLAYLOOP, $this, 'onEndPlayLoop');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::SM_ONPLAYERREMOVED, $this, 'onPlayerRemoved');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONPLAYERREMOVED, $this, 'onPlayerRemoved');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::SM_ONCAPTURE, $this, 'onCaptureCallback');
// Settings
2014-08-13 11:05:52 +02:00
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLLECT_STATS_ENABLED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS, 4);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ON_SHOOT_PRESTORE, 10);
2014-01-01 18:27:56 +01:00
}
2013-12-31 21:41:52 +01:00
2014-01-01 18:27:56 +01:00
/**
* Handle ManiaControl OnInit Callback
*
* @internal
2014-01-01 18:27:56 +01:00
*/
public function onInit() {
// Define Stats MetaData
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_PLAYTIME, StatisticManager::STAT_TYPE_TIME);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_MAP_WINS);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_SHOOT);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_NEARMISS);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_CAPTURE);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_HIT);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_GOT_HIT);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_DEATH);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_PLAYER_REQUEST_RESPAWN);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_KILL);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_LASER_HIT);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_LASER_SHOT);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_NUCLEUS_HIT);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_NUCLEUS_SHOT);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ROCKET_HIT);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ROCKET_SHOT);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ARROW_HIT);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ARROW_SHOT);
2013-12-31 21:41:52 +01:00
}
2017-03-31 22:07:00 +02:00
/**
* Checks if the Collecting is Enabled
*
* @api
2017-03-31 22:07:00 +02:00
* @return boolean
*/
public function isCollectingEnabled() {
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED);
}
/**
* Check for the Minimum Amount of Players to collect
*
* @api
2017-03-31 22:07:00 +02:00
* @return bool
*/
public function checkForMinimumPlayers() {
// Check for Minimum PlayerCount
return ($this->maniaControl->getPlayerManager()->getPlayerCount() < $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS));
}
/**
* Handles the onHitCallback
*
* @internal
2017-03-31 22:07:00 +02:00
* @param \ManiaControl\Callbacks\Structures\ShootMania\OnHitStructure $structure
*/
public function onHitCallback(OnHitStructure $structure) {
if (!$this->isCollectingEnabled() || !$this->checkForMinimumPlayers()) {
return;
}
if ($structure->getShooter()) {
$this->maniaControl->getStatisticManager()->incrementStat($this->getWeaponStat($structure->getWeapon(), false), $structure->getShooter());
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_HIT, $structure->getShooter());
}
if ($structure->getVictim()) {
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_GOT_HIT, $structure->getVictim());
}
}
/**
* Handles the onShoot Callback
*
* @internal
2017-03-31 22:07:00 +02:00
* @param \ManiaControl\Callbacks\Structures\ShootMania\OnShootStructure $structure
*/
public function onShootCallback(OnShootStructure $structure) {
if (!$this->isCollectingEnabled() || !$this->checkForMinimumPlayers()) {
return;
}
$this->handleOnShoot($structure->getShooter()->login, $structure->getWeapon());
}
/**
* Handles the OnNearMiss Callback
*
* @internal
2017-03-31 22:07:00 +02:00
* @param \ManiaControl\Callbacks\Structures\ShootMania\OnNearMissStructure $structure
*/
public function onNearMissCallback(OnNearMissStructure $structure) {
if (!$this->isCollectingEnabled() || !$this->checkForMinimumPlayers()) {
return;
}
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_NEARMISS, $structure->getShooter());
}
/**
* Handles the OnCapture Callback
*
* @internal
2017-03-31 22:07:00 +02:00
* @param \ManiaControl\Callbacks\Structures\ShootMania\OnCaptureStructure $structure
*/
public function onCaptureCallback(OnCaptureStructure $structure) {
if (!$this->isCollectingEnabled() || !$this->checkForMinimumPlayers()) {
return;
}
foreach ($structure->getPlayerArray() as $player) {
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_CAPTURE, $player);
}
}
/**
* Handles the OnArmorEmpty Callback
*
* @internal
2017-03-31 22:07:00 +02:00
* @param \ManiaControl\Callbacks\Structures\ShootMania\OnArmorEmptyStructure $structure
*/
public function onArmorEmptyCallback(OnArmorEmptyStructure $structure) {
if (!$this->isCollectingEnabled() || !$this->checkForMinimumPlayers()) {
return;
}
if ($structure->getShooter()) {
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_KILL, $structure->getShooter());
}
if ($structure->getVictim()) {
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_DEATH, $structure->getVictim());
}
}
/**
* Handles the OnPlayerRequestRespawn Callback
*
* @internal
2017-03-31 22:07:00 +02:00
* @param \ManiaControl\Callbacks\Structures\ShootMania\OnPlayerRequestRespawnStructure $structure
*/
public function onPlayerRequestRespawnCallback(OnPlayerRequestRespawnStructure $structure) {
if (!$this->isCollectingEnabled() || !$this->checkForMinimumPlayers()) {
return;
}
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $structure->getPlayer());
}
2014-02-06 21:18:25 +01:00
/**
* Handle EndMap
*
* @internal
2014-02-06 21:18:25 +01:00
* @param array $callback
*/
public function onEndMap(array $callback) {
//Check for Minimum PlayerCount
2017-03-31 22:07:00 +02:00
if ($this->maniaControl->getPlayerManager()->getPlayerCount() < $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)) {
2014-02-06 21:18:25 +01:00
return;
}
2014-08-13 11:05:52 +02:00
$leaders = $this->maniaControl->getServer()->getRankingManager()->getLeaders();
2014-02-06 21:18:25 +01:00
2014-05-02 17:50:30 +02:00
foreach ($leaders as $leaderLogin) {
2014-08-13 11:05:52 +02:00
$leader = $this->maniaControl->getPlayerManager()->getPlayer($leaderLogin);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_MAP_WINS, $leader);
2014-02-06 21:18:25 +01:00
}
}
/**
* Insert OnShoot Statistic when a player leaves
2014-01-02 13:35:52 +01:00
*
* @internal
* @param Player $player
*/
public function onPlayerDisconnect(Player $player) {
if (!$this->isCollectingEnabled() || !$this->checkForMinimumPlayers()) {
return;
}
// Insert Data into Database, and destroy player
2014-01-28 22:27:33 +01:00
if (isset($this->onShootArray[$player->login])) {
if ($this->onShootArray[$player->login] > 0) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->getServer()->index, $this->onShootArray[$player->login]);
}
unset($this->onShootArray[$player->login]);
}
}
/**
* Update PlayTime if the Player leaves
*
* @internal
* @param \ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure $structure
*/
public function onPlayerRemoved(BasePlayerTimeStructure $structure) {
if (!$this->isCollectingEnabled() || !$this->checkForMinimumPlayers()) {
return;
}
//Check if in a PlayLoop actually has been started
if ($this->startPlayLoopTime < 0) {
return;
}
$durationTime = ($structure->getTime() - $this->startPlayLoopTime) / 1000;
2017-05-12 21:34:41 +02:00
//TODO reverify why player can be 0
if($structure->getPlayer()){
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_PLAYTIME, $structure->getPlayer(), $this->maniaControl->getServer()->index, $durationTime);
}
}
/**
* Handles the PlayerTime on Join
*
* @internal
* @param \ManiaControl\Callbacks\Structures\ManiaPlanet\StartEndStructure $structure
*/
public function onStartPlayLoop(StartEndStructure $structure) {
$this->startPlayLoopTime = $structure->getTime();
}
/**
* Handles The Playtime Statistic on EndPlayerLoop
*
* @internal
* @param \ManiaControl\Callbacks\Structures\ManiaPlanet\StartEndStructure $structure
*/
public function onEndPlayLoop(StartEndStructure $structure) {
// Check if Stat Collecting is enabled
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)) {
return;
}
//Check if in a PlayLoop actually has been started
if ($this->startPlayLoopTime < 0) {
return;
}
$durationTime = ($structure->getTime() - $this->startPlayLoopTime) / 1000;
foreach ($this->maniaControl->getPlayerManager()->getPlayers() as $player) {
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_PLAYTIME, $player, $this->maniaControl->getServer()->index, $durationTime);
}
$this->startPlayLoopTime = -1;
}
2013-12-31 21:41:52 +01:00
/**
* Handle stats on callbacks
*
* @deprecated
* @internal
2013-12-31 21:41:52 +01:00
* @param array $callback
*/
2014-05-13 16:03:26 +02:00
public function handleCallbacks(array $callback) {
//TODO remove later, only used for MP3
2014-05-13 16:03:26 +02:00
//TODO survivals
2014-05-27 22:44:22 +02:00
// Check if Stat Collecting is enabled
2017-03-31 22:07:00 +02:00
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)) {
2013-12-31 21:41:52 +01:00
return;
}
2014-05-27 22:44:22 +02:00
// Check for Minimum PlayerCount
2017-03-31 22:07:00 +02:00
if ($this->maniaControl->getPlayerManager()->getPlayerCount() < $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)) {
2013-12-31 21:41:52 +01:00
return;
}
$callbackName = $callback[1][0];
2017-03-31 22:07:00 +02:00
//TODO remove later
2014-05-02 17:50:30 +02:00
switch ($callbackName) {
case 'LibXmlRpc_OnShoot':
2014-01-31 19:00:01 +01:00
$this->handleOnShoot($callback[1][1][0], $callback[1][1][1]);
break;
case 'LibXmlRpc_OnHit':
2014-08-13 11:05:52 +02:00
$shooter = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][0]);
$victim = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][1]);
2014-01-24 22:34:35 +01:00
$weapon = $callback[1][1][3];
2014-04-09 11:11:22 +02:00
if ($shooter) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->incrementStat($this->getWeaponStat(intval($weapon), false), $shooter);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_HIT, $shooter);
2014-04-09 11:11:22 +02:00
}
if ($victim) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_GOT_HIT, $victim);
2014-04-09 11:11:22 +02:00
}
break;
case 'LibXmlRpc_OnNearMiss':
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][0]);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_NEARMISS, $player);
break;
case 'LibXmlRpc_OnCapture':
2014-01-05 19:15:27 +01:00
$logins = $callback[1][1][0];
$logins = explode(';', $logins);
2014-05-02 17:50:30 +02:00
foreach ($logins as $login) {
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
2014-01-28 22:27:33 +01:00
if (!$player) {
2014-01-11 18:24:44 +01:00
continue;
}
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_CAPTURE, $player);
2014-01-05 19:15:27 +01:00
}
break;
case 'LibXmlRpc_OnArmorEmpty':
2014-08-13 11:05:52 +02:00
$victim = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][1]);
2014-02-13 20:46:40 +01:00
if (isset($callback[1][1][0])) {
2014-08-13 11:05:52 +02:00
$shooter = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][0]);
if ($shooter) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_KILL, $shooter);
2014-02-15 16:42:18 +01:00
}
2014-01-11 18:24:44 +01:00
}
2014-03-02 10:27:55 +01:00
if ($victim) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_DEATH, $victim);
2014-03-02 10:27:55 +01:00
}
break;
case 'LibXmlRpc_OnPlayerRequestRespawn':
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][0]);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
break;
case 'OnShoot':
$paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) {
$this->handleOnShoot($paramsObject->Event->Shooter->Login, $paramsObject->Event->WeaponNum);
}
break;
case 'OnNearMiss':
$paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) {
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Shooter->Login);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_NEARMISS, $player);
}
break;
case 'OnCapture':
$paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) {
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Player->Login);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_CAPTURE, $player);
}
break;
case 'OnHit':
$paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) {
2017-03-31 22:07:00 +02:00
$weapon = (int) $paramsObject->Event->WeaponNum;
if (isset($paramsObject->Event->Shooter)) {
2014-08-13 11:05:52 +02:00
$shooter = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Shooter->Login);
if ($shooter) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->incrementStat($this->getWeaponStat($weapon, false), $shooter);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_HIT, $shooter);
}
2014-06-14 17:10:06 +02:00
}
if (isset($paramsObject->Event->Victim)) {
2014-08-13 11:05:52 +02:00
$victim = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Victim->Login);
if ($victim) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_GOT_HIT, $victim);
}
2014-06-14 17:10:06 +02:00
}
2014-04-09 11:11:22 +02:00
}
break;
case 'OnArmorEmpty':
$paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) {
2014-08-13 11:05:52 +02:00
$victim = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Victim->Login);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_DEATH, $victim);
if (isset($paramsObject->Event->Shooter->Login)) {
2014-08-13 11:05:52 +02:00
$shooter = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Shooter->Login);
if ($shooter) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_KILL, $shooter);
}
2014-02-15 16:42:18 +01:00
}
2014-01-11 18:24:44 +01:00
}
break;
case 'OnRequestRespawn':
$paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) {
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Player->Login);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
}
break;
2017-03-31 22:07:00 +02:00
case 'EndTurn': //TODO make it for other modes working //TODO also not available in MP4 atm
2014-01-11 18:24:44 +01:00
$paramsObject = json_decode($callback[1][1]);
2014-07-29 00:00:07 +02:00
if ($paramsObject && is_array($paramsObject->ScoresTable)) {
2017-03-31 22:07:00 +02:00
$durationTime = (int) (($paramsObject->EndTime - $paramsObject->StartTime) / 1000);
2014-07-29 00:00:07 +02:00
foreach ($paramsObject->ScoresTable as $score) {
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($score->Login);
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_PLAYTIME, $player, -1, $durationTime);
2014-07-29 00:00:07 +02:00
}
2014-01-11 18:24:44 +01:00
}
break;
}
2013-12-31 21:41:52 +01:00
}
2014-05-02 17:50:30 +02:00
/**
* Handle Player Shots
*
* @param string $login
* @param int $weaponNumber
*/
private function handleOnShoot($login, $weaponNumber) {
2017-03-31 22:07:00 +02:00
//TODO update to player in MP4
2014-05-02 17:50:30 +02:00
if (!isset($this->onShootArray[$login])) {
2017-03-31 22:07:00 +02:00
$this->onShootArray[$login] = array(Weapons::ROCKET => 0, Weapons::ARROW => 0, Weapons::NUCLEUS => 0, Weapons::LASER => 0);
2014-05-02 17:50:30 +02:00
}
2014-06-14 16:44:49 +02:00
if (!isset($this->onShootArray[$login][$weaponNumber])) {
$this->onShootArray[$login][$weaponNumber] = 0;
}
$this->onShootArray[$login][$weaponNumber]++;
2014-05-02 17:50:30 +02:00
//Write Shoot Data into database
2017-03-31 22:07:00 +02:00
if (array_sum($this->onShootArray[$login]) > $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ON_SHOOT_PRESTORE)) {
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
2014-05-02 17:50:30 +02:00
2017-03-31 22:07:00 +02:00
$rocketShots = $this->onShootArray[$login][Weapons::ROCKET];
$laserShots = $this->onShootArray[$login][Weapons::LASER];
$arrowShots = $this->onShootArray[$login][Weapons::ARROW];
$nucleusShots = $this->onShootArray[$login][Weapons::NUCLEUS];
2014-05-02 17:50:30 +02:00
if ($rocketShots > 0) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_ROCKET_SHOT, $player, $this->maniaControl->getServer()->index, $rocketShots);
2017-03-31 22:07:00 +02:00
$this->onShootArray[$login][Weapons::ROCKET] = 0;
2014-05-02 17:50:30 +02:00
}
if ($laserShots > 0) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_LASER_SHOT, $player, $this->maniaControl->getServer()->index, $laserShots);
2017-03-31 22:07:00 +02:00
$this->onShootArray[$login][Weapons::LASER] = 0;
2014-05-02 17:50:30 +02:00
}
if ($arrowShots > 0) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_ARROW_SHOT, $player, $this->maniaControl->getServer()->index, $arrowShots);
2017-03-31 22:07:00 +02:00
$this->onShootArray[$login][Weapons::ARROW] = 0;
2014-05-02 17:50:30 +02:00
}
if ($nucleusShots > 0) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_NUCLEUS_SHOT, $player, $this->maniaControl->getServer()->index, $nucleusShots);
2017-03-31 22:07:00 +02:00
$this->onShootArray[$login][Weapons::NUCLEUS] = 0;
2014-05-02 17:50:30 +02:00
}
2014-08-13 11:05:52 +02:00
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->getServer()->index, $rocketShots + $laserShots + $arrowShots + $nucleusShots);
2014-05-02 17:50:30 +02:00
}
}
/**
* Get the Weapon stat
*
* @param int $weaponNumber
* @param bool $shot
* @return string
*/
private function getWeaponStat($weaponNumber, $shot = true) {
if ($shot) {
switch ($weaponNumber) {
2017-03-31 22:07:00 +02:00
case Weapons::ROCKET:
2014-05-02 17:50:30 +02:00
return self::STAT_ROCKET_SHOT;
2017-03-31 22:07:00 +02:00
case Weapons::LASER:
2014-05-02 17:50:30 +02:00
return self::STAT_LASER_SHOT;
2017-03-31 22:07:00 +02:00
case Weapons::ARROW:
2014-05-02 17:50:30 +02:00
return self::STAT_ARROW_SHOT;
2017-03-31 22:07:00 +02:00
case Weapons::NUCLEUS:
2014-05-02 17:50:30 +02:00
return self::STAT_NUCLEUS_SHOT;
default:
return -1;
}
} else {
switch ($weaponNumber) {
2017-03-31 22:07:00 +02:00
case Weapons::ROCKET:
2014-05-02 17:50:30 +02:00
return self::STAT_ROCKET_HIT;
2017-03-31 22:07:00 +02:00
case Weapons::LASER:
2014-05-02 17:50:30 +02:00
return self::STAT_LASER_HIT;
2017-03-31 22:07:00 +02:00
case Weapons::ARROW:
2014-05-02 17:50:30 +02:00
return self::STAT_ARROW_HIT;
2017-03-31 22:07:00 +02:00
case Weapons::NUCLEUS:
2014-05-02 17:50:30 +02:00
return self::STAT_NUCLEUS_HIT;
default:
return -1;
}
}
}
2013-12-31 21:41:52 +01:00
}