source: aowow/quest.php

Last change on this file was 170, checked in by maron, 15 years ago
  • Property svn:executable set to *
File size: 15.4 KB
Line 
1<?php
2
3// Необходима функция questinfo
4require_once('includes/allquests.php');
5require_once('includes/allobjects.php');
6require_once('includes/allnpcs.php');
7require_once('includes/allcomments.php');
8
9$smarty->config_load($conf_file, 'quest');
10
11// Номер квеста
12$id = $podrazdel;
13
14if(!$quest = load_cache(10, intval($id)))
15{
16 unset($quest);
17
18 // Подключаемся к ДБ:
19 global $DB;
20
21 // Основная инфа
22 $quest = GetDBQuestInfo($id, 0xFFFFFF);
23
24
25 /* ЦЕПОЧКА КВЕСТОВ */
26 // Добавляем сам квест в цепочку
27 $quest['series'] = array(
28 array(
29 'entry' => $quest['entry'],
30 'Title' => $quest['Title'],
31 'NextQuestInChain' => $quest['NextQuestInChain']
32 )
33 );
34 // Квесты в цепочке до этого квеста
35 $tmp = $quest['series'][0];
36 while($tmp)
37 {
38 $tmp = $DB->selectRow('
39 SELECT q.entry, q.Title
40 {, l.Title_loc?d AS `Title_loc`}
41 FROM quest_template q
42 {LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?d}
43 WHERE q.NextQuestInChain=?d
44 LIMIT 1
45 ',
46 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
47 ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
48 $quest['series'][0]['entry']
49 );
50 if($tmp)
51 {
52 if(!empty($tmp['Title_loc']))
53 $tmp['Title'] = $tmp['Title_loc'];
54 array_unshift($quest['series'], $tmp);
55 }
56 }
57 // Квесты в цепочке после этого квеста
58 $tmp = end($quest['series']);
59 while($tmp)
60 {
61 $tmp = $DB->selectRow('
62 SELECT q.entry, q.Title, q.NextQuestInChain
63 {, l.Title_loc?d AS `Title_loc`}
64 FROM quest_template q
65 {LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
66 WHERE q.entry=?d
67 LIMIT 1
68 ',
69 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
70 ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
71 $quest['series'][count($quest['series'])-1]['NextQuestInChain']
72 );
73 if($tmp)
74 {
75 if(!empty($tmp['Title_loc']))
76 $tmp['Title'] = $tmp['Title_loc'];
77 array_push($quest['series'], $tmp);
78 }
79 }
80 unset($tmp);
81 if (count($quest['series'])<=1)
82 unset($quest['series']);
83
84
85 /* ДРУГИЕ КВЕСТЫ */
86 // (после их нахождения проверяем их тайтлы на наличие локализации)
87
88
89 // Квесты, которые необходимо выполнить, что бы получить этот квест
90 if (!$quest['req'] = $DB->select('
91 SELECT q.entry, q.Title, q.NextQuestInChain
92 {, l.Title_loc?d AS `Title_loc`}
93 FROM quest_template q
94 {LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
95 WHERE
96 (q.NextQuestID=?d AND q.ExclusiveGroup<0)
97 OR (q.entry=?d AND q.NextQuestInChain<>?d)
98 LIMIT 20',
99 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
100 $quest['entry'], $quest['PrevQuestID'], $quest['entry']
101 )
102 )
103 unset($quest['req']);
104 else
105 $questItems[] = 'req';
106
107 // Квесты, которые становятся доступными, только после того как выполнен этот квест (необязательно только он)
108 if (!$quest['open'] = $DB->select('
109 SELECT q.entry, q.Title
110 {, l.Title_loc?d AS `Title_loc`}
111 FROM quest_template q
112 {LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
113 WHERE
114 (q.PrevQuestID=?d AND q.entry<>?d)
115 OR q.entry=?d
116 LIMIT 20',
117 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
118 $quest['entry'], $quest['NextQuestInChain'], $quest['NextQuestID']
119 )
120 )
121 unset($quest['open']);
122 else
123 $questItems[] = 'open';
124
125 // Квесты, которые становятся недоступными после выполнения этого квеста
126 if ($quest['ExclusiveGroup']>0)
127 if (!$quest['closes'] = $DB->select('
128 SELECT q.entry, q.Title
129 {, l.Title_loc?d AS `Title_loc`}
130 FROM quest_template q
131 {LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
132 WHERE
133 q.ExclusiveGroup=?d AND q.entry<>?d
134 LIMIT 20
135 ',
136 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
137 $quest['ExclusiveGroup'], $quest['entry']
138 )
139 )
140 unset($quest['closes']);
141 else
142 $questItems[] = 'closes';
143
144 // Требует выполнения одного из квестов, на выбор:
145 if(!$quest['reqone'] = $DB->select('
146 SELECT q.entry, q.Title
147 {, l.Title_loc?d AS `Title_loc`}
148 FROM quest_template q
149 {LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
150 WHERE
151 q.ExclusiveGroup>0 AND q.NextQuestId=?d
152 LIMIT 20
153 ',
154 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
155 $quest['entry']
156 )
157 )
158 unset($quest['reqone']);
159 else
160 $questItems[] = 'reqone';
161
162 // Квесты, которые доступны, только во время выполнения этого квеста
163 if(!$quest['enables'] = $DB->select('
164 SELECT q.entry, q.Title
165 {, l.Title_loc?d AS `Title_loc`}
166 FROM quest_template q
167 {LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
168 WHERE q.PrevQuestID=?d
169 LIMIT 20
170 ',
171 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
172 -$quest['entry']
173 )
174 )
175 unset($quest['enables']);
176 else
177 $questItems[] = 'enables';
178
179 // Квесты, во время выполнения которых доступен этот квест
180 if($quest['PrevQuestID']<0)
181 if(!$quest['enabledby'] = $DB->select('
182 SELECT q.entry, q.Title
183 {, l.Title_loc?d AS `Title_loc`}
184 FROM quest_template q
185 {LEFT JOIN (locales_quest l) ON l.entry=q.entry AND ?}
186 WHERE q.entry=?d
187 LIMIT 20
188 ',
189 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP, ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
190 -$quest['PrevQuestID']
191 )
192 )
193 unset($quest['enabledby']);
194 else
195 $questItems[] = 'enabledby';
196
197 // Теперь локализуем все тайтлы квестов
198 if($questItems)
199 foreach($questItems as $item)
200 foreach($quest[$item] as $i => $x)
201 if(!empty($quest[$item][$i]['Title_loc']))
202 $quest[$item][$i]['Title'] = $quest[$item][$i]['Title_loc'];
203
204
205
206 /* НАГРАДЫ И ТРЕБОВАНИЯ */
207
208 if($quest['RequiredSkillValue']>0 && $quest['SkillOrClass']>0)
209 {
210 // Требуемый уровень скилла, что бы получить квест
211 /*
212 $skills = array(
213 -264 => 197, // Tailoring
214 -182 => 165, // Leatherworking
215 -24 => 182, // Herbalism
216 -101 => 356, // Fishing
217 -324 => 129, // First Aid
218 -201 => 202, // Engineering
219 -304 => 185, // Cooking
220 -121 => 164, // Blacksmithing
221 -181 => 171 // Alchemy
222 );
223 */
224
225 // TODO: skill localization
226 $quest['reqskill'] = array(
227 'name' => $DB->selectCell('SELECT name FROM ?_skill WHERE skillID=?d LIMIT 1',$quest['SkillOrClass']),
228 'value' => $quest['RequiredSkillValue']
229 );
230 }
231 elseif($quest['SkillOrClass']<0)
232 // Требуемый класс, что бы получить квест
233 $quest['reqclass'] = $classes[abs($quest['SkillOrClass'])];
234
235 // Требуемые отношения с фракциями, что бы начать квест
236 if ($quest['RequiredMinRepFaction'] && $quest['RequiredMinRepValue'])
237 $quest['RequiredMinRep'] = array(
238 'name' => $DB->selectCell('SELECT name FROM ?_factions WHERE factionID=?d LIMIT 1', $quest['RequiredMinRepFaction']),
239 'entry' => $quest['RequiredMinRepFaction'],
240 'value' => $reputations[$quest['RequiredMinRepValue']]
241 );
242 if ($quest['RequiredMaxRepFaction'] && $quest['RequiredMaxRepValue'])
243 $quest['RequiredMaxRep'] = array(
244 'name' => $DB->selectCell('SELECT name FROM ?_factions WHERE factionID=?d LIMIT 1', $quest['RequiredMaxRepFaction']),
245 'entry' => $quest['RequiredMaxRepFaction'],
246 'value' => $reputations[$quest['RequiredMaxRepValue']]
247 );
248
249 // Спеллы не требуют локализации, их инфа берется из базы
250 // Хранить в базе все локализации - задачка на будующее
251
252 // Спелл, кастуемый на игрока в начале квеста
253 if($quest['SrcSpell'])
254 {
255 $tmp = $DB->selectRow('
256 SELECT ?#, s.spellname
257 FROM ?_spell s, ?_spellicons si
258 WHERE
259 s.spellID=?d
260 AND si.id=s.spellicon
261 LIMIT 1',
262 $spell_cols[0],
263 $quest['SrcSpell']
264 );
265 if($tmp)
266 {
267 $quest['SrcSpell'] = array(
268 'name' => $tmp['spellname'],
269 'entry' => $tmp['spellID']);
270 allspellsinfo2($tmp);
271 }
272 unset($tmp);
273 }
274
275 // Спелл, кастуемый на игрока в награду за выполнение
276 if($quest['RewSpellCast']>0 || $quest['RewSpell']>0)
277 {
278 $tmp = $DB->SelectRow('
279 SELECT ?#, s.spellname
280 FROM ?_spell s, ?_spellicons si
281 WHERE
282 s.spellID=?d
283 AND si.id=s.spellicon
284 LIMIT 1',
285 $spell_cols[0],
286 $quest['RewSpell']>0?$quest['RewSpell']:$quest['RewSpellCast']
287 );
288 if($tmp)
289 {
290 $quest['spellreward'] = array(
291 'name' => $tmp['spellname'],
292 'entry' => $tmp['spellID']);
293 allspellsinfo2($tmp);
294 }
295 unset($tmp);
296 }
297
298 // Создания, необходимые для квеста
299 //$quest['creaturereqs'] = array();
300 //$quest['objectreqs'] = array();
301 $quest['coreqs'] = array();
302 for($i=0;$i<=4;++$i)
303 {
304 //echo $quest['ReqCreatureOrGOCount'.$i].'<br />';
305 if($quest['ReqCreatureOrGOId'.$i] != 0 && $quest['ReqCreatureOrGOCount'.$i] != 0)
306 {
307 if($quest['ReqCreatureOrGOId'.$i] > 0)
308 {
309 // Необходимо какое-либо взамодействие с созданием
310 $quest['coreqs'][$i] = array_merge(
311 creatureinfo($quest['ReqCreatureOrGOId'.$i]),
312 array('req_type' => 'npc')
313 );
314 }
315 else
316 {
317 // необходимо какое-то взаимодействие с объектом
318 $quest['coreqs'][$i] = array_merge(
319 objectinfo(-$quest['ReqCreatureOrGOId'.$i]),
320 array('req_type' => 'object')
321 );
322 }
323 // Количество
324 $quest['coreqs'][$i]['count'] = $quest['ReqCreatureOrGOCount'.$i];
325 // Спелл
326 if ($quest['ReqSpellCast'.$i])
327 $quest['coreqs'][$i]['spell'] = array(
328 'name' => $DB->selectCell('SELECT spellname FROM ?_spell WHERE spellid=?d LIMIT 1', $quest['ReqSpellCast'.$i]),
329 'entry' => $quest['ReqSpellCast'.$i]
330 );
331 }
332 }
333 if(!$quest['coreqs'])
334 unset($quest['coreqs']);
335
336 // Вещи, необходимые для квеста
337 $quest['itemreqs'] = array();
338 for($i=0;$i<=4;++$i)
339 {
340 if($quest['ReqItemId'.$i]!=0 && $quest['ReqItemCount'.$i]!=0)
341 $quest['itemreqs'][] = array_merge(iteminfo($quest['ReqItemId'.$i]), array('count' => $quest['ReqItemCount'.$i]));
342 }
343 if(!$quest['itemreqs'])
344 unset($quest['itemreqs']);
345
346 // Фракции необходимые для квеста
347 if($quest['RepObjectiveFaction']>0 && $quest['RepObjectiveValue']>0)
348 {
349 $quest['factionreq'] = array(
350 'name' => $DB->selectCell('SELECT name FROM ?_factions WHERE factionID=?d LIMIT 1', $quest['RepObjectiveFaction']),
351 'entry' => $quest['RepObjectiveFaction'],
352 'value' => $reputations[$quest['RepObjectiveValue']]
353 );
354 }
355
356 /* КВЕСТГИВЕРЫ И КВЕСТТЕЙКЕРЫ */
357
358 // КВЕСТГИВЕРЫ
359 // НПС
360 $rows = $DB->select('
361 SELECT c.entry, c.name, A, H
362 {, l.name_loc?d as `name_loc`}
363 FROM creature_questrelation q, ?_factiontemplate, creature_template c
364 {LEFT JOIN (locales_creature l) ON l.entry=c.entry AND ?}
365 WHERE
366 q.quest=?d
367 AND c.entry=q.id
368 AND factiontemplateID=c.faction_A
369 ',
370 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
371 ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
372 $quest['entry']
373 );
374 if($rows)
375 {
376 foreach($rows as $tmp)
377 {
378 if(!empty($tmp['name_loc']))
379 $tmp['name'] = $tmp['name_loc'];
380 if($tmp['A'] == -1 && $tmp['H'] == 1)
381 $tmp['side'] = 'horde';
382 elseif($tmp['A'] == 1 && $tmp['H'] == -1)
383 $tmp['side'] = 'alliance';
384 $quest['start'][] = array_merge($tmp, array('type' => 'npc'));
385 }
386 }
387 unset($rows);
388
389 // ГО
390 $rows = $DB->select('
391 SELECT g.entry, g.name
392 {, l.name_loc?d as `name_loc`}
393 FROM gameobject_questrelation q, gameobject_template g
394 {LEFT JOIN (locales_gameobject l) ON l.entry = g.entry AND ?}
395 WHERE
396 q.quest=?d
397 AND g.entry=q.id
398 ',
399 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
400 ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
401 $quest['entry']
402 );
403 if($rows)
404 {
405 foreach($rows as $tmp)
406 {
407 if(!empty($tmp['name_loc']))
408 $tmp['name'] = $tmp['name_loc'];
409 $quest['start'][] = array_merge($tmp, array('type' => 'object'));
410 }
411 }
412 unset($rows);
413
414 // итем
415 $rows = $DB->select('
416 SELECT i.name, i.entry, i.quality, LOWER(a.iconname) AS iconname
417 {, l.name_loc?d as `name_loc`}
418 FROM ?_icons a, item_template i
419 {LEFT JOIN (locales_item l) ON l.entry=i.entry AND ?}
420 WHERE
421 startquest = ?d
422 AND id = displayid
423 ',
424 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
425 ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
426 $quest['entry']
427 );
428 if($rows)
429 {
430 foreach($rows as $tmp)
431 {
432 if(!empty($tmp['name_loc']))
433 $tmp['name'] = $tmp['name_loc'];
434 $quest['start'][] = array_merge($tmp, array('type' => 'item'));
435 }
436 }
437 unset($rows);
438
439 // КВЕСТТЕЙКЕРЫ
440 // НПС
441 $rows = $DB->select('
442 SELECT c.entry, c.name, A, H
443 {, l.name_loc?d as `name_loc`}
444 FROM creature_involvedrelation q, ?_factiontemplate, creature_template c
445 {LEFT JOIN (locales_creature l) ON l.entry=c.entry AND ?}
446 WHERE
447 q.quest=?d
448 AND c.entry=q.id
449 AND factiontemplateID=c.faction_A
450 ',
451 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
452 ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
453 $quest['entry']
454 );
455 if($rows)
456 {
457 foreach($rows as $tmp)
458 {
459 if(!empty($tmp['name_loc']))
460 $tmp['name'] = $tmp['name_loc'];
461 if($tmp['A'] == -1 && $tmp['H'] == 1)
462 $tmp['side'] = 'horde';
463 elseif($tmp['A'] == 1 && $tmp['H'] == -1)
464 $tmp['side'] = 'alliance';
465 $quest['end'][] = array_merge($tmp, array('type' => 'npc'));
466 }
467 }
468 unset($rows);
469
470 // ГО
471 $rows = $DB->select('
472 SELECT g.entry, g.name
473 {, l.name_loc?d as `name_loc`}
474 FROM gameobject_involvedrelation q, gameobject_template g
475 {LEFT JOIN (locales_gameobject l) ON l.entry = g.entry AND ?}
476 WHERE
477 q.quest=?d
478 AND g.entry=q.id
479 ',
480 ($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
481 ($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
482 $quest['entry']
483 );
484 if($rows)
485 {
486 foreach($rows as $tmp)
487 {
488 if(!empty($tmp['name_loc']))
489 $tmp['name'] = $tmp['name_loc'];
490 $quest['end'][] = array_merge($tmp, array('type' => 'object'));
491 }
492 }
493 unset($rows);
494
495 save_cache(10, $quest['entry'], $quest);
496}
497
498global $page;
499$page = array(
500 'Mapper' => false,
501 'Book' => false,
502 'Title' => $quest['Title'].' - '.$smarty->get_config_vars('Quests'),
503 'tab' => 0,
504 'type' => 5,
505 'typeid' => $quest['entry'],
506 'path' => '[]'
507);
508$smarty->assign('page', $page);
509
510// Комментарии
511$smarty->assign('comments', getcomments($page['type'], $page['typeid']));
512
513// Данные о квесте
514$smarty->assign('quest', $quest);
515// Если хоть одна информация о вещи найдена - передаём массив с информацией о вещях шаблонизатору
516if (isset($allitems))
517 $smarty->assign('allitems',$allitems);
518if (isset($allspells))
519 $smarty->assign('allspells',$allspells);
520// Количество MySQL запросов
521$smarty->assign('mysql', $DB->getStatistics());
522// Загружаем страницу
523$smarty->display('quest.tpl');
524
525?>
Note: See TracBrowser for help on using the repository browser.