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

Revision 283, 22.3 kB (checked in by yumileroy, 17 years ago)

*Alterac Valley. By Bogie and Balrok. Note: some core contents are modified. Will fix them later. Some sql are disabled because of possible conflict with offical DB. Use them at your own risk.

Original author: megamage
Date: 2008-11-21 19:45:49-06:00

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