1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
use Smr\Database; |
4
|
|
|
use Smr\Exceptions\PlayerNotFound; |
5
|
|
|
|
6
|
|
|
$template = Smr\Template::getInstance(); |
7
|
|
|
$session = Smr\Session::getInstance(); |
8
|
|
|
$var = $session->getCurrentVar(); |
9
|
|
|
|
10
|
|
|
//get game id |
11
|
|
|
$gameID = $var['game_id']; |
12
|
|
|
|
13
|
|
|
$statsGame = SmrGame::getGame($gameID); |
14
|
|
|
$template->assign('StatsGame', $statsGame); |
15
|
|
|
|
16
|
|
|
$template->assign('PageTopic', 'Game Stats: ' . $statsGame->getName() . ' (' . $gameID . ')'); |
17
|
|
|
|
18
|
|
|
$db = Database::getInstance(); |
19
|
|
|
$dbResult = $db->read('SELECT count(*) total_players, IFNULL(MAX(experience),0) max_exp, IFNULL(MAX(alignment),0) max_align, IFNULL(MIN(alignment),0) min_alignment, IFNULL(MAX(kills),0) max_kills FROM player WHERE game_id = ' . $gameID . ' ORDER BY experience DESC'); |
20
|
|
|
if ($dbResult->hasRecord()) { |
21
|
|
|
$dbRecord = $dbResult->record(); |
22
|
|
|
$template->assign('TotalPlayers', $dbRecord->getInt('total_players')); |
23
|
|
|
$template->assign('HighestExp', $dbRecord->getInt('max_exp')); |
24
|
|
|
$template->assign('HighestAlign', $dbRecord->getInt('max_align')); |
25
|
|
|
$template->assign('LowestAlign', $dbRecord->getInt('min_alignment')); |
26
|
|
|
$template->assign('HighestKills', $dbRecord->getInt('max_kills')); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$dbResult = $db->read('SELECT count(*) num_alliance FROM alliance WHERE game_id = ' . $gameID); |
30
|
|
|
$template->assign('TotalAlliances', $dbResult->record()->getInt('num_alliance')); |
31
|
|
|
|
32
|
|
|
// Get current account's player for this game (if any) |
33
|
|
|
try { |
34
|
|
|
$player = SmrPlayer::getPlayer($session->getAccountID(), $gameID); |
35
|
|
|
} catch (PlayerNotFound) { |
36
|
|
|
$player = null; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$playerExpRecords = Rankings::playerStats('experience', $gameID, 10); |
40
|
|
|
$playerExpRanks = Rankings::collectRankings($playerExpRecords, $player); |
41
|
|
|
$template->assign('ExperienceRankings', $playerExpRanks); |
42
|
|
|
|
43
|
|
|
$playerKillRecords = Rankings::playerStats('kills', $gameID, 10); |
44
|
|
|
$playerKillRanks = Rankings::collectRankings($playerKillRecords, $player); |
45
|
|
|
$template->assign('KillRankings', $playerKillRanks); |
46
|
|
|
|
47
|
|
|
$allianceTopTen = function(string $stat) use ($statsGame, $gameID, $player): array { |
48
|
|
|
$allianceRecords = Rankings::allianceStats($stat, $gameID, 10); |
49
|
|
|
$allianceRanks = Rankings::collectAllianceRankings($allianceRecords, $player); |
50
|
|
|
foreach ($allianceRanks as $rank => $info) { |
51
|
|
|
$alliance = $info['Alliance']; |
52
|
|
|
if ($statsGame->hasEnded()) { |
53
|
|
|
// If game has ended, offer a link to alliance roster details |
54
|
|
|
$data = ['game_id' => $gameID, 'alliance_id' => $alliance->getAllianceID()]; |
55
|
|
|
$href = Page::create('previous_game_alliance_detail.php', $data)->href(); |
56
|
|
|
$allianceName = create_link($href, $alliance->getAllianceDisplayName()); |
57
|
|
|
} else { |
58
|
|
|
$allianceName = $alliance->getAllianceDisplayName(); |
59
|
|
|
} |
60
|
|
|
$allianceRanks[$rank]['AllianceName'] = $allianceName; |
61
|
|
|
} |
62
|
|
|
return $allianceRanks; |
63
|
|
|
}; |
64
|
|
|
$template->assign('AllianceExpRankings', $allianceTopTen('experience')); |
65
|
|
|
$template->assign('AllianceKillRankings', $allianceTopTen('kills')); |
66
|
|
|
|