forked from wakachamo/PsychoStats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weapons.php
173 lines (154 loc) · 6.1 KB
/
weapons.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* This file is part of PsychoStats.
*
* Written by Jason Morriss <stormtrooper@psychostats.com>
* Copyright 2008 Jason Morriss
*
* PsychoStats is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PsychoStats is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PsychoStats. If not, see <http://www.gnu.org/licenses/>.
*
* Version: $Id: weapons.php 508 2008-07-02 18:58:07Z lifo $
*/
define("PSYCHOSTATS_PAGE", true);
include(dirname(__FILE__) . "/includes/common.php");
$cms->init_theme($ps->conf['main']['theme'], $ps->conf['theme']);
$ps->theme_setup($cms->theme);
$cms->theme->page_title('PsychoStats - Weapon Usage');
// change this if you want the default sort of the player listing to be something else like 'kills'
$DEFAULT_SORT = 'kills';
$validfields = array('sort','order','xml','v');
$cms->theme->assign_request_vars($validfields, true);
$v = strtolower($v);
$sort = trim(strtolower($sort));
$order = trim(strtolower($order));
$start = 0;
$limit = 500;
if (!preg_match('/^\w+$/', $sort)) $sort = $DEFAULT_SORT;
if (!in_array($order, array('asc','desc'))) $order = 'desc';
$stats = $ps->get_sum(array('kills','damage'), $ps->c_plr_data);
$weapons = $ps->get_weapon_list(array(
'sort' => $sort,
'order' => $order,
'start' => $start,
'limit' => $limit,
));
$totalweapons = count($weapons);
// calculate some extra percentages for each weapon and determine max values
$max = array();
$keys = array('kills', 'damage', 'headshotkills');
for ($i=0; $i < count($weapons); $i++) {
foreach ($keys as $k) {
if ($weapons[$i][$k] > $max[$k]) $max[$k] = $weapons[$i][$k];
}
}
// calculate percentages scaled to max values
for ($i=0; $i < count($weapons); $i++) {
foreach ($keys as $k) {
if ($max[$k]) {
$weapons[$i]['scaled'.$k.'pct'] = ceil($weapons[$i][$k] / $max[$k] * 100);
}
if ($stats[$k]) {
$weapons[$i]['real'.$k.'pct'] = ceil($weapons[$i][$k] / $stats[$k] * 100);
}
}
}
// calculate scale width of pct's based on max
//$scale = 200;
//$ofs = $scale; // + 40;
//for ($i=0; $i < count($weapons); $i++) {
// foreach ($keys as $k) {
// if ($max[$k] == 0) {
// $weapons[$i][$k.'width'] = $ofs - ceil($weapons[$i][$k] / 1 * $scale);
// } else {
// $weapons[$i][$k.'width'] = $ofs - ceil($weapons[$i][$k] / $max[$k] * $scale);
// }
// }
//}
if ($xml) {
$ary = array();
foreach ($weapons as $w) {
unset($w['dataid']);
$ary[ $w['uniqueid'] ] = $w;
}
print_xml($ary);
}
// organize the weapons by 'class'
$weaponclasses = array();
foreach ($weapons as $w) {
$class = !empty($w['class']) ? $w['class'] : $cms->trans('Unclassified');
$weaponclasses[$class][] = $w;
}
ksort($weaponclasses);
// build a dynamic table that plugins can use to add custom columns of data
$table = $cms->new_table($weapons);
$table->if_no_data($cms->trans("No Weapons Found"));
$table->attr('class', 'ps-table ps-weapon-table');
$table->start_and_sort($start, $sort, $order);
$table->columns(array(
'uniqueid' => array( 'label' => $cms->trans("Weapon"), 'callback' => 'ps_table_weapon_link' ),
'_killspct' => array( 'nolabel' => true, 'callback' => 'kills_pct' ),
'kills' => array( 'label' => $cms->trans("Kills"), 'modifier' => 'commify' ),
'headshotkills' => array( 'label' => $cms->trans("HS"), 'modifier' => 'commify', 'tooltip' => $cms->trans("Headshot Kills") ),
'headshotkillspct' => array( 'label' => $cms->trans("HS%"), 'modifier' => '%s%%', 'tooltip' => $cms->trans("Headshot Kills Percentage") ),
// '_headshotkillspct' => array( 'nolabel' => true, 'callback' => 'headshotkills_pct' ),
'ffkills' => array( 'label' => $cms->trans("FF"), 'modifier' => 'commify', 'tooltip' => $cms->trans("Friendly Fire Kills") ),
'ffkillspct' => array( 'label' => $cms->trans("FF%"), 'modifier' => '%s%%', 'tooltip' => $cms->trans("Friendly Fire Kills Percentage") ),
'accuracy' => array( 'label' => $cms->trans("Acc"), 'modifier' => '%s%%', 'tooltip' => $cms->trans("Accuracy") ),
'shotsperkill' => array( 'label' => $cms->trans("S:K"), 'tooltip' => $cms->trans("Shots Per Kill") ),
'damage' => array( 'label' => $cms->trans("Dmg"), 'callback' => 'abbr_dmg', 'tooltip' => $cms->trans("Damage") ),
));
$table->column_attr('uniqueid', 'class', 'first');
$table->column_attr('_killspct', 'width', '50');
$table->header_attr('kills', 'colspan', '2');
//$table->header_attr('headshotkillspct', 'colspan', '2');
$ps->weapons_table_mod($table);
$cms->filter('weapons_table_object', $table);
// assign variables to the theme
$cms->theme->assign(array(
'weapons_by_class' => $weaponclasses, // allow a theme to use either ...
'weapons' => $weapons, // ... way to display weapons
'weapons_table' => $table->render(),
'weapon_classes' => array_keys($weaponclasses),
'totalweapons' => $totalweapons,
'totalkills' => $stats['kills'],
'totaldamage' => $stats['damage'],
));
// display the output
$basename = basename(__FILE__, '.php');
//$cms->theme->add_css('css/tabs.css');
$cms->full_page($basename, $basename, $basename.'_header', $basename.'_footer');
function kills_pct($name, $weapon) {
global $cms, $max;
return pct_bar(array(
'pct' => $weapon['scaledkillspct'],
'title' => $cms->trans('Overall kills percentage') . ' (' . $weapon['realkillspct'] . '%)',
'color1' => 'cc0000',
'color2' => '00cc00',
// 'width' => 100
));
}
function headshotkills_pct($name, $weapon) {
global $cms, $max;
return pct_bar(array(
'pct' => $weapon['scaledheadshotkillspct'],
'title' => $cms->trans('Overall headshot kills percentage') . ' (' . $weapon['realheadshotkillspct'] . '%)',
'color1' => 'cc0000',
'color2' => '00cc00',
// 'width' => 100
));
}
function abbr_dmg($name, $weapon) {
return "<acronym title='" . commify($weapon['damage']) . "'>" . abbrnum0($weapon['damage'],1) . "</acronym>";
}
?>