forked from abelcaballero210890/rigaaowow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
quest.php
592 lines (545 loc) · 17.4 KB
/
quest.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
<?php
// Необходима функция questinfo
require_once('includes/allquests.php');
require_once('includes/allobjects.php');
require_once('includes/allnpcs.php');
require_once('includes/allcomments.php');
require_once('includes/allachievements.php');
require_once('includes/allevents.php');
$smarty->config_load($conf_file, 'quest');
// Номер квеста
$id = intval($podrazdel);
$cache_key = cache_key($id);
if(!$quest = load_cache(QUEST_PAGE, $cache_key))
{
unset($quest);
// Основная инфа
$quest = GetDBQuestInfo($id, 0xFFFFFF);
/* ЦЕПОЧКА КВЕСТОВ */
// Добавляем сам квест в цепочку
$quest['series'] = array(
array(
'entry' => $quest['entry'],
'Title' => $quest['Title'],
'NextQuestInChain' => $quest['NextQuestInChain']
)
);
// Квесты в цепочке до этого квеста
$tmp = $quest['series'][0];
while($tmp)
{
$tmp = $DB->selectRow('
SELECT q.entry, q.Title
{, l.Title_loc?d as Title_loc}
FROM quest_template q
{LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?d}
WHERE q.NextQuestInChain=?d
LIMIT 1
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$quest['series'][0]['entry']
);
if($tmp)
{
$tmp['Title'] = localizedName($tmp, 'Title');
array_unshift($quest['series'], $tmp);
}
}
// Квесты в цепочке после этого квеста
$tmp = end($quest['series']);
while($tmp)
{
$tmp = $DB->selectRow('
SELECT q.entry, q.Title, q.NextQuestInChain
{, l.Title_loc?d as Title_loc}
FROM quest_template q
{LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
WHERE q.entry=?d
LIMIT 1
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$quest['series'][count($quest['series'])-1]['NextQuestInChain']
);
if($tmp)
{
$tmp['Title'] = localizedName($tmp, 'Title');
array_push($quest['series'], $tmp);
}
}
unset($tmp);
if(count($quest['series'])<=1)
unset($quest['series']);
/* ДРУГИЕ КВЕСТЫ */
// (после их нахождения проверяем их тайтлы на наличие локализации)
// Квесты, которые необходимо выполнить, что бы получить этот квест
if(!$quest['req'] = $DB->select('
SELECT q.entry, q.Title, q.NextQuestInChain
{, l.Title_loc?d as Title_loc}
FROM quest_template q
{LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
WHERE
(q.NextQuestID=?d AND q.ExclusiveGroup<0)
OR (q.entry=?d AND q.NextQuestInChain<>?d)
LIMIT 20',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$quest['entry'], $quest['PrevQuestID'], $quest['entry']
)
)
unset($quest['req']);
else
$questItems[] = 'req';
// Квесты, которые становятся доступными, только после того как выполнен этот квест (необязательно только он)
if(!$quest['open'] = $DB->select('
SELECT q.entry, q.Title
{, l.Title_loc?d as Title_loc}
FROM quest_template q
{LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
WHERE
(q.PrevQuestID=?d AND q.entry<>?d)
OR q.entry=?d
LIMIT 20',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$quest['entry'], $quest['NextQuestInChain'], $quest['NextQuestID']
)
)
unset($quest['open']);
else
$questItems[] = 'open';
// Квесты, которые становятся недоступными после выполнения этого квеста
if($quest['ExclusiveGroup']>0)
if(!$quest['closes'] = $DB->select('
SELECT q.entry, q.Title
{, l.Title_loc?d as Title_loc}
FROM quest_template q
{LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
WHERE
q.ExclusiveGroup=?d AND q.entry<>?d
LIMIT 20
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$quest['ExclusiveGroup'], $quest['entry']
)
)
unset($quest['closes']);
else
$questItems[] = 'closes';
// Требует выполнения одного из квестов, на выбор:
if(!$quest['reqone'] = $DB->select('
SELECT q.entry, q.Title
{, l.Title_loc?d as Title_loc}
FROM quest_template q
{LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
WHERE
q.ExclusiveGroup>0 AND q.NextQuestId=?d
LIMIT 20
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$quest['entry']
)
)
unset($quest['reqone']);
else
$questItems[] = 'reqone';
// Квесты, которые доступны, только во время выполнения этого квеста
if(!$quest['enables'] = $DB->select('
SELECT q.entry, q.Title
{, l.Title_loc?d as Title_loc}
FROM quest_template q
{LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
WHERE q.PrevQuestID=?d
LIMIT 20
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
-$quest['entry']
)
)
unset($quest['enables']);
else
$questItems[] = 'enables';
// Квесты, во время выполнения которых доступен этот квест
if($quest['PrevQuestID']<0)
if(!$quest['enabledby'] = $DB->select('
SELECT q.entry, q.Title
{, l.Title_loc?d as Title_loc}
FROM quest_template q
{LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
WHERE q.entry=?d
LIMIT 20
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
-$quest['PrevQuestID']
)
)
unset($quest['enabledby']);
else
$questItems[] = 'enabledby';
// Теперь локализуем все тайтлы квестов
if($questItems)
foreach($questItems as $item)
foreach($quest[$item] as $i => $x)
$quest[$item][$i]['Title'] = localizedName($quest[$item][$i], 'Title');
/* НАГРАДЫ И ТРЕБОВАНИЯ */
if($quest['RequiredSkillValue']>0 && $quest['SkillOrClassMask']>0)
{
// Требуемый уровень скилла, что бы получить квест
/*
$skills = array(
-264 => 197, // Tailoring
-182 => 165, // Leatherworking
-24 => 182, // Herbalism
-101 => 356, // Fishing
-324 => 129, // First Aid
-201 => 202, // Engineering
-304 => 185, // Cooking
-121 => 164, // Blacksmithing
-181 => 171 // Alchemy
);
*/
// TODO: skill localization
$quest['reqskill'] = array(
'name' => $DB->selectCell('SELECT name_loc'.$_SESSION['locale'].' FROM ?_skill WHERE skillID=?d LIMIT 1',$quest['SkillOrClassMask']),
'value' => $quest['RequiredSkillValue']
);
}
elseif($quest['SkillOrClassMask']<0)
{
$s = array();
foreach($classes as $i => $class)
if (intval(-$quest['SkillOrClassMask']) & (1<<$i))
$s[] = $class;
if (count($s) == 0) $s[] = "UNKNOWN";
// Требуемый класс, что бы получить квест
$quest['reqclass'] = implode(", ", $s);
}
// Требуемые отношения с фракциями, что бы начать квест
if($quest['RequiredMinRepFaction'])
$quest['RequiredMinRep'] = array(
'name' => $DB->selectCell('SELECT name_loc'.$_SESSION['locale'].' FROM ?_factions WHERE factionID=?d LIMIT 1', $quest['RequiredMinRepFaction']),
'entry' => $quest['RequiredMinRepFaction'],
'value' => reputations($quest['RequiredMinRepValue'])
);
if($quest['RequiredMaxRepFaction'])
$quest['RequiredMaxRep'] = array(
'name' => $DB->selectCell('SELECT name_loc'.$_SESSION['locale'].' FROM ?_factions WHERE factionID=?d LIMIT 1', $quest['RequiredMaxRepFaction']),
'entry' => $quest['RequiredMaxRepFaction'],
'value' => reputations($quest['RequiredMaxRepValue'])
);
// Спеллы не требуют локализации, их инфа берется из базы
// Хранить в базе все локализации - задачка на будующее
// Спелл, кастуемый на игрока в начале квеста
if($quest['SrcSpell'])
{
$tmp = $DB->selectRow('
SELECT ?#, s.spellname_loc'.$_SESSION['locale'].'
FROM ?_spell s, ?_spellicons si
WHERE
s.spellID=?d
AND si.id=s.spellicon
LIMIT 1',
$spell_cols[0],
$quest['SrcSpell']
);
if($tmp)
{
$quest['SrcSpell'] = array(
'name' => $tmp['spellname_loc'.$_SESSION['locale']],
'entry' => $tmp['spellID']);
allspellsinfo2($tmp);
}
unset($tmp);
}
// Итем, выдаваемый игроку в начале квеста
if($quest['SrcItemId'])
{
$quest['SrcItem'] = iteminfo($quest['SrcItemId']);
$quest['SrcItem']['count'] = $quest['SrcItemCount'];
}
// Дополнительная информация о квесте (флаги, повторяемость, скрипты)
$quest['flagsdetails'] = GetQuestFlagsDetails($quest);
if (!$quest['flagsdetails'])
unset($quest['flagsdetails']);
// Спелл, кастуемый на игрока в награду за выполнение
if($quest['RewSpellCast']>0 || $quest['RewSpell']>0)
{
$tmp = $DB->SelectRow('
SELECT ?#, s.spellname_loc'.$_SESSION['locale'].'
FROM ?_spell s, ?_spellicons si
WHERE
s.spellID=?d
AND si.id=s.spellicon
LIMIT 1',
$spell_cols[0],
$quest['RewSpell']>0?$quest['RewSpell']:$quest['RewSpellCast']
);
if($tmp)
{
$quest['spellreward'] = array(
'name' => $tmp['spellname_loc'.$_SESSION['locale']],
'entry' => $tmp['spellID'],
'realentry' => $quest['RewSpellCast']>0 ? $quest['RewSpellCast'] : $quest['RewSpell']);
allspellsinfo2($tmp);
}
unset($tmp);
}
// Создания, необходимые для квеста
//$quest['creaturereqs'] = array();
//$quest['objectreqs'] = array();
$quest['coreqs'] = array();
for($i=0;$i<=4;++$i)
{
//echo $quest['ReqCreatureOrGOCount'.$i].'<br />';
if($quest['ReqCreatureOrGOId'.$i] != 0 && $quest['ReqCreatureOrGOCount'.$i] != 0)
{
if($quest['ReqCreatureOrGOId'.$i] > 0)
{
// Необходимо какое-либо взамодействие с созданием
$quest['coreqs'][$i] = array_merge(
creatureinfo($quest['ReqCreatureOrGOId'.$i]),
array('req_type' => 'npc')
);
}
else
{
// необходимо какое-то взаимодействие с объектом
$quest['coreqs'][$i] = array_merge(
objectinfo(-$quest['ReqCreatureOrGOId'.$i]),
array('req_type' => 'object')
);
}
// Количество
$quest['coreqs'][$i]['count'] = $quest['ReqCreatureOrGOCount'.$i];
// Спелл
if($quest['ReqSpellCast'.$i])
$quest['coreqs'][$i]['spell'] = array(
'name' => $DB->selectCell('SELECT spellname_loc'.$_SESSION['locale'].' FROM ?_spell WHERE spellid=?d LIMIT 1', $quest['ReqSpellCast'.$i]),
'entry' => $quest['ReqSpellCast'.$i]
);
}
}
if(!$quest['coreqs'])
unset($quest['coreqs']);
// Вещи, необходимые для квеста
$quest['itemreqs'] = array();
for($i=0;$i<=4;++$i)
{
if($quest['ReqItemId'.$i]!=0 && $quest['ReqItemCount'.$i]!=0)
$quest['itemreqs'][] = array_merge(iteminfo($quest['ReqItemId'.$i]), array('count' => $quest['ReqItemCount'.$i]));
}
if(!$quest['itemreqs'])
unset($quest['itemreqs']);
// Фракции необходимые для квеста
if($quest['RepObjectiveFaction']>0)
{
$quest['factionreq'] = array(
'name' => $DB->selectCell('SELECT name_loc'.$_SESSION['locale'].' FROM ?_factions WHERE factionID=?d LIMIT 1', $quest['RepObjectiveFaction']),
'entry' => $quest['RepObjectiveFaction'],
'value' => reputations($quest['RepObjectiveValue'])
);
}
/* КВЕСТГИВЕРЫ И КВЕСТТЕЙКЕРЫ */
// КВЕСТГИВЕРЫ
// НПС
$rows = $DB->select('
SELECT c.entry, c.name, A, H
{, l.name_loc?d AS name_loc}
FROM creature_questrelation q, ?_factiontemplate, creature_template c
{LEFT JOIN (locales_creature l) ON l.entry=c.entry AND ?}
WHERE
q.quest=?d
AND c.entry=q.id
AND factiontemplateID=c.faction_A
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$quest['entry']
);
if($rows)
{
foreach($rows as $tmp)
{
$tmp['name'] = localizedName($tmp);
if($tmp['A'] == -1 && $tmp['H'] == 1)
$tmp['side'] = 'horde';
elseif($tmp['A'] == 1 && $tmp['H'] == -1)
$tmp['side'] = 'alliance';
$quest['start'][] = array_merge($tmp, array('type' => 'npc'));
}
}
unset($rows);
// НПС-ивентовые
$rows = event_find(array('quest_id' => $quest['entry']));
if ($rows)
{
foreach ($rows as $event)
foreach ($event['creatures_quests_id'] as $ids)
if ($ids['quest'] == $quest['entry'])
{
$tmp = creatureinfo($ids['creature']);
if($tmp['react'] == '-1,1')
$tmp['side'] = 'horde';
elseif($tmp['react'] == '1,-1')
$tmp['side'] = 'alliance';
$tmp['type'] = 'npc';
$tmp['event'] = $event['entry'];
$quest['start'][] = $tmp;
}
}
unset($rows);
// ГО
$rows = $DB->select('
SELECT g.entry, g.name
{, l.name_loc?d AS name_loc}
FROM gameobject_questrelation q, gameobject_template g
{LEFT JOIN (locales_gameobject l) ON l.entry = g.entry AND ?}
WHERE
q.quest=?d
AND g.entry=q.id
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$quest['entry']
);
if($rows)
{
foreach($rows as $tmp)
{
$tmp['name'] = localizedName($tmp);
$quest['start'][] = array_merge($tmp, array('type' => 'object'));
}
}
unset($rows);
// итем
$rows = $DB->select('
SELECT i.name, i.entry, i.quality, LOWER(a.iconname) AS iconname
{, l.name_loc?d AS name_loc}
FROM ?_icons a, item_template i
{LEFT JOIN (locales_item l) ON l.entry=i.entry AND ?}
WHERE
startquest = ?d
AND id = displayid
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$quest['entry']
);
if($rows)
{
foreach($rows as $tmp)
{
$tmp['name'] = localizedName($tmp);
$quest['start'][] = array_merge($tmp, array('type' => 'item'));
}
}
unset($rows);
// КВЕСТТЕЙКЕРЫ
// НПС
$rows = $DB->select('
SELECT c.entry, c.name, A, H
{, l.name_loc?d AS name_loc}
FROM creature_involvedrelation q, ?_factiontemplate, creature_template c
{LEFT JOIN (locales_creature l) ON l.entry=c.entry AND ?}
WHERE
q.quest=?d
AND c.entry=q.id
AND factiontemplateID=c.faction_A
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$quest['entry']
);
if($rows)
{
foreach($rows as $tmp)
{
$tmp['name'] = localizedName($tmp);
if($tmp['A'] == -1 && $tmp['H'] == 1)
$tmp['side'] = 'horde';
elseif($tmp['A'] == 1 && $tmp['H'] == -1)
$tmp['side'] = 'alliance';
$quest['end'][] = array_merge($tmp, array('type' => 'npc'));
}
}
unset($rows);
// ГО
$rows = $DB->select('
SELECT g.entry, g.name
{, l.name_loc?d AS name_loc}
FROM gameobject_involvedrelation q, gameobject_template g
{LEFT JOIN (locales_gameobject l) ON l.entry = g.entry AND ?}
WHERE
q.quest=?d
AND g.entry=q.id
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$quest['entry']
);
if($rows)
{
foreach($rows as $tmp)
{
$tmp['name'] = localizedName($tmp);
$quest['end'][] = array_merge($tmp, array('type' => 'object'));
}
}
unset($rows);
// Цель критерии
$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 IN (?a)
AND c.value1 = ?d
GROUP BY a.id
ORDER BY a.name_loc?d
',
$_SESSION['locale'],
$_SESSION['locale'],
array(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST),
$quest['entry'],
$_SESSION['locale']
);
if($rows)
{
$quest['criteria_of'] = array();
foreach($rows as $row)
{
allachievementsinfo2($row['id']);
$quest['criteria_of'][] = achievementinfo2($row);
}
}
// Награды и благодарности, присылаемые почтой
if ($quest['RewMailTemplateId'])
{
if(!($quest['mailrewards'] = loot('mail_loot_template', $quest['RewMailTemplateId'])))
unset ($quest['mailrewards']);
}
if ($quest['RewMailDelaySecs'])
$quest['maildelay'] = sec_to_time($quest['RewMailDelaySecs']);
save_cache(QUEST_PAGE, $cache_key, $quest);
}
global $page;
$page = array(
'Mapper' => false,
'Book' => false,
'Title' => $quest['Title'].' - '.$smarty->get_config_vars('Quests'),
'tab' => 0,
'type' => 5,
'typeid' => $quest['entry'],
'path' => path(0, 5) // TODO
);
$smarty->assign('page', $page);
// Комментарии
$smarty->assign('comments', getcomments($page['type'], $page['typeid']));
// Данные о квесте
$smarty->assign('quest', $quest);
// Количество MySQL запросов
$smarty->assign('mysql', $DB->getStatistics());
// Загружаем страницу
$smarty->display('quest.tpl');
?>