refactor codestyle (chaining)

This commit is contained in:
kremsy
2014-08-13 11:05:52 +02:00
parent 699c5951d9
commit 22915bb934
56 changed files with 1572 additions and 3132 deletions

View File

@ -68,22 +68,15 @@ class StatisticCollector implements CallbackListener {
$this->maniaControl = $maniaControl;
// Callbacks
$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');
$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');
// Settings
$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);
$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);
}
/**
@ -91,42 +84,24 @@ class StatisticCollector implements CallbackListener {
*/
public function onInit() {
// Define Stats MetaData
$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);
$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);
}
/**
@ -136,22 +111,16 @@ class StatisticCollector implements CallbackListener {
*/
public function onEndMap(array $callback) {
//Check for Minimum PlayerCount
if ($this->maniaControl->getPlayerManager()
->getPlayerCount() < $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)
if ($this->maniaControl->getPlayerManager()->getPlayerCount() < $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)
) {
return;
}
$leaders = $this->maniaControl->getServer()
->getRankingManager()
->getLeaders();
$leaders = $this->maniaControl->getServer()->getRankingManager()->getLeaders();
foreach ($leaders as $leaderLogin) {
$leader = $this->maniaControl->getPlayerManager()
->getPlayer($leaderLogin);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_MAP_WINS, $leader);
$leader = $this->maniaControl->getPlayerManager()->getPlayer($leaderLogin);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_MAP_WINS, $leader);
}
}
@ -162,8 +131,7 @@ class StatisticCollector implements CallbackListener {
*/
public function onPlayerDisconnect(Player $player) {
// Check if Stat Collecting is enabled
if (!$this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)
) {
return;
}
@ -171,8 +139,7 @@ class StatisticCollector implements CallbackListener {
// Insert Data into Database, and destroy player
if (isset($this->onShootArray[$player->login])) {
if ($this->onShootArray[$player->login] > 0) {
$this->maniaControl->getStatisticManager()
->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->getServer()->index, $this->onShootArray[$player->login]);
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->getServer()->index, $this->onShootArray[$player->login]);
}
unset($this->onShootArray[$player->login]);
}
@ -186,16 +153,13 @@ class StatisticCollector implements CallbackListener {
public function handleCallbacks(array $callback) {
//TODO survivals
// Check if Stat Collecting is enabled
if (!$this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)
) {
return;
}
// Check for Minimum PlayerCount
if ($this->maniaControl->getPlayerManager()
->getPlayerCount() < $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)
if ($this->maniaControl->getPlayerManager()->getPlayerCount() < $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)
) {
return;
}
@ -207,62 +171,47 @@ class StatisticCollector implements CallbackListener {
$this->handleOnShoot($callback[1][1][0], $callback[1][1][1]);
break;
case 'LibXmlRpc_OnHit':
$shooter = $this->maniaControl->getPlayerManager()
->getPlayer($callback[1][1][0]);
$victim = $this->maniaControl->getPlayerManager()
->getPlayer($callback[1][1][1]);
$shooter = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][0]);
$victim = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][1]);
$weapon = $callback[1][1][3];
if ($shooter) {
$this->maniaControl->getStatisticManager()
->incrementStat($this->getWeaponStat(intval($weapon), false), $shooter);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_HIT, $shooter);
$this->maniaControl->getStatisticManager()->incrementStat($this->getWeaponStat(intval($weapon), false), $shooter);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_HIT, $shooter);
}
if ($victim) {
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_GOT_HIT, $victim);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_GOT_HIT, $victim);
}
break;
case 'LibXmlRpc_OnNearMiss':
$player = $this->maniaControl->getPlayerManager()
->getPlayer($callback[1][1][0]);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_NEARMISS, $player);
$player = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][0]);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_NEARMISS, $player);
break;
case 'LibXmlRpc_OnCapture':
$logins = $callback[1][1][0];
$logins = explode(';', $logins);
foreach ($logins as $login) {
$player = $this->maniaControl->getPlayerManager()
->getPlayer($login);
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if (!$player) {
continue;
}
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_CAPTURE, $player);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_CAPTURE, $player);
}
break;
case 'LibXmlRpc_OnArmorEmpty':
$victim = $this->maniaControl->getPlayerManager()
->getPlayer($callback[1][1][1]);
$victim = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][1]);
if (isset($callback[1][1][0])) {
$shooter = $this->maniaControl->getPlayerManager()
->getPlayer($callback[1][1][0]);
$shooter = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][0]);
if ($shooter) {
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_KILL, $shooter);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_KILL, $shooter);
}
}
if ($victim) {
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_DEATH, $victim);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_DEATH, $victim);
}
break;
case 'LibXmlRpc_OnPlayerRequestRespawn':
$player = $this->maniaControl->getPlayerManager()
->getPlayer($callback[1][1][0]);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
$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]);
@ -273,19 +222,15 @@ class StatisticCollector implements CallbackListener {
case 'OnNearMiss':
$paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) {
$player = $this->maniaControl->getPlayerManager()
->getPlayer($paramsObject->Event->Shooter->Login);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_NEARMISS, $player);
$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)) {
$player = $this->maniaControl->getPlayerManager()
->getPlayer($paramsObject->Event->Player->Login);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_CAPTURE, $player);
$player = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Player->Login);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_CAPTURE, $player);
}
break;
case 'OnHit':
@ -293,21 +238,16 @@ class StatisticCollector implements CallbackListener {
if ($paramsObject && isset($paramsObject->Event)) {
$weapon = (int)$paramsObject->Event->WeaponNum;
if (isset($paramsObject->Event->Shooter)) {
$shooter = $this->maniaControl->getPlayerManager()
->getPlayer($paramsObject->Event->Shooter->Login);
$shooter = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Shooter->Login);
if ($shooter) {
$this->maniaControl->getStatisticManager()
->incrementStat($this->getWeaponStat($weapon, false), $shooter);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_HIT, $shooter);
$this->maniaControl->getStatisticManager()->incrementStat($this->getWeaponStat($weapon, false), $shooter);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_HIT, $shooter);
}
}
if (isset($paramsObject->Event->Victim)) {
$victim = $this->maniaControl->getPlayerManager()
->getPlayer($paramsObject->Event->Victim->Login);
$victim = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Victim->Login);
if ($victim) {
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_GOT_HIT, $victim);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_GOT_HIT, $victim);
}
}
}
@ -315,29 +255,22 @@ class StatisticCollector implements CallbackListener {
case 'OnArmorEmpty':
$paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) {
$victim = $this->maniaControl->getPlayerManager()
->getPlayer($paramsObject->Event->Victim->Login);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_DEATH, $victim);
$victim = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Victim->Login);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_DEATH, $victim);
if (isset($paramsObject->Event->Shooter->Login)) {
$shooter = $this->maniaControl->getPlayerManager()
->getPlayer($paramsObject->Event->Shooter->Login);
$shooter = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Shooter->Login);
if ($shooter) {
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_KILL, $shooter);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_KILL, $shooter);
}
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_KILL, $shooter);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_KILL, $shooter);
}
}
break;
case 'OnRequestRespawn':
$paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) {
$player = $this->maniaControl->getPlayerManager()
->getPlayer($paramsObject->Event->Player->Login);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
$player = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Player->Login);
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
}
break;
case 'EndTurn': //TODO make it for other modes working
@ -345,10 +278,8 @@ class StatisticCollector implements CallbackListener {
if ($paramsObject && is_array($paramsObject->ScoresTable)) {
$durationTime = (int)(($paramsObject->EndTime - $paramsObject->StartTime) / 1000);
foreach ($paramsObject->ScoresTable as $score) {
$player = $this->maniaControl->getPlayerManager()
->getPlayer($score->Login);
$this->maniaControl->getStatisticManager()
->insertStat(self::STAT_PLAYTIME, $player, -1, $durationTime);
$player = $this->maniaControl->getPlayerManager()->getPlayer($score->Login);
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_PLAYTIME, $player, -1, $durationTime);
}
}
break;
@ -371,11 +302,9 @@ class StatisticCollector implements CallbackListener {
$this->onShootArray[$login][$weaponNumber]++;
//Write Shoot Data into database
if (array_sum($this->onShootArray[$login]) > $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_ON_SHOOT_PRESTORE)
if (array_sum($this->onShootArray[$login]) > $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ON_SHOOT_PRESTORE)
) {
$player = $this->maniaControl->getPlayerManager()
->getPlayer($login);
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
$rocketShots = $this->onShootArray[$login][self::WEAPON_ROCKET];
$laserShots = $this->onShootArray[$login][self::WEAPON_LASER];
@ -383,28 +312,23 @@ class StatisticCollector implements CallbackListener {
$nucleusShots = $this->onShootArray[$login][self::WEAPON_NUCLEUS];
if ($rocketShots > 0) {
$this->maniaControl->getStatisticManager()
->insertStat(self::STAT_ROCKET_SHOT, $player, $this->maniaControl->getServer()->index, $rocketShots);
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_ROCKET_SHOT, $player, $this->maniaControl->getServer()->index, $rocketShots);
$this->onShootArray[$login][self::WEAPON_ROCKET] = 0;
}
if ($laserShots > 0) {
$this->maniaControl->getStatisticManager()
->insertStat(self::STAT_LASER_SHOT, $player, $this->maniaControl->getServer()->index, $laserShots);
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_LASER_SHOT, $player, $this->maniaControl->getServer()->index, $laserShots);
$this->onShootArray[$login][self::WEAPON_LASER] = 0;
}
if ($arrowShots > 0) {
$this->maniaControl->getStatisticManager()
->insertStat(self::STAT_ARROW_SHOT, $player, $this->maniaControl->getServer()->index, $arrowShots);
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_ARROW_SHOT, $player, $this->maniaControl->getServer()->index, $arrowShots);
$this->onShootArray[$login][self::WEAPON_ARROW] = 0;
}
if ($nucleusShots > 0) {
$this->maniaControl->getStatisticManager()
->insertStat(self::STAT_NUCLEUS_SHOT, $player, $this->maniaControl->getServer()->index, $nucleusShots);
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_NUCLEUS_SHOT, $player, $this->maniaControl->getServer()->index, $nucleusShots);
$this->onShootArray[$login][self::WEAPON_NUCLEUS] = 0;
}
$this->maniaControl->getStatisticManager()
->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->getServer()->index, $rocketShots + $laserShots + $arrowShots + $nucleusShots);
$this->maniaControl->getStatisticManager()->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->getServer()->index, $rocketShots + $laserShots + $arrowShots + $nucleusShots);
}
}