forked from thijsdezoete/OpenArena-Stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
133 lines (123 loc) · 4.06 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* This method collects all logfiles from the logdir.
*/
function getLogFiles($logdir) {
$files = scandir($logdir);
$logs = array();
foreach($files as $file) {
if(preg_match('/openarena_([0-9-]+)\.log/', $file)) {
$logs[] = $logdir .'/'. $file;
}
}
return $logs;
}
/**
* This method generates the player skeletons.
*/
function generatePlayerSkeletons($known_players) {
$stats = array();
$players = array();
foreach($known_players as $nickname => $realname) {
$players[$realname] = 0;
}
foreach($known_players as $nickname => $realname) {
$filtered_players = array_diff($players, array($realname));
$stats[$realname] = array(
'AWARDS' => array(
'Excellent' => 0,
'Impressive' => 0,
'Gauntlet' => 0,
'Capture' => 0,
'Assist' => 0,
'Defence' => 0,
),
'CTF' => array(
'Flags taken' => 0,
'Flags captured' => 0,
'Flags returned' => 0,
'Flagcarriers killed' => 0,
),
'KILLS' => array(
'Frags' => 0,
'Deaths' => 0,
'Suicides' => 0,
'Ratio' => 0.0,
'Kill streak' => 0,
'Death streak' => 0,
),
'VICTIMS' => $filtered_players,
'ENEMIES' => $filtered_players,
'WEAPONS' => array(
'MOD_UNKNOWN' => 0,
'MOD_SHOTGUN' => 0,
'MOD_GAUNTLET' => 0,
'MOD_MACHINEGUN' => 0,
'MOD_GRENADE' => 0,
'MOD_GRENADE_SPLASH' => 0,
'MOD_ROCKET' => 0,
'MOD_ROCKET_SPLASH' => 0,
'MOD_PLASMA' => 0,
'MOD_PLASMA_SPLASH' => 0,
'MOD_RAILGUN' => 0,
'MOD_LIGHTNING' => 0,
'MOD_BFG' => 0,
'MOD_BFG_SPLASH' => 0,
'MOD_WATER' => 0,
'MOD_SLIME' => 0,
'MOD_LAVA' => 0,
'MOD_CRUSH' => 0,
'MOD_TELEFRAG' => 0,
'MOD_FALLING' => 0,
'MOD_SUICIDE' => 0,
'MOD_TARGET_LASER' => 0,
'MOD_TRIGGER_HURT' => 0,
'MOD_NAIL' => 0,
'MOD_CHAINGUN' => 0,
'MOD_PROXIMITY_MINE' => 0,
'MOD_KAMIKAZE' => 0,
'MOD_JUICED' => 0,
'MOD_GRAPPLE' => 0,
),
'RANKINGS' => array(),
);
}
return $stats;
}
function resetCurrentStreaks( &$stats ) {
foreach ( $stats as &$stat ) {
$stat['KILLS']['kill_streak'] = 0;
$stat['KILLS']['death_streak'] = 0;
}
}
function removeCurrentStreaks( &$stats ) {
foreach ( $stats as &$stat ) {
unset( $stat['KILLS']['kill_streak']);
unset( $stat['KILLS']['death_streak']);
}
}
// increase one (death or kill) streak, will reset the other
function increaseStreak( &$stats, $player, $type ) {
switch ( $type ) {
case 'kill': {
$curr = 'kill_streak';
$max = 'Kill streak';
$other = 'death_streak';
} break;
case 'death': {
$curr = 'death_streak';
$max = 'Death streak';
$other = 'kill_streak';
} break;
default: {
// Unknown
return;
}
}
$new = ++$stats[$player]['KILLS'][$curr];
if ( $stats[$player]['KILLS'][$max] < $new ) {
$stats[$player]['KILLS'][$max] = $new;
}
// Reset other streak
$stats[$player]['KILLS'][$other] = 0;
}