2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
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.
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.
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
19 #include "GossipDef.h"
21 #include "ObjectMgr.h"
23 #include "WorldPacket.h"
24 #include "WorldSession.h"
27 GossipMenu::GossipMenu(WorldSession
* session
) : m_session(session
)
29 m_gItems
.reserve(16); // can be set for max from most often sizes to speedup push_back and less memory use
33 GossipMenu::~GossipMenu()
38 void GossipMenu::AddMenuItem(uint8 Icon
, const std::string
& Message
, uint32 dtSender
, uint32 dtAction
, const std::string
& BoxMessage
, uint32 BoxMoney
, bool Coded
)
40 MANGOS_ASSERT(m_gItems
.size() <= GOSSIP_MAX_MENU_ITEMS
);
45 gItem
.m_gMessage
= Message
;
46 gItem
.m_gCoded
= Coded
;
47 gItem
.m_gSender
= dtSender
;
48 gItem
.m_gOptionId
= dtAction
;
49 gItem
.m_gBoxMessage
= BoxMessage
;
50 gItem
.m_gBoxMoney
= BoxMoney
;
52 m_gItems
.push_back(gItem
);
55 void GossipMenu::AddGossipMenuItemData(int32 action_menu
, uint32 action_poi
, uint32 action_script
)
57 GossipMenuItemData pItemData
;
59 pItemData
.m_gAction_menu
= action_menu
;
60 pItemData
.m_gAction_poi
= action_poi
;
61 pItemData
.m_gAction_script
= action_script
;
63 m_gItemsData
.push_back(pItemData
);
66 void GossipMenu::AddMenuItem(uint8 Icon
, const std::string
& Message
, bool Coded
)
68 AddMenuItem(Icon
, Message
, 0, 0, "", 0, Coded
);
71 void GossipMenu::AddMenuItem(uint8 Icon
, char const* Message
, bool Coded
)
73 AddMenuItem(Icon
, std::string(Message
? Message
: ""), Coded
);
76 void GossipMenu::AddMenuItem(uint8 Icon
, char const* Message
, uint32 dtSender
, uint32 dtAction
, char const* BoxMessage
, uint32 BoxMoney
, bool Coded
)
78 AddMenuItem(Icon
, std::string(Message
? Message
: ""), dtSender
, dtAction
, std::string(BoxMessage
? BoxMessage
: ""), BoxMoney
, Coded
);
81 void GossipMenu::AddMenuItem(uint8 Icon
, int32 itemText
, uint32 dtSender
, uint32 dtAction
, int32 boxText
, uint32 BoxMoney
, bool Coded
)
83 uint32 loc_idx
= m_session
->GetSessionDbLocaleIndex();
85 char const* item_text
= itemText
? sObjectMgr
.GetMangosString(itemText
, loc_idx
) : "";
86 char const* box_text
= boxText
? sObjectMgr
.GetMangosString(boxText
, loc_idx
) : "";
88 AddMenuItem(Icon
, std::string(item_text
), dtSender
, dtAction
, std::string(box_text
), BoxMoney
, Coded
);
91 uint32
GossipMenu::MenuItemSender(unsigned int ItemId
)
93 if (ItemId
>= m_gItems
.size())
96 return m_gItems
[ ItemId
].m_gSender
;
99 uint32
GossipMenu::MenuItemAction(unsigned int ItemId
)
101 if (ItemId
>= m_gItems
.size())
104 return m_gItems
[ ItemId
].m_gOptionId
;
107 bool GossipMenu::MenuItemCoded(unsigned int ItemId
)
109 if (ItemId
>= m_gItems
.size())
112 return m_gItems
[ ItemId
].m_gCoded
;
115 void GossipMenu::ClearMenu()
118 m_gItemsData
.clear();
122 PlayerMenu::PlayerMenu(WorldSession
* session
) : mGossipMenu(session
)
126 PlayerMenu::~PlayerMenu()
131 void PlayerMenu::ClearMenus()
133 mGossipMenu
.ClearMenu();
134 mQuestMenu
.ClearMenu();
137 uint32
PlayerMenu::GossipOptionSender(unsigned int Selection
)
139 return mGossipMenu
.MenuItemSender(Selection
);
142 uint32
PlayerMenu::GossipOptionAction(unsigned int Selection
)
144 return mGossipMenu
.MenuItemAction(Selection
);
147 bool PlayerMenu::GossipOptionCoded(unsigned int Selection
)
149 return mGossipMenu
.MenuItemCoded(Selection
);
152 void PlayerMenu::SendGossipMenu(uint32 TitleTextId
, ObjectGuid objectGuid
)
154 WorldPacket
data(SMSG_GOSSIP_MESSAGE
, (100)); // guess size
155 data
<< ObjectGuid(objectGuid
);
156 data
<< uint32(mGossipMenu
.GetMenuId()); // new 2.4.0
157 data
<< uint32(TitleTextId
);
158 data
<< uint32(mGossipMenu
.MenuItemCount()); // max count 0x20
160 for (uint32 iI
= 0; iI
< mGossipMenu
.MenuItemCount(); ++iI
)
162 GossipMenuItem
const& gItem
= mGossipMenu
.GetItem(iI
);
164 data
<< uint8(gItem
.m_gIcon
);
165 data
<< uint8(gItem
.m_gCoded
); // makes pop up box password
166 data
<< uint32(gItem
.m_gBoxMoney
); // money required to open menu, 2.0.3
167 data
<< gItem
.m_gMessage
; // text for gossip item, max 0x800
168 data
<< gItem
.m_gBoxMessage
; // accept text (related to money) pop up box, 2.0.3, max 0x800
171 data
<< uint32(mQuestMenu
.MenuItemCount()); // max count 0x20
173 for (uint32 iI
= 0; iI
< mQuestMenu
.MenuItemCount(); ++iI
)
175 QuestMenuItem
const& qItem
= mQuestMenu
.GetItem(iI
);
176 uint32 questID
= qItem
.m_qId
;
177 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(questID
);
179 data
<< uint32(questID
);
180 data
<< uint32(qItem
.m_qIcon
);
181 data
<< int32(pQuest
->GetQuestLevel());
182 data
<< uint32(pQuest
->GetQuestFlags()); // 3.3.3 quest flags
183 data
<< uint8(0); // 3.3.3 changes icon: blue question or yellow exclamation
185 int loc_idx
= GetMenuSession()->GetSessionDbLocaleIndex();
186 std::string title
= pQuest
->GetTitle();
187 sObjectMgr
.GetQuestLocaleStrings(questID
, loc_idx
, &title
);
189 data
<< title
; // max 0x200
192 GetMenuSession()->SendPacket(&data
);
193 // DEBUG_LOG( "WORLD: Sent SMSG_GOSSIP_MESSAGE NPCGuid=%u",GUID_LOPART(npcGUID) );
196 void PlayerMenu::CloseGossip()
198 WorldPacket
data(SMSG_GOSSIP_COMPLETE
, 0);
199 GetMenuSession()->SendPacket(&data
);
201 // DEBUG_LOG( "WORLD: Sent SMSG_GOSSIP_COMPLETE" );
205 void PlayerMenu::SendPointOfInterest(float X
, float Y
, uint32 Icon
, uint32 Flags
, uint32 Data
, char const* locName
)
207 WorldPacket
data(SMSG_GOSSIP_POI
, (4 + 4 + 4 + 4 + 4 + 10)); // guess size
208 data
<< uint32(Flags
);
211 data
<< uint32(Icon
);
212 data
<< uint32(Data
);
215 GetMenuSession()->SendPacket(&data
);
216 // DEBUG_LOG("WORLD: Sent SMSG_GOSSIP_POI");
219 void PlayerMenu::SendPointOfInterest(uint32 poi_id
)
221 PointOfInterest
const* poi
= sObjectMgr
.GetPointOfInterest(poi_id
);
224 sLog
.outErrorDb("Requested send nonexistent POI (Id: %u), ignore.", poi_id
);
228 std::string icon_name
= poi
->icon_name
;
230 int loc_idx
= GetMenuSession()->GetSessionDbLocaleIndex();
232 if (PointOfInterestLocale
const* pl
= sObjectMgr
.GetPointOfInterestLocale(poi_id
))
233 if (pl
->IconName
.size() > size_t(loc_idx
) && !pl
->IconName
[loc_idx
].empty())
234 icon_name
= pl
->IconName
[loc_idx
];
236 WorldPacket
data(SMSG_GOSSIP_POI
, (4 + 4 + 4 + 4 + 4 + 10)); // guess size
237 data
<< uint32(poi
->flags
);
238 data
<< float(poi
->x
);
239 data
<< float(poi
->y
);
240 data
<< uint32(poi
->icon
);
241 data
<< uint32(poi
->data
);
244 GetMenuSession()->SendPacket(&data
);
245 // DEBUG_LOG("WORLD: Sent SMSG_GOSSIP_POI");
248 void PlayerMenu::SendTalking(uint32 textID
)
250 GossipText
const* pGossip
= sObjectMgr
.GetGossipText(textID
);
252 WorldPacket
data(SMSG_NPC_TEXT_UPDATE
, 100); // guess size
253 data
<< textID
; // can be < 0
257 for (uint32 i
= 0; i
< 8; ++i
)
260 data
<< "Greetings $N";
261 data
<< "Greetings $N";
273 std::string Text_0
[MAX_GOSSIP_TEXT_OPTIONS
], Text_1
[MAX_GOSSIP_TEXT_OPTIONS
];
274 for (int i
= 0; i
< MAX_GOSSIP_TEXT_OPTIONS
; ++i
)
276 Text_0
[i
] = pGossip
->Options
[i
].Text_0
;
277 Text_1
[i
] = pGossip
->Options
[i
].Text_1
;
280 int loc_idx
= GetMenuSession()->GetSessionDbLocaleIndex();
282 sObjectMgr
.GetNpcTextLocaleStringsAll(textID
, loc_idx
, &Text_0
, &Text_1
);
284 for (int i
= 0; i
< MAX_GOSSIP_TEXT_OPTIONS
; ++i
)
286 data
<< pGossip
->Options
[i
].Probability
;
288 if (Text_0
[i
].empty())
293 if (Text_1
[i
].empty())
298 data
<< pGossip
->Options
[i
].Language
;
300 for (int j
= 0; j
< 3; ++j
)
302 data
<< pGossip
->Options
[i
].Emotes
[j
]._Delay
;
303 data
<< pGossip
->Options
[i
].Emotes
[j
]._Emote
;
307 GetMenuSession()->SendPacket(&data
);
309 DEBUG_LOG("WORLD: Sent SMSG_NPC_TEXT_UPDATE ");
312 void PlayerMenu::SendTalking(char const* title
, char const* text
)
314 WorldPacket
data(SMSG_NPC_TEXT_UPDATE
, 50); // guess size
316 for (uint32 i
= 0; i
< 8; ++i
)
330 GetMenuSession()->SendPacket(&data
);
332 DEBUG_LOG("WORLD: Sent SMSG_NPC_TEXT_UPDATE ");
335 /*********************************************************/
336 /*** QUEST SYSTEM ***/
337 /*********************************************************/
339 QuestMenu::QuestMenu()
341 m_qItems
.reserve(16); // can be set for max from most often sizes to speedup push_back and less memory use
344 QuestMenu::~QuestMenu()
349 void QuestMenu::AddMenuItem(uint32 QuestId
, uint8 Icon
)
351 Quest
const* qinfo
= sObjectMgr
.GetQuestTemplate(QuestId
);
355 MANGOS_ASSERT(m_qItems
.size() <= GOSSIP_MAX_MENU_ITEMS
);
359 qItem
.m_qId
= QuestId
;
360 qItem
.m_qIcon
= Icon
;
362 m_qItems
.push_back(qItem
);
365 bool QuestMenu::HasItem(uint32 questid
)
367 for (QuestMenuItemList::const_iterator i
= m_qItems
.begin(); i
!= m_qItems
.end(); ++i
)
368 if (i
->m_qId
== questid
)
373 void QuestMenu::ClearMenu()
378 void PlayerMenu::SendQuestGiverQuestList(QEmote eEmote
, const std::string
& Title
, ObjectGuid npcGUID
)
380 WorldPacket
data(SMSG_QUESTGIVER_QUEST_LIST
, 100); // guess size
381 data
<< ObjectGuid(npcGUID
);
383 data
<< uint32(eEmote
._Delay
); // player emote
384 data
<< uint32(eEmote
._Emote
); // NPC emote
386 size_t count_pos
= data
.wpos();
387 data
<< uint8(mQuestMenu
.MenuItemCount());
389 for (; count
< mQuestMenu
.MenuItemCount(); ++count
)
391 QuestMenuItem
const& qmi
= mQuestMenu
.GetItem(count
);
393 uint32 questID
= qmi
.m_qId
;
395 if (Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(questID
))
397 int loc_idx
= GetMenuSession()->GetSessionDbLocaleIndex();
398 std::string title
= pQuest
->GetTitle();
399 sObjectMgr
.GetQuestLocaleStrings(questID
, loc_idx
, &title
);
401 data
<< uint32(questID
);
402 data
<< uint32(qmi
.m_qIcon
);
403 data
<< int32(pQuest
->GetQuestLevel());
404 data
<< uint32(pQuest
->GetQuestFlags()); // 3.3.3 quest flags
405 data
<< uint8(0); // 3.3.3 changes icon: blue question or yellow exclamation
409 data
.put
<uint8
>(count_pos
, count
);
410 GetMenuSession()->SendPacket(&data
);
411 DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_QUEST_LIST NPC Guid = %s", npcGUID
.GetString().c_str());
414 void PlayerMenu::SendQuestGiverStatus(uint32 questStatus
, ObjectGuid npcGUID
)
416 WorldPacket
data(SMSG_QUESTGIVER_STATUS
, 12);
418 data
<< uint32(questStatus
);
420 GetMenuSession()->SendPacket(&data
);
421 DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_STATUS for %s", npcGUID
.GetString().c_str());
424 void PlayerMenu::SendQuestGiverQuestDetails(Quest
const* pQuest
, ObjectGuid guid
, bool ActivateAccept
)
426 std::string Title
= pQuest
->GetTitle();
427 std::string Details
= pQuest
->GetDetails();
428 std::string Objectives
= pQuest
->GetObjectives();
429 std::string PortraitGiverName
= pQuest
->GetPortraitGiverName();
430 std::string PortraitGiverText
= pQuest
->GetPortraitGiverText();
431 std::string PortraitTurnInName
= pQuest
->GetPortraitTurnInName();
432 std::string PortraitTurnInText
= pQuest
->GetPortraitTurnInText();
434 int loc_idx
= GetMenuSession()->GetSessionDbLocaleIndex();
437 if (QuestLocale
const* ql
= sObjectMgr
.GetQuestLocale(pQuest
->GetQuestId()))
439 if (ql
->Title
.size() > (size_t)loc_idx
&& !ql
->Title
[loc_idx
].empty())
440 Title
= ql
->Title
[loc_idx
];
441 if (ql
->Details
.size() > (size_t)loc_idx
&& !ql
->Details
[loc_idx
].empty())
442 Details
= ql
->Details
[loc_idx
];
443 if (ql
->Objectives
.size() > (size_t)loc_idx
&& !ql
->Objectives
[loc_idx
].empty())
444 Objectives
= ql
->Objectives
[loc_idx
];
445 if (ql
->PortraitGiverName
.size() > (size_t)loc_idx
&& !ql
->PortraitGiverName
[loc_idx
].empty())
446 PortraitGiverName
= ql
->PortraitGiverName
[loc_idx
];
447 if (ql
->PortraitGiverText
.size() > (size_t)loc_idx
&& !ql
->PortraitGiverText
[loc_idx
].empty())
448 PortraitGiverText
= ql
->PortraitGiverText
[loc_idx
];
449 if (ql
->PortraitTurnInName
.size() > (size_t)loc_idx
&& !ql
->PortraitTurnInName
[loc_idx
].empty())
450 PortraitTurnInName
= ql
->PortraitTurnInName
[loc_idx
];
451 if (ql
->PortraitTurnInText
.size() > (size_t)loc_idx
&& !ql
->PortraitTurnInText
[loc_idx
].empty())
452 PortraitTurnInText
= ql
->PortraitTurnInText
[loc_idx
];
456 WorldPacket
data(SMSG_QUESTGIVER_QUEST_DETAILS
, 100); // guess size
458 data
<< uint64(0); // wotlk, something todo with quest sharing?
459 data
<< uint32(pQuest
->GetQuestId());
463 data
<< PortraitGiverText
;
464 data
<< PortraitGiverName
;
465 data
<< PortraitTurnInText
;
466 data
<< PortraitTurnInName
;
467 data
<< uint32(pQuest
->GetPortraitGiver());
468 data
<< uint32(pQuest
->GetPortraitTurnIn());
469 data
<< uint8(ActivateAccept
? 1 : 0); // auto finish
470 data
<< uint32(pQuest
->GetQuestFlags()); // 3.3.3 questFlags
471 data
<< uint32(pQuest
->GetSuggestedPlayers());
472 data
<< uint8(0); // IsFinished? value is sent back to server in quest accept packet
473 data
<< uint8(0); // is areatrigger quest
474 data
<< uint32(pQuest
->GetReqSpellLearned());
477 /*if (pQuest->HasQuestFlag(QUEST_FLAGS_HIDDEN_REWARDS))
479 data << uint32(0); // Rewarded chosen items hidden
480 data << uint32(0); // Rewarded items hidden
481 data << uint32(0); // Rewarded money hidden
482 data << uint32(0); // Rewarded XP hidden
486 data
<< uint32(pQuest
->GetRewChoiceItemsCount());
488 for (uint32 i
= 0; i
< QUEST_REWARD_CHOICES_COUNT
; ++i
)
489 data
<< uint32(pQuest
->RewChoiceItemId
[i
]);
490 for (uint32 i
= 0; i
< QUEST_REWARD_CHOICES_COUNT
; ++i
)
491 data
<< uint32(pQuest
->RewChoiceItemCount
[i
]);
492 for (uint32 i
= 0; i
< QUEST_REWARD_CHOICES_COUNT
; ++i
)
493 if (ItemPrototype
const* IProto
= ObjectMgr::GetItemPrototype(pQuest
->RewChoiceItemId
[i
]))
494 data
<< uint32(IProto
->DisplayInfoID
);
498 data
<< uint32(pQuest
->GetRewItemsCount());
500 for (uint32 i
= 0; i
< QUEST_REWARDS_COUNT
; ++i
)
501 data
<< uint32(pQuest
->RewItemId
[i
]);
502 for (uint32 i
= 0; i
< QUEST_REWARDS_COUNT
; ++i
)
503 data
<< uint32(pQuest
->RewItemCount
[i
]);
504 for (uint32 i
= 0; i
< QUEST_REWARDS_COUNT
; ++i
)
505 if (ItemPrototype
const* IProto
= ObjectMgr::GetItemPrototype(pQuest
->RewItemId
[i
]))
506 data
<< uint32(IProto
->DisplayInfoID
);
510 // send rewMoneyMaxLevel explicit for max player level, else send RewOrReqMoney
511 if (GetMenuSession()->GetPlayer()->getLevel() >= sWorld
.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL
))
512 data
<< uint32(pQuest
->GetRewMoneyMaxLevel());
514 data
<< uint32(pQuest
->GetRewOrReqMoney());
516 data
<< uint32(pQuest
->XPValue(GetMenuSession()->GetPlayer()));
519 data
<< uint32(pQuest
->GetCharTitleId()); // CharTitleId, new 2.4.0, player gets this title (id from CharTitles)
520 data
<< uint32(0); // unk, unused 10 * GetRewHonorAddition ?
521 data
<< float(0); // unk, unused GetRewHonorMultiplier ?
522 data
<< uint32(pQuest
->GetBonusTalents()); // bonus talents
523 data
<< uint32(0); // unk, unused bonus arena points?
524 data
<< uint32(0); // rep reward show mask?
527 for (int i
= 0; i
< QUEST_REPUTATIONS_COUNT
; ++i
) // reward factions ids
528 data
<< uint32(pQuest
->RewRepFaction
[i
]);
530 for (int i
= 0; i
< QUEST_REPUTATIONS_COUNT
; ++i
) // columnid in QuestFactionReward.dbc (if negative, from second row)
531 data
<< int32(pQuest
->RewRepValueId
[i
]);
533 for (int i
= 0; i
< QUEST_REPUTATIONS_COUNT
; ++i
) // reward reputation override. No bonus is expected given
535 // data << int32(pQuest->RewRepValue[i]); // current field for store of rep value, can be reused to implement "override value"
537 data
<< uint32(pQuest
->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0)
538 data
<< uint32(pQuest
->GetRewSpellCast()); // casted spell
540 for (uint32 i
= 0; i
< QUEST_REWARD_CURRENCY_COUNT
; ++i
)
541 data
<< uint32(pQuest
->RewCurrencyId
[i
]);
543 for (uint32 i
= 0; i
< QUEST_REWARD_CURRENCY_COUNT
; ++i
)
544 data
<< uint32(pQuest
->RewCurrencyCount
[i
]);
546 data
<< uint32(pQuest
->GetRewSkill());
547 data
<< uint32(pQuest
->GetRewSkillValue());
549 data
<< uint32(QUEST_EMOTE_COUNT
);
551 for (uint32 i
= 0; i
< QUEST_EMOTE_COUNT
; ++i
)
553 data
<< uint32(pQuest
->DetailsEmote
[i
]);
554 data
<< uint32(pQuest
->DetailsEmoteDelay
[i
]); // DetailsEmoteDelay (in ms)
557 GetMenuSession()->SendPacket(&data
);
559 DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_QUEST_DETAILS - for %s of %s, questid = %u", GetMenuSession()->GetPlayer()->GetGuidStr().c_str(), guid
.GetString().c_str(), pQuest
->GetQuestId());
562 // send only static data in this packet!
563 void PlayerMenu::SendQuestQueryResponse(Quest
const* pQuest
)
565 std::string Title
, Details
, Objectives
, EndText
, CompletedText
;
566 std::string PortraitGiverText
, PortraitGiverName
;
567 std::string PortraitTurnInText
, PortraitTurnInName
;
568 std::string ObjectiveText
[QUEST_OBJECTIVES_COUNT
];
569 Title
= pQuest
->GetTitle();
570 Details
= pQuest
->GetDetails();
571 Objectives
= pQuest
->GetObjectives();
572 EndText
= pQuest
->GetEndText();
573 CompletedText
= pQuest
->GetCompletedText();
574 PortraitGiverName
= pQuest
->GetPortraitGiverName();
575 PortraitGiverText
= pQuest
->GetPortraitGiverText();
576 PortraitTurnInName
= pQuest
->GetPortraitTurnInName();
577 PortraitTurnInText
= pQuest
->GetPortraitTurnInText();
579 for (int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; ++i
)
580 ObjectiveText
[i
] = pQuest
->ObjectiveText
[i
];
582 int loc_idx
= GetMenuSession()->GetSessionDbLocaleIndex();
585 if (QuestLocale
const* ql
= sObjectMgr
.GetQuestLocale(pQuest
->GetQuestId()))
587 if (ql
->Title
.size() > (size_t)loc_idx
&& !ql
->Title
[loc_idx
].empty())
588 Title
= ql
->Title
[loc_idx
];
589 if (ql
->Details
.size() > (size_t)loc_idx
&& !ql
->Details
[loc_idx
].empty())
590 Details
= ql
->Details
[loc_idx
];
591 if (ql
->Objectives
.size() > (size_t)loc_idx
&& !ql
->Objectives
[loc_idx
].empty())
592 Objectives
= ql
->Objectives
[loc_idx
];
593 if (ql
->EndText
.size() > (size_t)loc_idx
&& !ql
->EndText
[loc_idx
].empty())
594 EndText
= ql
->EndText
[loc_idx
];
595 if (ql
->CompletedText
.size() > (size_t)loc_idx
&& !ql
->CompletedText
[loc_idx
].empty())
596 CompletedText
= ql
->CompletedText
[loc_idx
];
597 if (ql
->PortraitGiverName
.size() > (size_t)loc_idx
&& !ql
->PortraitGiverName
[loc_idx
].empty())
598 PortraitGiverName
= ql
->PortraitGiverName
[loc_idx
];
599 if (ql
->PortraitGiverText
.size() > (size_t)loc_idx
&& !ql
->PortraitGiverText
[loc_idx
].empty())
600 PortraitGiverText
= ql
->PortraitGiverText
[loc_idx
];
601 if (ql
->PortraitTurnInName
.size() > (size_t)loc_idx
&& !ql
->PortraitTurnInName
[loc_idx
].empty())
602 PortraitTurnInName
= ql
->PortraitTurnInName
[loc_idx
];
603 if (ql
->PortraitTurnInText
.size() > (size_t)loc_idx
&& !ql
->PortraitTurnInText
[loc_idx
].empty())
604 PortraitTurnInText
= ql
->PortraitTurnInText
[loc_idx
];
606 for (int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; ++i
)
607 if (ql
->ObjectiveText
[i
].size() > (size_t)loc_idx
&& !ql
->ObjectiveText
[i
][loc_idx
].empty())
608 ObjectiveText
[i
] = ql
->ObjectiveText
[i
][loc_idx
];
612 WorldPacket
data(SMSG_QUEST_QUERY_RESPONSE
, 100); // guess size
614 data
<< uint32(pQuest
->GetQuestId()); // quest id
615 data
<< uint32(pQuest
->GetQuestMethod()); // Accepted values: 0, 1 or 2. 0==IsAutoComplete() (skip objectives/details)
616 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)
617 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)
618 data
<< uint32(pQuest
->GetZoneOrSort()); // zone or sort to display in quest log
620 data
<< uint32(pQuest
->GetType()); // quest type
621 data
<< uint32(pQuest
->GetSuggestedPlayers()); // suggested players count
623 data
<< uint32(pQuest
->GetRepObjectiveFaction()); // shown in quest log as part of quest objective
624 data
<< uint32(pQuest
->GetRepObjectiveValue()); // shown in quest log as part of quest objective
626 data
<< uint32(0); // RequiredOppositeRepFaction
627 data
<< uint32(0); // RequiredOppositeRepValue, required faction value with another (oposite) faction (objective)
629 data
<< uint32(pQuest
->GetNextQuestInChain()); // client will request this quest from NPC, if not 0
630 data
<< uint32(pQuest
->GetRewXPId()); // column index in QuestXP.dbc (row based on quest level)
633 /*if (pQuest->HasQuestFlag(QUEST_FLAGS_HIDDEN_REWARDS))
634 data << uint32(0); // Hide money rewarded
636 data
<< uint32(pQuest
->GetRewOrReqMoney()); // reward money (below max lvl)
638 data
<< uint32(pQuest
->GetRewMoneyMaxLevel()); // used in XP calculation at client
639 data
<< uint32(pQuest
->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0)
640 data
<< uint32(pQuest
->GetRewSpellCast()); // casted spell
642 // rewarded honor points
643 data
<< uint32(pQuest
->GetRewHonorAddition()); // unused 4.x.x ?
644 data
<< float(pQuest
->GetRewHonorMultiplier()); // unused 4.x.x ? new reward honor (multiplied by ~62 at client side)
646 data
<< uint32(pQuest
->GetSrcItemId()); // source item id
647 data
<< uint32(pQuest
->GetQuestFlags()); // quest flags
649 data
<< uint32(0); // MinimapTargetMark
651 data
<< uint32(pQuest
->GetCharTitleId()); // CharTitleId, new 2.4.0, player gets this title (id from CharTitles)
652 data
<< uint32(pQuest
->GetPlayersSlain()); // players slain
653 data
<< uint32(pQuest
->GetBonusTalents()); // bonus talents
655 data
<< uint32(0); // unused 4.x.x ? bonus arena points
656 data
<< uint32(pQuest
->GetRewSkill()); // Rewarded skill id
657 data
<< uint32(pQuest
->GetRewSkillValue()); // Rewarded skill bonus points
658 data
<< uint32(0); // rew rep show mask?
659 data
<< uint32(pQuest
->GetPortraitGiver());
660 data
<< uint32(pQuest
->GetPortraitTurnIn());
665 /*if (pQuest->HasQuestFlag(QUEST_FLAGS_HIDDEN_REWARDS))
667 for (iI = 0; iI < QUEST_REWARDS_COUNT; ++iI)
668 data << uint32(0) << uint32(0);
669 for (iI = 0; iI < QUEST_REWARD_CHOICES_COUNT; ++iI)
670 data << uint32(0) << uint32(0);
674 for (iI
= 0; iI
< QUEST_REWARDS_COUNT
; ++iI
)
676 data
<< uint32(pQuest
->RewItemId
[iI
]);
677 data
<< uint32(pQuest
->RewItemCount
[iI
]);
679 for (iI
= 0; iI
< QUEST_REWARD_CHOICES_COUNT
; ++iI
)
681 data
<< uint32(pQuest
->RewChoiceItemId
[iI
]);
682 data
<< uint32(pQuest
->RewChoiceItemCount
[iI
]);
686 for (int i
= 0; i
< QUEST_REPUTATIONS_COUNT
; ++i
) // reward factions ids
687 data
<< uint32(pQuest
->RewRepFaction
[i
]);
689 for (int i
= 0; i
< QUEST_REPUTATIONS_COUNT
; ++i
) // columnid in QuestFactionReward.dbc (if negative, from second row)
690 data
<< int32(pQuest
->RewRepValueId
[i
]);
692 for (int i
= 0; i
< QUEST_REPUTATIONS_COUNT
; ++i
) // reward reputation override. No bonus is expected given
694 // data << int32(pQuest->RewRepValue[i]); // current field for store of rep value, can be reused to implement "override value"
696 data
<< pQuest
->GetPointMapId();
697 data
<< pQuest
->GetPointX();
698 data
<< pQuest
->GetPointY();
699 data
<< pQuest
->GetPointOpt();
705 data
<< CompletedText
; // display in quest objectives window once all objectives are completed
707 for (iI
= 0; iI
< QUEST_OBJECTIVES_COUNT
; ++iI
)
709 if (pQuest
->ReqCreatureOrGOId
[iI
] < 0)
711 // client expected gameobject template id in form (id|0x80000000)
712 data
<< uint32((pQuest
->ReqCreatureOrGOId
[iI
] * (-1)) | 0x80000000);
716 data
<< uint32(pQuest
->ReqCreatureOrGOId
[iI
]);
718 data
<< uint32(pQuest
->ReqCreatureOrGOCount
[iI
]);
719 data
<< uint32(pQuest
->ReqSourceId
[iI
]);
720 data
<< uint32(pQuest
->ReqSourceCount
[iI
]);
723 for (iI
= 0; iI
< QUEST_ITEM_OBJECTIVES_COUNT
; ++iI
)
725 data
<< uint32(pQuest
->ReqItemId
[iI
]);
726 data
<< uint32(pQuest
->ReqItemCount
[iI
]);
729 data
<< uint32(pQuest
->GetReqSpellLearned());
731 for (iI
= 0; iI
< QUEST_OBJECTIVES_COUNT
; ++iI
)
732 data
<< ObjectiveText
[iI
];
734 for(iI
= 0; iI
< QUEST_REWARD_CURRENCY_COUNT
; ++iI
)
736 data
<< uint32(pQuest
->RewCurrencyId
[iI
]);
737 data
<< uint32(pQuest
->RewCurrencyCount
[iI
]);
740 for(iI
= 0; iI
< QUEST_REQUIRED_CURRENCY_COUNT
; ++iI
)
742 data
<< uint32(pQuest
->ReqCurrencyId
[iI
]);
743 data
<< uint32(pQuest
->ReqCurrencyCount
[iI
]);
746 data
<< PortraitGiverText
;
747 data
<< PortraitGiverName
;
748 data
<< PortraitTurnInText
;
749 data
<< PortraitTurnInName
;
751 data
<< uint32(pQuest
->GetSoundAcceptId());
752 data
<< uint32(pQuest
->GetSoundTurnInId());
754 GetMenuSession()->SendPacket(&data
);
755 DEBUG_LOG("WORLD: Sent SMSG_QUEST_QUERY_RESPONSE questid=%u", pQuest
->GetQuestId());
758 void PlayerMenu::SendQuestGiverOfferReward(Quest
const* pQuest
, ObjectGuid npcGUID
, bool EnableNext
)
760 std::string Title
= pQuest
->GetTitle();
761 std::string OfferRewardText
= pQuest
->GetOfferRewardText();
762 std::string PortraitGiverName
= pQuest
->GetPortraitGiverName();
763 std::string PortraitGiverText
= pQuest
->GetPortraitGiverText();
764 std::string PortraitTurnInName
= pQuest
->GetPortraitTurnInName();
765 std::string PortraitTurnInText
= pQuest
->GetPortraitTurnInText();
767 int loc_idx
= GetMenuSession()->GetSessionDbLocaleIndex();
770 if (QuestLocale
const* ql
= sObjectMgr
.GetQuestLocale(pQuest
->GetQuestId()))
772 if (ql
->Title
.size() > (size_t)loc_idx
&& !ql
->Title
[loc_idx
].empty())
773 Title
= ql
->Title
[loc_idx
];
774 if (ql
->OfferRewardText
.size() > (size_t)loc_idx
&& !ql
->OfferRewardText
[loc_idx
].empty())
775 OfferRewardText
= ql
->OfferRewardText
[loc_idx
];
776 if (ql
->PortraitGiverName
.size() > (size_t)loc_idx
&& !ql
->PortraitGiverName
[loc_idx
].empty())
777 PortraitGiverName
= ql
->PortraitGiverName
[loc_idx
];
778 if (ql
->PortraitGiverText
.size() > (size_t)loc_idx
&& !ql
->PortraitGiverText
[loc_idx
].empty())
779 PortraitGiverText
= ql
->PortraitGiverText
[loc_idx
];
780 if (ql
->PortraitTurnInName
.size() > (size_t)loc_idx
&& !ql
->PortraitTurnInName
[loc_idx
].empty())
781 PortraitTurnInName
= ql
->PortraitTurnInName
[loc_idx
];
782 if (ql
->PortraitTurnInText
.size() > (size_t)loc_idx
&& !ql
->PortraitTurnInText
[loc_idx
].empty())
783 PortraitTurnInText
= ql
->PortraitTurnInText
[loc_idx
];
787 WorldPacket
data(SMSG_QUESTGIVER_OFFER_REWARD
, 50); // guess size
789 data
<< ObjectGuid(npcGUID
);
790 data
<< uint32(pQuest
->GetQuestId());
792 data
<< OfferRewardText
;
794 data
<< PortraitGiverText
;
795 data
<< PortraitGiverName
;
796 data
<< PortraitTurnInText
;
797 data
<< PortraitTurnInName
;
798 data
<< uint32(pQuest
->GetPortraitGiver());
799 data
<< uint32(pQuest
->GetPortraitTurnIn());
801 data
<< uint8(EnableNext
? 1 : 0); // Auto Finish
802 data
<< uint32(pQuest
->GetQuestFlags()); // 3.3.3 questFlags
803 data
<< uint32(pQuest
->GetSuggestedPlayers()); // SuggestedGroupNum
805 uint32 EmoteCount
= 0;
806 for (uint32 i
= 0; i
< QUEST_EMOTE_COUNT
; ++i
)
808 if (pQuest
->OfferRewardEmote
[i
] <= 0)
813 data
<< EmoteCount
; // Emote Count
814 for (uint32 i
= 0; i
< EmoteCount
; ++i
)
816 data
<< uint32(pQuest
->OfferRewardEmoteDelay
[i
]); // Delay Emote
817 data
<< uint32(pQuest
->OfferRewardEmote
[i
]);
820 data
<< uint32(pQuest
->GetRewChoiceItemsCount());
821 for (uint32 i
= 0; i
< QUEST_REWARD_CHOICES_COUNT
; ++i
)
822 data
<< uint32(pQuest
->RewChoiceItemId
[i
]);
823 for (uint32 i
= 0; i
< QUEST_REWARD_CHOICES_COUNT
; ++i
)
824 data
<< uint32(pQuest
->RewChoiceItemCount
[i
]);
825 for (uint32 i
= 0; i
< QUEST_REWARD_CHOICES_COUNT
; ++i
)
826 if (ItemPrototype
const* pItem
= ObjectMgr::GetItemPrototype(pQuest
->RewChoiceItemId
[i
]))
827 data
<< uint32(pItem
->DisplayInfoID
);
831 data
<< uint32(pQuest
->GetRewItemsCount());
832 for (uint32 i
= 0; i
< QUEST_REWARDS_COUNT
; ++i
)
833 data
<< uint32(pQuest
->RewItemId
[i
]);
834 for (uint32 i
= 0; i
< QUEST_REWARDS_COUNT
; ++i
)
835 data
<< uint32(pQuest
->RewItemCount
[i
]);
836 for (uint32 i
= 0; i
< QUEST_REWARDS_COUNT
; ++i
)
837 if (ItemPrototype
const* pItem
= ObjectMgr::GetItemPrototype(pQuest
->RewItemId
[i
]))
838 data
<< uint32(pItem
->DisplayInfoID
);
842 // send rewMoneyMaxLevel explicit for max player level, else send RewOrReqMoney
843 if (GetMenuSession()->GetPlayer()->getLevel() >= sWorld
.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL
))
844 data
<< uint32(pQuest
->GetRewMoneyMaxLevel());
846 data
<< uint32(pQuest
->GetRewOrReqMoney());
849 data
<< uint32(pQuest
->XPValue(GetMenuSession()->GetPlayer()));
851 data
<< uint32(pQuest
->GetCharTitleId()); // character title
852 data
<< uint32(0); // unk, unused 10 * GetRewHonorAddition ?
853 data
<< float(0); // unk, unused GetRewHonorMultiplier ?
854 data
<< uint32(pQuest
->GetBonusTalents()); // bonus talents
855 data
<< uint32(0); // unk, unused bonus arena points?
856 data
<< uint32(0); // rep reward show mask?
858 for(int i
= 0; i
< QUEST_REPUTATIONS_COUNT
; ++i
) // reward factions ids
859 data
<< uint32(pQuest
->RewRepFaction
[i
]);
861 for(int i
= 0; i
< QUEST_REPUTATIONS_COUNT
; ++i
) // columnid in QuestFactionReward.dbc (if negative, from second row)
862 data
<< int32(pQuest
->RewRepValueId
[i
]);
864 for(int i
= 0; i
< QUEST_REPUTATIONS_COUNT
; ++i
) // reward reputation override. No diplomacy bonus is expected given, reward also does not display in chat window
866 //data << int32(pQuest->RewRepValue[i]);
868 data
<< uint32(pQuest
->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0)
869 data
<< uint32(pQuest
->GetRewSpellCast()); // casted spell
871 for (uint32 i
= 0; i
< QUEST_REWARD_CURRENCY_COUNT
; ++i
)
872 data
<< uint32(pQuest
->RewCurrencyId
[i
]);
874 for (uint32 i
= 0; i
< QUEST_REWARD_CURRENCY_COUNT
; ++i
)
875 data
<< uint32(pQuest
->RewCurrencyCount
[i
]);
877 data
<< uint32(pQuest
->GetRewSkill());
878 data
<< uint32(pQuest
->GetRewSkillValue());
880 GetMenuSession()->SendPacket(&data
);
881 DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_OFFER_REWARD NPCGuid = %s, questid = %u", npcGUID
.GetString().c_str(), pQuest
->GetQuestId());
884 void PlayerMenu::SendQuestGiverRequestItems(Quest
const* pQuest
, ObjectGuid npcGUID
, bool Completable
, bool CloseOnCancel
)
886 // We can always call to RequestItems, but this packet only goes out if there are actually
887 // items. Otherwise, we'll skip straight to the OfferReward
889 if (!pQuest
->GetReqItemsCount() && !pQuest
->GetReqCurrencyCount() && Completable
)
891 SendQuestGiverOfferReward(pQuest
, npcGUID
, true);
895 std::string Title
= pQuest
->GetTitle();
896 std::string RequestItemsText
= pQuest
->GetRequestItemsText();
898 int loc_idx
= GetMenuSession()->GetSessionDbLocaleIndex();
901 if (QuestLocale
const* ql
= sObjectMgr
.GetQuestLocale(pQuest
->GetQuestId()))
903 if (ql
->Title
.size() > (size_t)loc_idx
&& !ql
->Title
[loc_idx
].empty())
904 Title
= ql
->Title
[loc_idx
];
905 if (ql
->RequestItemsText
.size() > (size_t)loc_idx
&& !ql
->RequestItemsText
[loc_idx
].empty())
906 RequestItemsText
= ql
->RequestItemsText
[loc_idx
];
910 WorldPacket
data(SMSG_QUESTGIVER_REQUEST_ITEMS
, 50); // guess size
911 data
<< ObjectGuid(npcGUID
);
912 data
<< uint32(pQuest
->GetQuestId());
914 data
<< RequestItemsText
;
916 data
<< uint32(0x00); // emote delay
919 data
<< pQuest
->GetCompleteEmote(); // emote id
921 data
<< pQuest
->GetIncompleteEmote();
923 // Close Window after cancel
925 data
<< uint32(0x01); // auto finish
927 data
<< uint32(0x00);
929 data
<< uint32(pQuest
->GetQuestFlags()); // 3.3.3 questFlags
930 data
<< uint32(pQuest
->GetSuggestedPlayers()); // SuggestedGroupNum
933 data
<< uint32(pQuest
->GetRewOrReqMoney() < 0 ? -pQuest
->GetRewOrReqMoney() : 0);
935 data
<< uint32(pQuest
->GetReqItemsCount());
936 ItemPrototype
const* pItem
;
937 for (int i
= 0; i
< QUEST_ITEM_OBJECTIVES_COUNT
; ++i
)
939 if (!pQuest
->ReqItemId
[i
])
941 pItem
= ObjectMgr::GetItemPrototype(pQuest
->ReqItemId
[i
]);
942 data
<< uint32(pQuest
->ReqItemId
[i
]);
943 data
<< uint32(pQuest
->ReqItemCount
[i
]);
946 data
<< uint32(pItem
->DisplayInfoID
);
951 data
<< uint32(pQuest
->GetReqCurrencyCount());
952 for (int i
= 0; i
< QUEST_REQUIRED_CURRENCY_COUNT
; ++i
)
954 if (!pQuest
->ReqCurrencyId
[i
])
957 data
<< uint32(pQuest
->ReqCurrencyId
[i
]);
958 data
<< uint32(pQuest
->ReqCurrencyCount
[i
]);
961 if (!Completable
) // Completable = flags1 && flags2 && flags3 && flags4
962 data
<< uint32(0x00); // flags1
964 data
<< uint32(0x03);
966 data
<< uint32(0x04); // flags2
967 data
<< uint32(0x08); // flags3
968 data
<< uint32(0x10); // flags4
969 data
<< uint32(0x40); // flags5
971 GetMenuSession()->SendPacket(&data
);
972 DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_REQUEST_ITEMS NPCGuid = %s, questid = %u", npcGUID
.GetString().c_str(), pQuest
->GetQuestId());