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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
|
/*
* Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
*
* Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Common.h"
#include "Log.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "Opcodes.h"
#include "World.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "GossipDef.h"
#include "QuestDef.h"
#include "ObjectAccessor.h"
#include "ScriptCalls.h"
#include "Group.h"
void WorldSession::HandleQuestgiverStatusQueryOpcode( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8);
uint64 guid;
recv_data >> guid;
uint8 questStatus = DIALOG_STATUS_NONE;
uint8 defstatus = DIALOG_STATUS_NONE;
Object* questgiver = ObjectAccessor::GetObjectByTypeMask(*_player, guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
if(!questgiver)
{
sLog.outDetail("Error in CMSG_QUESTGIVER_STATUS_QUERY, called for not found questgiver (Typeid: %u GUID: %u)",GuidHigh2TypeId(GUID_HIPART(guid)),GUID_LOPART(guid));
return;
}
switch(questgiver->GetTypeId())
{
case TYPEID_UNIT:
{
sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_STATUS_QUERY for npc, guid = %u",uint32(GUID_LOPART(guid)) );
Creature* cr_questgiver=(Creature*)questgiver;
if( !cr_questgiver->IsHostileTo(_player)) // not show quest status to enemies
{
questStatus = Script->NPCDialogStatus(_player, cr_questgiver);
if( questStatus > 6 )
questStatus = getDialogStatus(_player, cr_questgiver, defstatus);
}
break;
}
case TYPEID_GAMEOBJECT:
{
sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_STATUS_QUERY for GameObject guid = %u",uint32(GUID_LOPART(guid)) );
GameObject* go_questgiver=(GameObject*)questgiver;
questStatus = Script->GODialogStatus(_player, go_questgiver);
if( questStatus > 6 )
questStatus = getDialogStatus(_player, go_questgiver, defstatus);
break;
}
default:
sLog.outError("QuestGiver called for unexpected type %u", questgiver->GetTypeId());
break;
}
//inform client about status of quest
_player->PlayerTalkClass->SendQuestGiverStatus(questStatus, guid);
}
void WorldSession::HandleQuestgiverHelloOpcode( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8);
uint64 guid;
recv_data >> guid;
sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_HELLO npc = %u",guid );
Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_NONE);
if (!pCreature)
{
sLog.outDebug( "WORLD: HandleQuestgiverHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
return;
}
// remove fake death
if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
// Stop the npc if moving
pCreature->StopMoving();
if(Script->GossipHello( _player, pCreature ) )
return;
pCreature->prepareGossipMenu(_player);
pCreature->sendPreparedGossip(_player);
}
void WorldSession::HandleQuestgiverAcceptQuestOpcode( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8+4);
uint64 guid;
uint32 quest;
recv_data >> guid >> quest;
if(!GetPlayer()->isAlive())
return;
sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_ACCEPT_QUEST npc = %u, quest = %u",uint32(GUID_LOPART(guid)),quest );
Object* pObject = ObjectAccessor::GetObjectByTypeMask(*_player, guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT|TYPEMASK_ITEM|TYPEMASK_PLAYER);
// no or incorrect quest giver
if(!pObject
|| (pObject->GetTypeId()!=TYPEID_PLAYER && !pObject->hasQuest(quest))
|| (pObject->GetTypeId()==TYPEID_PLAYER && !((Player*)pObject)->CanShareQuest(quest))
)
{
_player->PlayerTalkClass->CloseGossip();
_player->SetDivider( 0 );
return;
}
Quest const* qInfo = objmgr.GetQuestTemplate(quest);
if ( qInfo )
{
// prevent cheating
if(!GetPlayer()->CanTakeQuest(qInfo,true) )
{
_player->PlayerTalkClass->CloseGossip();
_player->SetDivider( 0 );
return;
}
if( _player->GetDivider() != 0 )
{
Player *pPlayer = ObjectAccessor::FindPlayer( _player->GetDivider() );
if( pPlayer )
{
pPlayer->SendPushToPartyResponse( _player, QUEST_PARTY_MSG_ACCEPT_QUEST );
_player->SetDivider( 0 );
}
}
if( _player->CanAddQuest( qInfo, true ) )
{
_player->AddQuest( qInfo, pObject );
if ( _player->CanCompleteQuest( quest ) )
_player->CompleteQuest( quest );
switch(pObject->GetTypeId())
{
case TYPEID_UNIT:
Script->QuestAccept(_player, ((Creature*)pObject), qInfo );
break;
case TYPEID_ITEM:
case TYPEID_CONTAINER:
{
Script->ItemQuestAccept(_player, ((Item*)pObject), qInfo );
// destroy not required for quest finish quest starting item
bool destroyItem = true;
for(int i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
{
if ((qInfo->ReqItemId[i] == ((Item*)pObject)->GetEntry()) && (((Item*)pObject)->GetProto()->MaxCount != 0))
{
destroyItem = false;
break;
}
}
if(destroyItem)
_player->DestroyItem(((Item*)pObject)->GetBagSlot(),((Item*)pObject)->GetSlot(),true);
break;
}
case TYPEID_GAMEOBJECT:
Script->GOQuestAccept(_player, ((GameObject*)pObject), qInfo );
break;
}
_player->PlayerTalkClass->CloseGossip();
if( qInfo->GetSrcSpell() > 0 )
_player->CastSpell( _player, qInfo->GetSrcSpell(), true);
return;
}
}
_player->PlayerTalkClass->CloseGossip();
}
void WorldSession::HandleQuestgiverQuestQueryOpcode( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8+4);
uint64 guid;
uint32 quest;
recv_data >> guid >> quest;
sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_QUERY_QUEST npc = %u, quest = %u",uint32(GUID_LOPART(guid)),quest );
// Verify that the guid is valid and is a questgiver or involved in the requested quest
Object* pObject = ObjectAccessor::GetObjectByTypeMask(*_player, guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT|TYPEMASK_ITEM);
if(!pObject||!pObject->hasQuest(quest) && !pObject->hasInvolvedQuest(quest))
{
_player->PlayerTalkClass->CloseGossip();
return;
}
Quest const* pQuest = objmgr.GetQuestTemplate(quest);
if ( pQuest )
{
_player->PlayerTalkClass->SendQuestGiverQuestDetails(pQuest, pObject->GetGUID(), true);
}
}
void WorldSession::HandleQuestQueryOpcode( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,4);
uint32 quest;
recv_data >> quest;
sLog.outDebug( "WORLD: Received CMSG_QUEST_QUERY quest = %u",quest );
Quest const *pQuest = objmgr.GetQuestTemplate(quest);
if ( pQuest )
{
_player->PlayerTalkClass->SendQuestQueryResponse( pQuest );
}
}
void WorldSession::HandleQuestgiverChooseRewardOpcode( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8+4+4);
uint32 quest, reward;
uint64 guid;
recv_data >> guid >> quest >> reward;
if(reward >= QUEST_REWARD_CHOICES_COUNT)
{
sLog.outError("Error in CMSG_QUESTGIVER_CHOOSE_REWARD: player %s (guid %d) tried to get invalid reward (%u) (probably packet hacking)", _player->GetName(), _player->GetGUIDLow(), reward);
return;
}
if(!GetPlayer()->isAlive())
return;
sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_CHOOSE_REWARD npc = %u, quest = %u, reward = %u",uint32(GUID_LOPART(guid)),quest,reward );
Object* pObject = ObjectAccessor::GetObjectByTypeMask(*_player, guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
if(!pObject)
return;
if(!pObject->hasInvolvedQuest(quest))
return;
Quest const *pQuest = objmgr.GetQuestTemplate(quest);
if( pQuest )
{
if( _player->CanRewardQuest( pQuest, reward, true ) )
{
_player->RewardQuest( pQuest, reward, pObject );
switch(pObject->GetTypeId())
{
case TYPEID_UNIT:
if( !(Script->ChooseReward( _player, ((Creature*)pObject), pQuest, reward )) )
{
// Send next quest
if(Quest const* nextquest = _player->GetNextQuest( guid ,pQuest ) )
_player->PlayerTalkClass->SendQuestGiverQuestDetails(nextquest,guid,true);
}
break;
case TYPEID_GAMEOBJECT:
if( !Script->GOChooseReward( _player, ((GameObject*)pObject), pQuest, reward ) )
{
// Send next quest
if(Quest const* nextquest = _player->GetNextQuest( guid ,pQuest ) )
_player->PlayerTalkClass->SendQuestGiverQuestDetails(nextquest,guid,true);
}
break;
}
}
else
_player->PlayerTalkClass->SendQuestGiverOfferReward( pQuest, guid, true );
}
}
void WorldSession::HandleQuestgiverRequestRewardOpcode( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8+4);
uint32 quest;
uint64 guid;
recv_data >> guid >> quest;
if(!GetPlayer()->isAlive())
return;
sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_REQUEST_REWARD npc = %u, quest = %u",uint32(GUID_LOPART(guid)),quest );
Object* pObject = ObjectAccessor::GetObjectByTypeMask(*_player, guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
if(!pObject||!pObject->hasInvolvedQuest(quest))
return;
if ( _player->CanCompleteQuest( quest ) )
_player->CompleteQuest( quest );
if( _player->GetQuestStatus( quest ) != QUEST_STATUS_COMPLETE )
return;
if(Quest const *pQuest = objmgr.GetQuestTemplate(quest))
_player->PlayerTalkClass->SendQuestGiverOfferReward( pQuest, guid, true );
}
void WorldSession::HandleQuestgiverCancel(WorldPacket& /*recv_data*/ )
{
sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_CANCEL" );
_player->PlayerTalkClass->CloseGossip();
}
void WorldSession::HandleQuestLogSwapQuest(WorldPacket& recv_data )
{
CHECK_PACKET_SIZE(recv_data,1+1);
uint8 slot1, slot2;
recv_data >> slot1 >> slot2;
if(slot1 == slot2 || slot1 >= MAX_QUEST_LOG_SIZE || slot2 >= MAX_QUEST_LOG_SIZE)
return;
sLog.outDebug( "WORLD: Received CMSG_QUESTLOG_SWAP_QUEST slot 1 = %u, slot 2 = %u", slot1, slot2 );
GetPlayer()->SwapQuestSlot(slot1,slot2);
}
void WorldSession::HandleQuestLogRemoveQuest(WorldPacket& recv_data)
{
CHECK_PACKET_SIZE(recv_data,1);
uint8 slot;
recv_data >> slot;
sLog.outDebug( "WORLD: Received CMSG_QUESTLOG_REMOVE_QUEST slot = %u",slot );
if( slot < MAX_QUEST_LOG_SIZE )
{
if(uint32 quest = _player->GetQuestSlotQuestId(slot))
{
if(!_player->TakeQuestSourceItem( quest, true ))
return; // can't un-equip some items, reject quest cancel
_player->SetQuestStatus( quest, QUEST_STATUS_NONE);
}
_player->SetQuestSlot(slot, 0);
}
}
void WorldSession::HandleQuestConfirmAccept(WorldPacket& recv_data)
{
CHECK_PACKET_SIZE(recv_data,4);
uint32 quest;
recv_data >> quest;
sLog.outDebug( "WORLD: Received CMSG_QUEST_CONFIRM_ACCEPT quest = %u",quest );
}
void WorldSession::HandleQuestComplete(WorldPacket& recv_data)
{
CHECK_PACKET_SIZE(recv_data,8+4);
uint32 quest;
uint64 guid;
recv_data >> guid >> quest;
if(!GetPlayer()->isAlive())
return;
sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_COMPLETE_QUEST npc = %u, quest = %u",uint32(GUID_LOPART(guid)),quest );
Quest const *pQuest = objmgr.GetQuestTemplate(quest);
if( pQuest )
{
if( _player->GetQuestStatus( quest ) != QUEST_STATUS_COMPLETE )
{
if( pQuest->IsRepeatable() )
_player->PlayerTalkClass->SendQuestGiverRequestItems(pQuest, guid, _player->CanCompleteRepeatableQuest(pQuest), false);
else
_player->PlayerTalkClass->SendQuestGiverRequestItems(pQuest, guid, _player->CanRewardQuest(pQuest,false), false);
}
else
_player->PlayerTalkClass->SendQuestGiverRequestItems(pQuest, guid, _player->CanRewardQuest(pQuest,false), false);
}
}
void WorldSession::HandleQuestAutoLaunch(WorldPacket& /*recvPacket*/)
{
sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_QUEST_AUTOLAUNCH (Send your log to anakin if you see this message)" );
}
void WorldSession::HandleQuestPushToParty(WorldPacket& recvPacket)
{
CHECK_PACKET_SIZE(recvPacket,4);
uint32 quest;
recvPacket >> quest;
sLog.outDebug( "WORLD: Received CMSG_PUSHQUESTTOPARTY quest = %u", quest );
Quest const *pQuest = objmgr.GetQuestTemplate(quest);
if( pQuest )
{
if( _player->GetGroup() )
{
Group *pGroup = _player->GetGroup();
if( pGroup )
{
for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
{
Player *pPlayer = itr->getSource();
if (!pPlayer || pPlayer == _player) // skip self
continue;
_player->SendPushToPartyResponse(pPlayer, QUEST_PARTY_MSG_SHARING_QUEST);
if( _player->GetDistance( pPlayer ) > 10 )
{
_player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_TOO_FAR );
continue;
}
if( !pPlayer->SatisfyQuestStatus( pQuest, false ) )
{
_player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_HAVE_QUEST );
continue;
}
if( pPlayer->GetQuestStatus( quest ) == QUEST_STATUS_COMPLETE )
{
_player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_FINISH_QUEST );
continue;
}
if( !pPlayer->CanTakeQuest( pQuest, false ) )
{
_player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_CANT_TAKE_QUEST );
continue;
}
if( !pPlayer->SatisfyQuestLog( false ) )
{
_player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_LOG_FULL );
continue;
}
if( pPlayer->GetDivider() != 0 )
{
_player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_BUSY );
continue;
}
pPlayer->PlayerTalkClass->SendQuestGiverQuestDetails( pQuest, _player->GetGUID(), true );
pPlayer->SetDivider( _player->GetGUID() );
}
}
}
}
}
void WorldSession::HandleQuestPushResult(WorldPacket& recvPacket)
{
CHECK_PACKET_SIZE(recvPacket,8+1);
uint64 guid;
uint8 msg;
recvPacket >> guid >> msg;
sLog.outDebug( "WORLD: Received MSG_QUEST_PUSH_RESULT" );
if( _player->GetDivider() != 0 )
{
Player *pPlayer = ObjectAccessor::FindPlayer( _player->GetDivider() );
if( pPlayer )
{
WorldPacket data( MSG_QUEST_PUSH_RESULT, (8+1) );
data << uint64(guid);
data << uint8(msg); // valid values: 0-8
pPlayer->GetSession()->SendPacket(&data);
_player->SetDivider( 0 );
}
}
}
uint32 WorldSession::getDialogStatus(Player *pPlayer, Object* questgiver, uint32 defstatus)
{
uint32 result = defstatus;
QuestRelations const* qir;
QuestRelations const* qr;
switch(questgiver->GetTypeId())
{
case TYPEID_GAMEOBJECT:
{
qir = &objmgr.mGOQuestInvolvedRelations;
qr = &objmgr.mGOQuestRelations;
break;
}
case TYPEID_UNIT:
{
qir = &objmgr.mCreatureQuestInvolvedRelations;
qr = &objmgr.mCreatureQuestRelations;
break;
}
default:
//its imposible, but check ^)
sLog.outError("Warning: GetDialogStatus called for unexpected type %u", questgiver->GetTypeId());
return DIALOG_STATUS_NONE;
}
for(QuestRelations::const_iterator i = qir->lower_bound(questgiver->GetEntry()); i != qir->upper_bound(questgiver->GetEntry()); ++i )
{
uint32 result2 = 0;
uint32 quest_id = i->second;
Quest const *pQuest = objmgr.GetQuestTemplate(quest_id);
if ( !pQuest ) continue;
QuestStatus status = pPlayer->GetQuestStatus( quest_id );
if( (status == QUEST_STATUS_COMPLETE && !pPlayer->GetQuestRewardStatus(quest_id)) ||
(pQuest->IsAutoComplete() && pPlayer->CanTakeQuest(pQuest, false)) )
{
if ( pQuest->IsAutoComplete() && pQuest->IsRepeatable() )
result2 = DIALOG_STATUS_REWARD_REP;
else
result2 = DIALOG_STATUS_REWARD;
}
else if ( status == QUEST_STATUS_INCOMPLETE )
result2 = DIALOG_STATUS_INCOMPLETE;
if (result2 > result)
result = result2;
}
for(QuestRelations::const_iterator i = qr->lower_bound(questgiver->GetEntry()); i != qr->upper_bound(questgiver->GetEntry()); ++i )
{
uint32 result2 = 0;
uint32 quest_id = i->second;
Quest const *pQuest = objmgr.GetQuestTemplate(quest_id);
if ( !pQuest )
continue;
QuestStatus status = pPlayer->GetQuestStatus( quest_id );
if ( status == QUEST_STATUS_NONE )
{
if ( pPlayer->CanSeeStartQuest( pQuest ) )
{
if ( pPlayer->SatisfyQuestLevel(pQuest, false) )
{
if ( pQuest->IsAutoComplete() || (pQuest->IsRepeatable() && pPlayer->getQuestStatusMap()[quest_id].m_rewarded))
result2 = DIALOG_STATUS_REWARD_REP;
else if (pPlayer->getLevel() <= pQuest->GetQuestLevel() + sWorld.getConfig(CONFIG_QUEST_LOW_LEVEL_HIDE_DIFF) )
{
if (pQuest->HasFlag(QUEST_FLAGS_DAILY))
result2 = DIALOG_STATUS_AVAILABLE_REP;
else
result2 = DIALOG_STATUS_AVAILABLE;
}
else
result2 = DIALOG_STATUS_CHAT;
}
else
result2 = DIALOG_STATUS_UNAVAILABLE;
}
}
if (result2 > result)
result = result2;
}
if(questgiver->GetTypeId()==TYPEID_UNIT && ((Creature*)questgiver)->isCanTrainingAndResetTalentsOf(pPlayer) && result < DIALOG_STATUS_CHAT)
result = DIALOG_STATUS_CHAT;
return result;
}
void WorldSession::HandleQuestgiverStatusQueryMultipleOpcode(WorldPacket& /*recvPacket*/)
{
sLog.outDebug("WORLD: Received CMSG_QUESTGIVER_STATUS_MULTIPLE_QUERY");
uint32 count = 0;
WorldPacket data(SMSG_QUESTGIVER_STATUS_MULTIPLE, 4);
data << uint32(count); // placeholder
for(Player::ClientGUIDs::iterator itr = _player->m_clientGUIDs.begin(); itr != _player->m_clientGUIDs.end(); ++itr)
{
uint8 questStatus = DIALOG_STATUS_NONE;
uint8 defstatus = DIALOG_STATUS_NONE;
if(IS_CREATURE_GUID(*itr))
{
Creature *questgiver = ObjectAccessor::GetCreature(*_player, *itr);
if(!questgiver || questgiver->IsHostileTo(_player))
continue;
if(!questgiver->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER))
continue;
questStatus = Script->NPCDialogStatus(_player, questgiver);
if( questStatus > 6 )
questStatus = getDialogStatus(_player, questgiver, defstatus);
data << uint64(questgiver->GetGUID());
data << uint8(questStatus);
++count;
}
else if(IS_GAMEOBJECT_GUID(*itr))
{
GameObject *questgiver = ObjectAccessor::GetGameObject(*_player, *itr);
if(!questgiver)
continue;
if(questgiver->GetGoType() != GAMEOBJECT_TYPE_QUESTGIVER)
continue;
questStatus = Script->GODialogStatus(_player, questgiver);
if( questStatus > 6 )
questStatus = getDialogStatus(_player, questgiver, defstatus);
data << uint64(questgiver->GetGUID());
data << uint8(questStatus);
++count;
}
}
data.put<uint32>(0, count); // write real count
SendPacket(&data);
}
|