root/trunk/src/game/QuestHandler.cpp @ 6

Revision 2, 21.9 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18
19#include "Common.h"
20#include "Log.h"
21#include "WorldPacket.h"
22#include "WorldSession.h"
23#include "Opcodes.h"
24#include "World.h"
25#include "ObjectMgr.h"
26#include "Player.h"
27#include "GossipDef.h"
28#include "QuestDef.h"
29#include "ObjectAccessor.h"
30#include "ScriptCalls.h"
31#include "Group.h"
32
33void WorldSession::HandleQuestgiverStatusQueryOpcode( WorldPacket & recv_data )
34{
35    CHECK_PACKET_SIZE(recv_data,8);
36
37    uint64 guid;
38    recv_data >> guid;
39    uint8 questStatus = DIALOG_STATUS_NONE;
40    uint8 defstatus = DIALOG_STATUS_NONE;
41
42    Object* questgiver = ObjectAccessor::GetObjectByTypeMask(*_player, guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
43    if(!questgiver)
44    {
45        sLog.outDetail("Error in CMSG_QUESTGIVER_STATUS_QUERY, called for not found questgiver (Typeid: %u GUID: %u)",GuidHigh2TypeId(GUID_HIPART(guid)),GUID_LOPART(guid));
46        return;
47    }
48
49    switch(questgiver->GetTypeId())
50    {
51        case TYPEID_UNIT:
52        {
53            sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_STATUS_QUERY for npc, guid = %u",uint32(GUID_LOPART(guid)) );
54            Creature* cr_questgiver=(Creature*)questgiver;
55            if( !cr_questgiver->IsHostileTo(_player))       // not show quest status to enemies
56            {
57                questStatus = Script->NPCDialogStatus(_player, cr_questgiver);
58                if( questStatus > 6 )
59                    questStatus = getDialogStatus(_player, cr_questgiver, defstatus);
60            }
61            break;
62        }
63        case TYPEID_GAMEOBJECT:
64        {
65            sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_STATUS_QUERY for GameObject guid = %u",uint32(GUID_LOPART(guid)) );
66            GameObject* go_questgiver=(GameObject*)questgiver;
67            questStatus = Script->GODialogStatus(_player, go_questgiver);
68            if( questStatus > 6 )
69                questStatus = getDialogStatus(_player, go_questgiver, defstatus);
70            break;
71        }
72        default:
73            sLog.outError("QuestGiver called for unexpected type %u", questgiver->GetTypeId());
74            break;
75    }
76
77    //inform client about status of quest
78    _player->PlayerTalkClass->SendQuestGiverStatus(questStatus, guid);
79}
80
81void WorldSession::HandleQuestgiverHelloOpcode( WorldPacket & recv_data )
82{
83    CHECK_PACKET_SIZE(recv_data,8);
84
85    uint64 guid;
86    recv_data >> guid;
87
88    sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_HELLO npc = %u",guid );
89
90    Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_NONE);
91    if (!pCreature)
92    {
93        sLog.outDebug( "WORLD: HandleQuestgiverHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
94        return;
95    }
96
97    // remove fake death
98    if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
99        GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
100    // Stop the npc if moving
101    pCreature->StopMoving();
102
103    if(Script->GossipHello( _player, pCreature ) )
104        return;
105
106    pCreature->prepareGossipMenu(_player,0);
107    pCreature->sendPreparedGossip( _player );
108}
109
110void WorldSession::HandleQuestgiverAcceptQuestOpcode( WorldPacket & recv_data )
111{
112    CHECK_PACKET_SIZE(recv_data,8+4);
113
114    uint64 guid;
115    uint32 quest;
116    recv_data >> guid >> quest;
117
118    if(!GetPlayer()->isAlive())
119        return;
120
121    sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_ACCEPT_QUEST npc = %u, quest = %u",uint32(GUID_LOPART(guid)),quest );
122
123    Object* pObject = ObjectAccessor::GetObjectByTypeMask(*_player, guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT|TYPEMASK_ITEM|TYPEMASK_PLAYER);
124
125    // no or incorrect quest giver
126    if(!pObject
127        || (pObject->GetTypeId()!=TYPEID_PLAYER && !pObject->hasQuest(quest))
128        || (pObject->GetTypeId()==TYPEID_PLAYER && !((Player*)pObject)->CanShareQuest(quest))
129        )
130    {
131        _player->PlayerTalkClass->CloseGossip();
132        _player->SetDivider( 0 );
133        return;
134    }
135
136    Quest const* qInfo = objmgr.GetQuestTemplate(quest);
137    if ( qInfo )
138    {
139        // prevent cheating
140        if(!GetPlayer()->CanTakeQuest(qInfo,true) )
141        {
142            _player->PlayerTalkClass->CloseGossip();
143            _player->SetDivider( 0 );
144            return;
145        }
146
147        if( _player->GetDivider() != 0 )
148        {
149            Player *pPlayer = ObjectAccessor::FindPlayer( _player->GetDivider() );
150            if( pPlayer )
151            {
152                pPlayer->SendPushToPartyResponse( _player, QUEST_PARTY_MSG_ACCEPT_QUEST );
153                _player->SetDivider( 0 );
154            }
155        }
156
157        if( _player->CanAddQuest( qInfo, true ) )
158        {
159            _player->AddQuest( qInfo, pObject );
160
161            if ( _player->CanCompleteQuest( quest ) )
162                _player->CompleteQuest( quest );
163
164            switch(pObject->GetTypeId())
165            {
166                case TYPEID_UNIT:
167                    Script->QuestAccept(_player, ((Creature*)pObject), qInfo );
168                    break;
169                case TYPEID_ITEM:
170                case TYPEID_CONTAINER:
171                {
172                    Script->ItemQuestAccept(_player, ((Item*)pObject), qInfo );
173
174                    // destroy not required for quest finish quest starting item
175                    bool destroyItem = true;
176                    for(int i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
177                    {
178                        if ((qInfo->ReqItemId[i] == ((Item*)pObject)->GetEntry()) && (((Item*)pObject)->GetProto()->MaxCount != 0))
179                        {
180                            destroyItem = false;
181                            break;
182                        }
183                    }
184
185                    if(destroyItem)
186                        _player->DestroyItem(((Item*)pObject)->GetBagSlot(),((Item*)pObject)->GetSlot(),true);
187
188                    break;
189                }
190                case TYPEID_GAMEOBJECT:
191                    Script->GOQuestAccept(_player, ((GameObject*)pObject), qInfo );
192                    break;
193            }
194            _player->PlayerTalkClass->CloseGossip();
195
196            if( qInfo->GetSrcSpell() > 0 )
197                _player->CastSpell( _player, qInfo->GetSrcSpell(), true);
198
199            return;
200        }
201    }
202
203    _player->PlayerTalkClass->CloseGossip();
204}
205
206void WorldSession::HandleQuestgiverQuestQueryOpcode( WorldPacket & recv_data )
207{
208    CHECK_PACKET_SIZE(recv_data,8+4);
209
210    uint64 guid;
211    uint32 quest;
212    recv_data >> guid >> quest;
213    sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_QUERY_QUEST npc = %u, quest = %u",uint32(GUID_LOPART(guid)),quest );
214
215    // Verify that the guid is valid and is a questgiver or involved in the requested quest
216    Object* pObject = ObjectAccessor::GetObjectByTypeMask(*_player, guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT|TYPEMASK_ITEM);
217    if(!pObject||!pObject->hasQuest(quest) && !pObject->hasInvolvedQuest(quest))
218    {
219        _player->PlayerTalkClass->CloseGossip();
220        return;
221    }
222
223    Quest const* pQuest = objmgr.GetQuestTemplate(quest);
224    if ( pQuest )
225    {
226        _player->PlayerTalkClass->SendQuestGiverQuestDetails(pQuest, pObject->GetGUID(), true);
227    }
228}
229
230void WorldSession::HandleQuestQueryOpcode( WorldPacket & recv_data )
231{
232    CHECK_PACKET_SIZE(recv_data,4);
233
234    uint32 quest;
235    recv_data >> quest;
236    sLog.outDebug( "WORLD: Received CMSG_QUEST_QUERY quest = %u",quest );
237
238    Quest const *pQuest = objmgr.GetQuestTemplate(quest);
239    if ( pQuest )
240    {
241        _player->PlayerTalkClass->SendQuestQueryResponse( pQuest );
242    }
243}
244
245void WorldSession::HandleQuestgiverChooseRewardOpcode( WorldPacket & recv_data )
246{
247    CHECK_PACKET_SIZE(recv_data,8+4+4);
248
249    uint32 quest, reward;
250    uint64 guid;
251    recv_data >> guid >> quest >> reward;
252
253    if(reward >= QUEST_REWARD_CHOICES_COUNT)
254    {
255        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);
256        return;
257    }
258
259    if(!GetPlayer()->isAlive())
260        return;
261
262    sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_CHOOSE_REWARD npc = %u, quest = %u, reward = %u",uint32(GUID_LOPART(guid)),quest,reward );
263
264    Object* pObject = ObjectAccessor::GetObjectByTypeMask(*_player, guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
265    if(!pObject)
266        return;
267
268    if(!pObject->hasInvolvedQuest(quest))
269        return;
270
271    Quest const *pQuest = objmgr.GetQuestTemplate(quest);
272    if( pQuest )
273    {
274        if( _player->CanRewardQuest( pQuest, reward, true ) )
275        {
276            _player->RewardQuest( pQuest, reward, pObject );
277
278            switch(pObject->GetTypeId())
279            {
280                case TYPEID_UNIT:
281                    if( !(Script->ChooseReward( _player, ((Creature*)pObject), pQuest, reward )) )
282                    {
283                        // Send next quest
284                        if(Quest const* nextquest = _player->GetNextQuest( guid ,pQuest ) )
285                            _player->PlayerTalkClass->SendQuestGiverQuestDetails(nextquest,guid,true);
286                    }
287                    break;
288                case TYPEID_GAMEOBJECT:
289                    if( !Script->GOChooseReward( _player, ((GameObject*)pObject), pQuest, reward ) )
290                    {
291                        // Send next quest
292                        if(Quest const* nextquest = _player->GetNextQuest( guid ,pQuest ) )
293                            _player->PlayerTalkClass->SendQuestGiverQuestDetails(nextquest,guid,true);
294                    }
295                    break;
296            }
297        }
298        else
299            _player->PlayerTalkClass->SendQuestGiverOfferReward( pQuest, guid, true );
300    }
301}
302
303void WorldSession::HandleQuestgiverRequestRewardOpcode( WorldPacket & recv_data )
304{
305    CHECK_PACKET_SIZE(recv_data,8+4);
306
307    uint32 quest;
308    uint64 guid;
309    recv_data >> guid >> quest;
310
311    if(!GetPlayer()->isAlive())
312        return;
313
314    sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_REQUEST_REWARD npc = %u, quest = %u",uint32(GUID_LOPART(guid)),quest );
315
316    Object* pObject = ObjectAccessor::GetObjectByTypeMask(*_player, guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
317    if(!pObject||!pObject->hasInvolvedQuest(quest))
318        return;
319
320    if ( _player->CanCompleteQuest( quest ) )
321        _player->CompleteQuest( quest );
322
323    if( _player->GetQuestStatus( quest ) != QUEST_STATUS_COMPLETE )
324        return;
325
326    if(Quest const *pQuest = objmgr.GetQuestTemplate(quest))
327        _player->PlayerTalkClass->SendQuestGiverOfferReward( pQuest, guid, true );
328}
329
330void WorldSession::HandleQuestgiverCancel(WorldPacket& /*recv_data*/ )
331{
332    sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_CANCEL" );
333
334    _player->PlayerTalkClass->CloseGossip();
335}
336
337void WorldSession::HandleQuestLogSwapQuest(WorldPacket& recv_data )
338{
339    CHECK_PACKET_SIZE(recv_data,1+1);
340
341    uint8 slot1, slot2;
342    recv_data >> slot1 >> slot2;
343
344    if(slot1 == slot2 || slot1 >= MAX_QUEST_LOG_SIZE || slot2 >= MAX_QUEST_LOG_SIZE)
345        return;
346
347    sLog.outDebug( "WORLD: Received CMSG_QUESTLOG_SWAP_QUEST slot 1 = %u, slot 2 = %u", slot1, slot2 );
348
349    GetPlayer()->SwapQuestSlot(slot1,slot2);
350}
351
352void WorldSession::HandleQuestLogRemoveQuest(WorldPacket& recv_data)
353{
354    CHECK_PACKET_SIZE(recv_data,1);
355
356    uint8 slot;
357    recv_data >> slot;
358
359    sLog.outDebug( "WORLD: Received CMSG_QUESTLOG_REMOVE_QUEST slot = %u",slot );
360
361    if( slot < MAX_QUEST_LOG_SIZE )
362    {
363        if(uint32 quest = _player->GetQuestSlotQuestId(slot))
364        {
365            if(!_player->TakeQuestSourceItem( quest, true ))
366                return;                                     // can't un-equip some items, reject quest cancel
367
368            _player->SetQuestStatus( quest, QUEST_STATUS_NONE);
369        }
370
371        _player->SetQuestSlot(slot, 0);
372    }
373}
374
375void WorldSession::HandleQuestConfirmAccept(WorldPacket& recv_data)
376{
377    CHECK_PACKET_SIZE(recv_data,4);
378
379    uint32 quest;
380    recv_data >> quest;
381
382    sLog.outDebug( "WORLD: Received CMSG_QUEST_CONFIRM_ACCEPT quest = %u",quest );
383}
384
385void WorldSession::HandleQuestComplete(WorldPacket& recv_data)
386{
387    CHECK_PACKET_SIZE(recv_data,8+4);
388
389    uint32 quest;
390    uint64 guid;
391    recv_data >> guid >> quest;
392
393    if(!GetPlayer()->isAlive())
394        return;
395
396    sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_COMPLETE_QUEST npc = %u, quest = %u",uint32(GUID_LOPART(guid)),quest );
397
398    Quest const *pQuest = objmgr.GetQuestTemplate(quest);
399    if( pQuest )
400    {
401        if( _player->GetQuestStatus( quest ) != QUEST_STATUS_COMPLETE )
402        {
403            if( pQuest->IsRepeatable() )
404                _player->PlayerTalkClass->SendQuestGiverRequestItems(pQuest, guid, _player->CanCompleteRepeatableQuest(pQuest), false);
405            else
406                _player->PlayerTalkClass->SendQuestGiverRequestItems(pQuest, guid, _player->CanRewardQuest(pQuest,false), false);
407        }
408        else
409            _player->PlayerTalkClass->SendQuestGiverRequestItems(pQuest, guid, _player->CanRewardQuest(pQuest,false), false);
410    }
411}
412
413void WorldSession::HandleQuestAutoLaunch(WorldPacket& /*recvPacket*/)
414{
415    sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_QUEST_AUTOLAUNCH (Send your log to anakin if you see this message)" );
416}
417
418void WorldSession::HandleQuestPushToParty(WorldPacket& recvPacket)
419{
420    CHECK_PACKET_SIZE(recvPacket,4);
421
422    uint32 quest;
423    recvPacket >> quest;
424
425    sLog.outDebug( "WORLD: Received CMSG_PUSHQUESTTOPARTY quest = %u", quest );
426
427    Quest const *pQuest = objmgr.GetQuestTemplate(quest);
428    if( pQuest )
429    {
430        if( _player->GetGroup() )
431        {
432            Group *pGroup = _player->GetGroup();
433            if( pGroup )
434            {
435                for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
436                {
437                    Player *pPlayer = itr->getSource();
438                    if (!pPlayer || pPlayer == _player)     // skip self
439                        continue;
440
441                    _player->SendPushToPartyResponse(pPlayer, QUEST_PARTY_MSG_SHARING_QUEST);
442
443                    if( _player->GetDistance( pPlayer ) > 10 )
444                    {
445                        _player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_TOO_FAR );
446                        continue;
447                    }
448
449                    if( !pPlayer->SatisfyQuestStatus( pQuest, false ) )
450                    {
451                        _player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_HAVE_QUEST );
452                        continue;
453                    }
454
455                    if( pPlayer->GetQuestStatus( quest ) == QUEST_STATUS_COMPLETE )
456                    {
457                        _player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_FINISH_QUEST );
458                        continue;
459                    }
460
461                    if( !pPlayer->CanTakeQuest( pQuest, false ) )
462                    {
463                        _player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_CANT_TAKE_QUEST );
464                        continue;
465                    }
466
467                    if( !pPlayer->SatisfyQuestLog( false ) )
468                    {
469                        _player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_LOG_FULL );
470                        continue;
471                    }
472
473                    if( pPlayer->GetDivider() != 0  )
474                    {
475                        _player->SendPushToPartyResponse( pPlayer, QUEST_PARTY_MSG_BUSY );
476                        continue;
477                    }
478
479                    pPlayer->PlayerTalkClass->SendQuestGiverQuestDetails( pQuest, _player->GetGUID(), true );
480                    pPlayer->SetDivider( _player->GetGUID() );
481                }
482            }
483        }
484    }
485}
486
487void WorldSession::HandleQuestPushResult(WorldPacket& recvPacket)
488{
489    CHECK_PACKET_SIZE(recvPacket,8+1);
490
491    uint64 guid;
492    uint8 msg;
493    recvPacket >> guid >> msg;
494
495    sLog.outDebug( "WORLD: Received MSG_QUEST_PUSH_RESULT" );
496
497    if( _player->GetDivider() != 0 )
498    {
499        Player *pPlayer = ObjectAccessor::FindPlayer( _player->GetDivider() );
500        if( pPlayer )
501        {
502            WorldPacket data( MSG_QUEST_PUSH_RESULT, (8+1) );
503            data << uint64(guid);
504            data << uint8(msg);                             // valid values: 0-8
505            pPlayer->GetSession()->SendPacket(&data);
506            _player->SetDivider( 0 );
507        }
508    }
509}
510
511uint32 WorldSession::getDialogStatus(Player *pPlayer, Object* questgiver, uint32 defstatus)
512{
513    uint32 result = defstatus;
514
515    QuestRelations const* qir;
516    QuestRelations const* qr;
517
518    switch(questgiver->GetTypeId())
519    {
520        case TYPEID_GAMEOBJECT:
521        {
522            qir = &objmgr.mGOQuestInvolvedRelations;
523            qr  = &objmgr.mGOQuestRelations;
524            break;
525        }
526        case TYPEID_UNIT:
527        {
528            qir = &objmgr.mCreatureQuestInvolvedRelations;
529            qr  = &objmgr.mCreatureQuestRelations;
530            break;
531        }
532        default:
533            //its imposible, but check ^)
534            sLog.outError("Warning: GetDialogStatus called for unexpected type %u", questgiver->GetTypeId());
535            return DIALOG_STATUS_NONE;
536    }
537
538    for(QuestRelations::const_iterator i = qir->lower_bound(questgiver->GetEntry()); i != qir->upper_bound(questgiver->GetEntry()); ++i )
539    {
540        uint32 result2 = 0;
541        uint32 quest_id = i->second;
542        Quest const *pQuest = objmgr.GetQuestTemplate(quest_id);
543        if ( !pQuest ) continue;
544
545        QuestStatus status = pPlayer->GetQuestStatus( quest_id );
546        if( (status == QUEST_STATUS_COMPLETE && !pPlayer->GetQuestRewardStatus(quest_id)) ||
547            (pQuest->IsAutoComplete() && pPlayer->CanTakeQuest(pQuest, false)) )
548        {
549            if ( pQuest->IsAutoComplete() && pQuest->IsRepeatable() )
550                result2 = DIALOG_STATUS_REWARD_REP;
551            else
552                result2 = DIALOG_STATUS_REWARD;
553        }
554        else if ( status == QUEST_STATUS_INCOMPLETE )
555            result2 = DIALOG_STATUS_INCOMPLETE;
556
557        if (result2 > result)
558            result = result2;
559    }
560
561    for(QuestRelations::const_iterator i = qr->lower_bound(questgiver->GetEntry()); i != qr->upper_bound(questgiver->GetEntry()); ++i )
562    {
563        uint32 result2 = 0;
564        uint32 quest_id = i->second;
565        Quest const *pQuest = objmgr.GetQuestTemplate(quest_id);
566        if ( !pQuest )
567            continue;
568
569        QuestStatus status = pPlayer->GetQuestStatus( quest_id );
570        if ( status == QUEST_STATUS_NONE )
571        {
572            if ( pPlayer->CanSeeStartQuest( pQuest ) )
573            {
574                if ( pPlayer->SatisfyQuestLevel(pQuest, false) )
575                {
576                    if ( pQuest->IsAutoComplete() || (pQuest->IsRepeatable() && pPlayer->getQuestStatusMap()[quest_id].m_rewarded))
577                        result2 = DIALOG_STATUS_REWARD_REP;
578                    else if (pPlayer->getLevel() <= pQuest->GetQuestLevel() + sWorld.getConfig(CONFIG_QUEST_LOW_LEVEL_HIDE_DIFF) )
579                    {
580                        if (pQuest->HasFlag(QUEST_FLAGS_DAILY))
581                            result2 = DIALOG_STATUS_AVAILABLE_REP;
582                        else
583                            result2 = DIALOG_STATUS_AVAILABLE;
584                    }
585                    else
586                        result2 = DIALOG_STATUS_CHAT;
587                }
588                else
589                    result2 = DIALOG_STATUS_UNAVAILABLE;
590            }
591        }
592
593        if (result2 > result)
594            result = result2;
595    }
596
597    if(questgiver->GetTypeId()==TYPEID_UNIT && ((Creature*)questgiver)->isCanTrainingAndResetTalentsOf(pPlayer) && result < DIALOG_STATUS_CHAT)
598        result = DIALOG_STATUS_CHAT;
599
600    return result;
601}
602
603void WorldSession::HandleQuestgiverStatusQueryMultipleOpcode(WorldPacket& /*recvPacket*/)
604{
605    sLog.outDebug("WORLD: Received CMSG_QUESTGIVER_STATUS_MULTIPLE_QUERY");
606
607    uint32 count = 0;
608
609    WorldPacket data(SMSG_QUESTGIVER_STATUS_MULTIPLE, 4);
610    data << uint32(count);                                  // placeholder
611
612    for(Player::ClientGUIDs::iterator itr = _player->m_clientGUIDs.begin(); itr != _player->m_clientGUIDs.end(); ++itr)
613    {
614        uint8 questStatus = DIALOG_STATUS_NONE;
615        uint8 defstatus = DIALOG_STATUS_NONE;
616
617        if(IS_CREATURE_GUID(*itr))
618        {
619            Creature *questgiver = ObjectAccessor::GetCreature(*_player, *itr);
620            if(!questgiver || questgiver->IsHostileTo(_player))
621                continue;
622            if(!questgiver->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER))
623                continue;
624            questStatus = Script->NPCDialogStatus(_player, questgiver);
625            if( questStatus > 6 )
626                questStatus = getDialogStatus(_player, questgiver, defstatus);
627
628            data << uint64(questgiver->GetGUID());
629            data << uint8(questStatus);
630            ++count;
631        }
632        else if(IS_GAMEOBJECT_GUID(*itr))
633        {
634            GameObject *questgiver = ObjectAccessor::GetGameObject(*_player, *itr);
635            if(!questgiver)
636                continue;
637            if(questgiver->GetGoType() != GAMEOBJECT_TYPE_QUESTGIVER)
638                continue;
639            questStatus = Script->GODialogStatus(_player, questgiver);
640            if( questStatus > 6 )
641                questStatus = getDialogStatus(_player, questgiver, defstatus);
642
643            data << uint64(questgiver->GetGUID());
644            data << uint8(questStatus);
645            ++count;
646        }
647    }
648
649    data.put<uint32>(0, count);                             // write real count
650    SendPacket(&data);
651}
Note: See TracBrowser for help on using the browser.