-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathaas.php
283 lines (241 loc) · 8.52 KB
/
aas.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
/***************************************************************************
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Portions of this program are derived from publicly licensed software
* projects including, but not limited to phpBB, Magelo Clone,
* EQEmulator, EQEditor, and Allakhazam Clone.
*
* Author:
* Maudigan(Airwalking)
*
* October 16, 2013 - Leere
* Fixed an error in the AA query that left out berzerker AAs
* September 26, 2014 - Maudigan
* Added underscore to 'aapoints' to make it the same as the column name
* Updated character table name
* September 28, 2014 - Maudigan
* added code to monitor database performance
* altered character profile initialization to remove redundant query
* September 28, 2014 - Maudigan
* replaced char blob
* added new aa tabs
* May 24, 2016 - Maudigan
* general code cleanup, whitespace correction, removed old comments,
* organized some code. A lot has changed, but not much functionally
* do a compare to 2.41 to see the differences.
* Implemented new database wrapper.
* May 30, 2016 - Maudigan
* updated the entire script to work with the new AA system, again do
* a compare to 2.41 to see the differences, it's basically a rewrite.
* January 7, 2018 - Maudigan
* Modified database to use a class.
* March 7, 2020 - Maudigan
* Fixed an error causing the wrong class's AA to display
* March 9, 2020 - Maudigan
* modularized the profile menu output
* March 22, 2020 - Maudigan
* impemented common.php
* April 3, 2020 - Maudigan
* dont show AAs if they dont have a first rank, some custom server
* hide AA by deleting their ranks
* April 25, 2020 - Maudigan
* implement multi-tenancy
*
***************************************************************************/
/*********************************************
INCLUDES
*********************************************/
//define this as an entry point to unlock includes
if ( !defined('INCHARBROWSER') )
{
define('INCHARBROWSER', true);
}
include_once(__DIR__ . "/include/common.php");
include_once(__DIR__ . "/include/profile.php");
include_once(__DIR__ . "/include/db.php");
/*********************************************
SUPPORT FUNCTIONS
*********************************************/
//counts how many ranks follow the provided rank
function getTotalRanks($first_rank)
{
global $aa_ranks;
$next_rank = $aa_ranks[$first_rank]['NEXT'];
//if the next id exists, then that reflects
//there being another rank after this current one
//so recursively call to add it in
if (array_key_exists($next_rank, $aa_ranks))
return 1 + getTotalRanks($next_rank);
else
return 1;
}
//gets the cost of the rank provided the
//first rank and value the character has
function getRankCost($first_rank, $value)
{
global $aa_ranks;
$next_rank = $aa_ranks[$first_rank]['NEXT'];
//if our value has reached zero then we are on the
//one that has the relevant cost but we also need
//to make sure we don't go past the tail. If we do
//return a 0.
if ($value > 0) //most likely scenario is first for speed
{
if (array_key_exists($next_rank, $aa_ranks))
return getRankCost($next_rank, --$value);
else //too high of a value was provided
return '--';
}
elseif ($value == 0) //next most likely scenario
{
return $aa_ranks[$first_rank]['COST'];
}
return 0; //cant hurt
}
/*********************************************
SETUP CHARACTER CLASS & PERMISSIONS
*********************************************/
$charName = preg_Get_Post('char', '/^[a-zA-Z]+$/', false, $language['MESSAGE_ERROR'],$language['MESSAGE_NO_CHAR'], true);
//character initializations
$char = new Charbrowser_Character($charName, $showsoftdelete, $charbrowser_is_admin_page); //the Charbrowser_Character class will sanitize the character name
$charID = $char->char_id();
$name = $char->GetValue('name');
//block view if user level doesnt have permission
if ($char->Permission('AAs')) $cb_error->message_die($language['MESSAGE_NOTICE'],$language['MESSAGE_ITEM_NO_VIEW']);
/*********************************************
GATHER RELEVANT PAGE DATA
*********************************************/
//setup an array to output the display tabs
$aatabs = array();
$aatabs[1] = $language['AAS_TAB_1'];
$aatabs[2] = $language['AAS_TAB_2'];
$aatabs[3] = $language['AAS_TAB_3'];
$aatabs[4] = $language['AAS_TAB_4'];
//GET THIS CHARS SPENT AA
$classbit = pow(2, $char->GetValue('class') - 1);
$character_aas = $char->GetTable("character_alternate_abilities");
//GET RANK COSTS
$tpl = <<<TPL
SELECT id, cost, next_id
FROM aa_ranks
TPL;
$query = $tpl;
$result = $cbsql_content->query($query);
//the ranks are stored in a record
//that is similar to a linked list
//loop through each one and load it
//into a poor-man's linked list
$aa_ranks = array();
while ($row = $cbsql_content->nextrow($result))
{
$aa_rank = array('COST' => intval($row['cost']),
'NEXT' => intval($row['next_id']));
$aa_ranks[intval($row['id'])] = $aa_rank;
}
//GET ALL AAS FOR THIS CLASS
$tpl = <<<TPL
SELECT first_rank_id, name, type
FROM aa_ability
WHERE classes & %s
AND enabled = 1
ORDER BY type, name
TPL;
$query = sprintf($tpl, $classbit);
$result = $cbsql_content->query($query);
//stage them in the final array
$aa_abilities = array();
while ($row = $cbsql_content->nextrow($result))
{
//calculate all the values
$first_rank_id = $row['first_rank_id'];
//skip this one if there is no first rank data
if (!array_key_exists($first_rank_id, $aa_ranks)) continue;
//if the char has this AA, get its value
if (is_array($character_aas) && array_key_exists($first_rank_id, $character_aas))
{
$cur = intval($character_aas[$first_rank_id]['aa_value']);
}
//else it's at 0
else
{
$cur = 0;
}
$cost = getRankCost($first_rank_id, $cur);
$max = getTotalRanks($first_rank_id);
$aa_abilities[] = array(
'TYPE' => $row['type'],
'NAME' => $row['name'],
'MAX' => $max,
'CUR' => $cur,
'COST' => $cost
);
}
/*********************************************
DROP HEADER
*********************************************/
$d_title = " - ".$name.$language['PAGE_TITLES_AAS'];
include(__DIR__ . "/include/header.php");
/*********************************************
DROP PROFILE MENU
*********************************************/
output_profile_menu($name, 'aas');
/*********************************************
POPULATE BODY
*********************************************/
$cb_template->set_filenames(array(
'aas' => 'aas_body.tpl')
);
$cb_template->assign_both_vars(array(
'NAME' => $name,
'AA_POINTS' => $char->GetValue("aa_points"),
'POINTS_SPENT' => $char->GetValue("aa_points_spent"))
);
$cb_template->assign_vars(array(
'L_ALTERNATE_ABILITIES' => $language['AAS_ALTERNATE_ABILITIES'],
'L_TITLE' => $language['AAS_TITLE'],
'L_CUR_MAX' => $language['AAS_CUR_MAX'],
'L_COST' => $language['AAS_COST'],
'L_AA_POINTS' => $language['AAS_AA_POINTS'],
'L_POINTS_SPENT' => $language['AAS_POINTS_SPENT'],
'L_DONE' => $language['BUTTON_DONE'])
);
//TODO don't hardcode these colors. It should maybe
// get set using two stylesheet flags... maybe
$Color = "7b714a";
foreach ($aatabs as $key => $value) {
$cb_template->assign_block_vars("tabs", array(
'COLOR' => $Color,
'ID' => $key,
'TEXT' => $value)
);
$Color = "FFFFFF";
}
$Display = "block";
$lasttype = 0;
foreach ($aa_abilities as $aa_ability)
{
//put them in a new box if it's a new type
if ($aa_ability['TYPE'] != $lasttype)
{
$lasttype = $aa_ability['TYPE'];
$cb_template->assign_both_block_vars("boxes", array(
'ID' => $lasttype,
'DISPLAY' => $Display)
);
$Display = "none";
}
//output the row
$cb_template->assign_both_block_vars("boxes.aas", $aa_ability);
}
/*********************************************
OUTPUT BODY AND FOOTER
*********************************************/
$cb_template->pparse('aas');
$cb_template->destroy();
include(__DIR__ . "/include/footer.php");
?>