-
Notifications
You must be signed in to change notification settings - Fork 294
/
QuestHandler.cpp
808 lines (662 loc) · 31 KB
/
QuestHandler.cpp
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/*
* This file is part of the CMaNGOS Project. See AUTHORS file for Copyright information
*
* 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/Log.h"
#include "Server/WorldPacket.h"
#include "Server/WorldSession.h"
#include "Server/Opcodes.h"
#include "World/World.h"
#include "Globals/ObjectMgr.h"
#include "Entities/Player.h"
#include "Entities/GossipDef.h"
#include "Quests/QuestDef.h"
#include "Globals/ObjectAccessor.h"
#include "AI/ScriptDevAI/ScriptDevAIMgr.h"
#include "Groups/Group.h"
#include "Tools/Formulas.h"
#ifdef BUILD_DEPRECATED_PLAYERBOT
#include "PlayerBot/Base/PlayerbotAI.h"
#endif
void WorldSession::HandleQuestgiverStatusQueryOpcode(WorldPacket& recv_data)
{
ObjectGuid guid;
recv_data >> guid;
uint8 dialogStatus = DIALOG_STATUS_NONE;
Object* questgiver = _player->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_OR_GAMEOBJECT);
if (!questgiver)
{
DETAIL_LOG("Error in CMSG_QUESTGIVER_STATUS_QUERY, called for not found questgiver %s", guid.GetString().c_str());
return;
}
DEBUG_LOG("WORLD: Received opcode CMSG_QUESTGIVER_STATUS_QUERY - for %s to %s", _player->GetGuidStr().c_str(), guid.GetString().c_str());
switch (questgiver->GetTypeId())
{
case TYPEID_UNIT:
{
Creature* cr_questgiver = (Creature*)questgiver;
if (_player->CanInteract(static_cast<Unit*>(questgiver))) // not show quest status to enemies
{
dialogStatus = sScriptDevAIMgr.GetDialogStatus(_player, cr_questgiver);
if (dialogStatus == DIALOG_STATUS_UNDEFINED)
dialogStatus = getDialogStatus(_player, cr_questgiver, DIALOG_STATUS_NONE);
}
break;
}
case TYPEID_GAMEOBJECT:
{
GameObject* go_questgiver = (GameObject*)questgiver;
if (_player->CanInteract(go_questgiver))
{
dialogStatus = sScriptDevAIMgr.GetDialogStatus(_player, go_questgiver);
if (dialogStatus == DIALOG_STATUS_UNDEFINED)
dialogStatus = getDialogStatus(_player, go_questgiver, DIALOG_STATUS_NONE);
}
break;
}
default:
sLog.outError("QuestGiver called for unexpected type %u", questgiver->GetTypeId());
break;
}
// inform client about status of quest
_player->GetPlayerMenu()->SendQuestGiverStatus(dialogStatus, guid);
}
void WorldSession::HandleQuestgiverHelloOpcode(WorldPacket& recv_data)
{
ObjectGuid guid;
recv_data >> guid;
DEBUG_LOG("WORLD: Received opcode CMSG_QUESTGIVER_HELLO - for %s to %s", _player->GetGuidStr().c_str(), guid.GetString().c_str());
Creature* pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE);
if (!pCreature)
{
DEBUG_LOG("WORLD: HandleQuestgiverHelloOpcode - for %s to %s not found or you can't interact with him.", _player->GetGuidStr().c_str(), guid.GetString().c_str());
return;
}
// Stop the npc if moving
if (uint32 pauseTimer = pCreature->GetInteractionPauseTimer())
pCreature->GetMotionMaster()->PauseWaypoints(pauseTimer);
if (sScriptDevAIMgr.OnGossipHello(_player, pCreature))
return;
_player->PrepareGossipMenu(pCreature, pCreature->GetDefaultGossipMenuId());
_player->SendPreparedGossip(pCreature);
}
void WorldSession::HandleQuestgiverAcceptQuestOpcode(WorldPacket& recv_data)
{
ObjectGuid guid;
uint32 quest;
uint32 unk1;
recv_data >> guid >> quest >> unk1;
if (!CanInteractWithQuestGiver(guid, "CMSG_QUESTGIVER_ACCEPT_QUEST"))
return;
DEBUG_LOG("WORLD: Received opcode CMSG_QUESTGIVER_ACCEPT_QUEST - for %s to %s, quest = %u, unk1 = %u", _player->GetGuidStr().c_str(), guid.GetString().c_str(), quest, unk1);
Object* pObject = _player->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_GAMEOBJECT_PLAYER_OR_ITEM);
// no or incorrect quest giver (player himself is questgiver for SPELL_EFFECT_QUEST_OFFER)
if (!pObject
|| (pObject->GetTypeId() != TYPEID_PLAYER && !pObject->HasQuest(quest))
|| (pObject->GetTypeId() == TYPEID_PLAYER && pObject != _player && !((Player*)pObject)->CanShareQuest(quest))
)
{
_player->GetPlayerMenu()->CloseGossip();
_player->ClearDividerGuid();
return;
}
Quest const* qInfo = sObjectMgr.GetQuestTemplate(quest);
if (qInfo)
{
// prevent cheating
if (!GetPlayer()->CanTakeQuest(qInfo, true))
{
_player->GetPlayerMenu()->CloseGossip();
_player->ClearDividerGuid();
return;
}
if (Player* pPlayer = ObjectAccessor::FindPlayer(_player->GetDividerGuid()))
{
pPlayer->SendPushToPartyResponse(_player, QUEST_PARTY_MSG_ACCEPT_QUEST);
_player->ClearDividerGuid();
}
if (_player->CanAddQuest(qInfo, true))
{
_player->AddQuest(qInfo, pObject); // pObject (if it item) can be destroyed at call
if (qInfo->HasQuestFlag(QUEST_FLAGS_PARTY_ACCEPT))
{
if (Group* pGroup = _player->GetGroup())
{
for (GroupReference* itr = pGroup->GetFirstMember(); itr != nullptr; itr = itr->next())
{
Player* pPlayer = itr->getSource();
if (!pPlayer || pPlayer == _player || !pPlayer->IsInWorld()) // not self
continue;
if (pPlayer->CanTakeQuest(qInfo, true))
{
pPlayer->SetDividerGuid(_player->GetObjectGuid());
// need confirmation that any gossip window will close
pPlayer->GetPlayerMenu()->CloseGossip();
_player->SendQuestConfirmAccept(qInfo, pPlayer);
}
}
}
}
if (_player->CanCompleteQuest(quest))
_player->CompleteQuest(quest);
_player->GetAchievementMgr().StartTimedAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST, quest);
_player->GetPlayerMenu()->CloseGossip();
if (qInfo->GetSrcSpell() > 0)
_player->CastSpell(_player, qInfo->GetSrcSpell(), TRIGGERED_OLD_TRIGGERED);
return;
}
}
_player->GetPlayerMenu()->CloseGossip();
}
void WorldSession::HandleQuestgiverQueryQuestOpcode(WorldPacket& recv_data)
{
ObjectGuid guid;
uint32 quest;
uint8 unk1;
recv_data >> guid >> quest >> unk1;
DEBUG_LOG("WORLD: Received opcode CMSG_QUESTGIVER_QUERY_QUEST - for %s to %s, quest = %u, unk1 = %u", _player->GetGuidStr().c_str(), guid.GetString().c_str(), quest, unk1);
// Verify that the guid is valid and is a questgiver or involved in the requested quest
Object* pObject = _player->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_GAMEOBJECT_OR_ITEM);
if (!pObject || (!pObject->HasQuest(quest) && !pObject->HasInvolvedQuest(quest)))
{
_player->GetPlayerMenu()->CloseGossip();
return;
}
if (Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest))
_player->GetPlayerMenu()->SendQuestGiverQuestDetails(pQuest, pObject->GetObjectGuid(), true);
}
void WorldSession::HandleQuestQueryOpcode(WorldPacket& recv_data)
{
uint32 quest;
recv_data >> quest;
DEBUG_LOG("WORLD: Received opcode CMSG_QUEST_QUERY quest = %u", quest);
Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest);
if (pQuest)
{
std::string ObjectiveText[QUEST_OBJECTIVES_COUNT];
std::string Title = pQuest->GetTitle();
std::string Details = pQuest->GetDetails();
std::string Objectives = pQuest->GetObjectives();
std::string EndText = pQuest->GetEndText();
std::string CompletedText = pQuest->GetCompletedText();
for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
ObjectiveText[i] = pQuest->ObjectiveText[i];
int loc_idx = GetSessionDbLocaleIndex();
if (loc_idx >= 0)
{
if (QuestLocale const* ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId()))
{
if (ql->Title.size() > (size_t)loc_idx && !ql->Title[loc_idx].empty())
Title = ql->Title[loc_idx];
if (ql->Details.size() > (size_t)loc_idx && !ql->Details[loc_idx].empty())
Details = ql->Details[loc_idx];
if (ql->Objectives.size() > (size_t)loc_idx && !ql->Objectives[loc_idx].empty())
Objectives = ql->Objectives[loc_idx];
if (ql->EndText.size() > (size_t)loc_idx && !ql->EndText[loc_idx].empty())
EndText = ql->EndText[loc_idx];
if (ql->CompletedText.size() > (size_t)loc_idx && !ql->CompletedText[loc_idx].empty())
CompletedText = ql->CompletedText[loc_idx];
for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
if (ql->ObjectiveText[i].size() > (size_t)loc_idx && !ql->ObjectiveText[i][loc_idx].empty())
ObjectiveText[i] = ql->ObjectiveText[i][loc_idx];
}
}
WorldPacket data(SMSG_QUEST_QUERY_RESPONSE, 100); // guess size
data << uint32(pQuest->GetQuestId()); // quest id
data << uint32(pQuest->GetQuestMethod()); // Accepted values: 0, 1 or 2. 0==IsAutoComplete() (skip objectives/details)
data << int32(pQuest->GetQuestLevel()); // may be -1, static data, in other cases must be used dynamic level: Player::GetQuestLevelForPlayer (0 is not known, but assuming this is no longer valid for quest intended for client)
data << uint32(pQuest->GetMinLevel()); // min required level to obtain (added for 3.3). Assumed allowed (database) range is -1 to 255 (still using uint32, since negative value would not be of any known use for client)
data << uint32(pQuest->GetZoneOrSort()); // zone or sort to display in quest log
data << uint32(pQuest->GetType()); // quest type
data << uint32(pQuest->GetSuggestedPlayers()); // suggested players count
data << uint32(pQuest->GetRepObjectiveFaction()); // shown in quest log as part of quest objective
data << uint32(pQuest->GetRepObjectiveValue()); // shown in quest log as part of quest objective
data << uint32(0); // RequiredOpositeRepFaction
data << uint32(0); // RequiredOpositeRepValue, required faction value with another (oposite) faction (objective)
data << uint32(pQuest->GetNextQuestInChain()); // client will request this quest from NPC, if not 0
data << uint32(pQuest->GetRewXPId()); // column index in QuestXP.dbc (row based on quest level)
if (pQuest->HasQuestFlag(QUEST_FLAGS_HIDDEN_REWARDS))
data << uint32(0); // Hide money rewarded
else
data << uint32(pQuest->GetRewOrReqMoney()); // reward money (below max lvl)
data << uint32(pQuest->GetRewMoneyMaxLevel()); // used in XP calculation at client
data << uint32(pQuest->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0)
data << uint32(pQuest->GetRewSpellCast()); // casted spell
// rewarded honor points
data << uint32(pQuest->GetRewHonorAddition());
data << float(pQuest->GetRewHonorMultiplier()); // new reward honor (multiplied by ~62 at client side)
data << uint32(pQuest->GetSrcItemId()); // source item id
data << uint32(pQuest->GetQuestFlags()); // quest flags
data << uint32(pQuest->GetCharTitleId()); // CharTitleId, new 2.4.0, player gets this title (id from CharTitles)
data << uint32(pQuest->GetPlayersSlain()); // players slain
data << uint32(pQuest->GetBonusTalents()); // bonus talents
data << uint32(0); // bonus arena points
data << uint32(0); // rew rep show mask?
int iI;
if (pQuest->HasQuestFlag(QUEST_FLAGS_HIDDEN_REWARDS))
{
for (iI = 0; iI < QUEST_REWARDS_COUNT; ++iI)
data << uint32(0) << uint32(0);
for (iI = 0; iI < QUEST_REWARD_CHOICES_COUNT; ++iI)
data << uint32(0) << uint32(0);
}
else
{
for (iI = 0; iI < QUEST_REWARDS_COUNT; ++iI)
{
data << uint32(pQuest->RewItemId[iI]);
data << uint32(pQuest->RewItemCount[iI]);
}
for (iI = 0; iI < QUEST_REWARD_CHOICES_COUNT; ++iI)
{
data << uint32(pQuest->RewChoiceItemId[iI]);
data << uint32(pQuest->RewChoiceItemCount[iI]);
}
}
for (unsigned int i : pQuest->RewRepFaction) // reward factions ids
data << uint32(i);
for (int i : pQuest->RewRepValueId) // columnid in QuestFactionReward.dbc (if negative, from second row)
data << int32(i);
for (int i = 0; i < QUEST_REPUTATIONS_COUNT; ++i) // reward reputation override. No bonus is expected given
data << int32(0);
// data << int32(pQuest->RewRepValue[i]); // current field for store of rep value, can be reused to implement "override value"
data << pQuest->GetPointMapId();
data << pQuest->GetPointX();
data << pQuest->GetPointY();
data << pQuest->GetPointOpt();
data << Title;
data << Objectives;
data << Details;
data << EndText;
data << CompletedText; // display in quest objectives window once all objectives are completed
for (iI = 0; iI < QUEST_OBJECTIVES_COUNT; ++iI)
{
if (pQuest->ReqCreatureOrGOId[iI] < 0)
{
// client expected gameobject template id in form (id|0x80000000)
data << uint32((pQuest->ReqCreatureOrGOId[iI] * (-1)) | 0x80000000);
}
else
{
data << uint32(pQuest->ReqCreatureOrGOId[iI]);
}
data << uint32(pQuest->ReqCreatureOrGOCount[iI]);
data << uint32(pQuest->ReqSourceId[iI]);
data << uint32(0); // req source count?
}
for (iI = 0; iI < QUEST_ITEM_OBJECTIVES_COUNT; ++iI)
{
data << uint32(pQuest->ReqItemId[iI]);
data << uint32(pQuest->ReqItemCount[iI]);
}
for (iI = 0; iI < QUEST_OBJECTIVES_COUNT; ++iI)
data << ObjectiveText[iI];
SendPacket(data);
DEBUG_LOG("WORLD: Sent SMSG_QUEST_QUERY_RESPONSE questid=%u", pQuest->GetQuestId());
}
}
void WorldSession::HandleQuestgiverChooseRewardOpcode(WorldPacket& recv_data)
{
uint32 quest, reward;
ObjectGuid guid;
recv_data >> guid >> quest >> reward;
if (reward >= QUEST_REWARD_CHOICES_COUNT)
{
sLog.outError("Error in CMSG_QUESTGIVER_CHOOSE_REWARD - %s tried to get invalid reward (%u) (probably packet hacking)", _player->GetGuidStr().c_str(), reward);
return;
}
if (!CanInteractWithQuestGiver(guid, "CMSG_QUESTGIVER_CHOOSE_REWARD"))
return;
DEBUG_LOG("WORLD: Received opcode CMSG_QUESTGIVER_CHOOSE_REWARD - for %s to %s, quest = %u, reward = %u", _player->GetGuidStr().c_str(), guid.GetString().c_str(), quest, reward);
Object* pObject = _player->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_OR_GAMEOBJECT);
if (!pObject)
return;
if (!pObject->HasInvolvedQuest(quest))
return;
Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest);
if (pQuest)
{
if (_player->CanRewardQuest(pQuest, reward, true))
{
_player->RewardQuest(pQuest, reward, pObject);
// Send next quest
if (Quest const* nextquest = _player->GetNextQuest(guid, pQuest))
_player->GetPlayerMenu()->SendQuestGiverQuestDetails(nextquest, guid, true);
}
else
_player->GetPlayerMenu()->SendQuestGiverOfferReward(pQuest, guid, true);
}
}
void WorldSession::HandleQuestgiverRequestRewardOpcode(WorldPacket& recv_data)
{
uint32 quest;
ObjectGuid guid;
recv_data >> guid >> quest;
if (!CanInteractWithQuestGiver(guid, "CMSG_QUESTGIVER_REQUEST_REWARD"))
return;
DEBUG_LOG("WORLD: Received opcode CMSG_QUESTGIVER_REQUEST_REWARD - for %s to %s, quest = %u", _player->GetGuidStr().c_str(), guid.GetString().c_str(), quest);
Object* pObject = _player->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_OR_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 = sObjectMgr.GetQuestTemplate(quest))
_player->GetPlayerMenu()->SendQuestGiverOfferReward(pQuest, guid, true);
}
void WorldSession::HandleQuestgiverCancel(WorldPacket& /*recv_data*/)
{
DEBUG_LOG("WORLD: Received opcode CMSG_QUESTGIVER_CANCEL");
_player->GetPlayerMenu()->CloseGossip();
}
void WorldSession::HandleQuestLogSwapQuest(WorldPacket& recv_data)
{
uint8 slot1, slot2;
recv_data >> slot1 >> slot2;
if (slot1 == slot2 || slot1 >= MAX_QUEST_LOG_SIZE || slot2 >= MAX_QUEST_LOG_SIZE)
return;
DEBUG_LOG("WORLD: Received opcode CMSG_QUESTLOG_SWAP_QUEST slot 1 = %u, slot 2 = %u", slot1, slot2);
GetPlayer()->SwapQuestSlot(slot1, slot2);
}
void WorldSession::HandleQuestLogRemoveQuest(WorldPacket& recv_data)
{
uint8 slot;
recv_data >> slot;
DEBUG_LOG("WORLD: Received opcode 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
if (const Quest* pQuest = sObjectMgr.GetQuestTemplate(quest))
{
if (pQuest->HasSpecialFlag(QUEST_SPECIAL_FLAG_TIMED))
_player->RemoveTimedQuest(quest);
for (int i = 0; i < QUEST_SOURCE_ITEM_IDS_COUNT; ++i)
{
if (pQuest->ReqSourceId[i])
{
ItemPrototype const* iProto = ObjectMgr::GetItemPrototype(pQuest->ReqSourceId[i]);
if (iProto && iProto->Bonding == BIND_QUEST_ITEM)
_player->DestroyItemCount(pQuest->ReqSourceId[i], pQuest->ReqSourceCount[i], true, false, true);
}
}
}
_player->SetQuestStatus(quest, QUEST_STATUS_NONE);
}
_player->SetQuestSlot(slot, 0);
_player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_QUEST_ABANDONED, 1);
}
}
void WorldSession::HandleQuestConfirmAccept(WorldPacket& recv_data)
{
uint32 quest;
recv_data >> quest;
DEBUG_LOG("WORLD: Received opcode CMSG_QUEST_CONFIRM_ACCEPT quest = %u", quest);
if (const Quest* pQuest = sObjectMgr.GetQuestTemplate(quest))
{
if (!pQuest->HasQuestFlag(QUEST_FLAGS_PARTY_ACCEPT))
return;
Player* pOriginalPlayer = ObjectAccessor::FindPlayer(_player->GetDividerGuid());
if (!pOriginalPlayer)
return;
if (pQuest->IsAllowedInRaid())
{
if (!_player->IsInGroup(pOriginalPlayer))
return;
}
else
{
if (!_player->IsInParty(pOriginalPlayer))
return;
}
if (_player->CanAddQuest(pQuest, true))
_player->AddQuest(pQuest, nullptr); // nullptr, this prevent DB script from duplicate running
_player->ClearDividerGuid();
}
}
void WorldSession::HandleQuestgiverCompleteQuest(WorldPacket& recv_data)
{
uint32 quest;
ObjectGuid guid;
recv_data >> guid >> quest;
if (!CanInteractWithQuestGiver(guid, "CMSG_QUESTGIVER_COMPLETE_QUEST"))
return;
// All ok, continue
DEBUG_LOG("WORLD: Received opcode CMSG_QUESTGIVER_COMPLETE_QUEST - for %s to %s, quest = %u", _player->GetGuidStr().c_str(), guid.GetString().c_str(), quest);
if (Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest))
{
if (_player->GetQuestStatus(quest) != QUEST_STATUS_COMPLETE)
{
if (pQuest->IsRepeatable())
_player->GetPlayerMenu()->SendQuestGiverRequestItems(pQuest, guid, _player->CanCompleteRepeatableQuest(pQuest), false);
else
_player->GetPlayerMenu()->SendQuestGiverRequestItems(pQuest, guid, _player->CanRewardQuest(pQuest, false), false);
}
else
{
if (pQuest->GetReqItemsCount()) // some items required
_player->GetPlayerMenu()->SendQuestGiverRequestItems(pQuest, guid, _player->CanRewardQuest(pQuest, false), false);
else // no items required
_player->GetPlayerMenu()->SendQuestGiverOfferReward(pQuest, guid, true);
}
}
}
void WorldSession::HandleQuestgiverQuestAutoLaunch(WorldPacket& /*recvPacket*/)
{
DEBUG_LOG("WORLD: Received opcode CMSG_QUESTGIVER_QUEST_AUTOLAUNCH");
}
void WorldSession::HandlePushQuestToParty(WorldPacket& recvPacket)
{
uint32 questId;
recvPacket >> questId;
DEBUG_LOG("WORLD: Received opcode CMSG_PUSHQUESTTOPARTY quest = %u", questId);
if (!_player->CanShareQuest(questId))
{
sLog.outError("Error in CMSG_PUSHQUESTTOPARTY - %s tried to share invalid quest (%u) (probably packet hacking)", _player->GetGuidStr().c_str(), questId);
return;
}
if (Quest const* pQuest = sObjectMgr.GetQuestTemplate(questId))
{
if (Group* pGroup = _player->GetGroup())
{
for (GroupReference* itr = pGroup->GetFirstMember(); itr != nullptr; itr = itr->next())
{
Player* pPlayer = itr->getSource();
if (!pPlayer || pPlayer == _player || !pPlayer->IsInWorld()) // skip self
continue;
_player->SendPushToPartyResponse(pPlayer, QUEST_PARTY_MSG_SHARING_QUEST);
if (!pPlayer->SatisfyQuestStatus(pQuest, false))
{
_player->SendPushToPartyResponse(pPlayer, QUEST_PARTY_MSG_HAVE_QUEST);
continue;
}
if (pPlayer->GetQuestStatus(questId) == 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->GetDividerGuid())
{
_player->SendPushToPartyResponse(pPlayer, QUEST_PARTY_MSG_BUSY);
continue;
}
#ifndef BUILD_DEPRECATED_PLAYERBOT
pPlayer->GetPlayerMenu()->SendQuestGiverQuestDetails(pQuest, _player->GetObjectGuid(), true);
#endif
pPlayer->SetDividerGuid(_player->GetObjectGuid());
#ifdef BUILD_DEPRECATED_PLAYERBOT
if (pPlayer->GetPlayerbotAI())
pPlayer->GetPlayerbotAI()->AcceptQuest(pQuest, _player);
else
{
pPlayer->GetPlayerMenu()->SendQuestGiverQuestDetails(pQuest, _player->GetObjectGuid(), true);
pPlayer->SetDividerGuid(_player->GetObjectGuid());
}
#endif
}
}
}
}
void WorldSession::HandleQuestPushResult(WorldPacket& recvPacket)
{
ObjectGuid guid;
uint8 msg;
recvPacket >> guid >> msg;
DEBUG_LOG("WORLD: Received opcode MSG_QUEST_PUSH_RESULT");
if (Player* pPlayer = ObjectAccessor::FindPlayer(_player->GetDividerGuid()))
{
WorldPacket data(MSG_QUEST_PUSH_RESULT, (8 + 1));
data << ObjectGuid(guid);
data << uint8(msg); // valid values: 0-8
pPlayer->GetSession()->SendPacket(data);
_player->ClearDividerGuid();
}
}
/**
* What - if any - kind of explanation mark or question-mark should a quest-giver display for a player
* @param pPlayer - for whom
* @param questgiver - from whom
* @param defstatus - initial set status (usually it will be called with DIALOG_STATUS_NONE) - must not be DIALOG_STATUS_UNDEFINED
*/
uint32 WorldSession::getDialogStatus(const Player* pPlayer, const Object* questgiver, uint32 defstatus) const
{
MANGOS_ASSERT(defstatus != DIALOG_STATUS_UNDEFINED);
uint32 dialogStatus = defstatus;
QuestRelationsMapBounds rbounds; // QuestRelations (quest-giver)
QuestRelationsMapBounds irbounds; // InvolvedRelations (quest-finisher)
switch (questgiver->GetTypeId())
{
case TYPEID_UNIT:
{
rbounds = sObjectMgr.GetCreatureQuestRelationsMapBounds(questgiver->GetEntry());
irbounds = sObjectMgr.GetCreatureQuestInvolvedRelationsMapBounds(questgiver->GetEntry());
break;
}
case TYPEID_GAMEOBJECT:
{
rbounds = sObjectMgr.GetGOQuestRelationsMapBounds(questgiver->GetEntry());
irbounds = sObjectMgr.GetGOQuestInvolvedRelationsMapBounds(questgiver->GetEntry());
break;
}
default:
// it's impossible, but check ^)
sLog.outError("Warning: GetDialogStatus called for unexpected type %u", questgiver->GetTypeId());
return DIALOG_STATUS_NONE;
}
// Check markings for quest-finisher
for (QuestRelationsMap::const_iterator itr = irbounds.first; itr != irbounds.second; ++itr)
{
uint32 dialogStatusNew = DIALOG_STATUS_NONE;
uint32 quest_id = itr->second;
Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest_id);
if (!pQuest || !pQuest->IsActive())
continue;
QuestStatus status = pPlayer->GetQuestStatus(quest_id);
if (status == QUEST_STATUS_COMPLETE && !pPlayer->GetQuestRewardStatus(quest_id))
dialogStatusNew = pQuest->IsRepeatable() && !pQuest->IsDailyOrWeekly() ? DIALOG_STATUS_REWARD_REP : DIALOG_STATUS_REWARD;
else if (pQuest->IsAutoComplete() && pPlayer->CanTakeQuest(pQuest, false))
dialogStatusNew = pQuest->IsRepeatable() ? pQuest->IsDailyOrWeekly() ? DIALOG_STATUS_AVAILABLE_REP : DIALOG_STATUS_REWARD_REP : DIALOG_STATUS_AVAILABLE;
else if (status == QUEST_STATUS_INCOMPLETE)
dialogStatusNew = DIALOG_STATUS_INCOMPLETE;
if (dialogStatusNew > dialogStatus)
dialogStatus = dialogStatusNew;
}
// check markings for quest-giver
for (QuestRelationsMap::const_iterator itr = rbounds.first; itr != rbounds.second; ++itr)
{
uint32 dialogStatusNew = DIALOG_STATUS_NONE;
uint32 quest_id = itr->second;
Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest_id);
if (!pQuest || !pQuest->IsActive())
continue;
QuestStatus status = pPlayer->GetQuestStatus(quest_id);
if (status == QUEST_STATUS_NONE) // For all other cases the mark is handled either at some place else, or with involved-relations already
{
if (pPlayer->CanSeeStartQuest(pQuest))
{
if (pPlayer->SatisfyQuestLevel(pQuest, false))
{
int32 lowLevelDiff = sWorld.getConfig(CONFIG_INT32_QUEST_LOW_LEVEL_HIDE_DIFF);
if (pQuest->IsAutoComplete())
{
dialogStatusNew = DIALOG_STATUS_REWARD_REP;
}
else if (lowLevelDiff < 0 || pPlayer->GetLevel() <= pPlayer->GetQuestLevelForPlayer(pQuest) + uint32(lowLevelDiff))
{
if (pQuest->HasQuestFlag(QUEST_FLAGS_DAILY) || pQuest->HasQuestFlag(QUEST_FLAGS_WEEKLY))
dialogStatusNew = DIALOG_STATUS_AVAILABLE_REP;
else
dialogStatusNew = DIALOG_STATUS_AVAILABLE;
}
else // player level much higher then quest-level
dialogStatusNew = DIALOG_STATUS_LOW_LEVEL_AVAILABLE;
}
else
dialogStatusNew = DIALOG_STATUS_UNAVAILABLE;
}
}
if (dialogStatusNew > dialogStatus)
dialogStatus = dialogStatusNew;
}
return dialogStatus;
}
void WorldSession::HandleQuestgiverStatusMultipleQuery(WorldPacket& /*recvPacket*/)
{
DEBUG_LOG("WORLD: Received opcode CMSG_QUESTGIVER_STATUS_MULTIPLE_QUERY");
// TODO: Add parsing
_player->SendQuestGiverStatusMultiple();
}
bool WorldSession::CanInteractWithQuestGiver(ObjectGuid guid, char const* descr) const
{
if (guid.IsCreatureOrVehicle())
{
Creature* pCreature = _player->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_QUESTGIVER);
if (!pCreature)
{
DEBUG_LOG("WORLD: %s - %s cannot interact with %s.", descr, _player->GetGuidStr().c_str(), guid.GetString().c_str());
return false;
}
}
else if (guid.IsGameObject())
{
GameObject* pGo = _player->GetGameObjectIfCanInteractWith(guid, GAMEOBJECT_TYPE_QUESTGIVER);
if (!pGo)
{
DEBUG_LOG("WORLD: %s - %s cannot interact with %s.", descr, _player->GetGuidStr().c_str(), guid.GetString().c_str());
return false;
}
}
else if (!_player->IsAlive())
{
DEBUG_LOG("WORLD: %s - %s is dead, requested guid was %s", descr, _player->GetGuidStr().c_str(), guid.GetString().c_str());
return false;
}
return true;
}