forked from rigamrts/rigaaowow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
npc.php
451 lines (420 loc) · 12.1 KB
/
npc.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
<?php
require_once('includes/allspells.php');
require_once('includes/allquests.php');
require_once('includes/allnpcs.php');
require_once('includes/allcomments.php');
require_once('includes/allachievements.php');
require_once('includes/allevents.php');
// Настраиваем Smarty ;)
$smarty->config_load($conf_file, 'npc');
$id = intval($podrazdel);
$cache_key = cache_key($id);
if(!$npc = load_cache(NPC_PAGE, $cache_key))
{
unset($npc);
// Ищем NPC:
$npc = array();
$row = $DB->selectRow('
SELECT
?#, c.entry, c.name,
{
l.name_loc'.$_SESSION['locale'].' as `name_loc`,
l.subname_loc'.$_SESSION['locale'].' as `subname_loc`,
?,
}
f.name_loc'.$_SESSION['locale'].' as `faction-name`, ft.factionID as `factionID`,
((CASE exp WHEN 0 THEN mincls.basehp0 WHEN 1 THEN mincls.basehp1 WHEN 2 THEN mincls.basehp2 END)*Health_mod) AS minhealth,
((CASE exp WHEN 0 THEN maxcls.basehp0 WHEN 1 THEN maxcls.basehp1 WHEN 2 THEN maxcls.basehp2 END)*Health_mod) AS maxhealth,
(mincls.basemana*Mana_mod) AS minmana,
(maxcls.basemana*Mana_mod) AS maxmana,
(maxcls.basearmor*Armor_mod) AS armor
FROM ?_factiontemplate ft, ?_factions f, creature_template c
LEFT JOIN creature_classlevelstats mincls ON mincls.level=minlevel AND mincls.class=unit_class
LEFT JOIN creature_classlevelstats maxcls ON maxcls.level=maxlevel AND maxcls.class=unit_class
{
LEFT JOIN (locales_creature l)
ON l.entry = c.entry AND ?
}
WHERE
c.entry = ?
AND ft.factiontemplateID = c.faction_A
AND f.factionID = ft.factionID
LIMIT 1
',
$npc_cols[1],
($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$id
);
if($row)
{
$npc = $row;
$npc['name'] = localizedName($row);
$npc['subname'] = localizedName($row, 'subname');
if($npc['rank'] == 3)
{
$npc['minlevel'] = '??';
$npc['maxlevel'] = '??';
}
$npc['mindmg'] = round(($row['mindmg'] + $row['attackpower']) * $row['dmg_multiplier']);
$npc['maxdmg'] = round(($row['maxdmg'] + $row['attackpower']) * $row['dmg_multiplier']);
$toDiv = array('minhealth', 'maxmana', 'minmana', 'maxhealth', 'armor', 'mindmg', 'maxdmg');
// Разделяем на тысячи (ххххххххх => ххх,ххх,ххх)
foreach($toDiv as $e)
$npc[$e] = number_format($npc[$e]);
$npc['rank'] = $smarty->get_config_vars('rank'.$npc['rank']);
// faction_A = faction_H
$npc['faction_num'] = $row['factionID'];
$npc['faction'] = $row['faction-name'];
// Деньги
$money = ($row['mingold']+$row['maxgold']) / 2;
$npc = array_merge($npc, money2coins($money));
// Героик/нормал копия НПС
if($npc['difficulty_entry_1'])
{
// это нормал НПС, ищем героика
if($tmp = creatureinfo($npc['difficulty_entry_1']))
{
$npc['heroic'] = array(
'type' => 0,
'entry' => $tmp['entry'],
'name' => str_replace(LOCALE_HEROIC, '', $tmp['name'])
);
unset($tmp);
}
}
else
{
// А может быть героик НПС одним для нескольких нормалов?
// считаем что нет
$tmp = $DB->selectRow('
SELECT c.entry, c.name
{
, l.name_loc?d as `name_loc`
}
FROM creature_template c
{
LEFT JOIN (locales_creature l)
ON l.entry = c.entry AND ?
}
WHERE
c.difficulty_entry_1 = ?d
LIMIT 1
',
($_SESSION['locale']>0)? $_SESSION['locale']: DBSIMPLE_SKIP,
($_SESSION['locale']>0)? 1: DBSIMPLE_SKIP,
$npc['entry']
);
if($tmp)
{
$npc['heroic'] = array(
'type' => 1,
'entry' => $tmp['entry'],
'name' => localizedName($tmp)
);
$npc['name'] = str_replace(' (1)', '', $npc['name']);
$normal_entry = $tmp['entry'];
unset($tmp);
}
}
// Дроп
$lootid=$row['lootid'];
$skinid=$row['skinloot'];
$pickpocketid=$row['pickpocketloot'];
// Используемые спеллы
$npc['ablities'] = array();
$tmp = array();
for($j=0;$j<=4;++$j)
{
if($row['spell'.$j] && !in_array($row['spell'.$j], $tmp))
{
$tmp[] = $row['spell'.$j];
if($data = spellinfo($row['spell'.$j], 0))
{
if($data['name'])
$npc['abilities'][] = $data;
}
}
}
for($j=1;$j<4;$j++)
{
$tmp2 = $DB->select('
SELECT action?d_param1
FROM creature_ai_scripts
WHERE
creature_id=?d
AND action?d_type=11
',
$j,
$npc['entry'],
$j
);
if($tmp2)
foreach($tmp2 as $i=>$tmp3)
if(!in_array($tmp2[$i]['action'.$j.'_param1'], $tmp))
{
$tmp[] = $tmp2[$i]['action'.$j.'_param1'];
if($data = spellinfo($tmp2[$i]['action'.$j.'_param1'], 0))
{
if($data['name'])
$npc['abilities'][] = $data;
}
}
}
if(!$npc['ablities'])
unset($npc['ablities']);
// Обучает:
// Если это пет со способностью:
/* // Временно закомментировано
$row = $DB->selectRow('
SELECT Spell1, Spell2, Spell3, Spell4
FROM petcreateinfo_spell
WHERE
entry=?d
',
$npc['entry']
);
if($row)
{
$npc['teaches'] = array();
for($j=1;$j<=4;$j++)
if($row['Spell'.$j])
for($k=1;$k<=3;$k++)
{
$spellrow = $DB->selectRow('
SELECT ?#, spellID
FROM ?_spell, ?_spellicons
WHERE
spellID=(SELECT effect'.$k.'triggerspell FROM ?_spell WHERE spellID=?d AND (effect'.$k.'id IN (36,57)))
AND id=spellicon
LIMIT 1
',
$spell_cols[2],
$row['Spell'.$j]
);
if($spellrow)
{
$num = count($npc['teaches']);
$npc['teaches'][$num] = array();
$npc['teaches'][$num] = spellinfo2($spellrow);
}
}
}
unset ($row);*/
// Если это просто тренер
$teachspells = $DB->select('
SELECT ?#, spellID
FROM npc_trainer, ?_spell, ?_spellicons
WHERE
entry=?d
AND spellID=Spell
AND id=spellicon
',
$spell_cols[2],
$npc['entry']
);
if($teachspells)
{
if(!(IsSet($npc['teaches'])))
$npc['teaches'] = array();
foreach($teachspells as $teachspell)
{
$num = count($npc['teaches']);
$npc['teaches'][$num] = array();
$npc['teaches'][$num] = spellinfo2($teachspell);
}
}
unset ($teachspells);
// Продает:
$rows_s = $DB->select('
SELECT ?#, i.entry, i.maxcount, n.`maxcount` as `drop-maxcount`, n.ExtendedCost
{, l.name_loc?d AS `name_loc`}
FROM npc_vendor n, ?_icons, item_template i
{LEFT JOIN (locales_item l) ON l.entry=i.entry AND ?d}
WHERE
n.entry=?
AND i.entry=n.item
AND id=i.displayid
',
$item_cols[2],
($_SESSION['locale'])? $_SESSION['locale']: DBSIMPLE_SKIP,
($_SESSION['locale'])? 1: DBSIMPLE_SKIP,
$id
);
if($rows_s)
{
$npc['sells'] = array();
foreach($rows_s as $numRow=>$row)
{
$npc['sells'][$numRow] = array();
$npc['sells'][$numRow] = iteminfo2($row);
$npc['sells'][$numRow]['maxcount'] = $row['drop-maxcount'];
$npc['sells'][$numRow]['cost'] = array();
if($row['ExtendedCost'])
{
$extcost = $DB->selectRow('SELECT * FROM ?_item_extended_cost WHERE extendedcostID=?d LIMIT 1', abs($row['ExtendedCost']));
if($extcost['reqhonorpoints']>0)
$npc['sells'][$numRow]['cost']['honor'] = (($npc['A']==1)? 1: -1) * $extcost['reqhonorpoints'];
if($extcost['reqarenapoints']>0)
$npc['sells'][$numRow]['cost']['arena'] = $extcost['reqarenapoints'];
$npc['sells'][$numRow]['cost']['items'] = array();
for($j=1;$j<=5;$j++)
if(($extcost['reqitem'.$j]>0) and ($extcost['reqitemcount'.$j]>0))
{
allitemsinfo($extcost['reqitem'.$j], 0);
$npc['sells'][$numRow]['cost']['items'][] = array('item' => $extcost['reqitem'.$j], 'count' => $extcost['reqitemcount'.$j]);
}
}
if($row['BuyPrice']>0)
$npc['sells'][$numRow]['cost']['money'] = $row['BuyPrice'];
}
unset ($row);
unset ($numRow);
unset ($extcost);
}
unset ($rows_s);
// Дроп
if(!($npc['drop'] = loot('creature_loot_template', $lootid)))
unset ($npc['drop']);
// Кожа
if(!($npc['skinning'] = loot('skinning_loot_template', $skinid)))
unset ($npc['skinning']);
// Воруеццо
if(!($npc['pickpocketing'] = loot('pickpocketing_loot_template', $pickpocketid)))
unset ($npc['pickpocketing']);
// Начиниают квесты...
$rows_qs = $DB->select('
SELECT ?#
FROM creature_questrelation c, quest_template q
WHERE
c.id=?
AND q.entry=c.quest
',
$quest_cols[2],
$id
);
if($rows_qs)
{
$npc['starts'] = array();
foreach($rows_qs as $numRow=>$row) {
$npc['starts'][] = GetQuestInfo($row, 0xFFFFFF);
}
}
unset ($rows_qs);
// Начиниают event-only квесты...
$rows_qse = event_find(array('quest_creature_id' => $id));
if($rows_qse)
{
if (!isset($npc['starts']))
$npc['starts'] = array();
foreach($rows_qse as $event)
foreach($event['creatures_quests_id'] as $ids)
$npc['starts'][] = GetDBQuestInfo($ids['quest'], 0xFFFFFF);
}
unset ($rows_qse);
// Заканчивают квесты...
$rows_qe = $DB->select('
SELECT ?#
FROM creature_involvedrelation c, quest_template q
WHERE
c.id=?
AND q.entry=c.quest
',
$quest_cols[2],
$id
);
if($rows_qe)
{
$npc['ends'] = array();
foreach($rows_qe as $numRow=>$row) {
$npc['ends'][] = GetQuestInfo($row, 0xFFFFFF);
}
}
unset ($rows_qe);
// Необходимы для квеста..
$rows_qo = $DB->select('
SELECT ?#
FROM quest_template
WHERE
ReqCreatureOrGOId1=?
OR ReqCreatureOrGOId2=?
OR ReqCreatureOrGOId3=?
OR ReqCreatureOrGOId4=?
',
$quest_cols[2],
$id, $id, $id, $id
);
if($rows_qo)
{
$npc['objectiveof'] = array();
foreach($rows_qo as $numRow=>$row)
$npc['objectiveof'][] = GetQuestInfo($row, 0xFFFFFF);
}
unset ($rows_qo);
// Цель критерии
$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_KILL_CREATURE),
$npc['entry'],
$_SESSION['locale']
);
if($rows)
{
$npc['criteria_of'] = array();
foreach($rows as $row)
{
allachievementsinfo2($row['id']);
$npc['criteria_of'][] = achievementinfo2($row);
}
}
// Положения созданий божих (для героик НПС не задана карта, юзаем из нормала):
if($normal_entry)
// мы - героик НПС, определяем позицию по нормалу
$npc['position'] = position($normal_entry, 'creature', 2);
else
// мы - нормал НПС или НПС без сложности
$npc['position'] = position($npc['entry'], 'creature', 1);
// Исправить type, чтобы подсвечивались event-овые NPC
if ($npc['position'])
foreach ($npc['position'] as $z => $zone)
foreach ($zone['points'] as $p => $pos)
if ($pos['type'] == 0 && ($events = event_find(array('creature_guid' => $pos['guid']))))
{
$names = array_select_key(event_name($events), 'name');
$npc['position'][$z]['points'][$p]['type'] = 4;
$npc['position'][$z]['points'][$p]['events'] = implode(", ", $names);
}
save_cache(NPC_PAGE, $cache_key, $npc);
}
}
global $page;
$page = array(
'Mapper' => true,
'Book' => false,
'Title' => $npc['name'].' - '.$smarty->get_config_vars('NPCs'),
'tab' => 0,
'type' => 1,
'typeid' => $npc['entry'],
'path' => path(0, 4, $npc['type'])
);
$smarty->assign('page', $page);
// Комментарии
$smarty->assign('comments', getcomments($page['type'], $page['typeid']));
$smarty->assign('npc', $npc);
// Количество MySQL запросов
$smarty->assign('mysql', $DB->getStatistics());
// Запускаем шаблонизатор
$smarty->display('npc.tpl');
?>