forked from Tuxinou/Freehead
-
Notifications
You must be signed in to change notification settings - Fork 0
/
achievement.php
executable file
·331 lines (313 loc) · 9.77 KB
/
achievement.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
require_once('includes/allutil.php');
require_once('includes/allachievements.php');
require_once('includes/allitems.php');
require_once('includes/allcomments.php');
require_once('includes/allscreenshots.php');
$smarty->config_load($conf_file, 'achievement');
$id = intval($podrazdel);
$cache_key = cache_key($id);
if(!$achievement = load_cache(ACHIEVEMENT_PAGE, $cache_key))
{
unset($achievement);
$row = $DB->selectRow('
SELECT
a.id, a.faction, a.name_loc?d AS name, a.description_loc?d AS description,
a.reward_loc?d AS reward, a.category, a.points, a.count, a.parent, s.iconname, z.areatableID
FROM ?_spellicons s, ?_achievement a
LEFT JOIN (?_zones z) ON a.map != -1 AND a.map = z.mapID
WHERE
a.icon = s.id
AND a.id = ?
GROUP BY a.id
',
$_SESSION['locale'],
$_SESSION['locale'],
$_SESSION['locale'],
$id
);
if($row)
{
$achievement = array();
$achievement = achievementinfo2($row);
$achievement['side'] = $sides[$achievement['faction']];
// Категории
if($row['category'])
{
$catrow = $DB->selectRow('
SELECT c1.id, c1.name_loc?d AS name, c2.id AS id2
FROM ?_achievementcategory c1
LEFT JOIN (?_achievementcategory c2) ON c1.parentAchievement != -1 AND c1.parentAchievement = c2.id
WHERE
c1.id = ?
',
$_SESSION['locale'],
$row['category']
);
if($catrow)
{
$achievement['category1'] = $catrow['id'];
$achievement['category2'] = $catrow['id2'];
$achievement['category'] = $catrow['name'];
}
}
// Дополнительные достижения
$rows = $DB->select('
SELECT a.id, a.faction, a.name_loc?d AS name, a.description_loc?d AS description, a.category, a.points, s.iconname, z.areatableID
FROM ?_spellicons s, ?_achievement a
LEFT JOIN (?_zones z) ON a.map != -1 AND a.map = z.mapID
WHERE
a.icon = s.id
AND a.name_loc?d = ?
AND a.id != ?
GROUP BY a.id
ORDER BY a.name_loc?d
',
$_SESSION['locale'],
$_SESSION['locale'],
$_SESSION['locale'],
$achievement['name'],
$achievement['id'],
$_SESSION['locale']
);
if($rows)
{
$achievement['see_also'] = array();
foreach($rows as $row)
$achievement['see_also'][] = achievementinfo2($row);
}
// Достижения, у которых в критериях есть мы
$rows = $DB->select('
SELECT a.id, a.faction, a.name_loc?d AS name, a.description_loc?d AS description, a.category, a.points, s.iconname, z.areatableID
FROM ?_spellicons s, ?_achievementcriteria c, ?_achievement a
LEFT JOIN (?_zones z) ON a.map != -1 AND a.map = z.mapID
WHERE
a.icon = s.id
AND a.id = c.refAchievement
AND c.type = ?d
AND c.value1 = ?d
GROUP BY a.id
ORDER BY a.name_loc?d
',
$_SESSION['locale'],
$_SESSION['locale'],
ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_ACHIEVEMENT,
$achievement['id'],
$_SESSION['locale']
);
if($rows)
{
$achievement['criteria_of'] = array();
foreach($rows as $row)
$achievement['criteria_of'][] = achievementinfo2($row);
}
/*************** КРИТЕРИИ ДОСТИЖЕНИЯ ***************/
$rows = $DB->select('
SELECT id, type, value1, value2, value3, value4, value5, value6, name_loc?d AS name
FROM ?_achievementcriteria
WHERE refAchievement = ?
ORDER BY `order` ASC
',
$_SESSION['locale'],
$achievement['id']
);
$achievement['criterias'] = array();
$i = 0;
$iconId = 1;
$tmp_arr = array();
$achievement['icons'] = array();
$achievement['total_criterias'] = count($rows);
foreach($rows as $row)
{
$tmp = array(
'id' => $row['id'],
'name' => $row['name'],
'type' => $row['type'],
);
switch($row['type'])
{
// Добавляем ссылку на НПС
case ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE:
$tmp['link'] = array(
'href' => '?npc='.$row['value1'],
'text' => $row['name'],
);
$tmp['extra_text'] = $smarty->get_config_vars('slain');
break;
// Добавляем ссылку на зону, находим по карте
case ACHIEVEMENT_CRITERIA_TYPE_WIN_BG:
case ACHIEVEMENT_CRITERIA_TYPE_WIN_ARENA:
if($zoneId = $DB->selectCell('SELECT areatableID FROM ?_zones WHERE mapID = ? LIMIT 1', $row['value1']))
$tmp['link'] = array(
'href' => '?zone='.$zoneId,
'text' => $row['name'],
);
else
$tmp['extra_text'] = $row['name'];
break;
// TODO
/*ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL:
ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LEVEL:
break;*/
// Добавляем иконку и ссылку на ачив
case ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_ACHIEVEMENT:
$tmp['link'] = array(
'href' => '?achievement='.$row['value1'],
'text' => $row['name'],
);
$tmp['icon'] = $iconId;
$achievement['icons'][] = array(
'itr' => $iconId++,
'type' => 'g_achievements',
'id' => $row['value1'],
);
allachievementsinfo($row['value1']);
break;
// Добавляем ссылку на зону
case ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUESTS_IN_ZONE:
case ACHIEVEMENT_CRITERIA_TYPE_HONORABLE_KILL_AT_AREA:
$tmp['link'] = array(
'href' => '?zone='.$row['value1'],
'text' => $row['name'],
);
break;
// Добавляем ссылку на квест
case ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST:
$tmp['link'] = array(
'href' => '?quest='.$row['value1'],
'text' => $row['name'],
);
break;
// Добавляем иконку и ссылку на спелл
case ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET:
case ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2:
case ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL:
case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL:
case ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2:
$tmp['link'] = array(
'href' => '?spell='.$row['value1'],
'text' => $row['name'],
);
$tmp['icon'] = $iconId;
$achievement['icons'][] = array(
'itr' => $iconId++,
'type' => 'g_spells',
'id' => $row['value1'],
);
allspellsinfo($row['value1']);
break;
// Добавляем ссылку и иконку предмета
case ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM:
case ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM:
case ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM:
case ACHIEVEMENT_CRITERIA_TYPE_EQUIP_ITEM:
$item = allitemsinfo($row['value1']);
$tmp['link'] = array(
'href' => '?item='.$row['value1'],
'text' => $row['name'],
'quality' => $item['quality'],
);
$tmp['icon'] = $iconId;
$achievement['icons'][] = array(
'itr' => $iconId++,
'type' => 'g_items',
'id' => $row['value1'],
'count' => $row['value2']
);
break;
// Добавляем ссылку на фракцию и требуемую репутацию
case ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION:
$tmp['link'] = array(
'href' => '?faction='.$row['value1'],
'text' => $row['name'],
);
$tmp['extra_text'] = ' ('.reputations($row['value2']).')';
break;
// Добавляем иконку золотой монетки
case ACHIEVEMENT_CRITERIA_TYPE_MONEY_FROM_QUEST_REWARD:
case ACHIEVEMENT_CRITERIA_TYPE_LOOT_MONEY:
$tmp['standard'] = true;
$tmp['extra_text'] = '<span class="moneygold">'.number_format($row['value2' ] / 10000).'</span>';
break;
// Добавляем ссылку на ГО
case ACHIEVEMENT_CRITERIA_TYPE_USE_GAMEOBJECT:
case ACHIEVEMENT_CRITERIA_TYPE_FISH_IN_GAMEOBJECT:
$tmp['link'] = array(
'href' => '?object='.$row['value1'],
'text' => $row['name'],
);
break;
default:
$tmp['standard'] = true;
$tmp['extra_text'] = $row['name'];
break;
}
// Если столбик правый
if($i++ % 2)
$tmp_arr[] = $tmp;
else
$achievement['criterias'][] = $tmp;
}
// Если найден второй столбик - суем данные из него в конец основного массива
if($tmp_arr)
$achievement['criterias'] = array_merge($achievement['criterias'], $tmp_arr);
/*************** ЦЕПОЧКА ДОСТИЖЕНИЙ ***************/
$achievement['series'] = array(array(
'id' => $achievement['id'],
'name' => $achievement['name'],
'parent' => $achievement['parent']
));
$tmp = $achievement['series'][0];
while($tmp)
{
$tmp = $DB->selectRow('
SELECT id, name_loc?d AS name, parent
FROM ?_achievement
WHERE id = ?
',
$_SESSION['locale'],
$achievement['series'][0]['parent']
);
if($tmp)
array_unshift($achievement['series'], $tmp);
}
$tmp = end($achievement['series']);
while($tmp)
{
$end = end($achievement['series']);
$tmp = $DB->selectRow('
SELECT id, name_loc?d AS name, parent
FROM ?_achievement
WHERE parent = ?
',
$_SESSION['locale'],
$end['id']
);
if($tmp)
array_push($achievement['series'], $tmp);
}
if(count($achievement['series']) <= 1)
unset($achievement['series']);
save_cache(ACHIEVEMENT_PAGE, $cache_key, $achievement);
}
}
global $page;
$page = array(
'Mapper' => false,
'Book' => false,
'Title' => $achievement['name'].' - '.$smarty->get_config_vars('Achievement'),
'tab' => 0,
'type' => 9,
'typeid' => $achievement['id'],
'path' => path(0, 9, $achievement['category2'], $achievement['category1'])
);
$smarty->assign('page', $page);
// Комментарии
$smarty->assign('comments', getcomments($page['type'], $page['typeid']));
$smarty->assign('screenshots', getscreenshots($page['type'], $page['typeid']));
// Статистика выполнения mysql запросов
$smarty->assign('mysql', $DB->getStatistics());
$smarty->assign('achievement', $achievement);
// Загружаем страницу
$smarty->display('achievement.tpl');
?>