[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / GossipDef.cpp
blobe1fad9ef99ff243dca4a580067da6c04cc33c569
1 /*
2 * Copyright (C) 2005-2009 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 "QuestDef.h"
20 #include "GossipDef.h"
21 #include "ObjectMgr.h"
22 #include "Opcodes.h"
23 #include "WorldPacket.h"
24 #include "WorldSession.h"
25 #include "Formulas.h"
27 GossipMenu::GossipMenu()
29 m_gItems.reserve(16); // can be set for max from most often sizes to speedup push_back and less memory use
32 GossipMenu::~GossipMenu()
34 ClearMenu();
37 void GossipMenu::AddMenuItem(uint8 Icon, const std::string& Message, uint32 dtSender, uint32 dtAction, const std::string& BoxMessage, uint32 BoxMoney, bool Coded)
39 ASSERT( m_gItems.size() <= GOSSIP_MAX_MENU_ITEMS );
41 GossipMenuItem gItem;
43 gItem.m_gIcon = Icon;
44 gItem.m_gMessage = Message;
45 gItem.m_gCoded = Coded;
46 gItem.m_gSender = dtSender;
47 gItem.m_gAction = dtAction;
48 gItem.m_gBoxMessage = BoxMessage;
49 gItem.m_gBoxMoney = BoxMoney;
51 m_gItems.push_back(gItem);
54 void GossipMenu::AddMenuItem(uint8 Icon, const std::string& Message, bool Coded)
56 AddMenuItem( Icon, Message, 0, 0, "", 0, Coded);
59 void GossipMenu::AddMenuItem(uint8 Icon, char const* Message, bool Coded)
61 AddMenuItem(Icon, std::string(Message ? Message : ""),Coded);
64 void GossipMenu::AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, uint32 dtAction, char const* BoxMessage, uint32 BoxMoney, bool Coded)
66 AddMenuItem(Icon, std::string(Message ? Message : ""), dtSender, dtAction, std::string(BoxMessage ? BoxMessage : ""), BoxMoney, Coded);
69 uint32 GossipMenu::MenuItemSender( unsigned int ItemId )
71 if ( ItemId >= m_gItems.size() ) return 0;
73 return m_gItems[ ItemId ].m_gSender;
76 uint32 GossipMenu::MenuItemAction( unsigned int ItemId )
78 if ( ItemId >= m_gItems.size() ) return 0;
80 return m_gItems[ ItemId ].m_gAction;
83 bool GossipMenu::MenuItemCoded( unsigned int ItemId )
85 if ( ItemId >= m_gItems.size() ) return 0;
87 return m_gItems[ ItemId ].m_gCoded;
90 void GossipMenu::ClearMenu()
92 m_gItems.clear();
95 PlayerMenu::PlayerMenu( WorldSession *session ) : pSession(session)
99 PlayerMenu::~PlayerMenu()
101 ClearMenus();
104 void PlayerMenu::ClearMenus()
106 mGossipMenu.ClearMenu();
107 mQuestMenu.ClearMenu();
110 uint32 PlayerMenu::GossipOptionSender( unsigned int Selection )
112 return mGossipMenu.MenuItemSender( Selection );
115 uint32 PlayerMenu::GossipOptionAction( unsigned int Selection )
117 return mGossipMenu.MenuItemAction( Selection );
120 bool PlayerMenu::GossipOptionCoded( unsigned int Selection )
122 return mGossipMenu.MenuItemCoded( Selection );
125 void PlayerMenu::SendGossipMenu( uint32 TitleTextId, uint64 npcGUID )
127 WorldPacket data( SMSG_GOSSIP_MESSAGE, (100) ); // guess size
128 data << uint64(npcGUID);
129 data << uint32(0); // new 2.4.0
130 data << uint32( TitleTextId );
131 data << uint32( mGossipMenu.MenuItemCount() ); // max count 0x0F
133 for ( unsigned int iI = 0; iI < mGossipMenu.MenuItemCount(); iI++ )
135 GossipMenuItem const& gItem = mGossipMenu.GetItem(iI);
136 data << uint32( iI );
137 data << uint8( gItem.m_gIcon );
138 data << uint8( gItem.m_gCoded ); // makes pop up box password
139 data << uint32(gItem.m_gBoxMoney); // money required to open menu, 2.0.3
140 data << gItem.m_gMessage; // text for gossip item
141 data << gItem.m_gBoxMessage; // accept text (related to money) pop up box, 2.0.3
144 data << uint32( mQuestMenu.MenuItemCount() ); // max count 0x20
146 for ( uint16 iI = 0; iI < mQuestMenu.MenuItemCount(); iI++ )
148 QuestMenuItem const& qItem = mQuestMenu.GetItem(iI);
149 uint32 questID = qItem.m_qId;
150 Quest const* pQuest = objmgr.GetQuestTemplate(questID);
152 data << uint32(questID);
153 data << uint32( qItem.m_qIcon );
154 data << uint32(pQuest && pQuest->GetQuestLevel() ? pQuest->GetQuestLevel() : pSession->GetPlayer()->getLevel());
155 std::string Title = pQuest->GetTitle();
157 int loc_idx = pSession->GetSessionDbLocaleIndex();
158 if (loc_idx >= 0)
160 QuestLocale const *ql = objmgr.GetQuestLocale(questID);
161 if (ql)
163 if (ql->Title.size() > loc_idx && !ql->Title[loc_idx].empty())
164 Title=ql->Title[loc_idx];
167 data << Title;
170 pSession->SendPacket( &data );
171 //sLog.outDebug( "WORLD: Sent SMSG_GOSSIP_MESSAGE NPCGuid=%u",GUID_LOPART(npcGUID) );
174 void PlayerMenu::CloseGossip()
176 WorldPacket data( SMSG_GOSSIP_COMPLETE, 0 );
177 pSession->SendPacket( &data );
179 //sLog.outDebug( "WORLD: Sent SMSG_GOSSIP_COMPLETE" );
182 // Outdated
183 void PlayerMenu::SendPointOfInterest( float X, float Y, uint32 Icon, uint32 Flags, uint32 Data, char const * locName )
185 WorldPacket data( SMSG_GOSSIP_POI, (4+4+4+4+4+10) ); // guess size
186 data << Flags;
187 data << X << Y;
188 data << uint32(Icon);
189 data << uint32(Data);
190 data << locName;
192 pSession->SendPacket( &data );
193 //sLog.outDebug("WORLD: Sent SMSG_GOSSIP_POI");
196 void PlayerMenu::SendPointOfInterest( uint32 poi_id )
198 PointOfInterest const* poi = objmgr.GetPointOfInterest(poi_id);
199 if(!poi)
201 sLog.outErrorDb("Requested send not existed POI (Id: %u), ignore.");
202 return;
205 std::string icon_name = poi->icon_name;
207 int loc_idx = pSession->GetSessionDbLocaleIndex();
208 if (loc_idx >= 0)
210 PointOfInterestLocale const *pl = objmgr.GetPointOfInterestLocale(poi_id);
211 if (pl)
213 if (pl->IconName.size() > size_t(loc_idx) && !pl->IconName[loc_idx].empty())
214 icon_name = pl->IconName[loc_idx];
218 WorldPacket data( SMSG_GOSSIP_POI, (4+4+4+4+4+10) ); // guess size
219 data << uint32(poi->flags);
220 data << float(poi->x);
221 data << float(poi->y);
222 data << uint32(poi->icon);
223 data << uint32(poi->data);
224 data << icon_name;
226 pSession->SendPacket( &data );
227 //sLog.outDebug("WORLD: Sent SMSG_GOSSIP_POI");
230 void PlayerMenu::SendTalking( uint32 textID )
232 GossipText const* pGossip = objmgr.GetGossipText(textID);
234 WorldPacket data( SMSG_NPC_TEXT_UPDATE, 100 ); // guess size
235 data << textID; // can be < 0
237 if (!pGossip)
239 for(uint32 i = 0; i < 8; ++i)
241 data << float(0);
242 data << "Greetings $N";
243 data << "Greetings $N";
244 data << uint32(0);
245 data << uint32(0);
246 data << uint32(0);
247 data << uint32(0);
248 data << uint32(0);
249 data << uint32(0);
250 data << uint32(0);
253 else
255 std::string Text_0[8],Text_1[8];
256 for (int i=0;i<8;i++)
258 Text_0[i]=pGossip->Options[i].Text_0;
259 Text_1[i]=pGossip->Options[i].Text_1;
261 int loc_idx = pSession->GetSessionDbLocaleIndex();
262 if (loc_idx >= 0)
264 NpcTextLocale const *nl = objmgr.GetNpcTextLocale(textID);
265 if (nl)
267 for (int i=0;i<8;i++)
269 if (nl->Text_0[i].size() > loc_idx && !nl->Text_0[i][loc_idx].empty())
270 Text_0[i]=nl->Text_0[i][loc_idx];
271 if (nl->Text_1[i].size() > loc_idx && !nl->Text_1[i][loc_idx].empty())
272 Text_1[i]=nl->Text_1[i][loc_idx];
276 for (int i=0; i<8; i++)
278 data << pGossip->Options[i].Probability;
280 if ( Text_0[i].empty() )
281 data << Text_1[i];
282 else
283 data << Text_0[i];
285 if ( Text_1[i].empty() )
286 data << Text_0[i];
287 else
288 data << Text_1[i];
290 data << pGossip->Options[i].Language;
292 for(int j = 0; j < 3; ++j)
294 data << pGossip->Options[i].Emotes[j]._Delay;
295 data << pGossip->Options[i].Emotes[j]._Emote;
299 pSession->SendPacket( &data );
301 sLog.outDebug( "WORLD: Sent SMSG_NPC_TEXT_UPDATE " );
304 void PlayerMenu::SendTalking( char const * title, char const * text )
306 WorldPacket data( SMSG_NPC_TEXT_UPDATE, 50 ); // guess size
307 data << uint32(0);
308 for(uint32 i = 0; i < 8; ++i)
310 data << float(0);
311 data << title;
312 data << text;
313 data << uint32(0);
314 data << uint32(0);
315 data << uint32(0);
316 data << uint32(0);
317 data << uint32(0);
318 data << uint32(0);
319 data << uint32(0);
322 pSession->SendPacket( &data );
324 sLog.outDebug( "WORLD: Sent SMSG_NPC_TEXT_UPDATE " );
327 /*********************************************************/
328 /*** QUEST SYSTEM ***/
329 /*********************************************************/
331 QuestMenu::QuestMenu()
333 m_qItems.reserve(16); // can be set for max from most often sizes to speedup push_back and less memory use
336 QuestMenu::~QuestMenu()
338 ClearMenu();
341 void QuestMenu::AddMenuItem( uint32 QuestId, uint8 Icon)
343 Quest const* qinfo = objmgr.GetQuestTemplate(QuestId);
344 if (!qinfo) return;
346 ASSERT( m_qItems.size() <= GOSSIP_MAX_MENU_ITEMS );
348 QuestMenuItem qItem;
350 qItem.m_qId = QuestId;
351 qItem.m_qIcon = Icon;
353 m_qItems.push_back(qItem);
356 bool QuestMenu::HasItem( uint32 questid )
358 for (QuestMenuItemList::iterator i = m_qItems.begin(); i != m_qItems.end(); ++i)
360 if(i->m_qId==questid)
362 return true;
365 return false;
368 void QuestMenu::ClearMenu()
370 m_qItems.clear();
373 void PlayerMenu::SendQuestGiverQuestList( QEmote eEmote, const std::string& Title, uint64 npcGUID )
375 WorldPacket data( SMSG_QUESTGIVER_QUEST_LIST, 100 ); // guess size
376 data << uint64(npcGUID);
377 data << Title;
378 data << uint32(eEmote._Delay ); // player emote
379 data << uint32(eEmote._Emote ); // NPC emote
380 data << uint8 ( mQuestMenu.MenuItemCount() );
382 for ( uint16 iI = 0; iI < mQuestMenu.MenuItemCount(); iI++ )
384 QuestMenuItem const& qmi = mQuestMenu.GetItem(iI);
386 uint32 questID = qmi.m_qId;
387 Quest const *pQuest = objmgr.GetQuestTemplate(questID);
389 std::string title = pQuest ? pQuest->GetTitle() : "";
391 int loc_idx = pSession->GetSessionDbLocaleIndex();
392 if (loc_idx >= 0)
394 if(QuestLocale const *ql = objmgr.GetQuestLocale(questID))
396 if (ql->Title.size() > loc_idx && !ql->Title[loc_idx].empty())
397 title=ql->Title[loc_idx];
401 data << uint32(questID);
402 data << uint32(qmi.m_qIcon);
403 data << uint32(pQuest && pQuest->GetQuestLevel() ? pQuest->GetQuestLevel() : pSession->GetPlayer()->getLevel());
404 data << title;
406 pSession->SendPacket( &data );
407 sLog.outDebug("WORLD: Sent SMSG_QUESTGIVER_QUEST_LIST NPC Guid=%u", GUID_LOPART(npcGUID));
410 void PlayerMenu::SendQuestGiverStatus( uint8 questStatus, uint64 npcGUID )
412 WorldPacket data( SMSG_QUESTGIVER_STATUS, 9 );
413 data << uint64(npcGUID);
414 data << uint8(questStatus);
416 pSession->SendPacket( &data );
417 sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_STATUS NPC Guid=%u, status=%u", GUID_LOPART(npcGUID), questStatus);
420 void PlayerMenu::SendQuestGiverQuestDetails( Quest const *pQuest, uint64 npcGUID, bool ActivateAccept )
422 WorldPacket data(SMSG_QUESTGIVER_QUEST_DETAILS, 100); // guess size
424 std::string Title = pQuest->GetTitle();
425 std::string Details = pQuest->GetDetails();
426 std::string Objectives = pQuest->GetObjectives();
427 std::string EndText = pQuest->GetEndText();
429 int loc_idx = pSession->GetSessionDbLocaleIndex();
430 if (loc_idx >= 0)
432 QuestLocale const *ql = objmgr.GetQuestLocale(pQuest->GetQuestId());
433 if (ql)
435 if (ql->Title.size() > loc_idx && !ql->Title[loc_idx].empty())
436 Title=ql->Title[loc_idx];
437 if (ql->Details.size() > loc_idx && !ql->Details[loc_idx].empty())
438 Details=ql->Details[loc_idx];
439 if (ql->Objectives.size() > loc_idx && !ql->Objectives[loc_idx].empty())
440 Objectives=ql->Objectives[loc_idx];
441 if (ql->EndText.size() > loc_idx && !ql->EndText[loc_idx].empty())
442 EndText=ql->EndText[loc_idx];
446 data << uint64(npcGUID);
447 data << uint64(0); // wotlk, something todo with quest sharing?
448 data << uint32(pQuest->GetQuestId());
449 data << Title;
450 data << Details;
451 data << Objectives;
452 data << uint32(ActivateAccept);
453 data << uint32(pQuest->GetSuggestedPlayers());
454 data << uint8(0); // new wotlk
456 if (pQuest->HasFlag(QUEST_FLAGS_HIDDEN_REWARDS))
458 data << uint32(0); // Rewarded chosen items hidden
459 data << uint32(0); // Rewarded items hidden
460 data << uint32(0); // Rewarded money hidden
462 else
464 ItemPrototype const* IProto;
466 data << uint32(pQuest->GetRewChoiceItemsCount());
467 for (uint32 i=0; i < QUEST_REWARD_CHOICES_COUNT; i++)
469 if ( !pQuest->RewChoiceItemId[i] ) continue;
470 data << uint32(pQuest->RewChoiceItemId[i]);
471 data << uint32(pQuest->RewChoiceItemCount[i]);
472 IProto = objmgr.GetItemPrototype(pQuest->RewChoiceItemId[i]);
473 if ( IProto )
474 data << uint32(IProto->DisplayInfoID);
475 else
476 data << uint32( 0x00 );
479 data << uint32(pQuest->GetRewItemsCount());
480 for (uint32 i=0; i < QUEST_REWARDS_COUNT; i++)
482 if ( !pQuest->RewItemId[i] ) continue;
483 data << uint32(pQuest->RewItemId[i]);
484 data << uint32(pQuest->RewItemCount[i]);
485 IProto = objmgr.GetItemPrototype(pQuest->RewItemId[i]);
486 if ( IProto )
487 data << uint32(IProto->DisplayInfoID);
488 else
489 data << uint32(0);
492 data << uint32(pQuest->GetRewOrReqMoney());
495 // rewarded honor points. Multiply with 10 to satisfy client
496 data << uint32(10*MaNGOS::Honor::hk_honor_at_level(pSession->GetPlayer()->getLevel(), pQuest->GetRewHonorableKills()));
497 data << uint32(pQuest->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0)
498 data << uint32(pQuest->GetRewSpellCast()); // casted spell
499 data << uint32(pQuest->GetCharTitleId()); // CharTitleId, new 2.4.0, player gets this title (id from CharTitles)
500 data << uint32(pQuest->GetBonusTalents()); // bonus talents
502 data << uint32(QUEST_EMOTE_COUNT);
503 for (uint32 i=0; i < QUEST_EMOTE_COUNT; i++)
505 data << uint32(pQuest->DetailsEmote[i]);
506 data << uint32(0); // DetailsEmoteDelay
508 pSession->SendPacket( &data );
510 sLog.outDebug("WORLD: Sent SMSG_QUESTGIVER_QUEST_DETAILS NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId());
513 void PlayerMenu::SendQuestQueryResponse( Quest const *pQuest )
515 std::string Title,Details,Objectives,EndText;
516 std::string ObjectiveText[QUEST_OBJECTIVES_COUNT];
517 Title = pQuest->GetTitle();
518 Details = pQuest->GetDetails();
519 Objectives = pQuest->GetObjectives();
520 EndText = pQuest->GetEndText();
521 for (int i=0;i<QUEST_OBJECTIVES_COUNT;i++)
522 ObjectiveText[i]=pQuest->ObjectiveText[i];
524 int loc_idx = pSession->GetSessionDbLocaleIndex();
525 if (loc_idx >= 0)
527 QuestLocale const *ql = objmgr.GetQuestLocale(pQuest->GetQuestId());
528 if (ql)
530 if (ql->Title.size() > loc_idx && !ql->Title[loc_idx].empty())
531 Title=ql->Title[loc_idx];
532 if (ql->Details.size() > loc_idx && !ql->Details[loc_idx].empty())
533 Details=ql->Details[loc_idx];
534 if (ql->Objectives.size() > loc_idx && !ql->Objectives[loc_idx].empty())
535 Objectives=ql->Objectives[loc_idx];
536 if (ql->EndText.size() > loc_idx && !ql->EndText[loc_idx].empty())
537 EndText=ql->EndText[loc_idx];
539 for (int i=0;i<QUEST_OBJECTIVES_COUNT;i++)
540 if (ql->ObjectiveText[i].size() > loc_idx && !ql->ObjectiveText[i][loc_idx].empty())
541 ObjectiveText[i]=ql->ObjectiveText[i][loc_idx];
545 WorldPacket data( SMSG_QUEST_QUERY_RESPONSE, 100 ); // guess size
547 data << uint32(pQuest->GetQuestId());
548 data << uint32(pQuest->GetQuestMethod()); // Accepted values: 0, 1 or 2. 0==IsAutoComplete() (skip objectives/details)
549 data << uint32(pQuest->GetQuestLevel()); // may be 0
550 data << uint32(pQuest->GetZoneOrSort()); // zone or sort to display in quest log
552 data << uint32(pQuest->GetType());
553 data << uint32(pQuest->GetSuggestedPlayers());
555 data << uint32(pQuest->GetRepObjectiveFaction()); // shown in quest log as part of quest objective
556 data << uint32(pQuest->GetRepObjectiveValue()); // shown in quest log as part of quest objective
558 data << uint32(0); // RequiredOpositeRepFaction
559 data << uint32(0); // RequiredOpositeRepValue, required faction value with another (oposite) faction (objective)
561 data << uint32(pQuest->GetNextQuestInChain()); // client will request this quest from NPC, if not 0
563 if (pQuest->HasFlag(QUEST_FLAGS_HIDDEN_REWARDS))
564 data << uint32(0); // Hide money rewarded
565 else
566 data << uint32(pQuest->GetRewOrReqMoney());
568 data << uint32(pQuest->GetRewMoneyMaxLevel()); // used in XP calculation at client
569 data << uint32(pQuest->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0)
570 data << uint32(pQuest->GetRewSpellCast()); // casted spell
572 // rewarded honor points
573 data << uint32(MaNGOS::Honor::hk_honor_at_level(pSession->GetPlayer()->getLevel(), pQuest->GetRewHonorableKills()));
574 data << uint32(pQuest->GetSrcItemId());
575 data << uint32(pQuest->GetFlags() & 0xFFFF);
576 data << uint32(pQuest->GetCharTitleId()); // CharTitleId, new 2.4.0, player gets this title (id from CharTitles)
577 data << uint32(pQuest->GetPlayersSlain()); // players slain
578 data << uint32(pQuest->GetBonusTalents()); // bonus talents
580 int iI;
582 if (pQuest->HasFlag(QUEST_FLAGS_HIDDEN_REWARDS))
584 for (iI = 0; iI < QUEST_REWARDS_COUNT; iI++)
585 data << uint32(0) << uint32(0);
586 for (iI = 0; iI < QUEST_REWARD_CHOICES_COUNT; iI++)
587 data << uint32(0) << uint32(0);
589 else
591 for (iI = 0; iI < QUEST_REWARDS_COUNT; iI++)
593 data << uint32(pQuest->RewItemId[iI]);
594 data << uint32(pQuest->RewItemCount[iI]);
596 for (iI = 0; iI < QUEST_REWARD_CHOICES_COUNT; iI++)
598 data << uint32(pQuest->RewChoiceItemId[iI]);
599 data << uint32(pQuest->RewChoiceItemCount[iI]);
603 data << pQuest->GetPointMapId();
604 data << pQuest->GetPointX();
605 data << pQuest->GetPointY();
606 data << pQuest->GetPointOpt();
608 data << Title;
609 data << Objectives;
610 data << Details;
611 data << EndText;
613 for (iI = 0; iI < QUEST_OBJECTIVES_COUNT; iI++)
615 if (pQuest->ReqCreatureOrGOId[iI] < 0)
617 // client expected gameobject template id in form (id|0x80000000)
618 data << uint32((pQuest->ReqCreatureOrGOId[iI]*(-1))|0x80000000);
620 else
622 data << uint32(pQuest->ReqCreatureOrGOId[iI]);
624 data << uint32(pQuest->ReqCreatureOrGOCount[iI]);
625 data << uint32(0); // added in WotLK, dunno if offset if correct
628 for (iI = 0; iI < QUEST_OBJECTIVES_COUNT; ++iI)
630 data << uint32(pQuest->ReqItemId[iI]);
631 data << uint32(pQuest->ReqItemCount[iI]);
634 data << uint32(0); // TODO: 5 item objective
635 data << uint32(0);
637 for (iI = 0; iI < QUEST_OBJECTIVES_COUNT; iI++)
638 data << ObjectiveText[iI];
640 pSession->SendPacket( &data );
641 sLog.outDebug( "WORLD: Sent SMSG_QUEST_QUERY_RESPONSE questid=%u", pQuest->GetQuestId() );
644 void PlayerMenu::SendQuestGiverOfferReward( Quest const* pQuest, uint64 npcGUID, bool EnbleNext )
646 std::string Title = pQuest->GetTitle();
647 std::string OfferRewardText = pQuest->GetOfferRewardText();
649 int loc_idx = pSession->GetSessionDbLocaleIndex();
650 if (loc_idx >= 0)
652 QuestLocale const *ql = objmgr.GetQuestLocale(pQuest->GetQuestId());
653 if (ql)
655 if (ql->Title.size() > loc_idx && !ql->Title[loc_idx].empty())
656 Title=ql->Title[loc_idx];
657 if (ql->OfferRewardText.size() > loc_idx && !ql->OfferRewardText[loc_idx].empty())
658 OfferRewardText=ql->OfferRewardText[loc_idx];
662 WorldPacket data( SMSG_QUESTGIVER_OFFER_REWARD, 50 ); // guess size
664 data << npcGUID;
665 data << pQuest->GetQuestId();
666 data << Title;
667 data << OfferRewardText;
669 data << uint32( EnbleNext );
670 data << uint32(0); // unk
672 uint32 EmoteCount = 0;
673 for (uint32 i = 0; i < QUEST_EMOTE_COUNT; i++)
675 if(pQuest->OfferRewardEmote[i] <= 0)
676 break;
677 ++EmoteCount;
680 data << EmoteCount; // Emote Count
681 for (uint32 i = 0; i < EmoteCount; i++)
683 data << uint32(0); // Delay Emote
684 data << pQuest->OfferRewardEmote[i];
687 ItemPrototype const *pItem;
689 data << uint32(pQuest->GetRewChoiceItemsCount());
690 for (uint32 i=0; i < pQuest->GetRewChoiceItemsCount(); i++)
692 pItem = objmgr.GetItemPrototype( pQuest->RewChoiceItemId[i] );
694 data << uint32(pQuest->RewChoiceItemId[i]);
695 data << uint32(pQuest->RewChoiceItemCount[i]);
697 if ( pItem )
698 data << uint32(pItem->DisplayInfoID);
699 else
700 data << uint32(0);
703 data << uint32(pQuest->GetRewItemsCount());
704 for (uint16 i=0; i < pQuest->GetRewItemsCount(); i++)
706 pItem = objmgr.GetItemPrototype(pQuest->RewItemId[i]);
707 data << uint32(pQuest->RewItemId[i]);
708 data << uint32(pQuest->RewItemCount[i]);
710 if ( pItem )
711 data << uint32(pItem->DisplayInfoID);
712 else
713 data << uint32(0);
716 data << uint32(pQuest->GetRewOrReqMoney());
718 // rewarded honor points. Multiply with 10 to satisfy client
719 data << uint32(10*MaNGOS::Honor::hk_honor_at_level(pSession->GetPlayer()->getLevel(), pQuest->GetRewHonorableKills()));
720 data << uint32(0x08); // unused by client?
721 data << uint32(pQuest->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0)
722 data << uint32(pQuest->GetRewSpellCast()); // casted spell
723 data << uint32(0); // unknown
724 data << uint32(pQuest->GetBonusTalents()); // bonus talents
725 pSession->SendPacket( &data );
726 sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_OFFER_REWARD NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId() );
729 void PlayerMenu::SendQuestGiverRequestItems( Quest const *pQuest, uint64 npcGUID, bool Completable, bool CloseOnCancel )
731 // We can always call to RequestItems, but this packet only goes out if there are actually
732 // items. Otherwise, we'll skip straight to the OfferReward
734 std::string Title = pQuest->GetTitle();
735 std::string RequestItemsText = pQuest->GetRequestItemsText();
737 int loc_idx = pSession->GetSessionDbLocaleIndex();
738 if (loc_idx >= 0)
740 QuestLocale const *ql = objmgr.GetQuestLocale(pQuest->GetQuestId());
741 if (ql)
743 if (ql->Title.size() > loc_idx && !ql->Title[loc_idx].empty())
744 Title=ql->Title[loc_idx];
745 if (ql->RequestItemsText.size() > loc_idx && !ql->RequestItemsText[loc_idx].empty())
746 RequestItemsText=ql->RequestItemsText[loc_idx];
750 // We may wish a better check, perhaps checking the real quest requirements
751 if (RequestItemsText.empty())
753 SendQuestGiverOfferReward(pQuest, npcGUID, true);
754 return;
757 WorldPacket data( SMSG_QUESTGIVER_REQUEST_ITEMS, 50 ); // guess size
758 data << npcGUID;
759 data << pQuest->GetQuestId();
760 data << Title;
761 data << RequestItemsText;
763 data << uint32(0x00); // unknown
765 if(Completable)
766 data << pQuest->GetCompleteEmote();
767 else
768 data << pQuest->GetIncompleteEmote();
770 // Close Window after cancel
771 if (CloseOnCancel)
772 data << uint32(0x01);
773 else
774 data << uint32(0x00);
776 data << uint32(0x00); // unknown
778 // Required Money
779 data << uint32(pQuest->GetRewOrReqMoney() < 0 ? -pQuest->GetRewOrReqMoney() : 0);
781 data << uint32( pQuest->GetReqItemsCount() );
782 ItemPrototype const *pItem;
783 for (int i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
785 if ( !pQuest->ReqItemId[i] ) continue;
786 pItem = objmgr.GetItemPrototype(pQuest->ReqItemId[i]);
787 data << uint32(pQuest->ReqItemId[i]);
788 data << uint32(pQuest->ReqItemCount[i]);
790 if ( pItem )
791 data << uint32(pItem->DisplayInfoID);
792 else
793 data << uint32(0);
796 if ( !Completable )
797 data << uint32(0x00);
798 else
799 data << uint32(0x03);
801 data << uint32(0x04);
802 data << uint32(0x08);
803 data << uint32(0x10);
805 pSession->SendPacket( &data );
806 sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_REQUEST_ITEMS NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId() );