special stats begin

This commit is contained in:
kremsy 2014-01-28 22:59:18 +01:00 committed by Steffen Schröder
parent b0b6e6ef17
commit f301ad8240

View File

@ -20,6 +20,9 @@ class StatisticManager {
const TABLE_STATISTICS = 'mc_statistics';
const STAT_TYPE_INT = '0';
const STAT_TYPE_TIME = '1';
const STAT_TYPE_FLOAT = '2';
const SPECIAL_STAT_KD_RATIO = 'Kill Death Ratio'; //TODO dynamic later
/**
* Public Properties
@ -32,6 +35,7 @@ class StatisticManager {
*/
private $maniaControl = null;
private $stats = array();
private $specialStats = array();
/**
* Construct player manager
@ -119,6 +123,29 @@ class StatisticManager {
return $stats;
}
/**
* Gets The Ranking of an Special Stat
*
* @param string $statName
*/
public function getStatsRankingOfSpecialStat($statName = '') {
$statsArray = array();
switch($statName) {
case self::SPECIAL_STAT_KD_RATIO:
$kills = $this->getStatsRanking(StatisticCollector::STAT_ON_KILL);
$deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH);
foreach($deaths as $key => $death) {
if ($death == 0 || !isset($kills[$key])) {
continue;
}
$statsArray[$key] = intval($kills[$key]) / intval($death);
}
}
return $statsArray;
}
/**
* Store Stats Meta Data from the Database
*/
@ -136,6 +163,11 @@ class StatisticManager {
$this->stats[$row->name] = $row;
}
$result->close();
$stat = new \stdClass();
$stat->name = self::SPECIAL_STAT_KD_RATIO;
$stat->type = self::STAT_TYPE_FLOAT;
$this->specialStats[self::SPECIAL_STAT_KD_RATIO] = $stat;
}
/**
@ -167,6 +199,42 @@ class StatisticManager {
$playerStats[$stat->name] = array($stat, $value);
}
foreach($this->specialStats as $stat){
switch($stat->name){
case self::SPECIAL_STAT_KD_RATIO:
if(!isset($playerStats[StatisticCollector::STAT_ON_KILL]) || !isset($playerStats[StatisticCollector::STAT_ON_DEATH]))
continue;
$kills = intval($playerStats[StatisticCollector::STAT_ON_KILL]);
$deaths = intval($playerStats[StatisticCollector::STAT_ON_DEATH]);
if($deaths == 0)
continue;
$playerStats[$stat->name] = array($stat, $kills / $deaths);
}
}
return $playerStats;
}
/**
* Gets The Ranking of an Special Stat
*
* @param string $statName
*/
public function getAllSpecialPlayerStats(Player $player, $serverIndex = -1) {
$playerStats = array();
foreach($this->specialStats as $special){
switch($special){
case self::SPECIAL_STAT_KD_RATIO:
$kills = $this->getStatsRanking(StatisticCollector::STAT_ON_KILL);
$deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH);
foreach($deaths as $key => $death) {
if ($death == 0 || !isset($kills[$key])) {
continue;
}
$statsArray[$key] = intval($kills[$key]) / intval($death);
}
}
}
return $playerStats;
}