fixed statistics code for custom callbacks

This commit is contained in:
Steffen Schröder 2014-07-21 14:53:05 +02:00
parent e18e29de9d
commit b9c6e7cb85

View File

@ -210,51 +210,63 @@ class StatisticCollector implements CallbackListener {
break; break;
case 'OnShoot': case 'OnShoot':
$paramsObject = json_decode($callback[1][1]); $paramsObject = json_decode($callback[1][1]);
$this->handleOnShoot($paramsObject->Event->Shooter->Login, $paramsObject->Event->WeaponNum); if ($paramsObject && isset($paramsObject->Event)) {
$this->handleOnShoot($paramsObject->Event->Shooter->Login, $paramsObject->Event->WeaponNum);
}
break; break;
case 'OnNearMiss': case 'OnNearMiss':
$paramsObject = json_decode($callback[1][1]); $paramsObject = json_decode($callback[1][1]);
$player = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Shooter->Login); if ($paramsObject && isset($paramsObject->Event)) {
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_NEARMISS, $player); $player = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Shooter->Login);
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_NEARMISS, $player);
}
break; break;
case 'OnCapture': case 'OnCapture':
$paramsObject = json_decode($callback[1][1]); $paramsObject = json_decode($callback[1][1]);
$player = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Player->Login); if ($paramsObject && isset($paramsObject->Event)) {
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_CAPTURE, $player); $player = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Player->Login);
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_CAPTURE, $player);
}
break; break;
case 'OnHit': case 'OnHit':
$paramsObject = json_decode($callback[1][1]); $paramsObject = json_decode($callback[1][1]);
$weapon = (int)$paramsObject->Event->WeaponNum; if ($paramsObject && isset($paramsObject->Event)) {
if (isset($paramsObject->Event->Shooter)) { $weapon = (int)$paramsObject->Event->WeaponNum;
$shooter = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Shooter->Login); if (isset($paramsObject->Event->Shooter)) {
if ($shooter) { $shooter = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Shooter->Login);
$this->maniaControl->statisticManager->incrementStat($this->getWeaponStat($weapon, false), $shooter); if ($shooter) {
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_HIT, $shooter); $this->maniaControl->statisticManager->incrementStat($this->getWeaponStat($weapon, false), $shooter);
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_HIT, $shooter);
}
} }
} if (isset($paramsObject->Event->Victim)) {
if (isset($paramsObject->Event->Victim)) { $victim = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Victim->Login);
$victim = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Victim->Login); if ($victim) {
if ($victim) { $this->maniaControl->statisticManager->incrementStat(self::STAT_ON_GOT_HIT, $victim);
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_GOT_HIT, $victim); }
} }
} }
break; break;
case 'OnArmorEmpty': case 'OnArmorEmpty':
$paramsObject = json_decode($callback[1][1]); $paramsObject = json_decode($callback[1][1]);
$victim = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Victim->Login); if ($paramsObject && isset($paramsObject->Event)) {
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_DEATH, $victim); $victim = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Victim->Login);
if (isset($paramsObject->Event->Shooter->Login)) { $this->maniaControl->statisticManager->incrementStat(self::STAT_ON_DEATH, $victim);
$shooter = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Shooter->Login); if (isset($paramsObject->Event->Shooter->Login)) {
if ($shooter) { $shooter = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Shooter->Login);
if ($shooter) {
$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_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); if ($paramsObject && isset($paramsObject->Event)) {
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player); $player = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Player->Login);
$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
}
break; break;
case 'EndTurn': //TODO make it for other modes working case 'EndTurn': //TODO make it for other modes working
$paramsObject = json_decode($callback[1][1]); $paramsObject = json_decode($callback[1][1]);