[7123] Cleanup in using STD's containers erase method.
[getmangos.git] / src / game / GossipDef.cpp
blob8a8dcb7364ac4393e8737d96b254a2d7d37c48a0
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() : 0 );
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 void PlayerMenu::SendPointOfInterest( float X, float Y, uint32 Icon, uint32 Flags, uint32 Data, char const * locName )
184 WorldPacket data( SMSG_GOSSIP_POI, (4+4+4+4+4+10) ); // guess size
185 data << Flags;
186 data << X << Y;
187 data << uint32(Icon);
188 data << uint32(Data);
189 data << locName;
191 pSession->SendPacket( &data );
192 //sLog.outDebug("WORLD: Sent SMSG_GOSSIP_POI");
195 void PlayerMenu::SendTalking( uint32 textID )
197 GossipText *pGossip;
198 std::string GossipStr;
200 pGossip = objmgr.GetGossipText(textID);
202 WorldPacket data( SMSG_NPC_TEXT_UPDATE, 100 ); // guess size
203 data << textID; // can be < 0
205 if (!pGossip)
207 for(uint32 i = 0; i < 8; ++i)
209 data << float(0);
210 data << "Greetings $N";
211 data << "Greetings $N";
212 data << uint32(0);
213 data << uint32(0);
214 data << uint32(0);
215 data << uint32(0);
216 data << uint32(0);
217 data << uint32(0);
218 data << uint32(0);
221 else
223 std::string Text_0[8],Text_1[8];
224 for (int i=0;i<8;i++)
226 Text_0[i]=pGossip->Options[i].Text_0;
227 Text_1[i]=pGossip->Options[i].Text_1;
229 int loc_idx = pSession->GetSessionDbLocaleIndex();
230 if (loc_idx >= 0)
232 NpcTextLocale const *nl = objmgr.GetNpcTextLocale(textID);
233 if (nl)
235 for (int i=0;i<8;i++)
237 if (nl->Text_0[i].size() > loc_idx && !nl->Text_0[i][loc_idx].empty())
238 Text_0[i]=nl->Text_0[i][loc_idx];
239 if (nl->Text_1[i].size() > loc_idx && !nl->Text_1[i][loc_idx].empty())
240 Text_1[i]=nl->Text_1[i][loc_idx];
244 for (int i=0; i<8; i++)
246 data << pGossip->Options[i].Probability;
248 if ( Text_0[i].empty() )
249 data << Text_1[i];
250 else
251 data << Text_0[i];
253 if ( Text_1[i].empty() )
254 data << Text_0[i];
255 else
256 data << Text_1[i];
258 data << pGossip->Options[i].Language;
260 data << pGossip->Options[i].Emotes[0]._Delay;
261 data << pGossip->Options[i].Emotes[0]._Emote;
263 data << pGossip->Options[i].Emotes[1]._Delay;
264 data << pGossip->Options[i].Emotes[1]._Emote;
266 data << pGossip->Options[i].Emotes[2]._Delay;
267 data << pGossip->Options[i].Emotes[2]._Emote;
270 pSession->SendPacket( &data );
272 sLog.outDebug( "WORLD: Sent SMSG_NPC_TEXT_UPDATE " );
275 void PlayerMenu::SendTalking( char const * title, char const * text )
277 WorldPacket data( SMSG_NPC_TEXT_UPDATE, 50 ); // guess size
278 data << uint32(0);
279 for(uint32 i = 0; i < 8; ++i)
281 data << float(0);
282 data << title;
283 data << text;
284 data << uint32(0);
285 data << uint32(0);
286 data << uint32(0);
287 data << uint32(0);
288 data << uint32(0);
289 data << uint32(0);
290 data << uint32(0);
293 pSession->SendPacket( &data );
295 sLog.outDebug( "WORLD: Sent SMSG_NPC_TEXT_UPDATE " );
298 /*********************************************************/
299 /*** QUEST SYSTEM ***/
300 /*********************************************************/
302 QuestMenu::QuestMenu()
304 m_qItems.reserve(16); // can be set for max from most often sizes to speedup push_back and less memory use
307 QuestMenu::~QuestMenu()
309 ClearMenu();
312 void QuestMenu::AddMenuItem( uint32 QuestId, uint8 Icon)
314 Quest const* qinfo = objmgr.GetQuestTemplate(QuestId);
315 if (!qinfo) return;
317 ASSERT( m_qItems.size() <= GOSSIP_MAX_MENU_ITEMS );
319 QuestMenuItem qItem;
321 qItem.m_qId = QuestId;
322 qItem.m_qIcon = Icon;
324 m_qItems.push_back(qItem);
327 bool QuestMenu::HasItem( uint32 questid )
329 for (QuestMenuItemList::iterator i = m_qItems.begin(); i != m_qItems.end(); ++i)
331 if(i->m_qId==questid)
333 return true;
336 return false;
339 void QuestMenu::ClearMenu()
341 m_qItems.clear();
344 void PlayerMenu::SendQuestGiverQuestList( QEmote eEmote, const std::string& Title, uint64 npcGUID )
346 WorldPacket data( SMSG_QUESTGIVER_QUEST_LIST, 100 ); // guess size
347 data << uint64(npcGUID);
348 data << Title;
349 data << uint32(eEmote._Delay ); // player emote
350 data << uint32(eEmote._Emote ); // NPC emote
351 data << uint8 ( mQuestMenu.MenuItemCount() );
353 for ( uint16 iI = 0; iI < mQuestMenu.MenuItemCount(); iI++ )
355 QuestMenuItem const& qmi = mQuestMenu.GetItem(iI);
357 uint32 questID = qmi.m_qId;
358 Quest const *pQuest = objmgr.GetQuestTemplate(questID);
360 std::string title = pQuest ? pQuest->GetTitle() : "";
362 int loc_idx = pSession->GetSessionDbLocaleIndex();
363 if (loc_idx >= 0)
365 if(QuestLocale const *ql = objmgr.GetQuestLocale(questID))
367 if (ql->Title.size() > loc_idx && !ql->Title[loc_idx].empty())
368 title=ql->Title[loc_idx];
372 data << uint32(questID);
373 data << uint32(qmi.m_qIcon);
374 data << uint32(pQuest ? pQuest->GetQuestLevel() : 0);
375 data << title;
377 pSession->SendPacket( &data );
378 sLog.outDebug("WORLD: Sent SMSG_QUESTGIVER_QUEST_LIST NPC Guid=%u", GUID_LOPART(npcGUID));
381 void PlayerMenu::SendQuestGiverStatus( uint8 questStatus, uint64 npcGUID )
383 WorldPacket data( SMSG_QUESTGIVER_STATUS, 9 );
384 data << uint64(npcGUID);
385 data << uint8(questStatus);
387 pSession->SendPacket( &data );
388 sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_STATUS NPC Guid=%u, status=%u", GUID_LOPART(npcGUID), questStatus);
391 void PlayerMenu::SendQuestGiverQuestDetails( Quest const *pQuest, uint64 npcGUID, bool ActivateAccept )
393 WorldPacket data(SMSG_QUESTGIVER_QUEST_DETAILS, 100); // guess size
395 std::string Title = pQuest->GetTitle();
396 std::string Details = pQuest->GetDetails();
397 std::string Objectives = pQuest->GetObjectives();
398 std::string EndText = pQuest->GetEndText();
400 int loc_idx = pSession->GetSessionDbLocaleIndex();
401 if (loc_idx >= 0)
403 QuestLocale const *ql = objmgr.GetQuestLocale(pQuest->GetQuestId());
404 if (ql)
406 if (ql->Title.size() > loc_idx && !ql->Title[loc_idx].empty())
407 Title=ql->Title[loc_idx];
408 if (ql->Details.size() > loc_idx && !ql->Details[loc_idx].empty())
409 Details=ql->Details[loc_idx];
410 if (ql->Objectives.size() > loc_idx && !ql->Objectives[loc_idx].empty())
411 Objectives=ql->Objectives[loc_idx];
412 if (ql->EndText.size() > loc_idx && !ql->EndText[loc_idx].empty())
413 EndText=ql->EndText[loc_idx];
417 data << uint64(npcGUID);
418 data << uint64(0); // wotlk, something todo with quest sharing?
419 data << uint32(pQuest->GetQuestId());
420 data << Title;
421 data << Details;
422 data << Objectives;
423 data << uint32(ActivateAccept);
424 data << uint32(pQuest->GetSuggestedPlayers());
425 data << uint8(0); // new wotlk
427 if (pQuest->HasFlag(QUEST_FLAGS_HIDDEN_REWARDS))
429 data << uint32(0); // Rewarded chosen items hidden
430 data << uint32(0); // Rewarded items hidden
431 data << uint32(0); // Rewarded money hidden
433 else
435 ItemPrototype const* IProto;
437 data << uint32(pQuest->GetRewChoiceItemsCount());
438 for (uint32 i=0; i < QUEST_REWARD_CHOICES_COUNT; i++)
440 if ( !pQuest->RewChoiceItemId[i] ) continue;
441 data << uint32(pQuest->RewChoiceItemId[i]);
442 data << uint32(pQuest->RewChoiceItemCount[i]);
443 IProto = objmgr.GetItemPrototype(pQuest->RewChoiceItemId[i]);
444 if ( IProto )
445 data << uint32(IProto->DisplayInfoID);
446 else
447 data << uint32( 0x00 );
450 data << uint32(pQuest->GetRewItemsCount());
451 for (uint32 i=0; i < QUEST_REWARDS_COUNT; i++)
453 if ( !pQuest->RewItemId[i] ) continue;
454 data << uint32(pQuest->RewItemId[i]);
455 data << uint32(pQuest->RewItemCount[i]);
456 IProto = objmgr.GetItemPrototype(pQuest->RewItemId[i]);
457 if ( IProto )
458 data << uint32(IProto->DisplayInfoID);
459 else
460 data << uint32(0);
463 data << uint32(pQuest->GetRewOrReqMoney());
466 // rewarded honor points. Multiply with 10 to satisfy client
467 data << uint32(10*MaNGOS::Honor::hk_honor_at_level(pSession->GetPlayer()->getLevel(), pQuest->GetRewHonorableKills()));
468 data << uint32(pQuest->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0)
469 data << uint32(pQuest->GetRewSpellCast()); // casted spell
470 data << uint32(pQuest->GetCharTitleId()); // CharTitleId, new 2.4.0, player gets this title (id from CharTitles)
471 data << uint32(pQuest->GetBonusTalents()); // bonus talents
473 data << uint32(QUEST_EMOTE_COUNT);
474 for (uint32 i=0; i < QUEST_EMOTE_COUNT; i++)
476 data << uint32(pQuest->DetailsEmote[i]);
477 data << uint32(0); // DetailsEmoteDelay
479 pSession->SendPacket( &data );
481 sLog.outDebug("WORLD: Sent SMSG_QUESTGIVER_QUEST_DETAILS NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId());
484 void PlayerMenu::SendQuestQueryResponse( Quest const *pQuest )
486 std::string Title,Details,Objectives,EndText;
487 std::string ObjectiveText[QUEST_OBJECTIVES_COUNT];
488 Title = pQuest->GetTitle();
489 Details = pQuest->GetDetails();
490 Objectives = pQuest->GetObjectives();
491 EndText = pQuest->GetEndText();
492 for (int i=0;i<QUEST_OBJECTIVES_COUNT;i++)
493 ObjectiveText[i]=pQuest->ObjectiveText[i];
495 int loc_idx = pSession->GetSessionDbLocaleIndex();
496 if (loc_idx >= 0)
498 QuestLocale const *ql = objmgr.GetQuestLocale(pQuest->GetQuestId());
499 if (ql)
501 if (ql->Title.size() > loc_idx && !ql->Title[loc_idx].empty())
502 Title=ql->Title[loc_idx];
503 if (ql->Details.size() > loc_idx && !ql->Details[loc_idx].empty())
504 Details=ql->Details[loc_idx];
505 if (ql->Objectives.size() > loc_idx && !ql->Objectives[loc_idx].empty())
506 Objectives=ql->Objectives[loc_idx];
507 if (ql->EndText.size() > loc_idx && !ql->EndText[loc_idx].empty())
508 EndText=ql->EndText[loc_idx];
510 for (int i=0;i<QUEST_OBJECTIVES_COUNT;i++)
511 if (ql->ObjectiveText[i].size() > loc_idx && !ql->ObjectiveText[i][loc_idx].empty())
512 ObjectiveText[i]=ql->ObjectiveText[i][loc_idx];
516 WorldPacket data( SMSG_QUEST_QUERY_RESPONSE, 100 ); // guess size
518 data << uint32(pQuest->GetQuestId());
519 data << uint32(pQuest->GetQuestMethod()); // Accepted values: 0, 1 or 2. 0==IsAutoComplete() (skip objectives/details)
520 data << uint32(pQuest->GetQuestLevel()); // may be 0
521 data << uint32(pQuest->GetZoneOrSort()); // zone or sort to display in quest log
523 data << uint32(pQuest->GetType());
524 data << uint32(pQuest->GetSuggestedPlayers());
526 data << uint32(pQuest->GetRepObjectiveFaction()); // shown in quest log as part of quest objective
527 data << uint32(pQuest->GetRepObjectiveValue()); // shown in quest log as part of quest objective
529 data << uint32(0); // RequiredOpositeRepFaction
530 data << uint32(0); // RequiredOpositeRepValue, required faction value with another (oposite) faction (objective)
532 data << uint32(pQuest->GetNextQuestInChain()); // client will request this quest from NPC, if not 0
534 if (pQuest->HasFlag(QUEST_FLAGS_HIDDEN_REWARDS))
535 data << uint32(0); // Hide money rewarded
536 else
537 data << uint32(pQuest->GetRewOrReqMoney());
539 data << uint32(pQuest->GetRewMoneyMaxLevel()); // used in XP calculation at client
540 data << uint32(pQuest->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0)
541 data << uint32(pQuest->GetRewSpellCast()); // casted spell
543 // rewarded honor points
544 data << uint32(MaNGOS::Honor::hk_honor_at_level(pSession->GetPlayer()->getLevel(), pQuest->GetRewHonorableKills()));
545 data << uint32(pQuest->GetSrcItemId());
546 data << uint32(pQuest->GetFlags() & 0xFFFF);
547 data << uint32(pQuest->GetCharTitleId()); // CharTitleId, new 2.4.0, player gets this title (id from CharTitles)
548 data << uint32(pQuest->GetPlayersSlain()); // players slain
549 data << uint32(pQuest->GetBonusTalents()); // bonus talents
551 int iI;
553 if (pQuest->HasFlag(QUEST_FLAGS_HIDDEN_REWARDS))
555 for (iI = 0; iI < QUEST_REWARDS_COUNT; iI++)
556 data << uint32(0) << uint32(0);
557 for (iI = 0; iI < QUEST_REWARD_CHOICES_COUNT; iI++)
558 data << uint32(0) << uint32(0);
560 else
562 for (iI = 0; iI < QUEST_REWARDS_COUNT; iI++)
564 data << uint32(pQuest->RewItemId[iI]);
565 data << uint32(pQuest->RewItemCount[iI]);
567 for (iI = 0; iI < QUEST_REWARD_CHOICES_COUNT; iI++)
569 data << uint32(pQuest->RewChoiceItemId[iI]);
570 data << uint32(pQuest->RewChoiceItemCount[iI]);
574 data << pQuest->GetPointMapId();
575 data << pQuest->GetPointX();
576 data << pQuest->GetPointY();
577 data << pQuest->GetPointOpt();
579 data << Title;
580 data << Objectives;
581 data << Details;
582 data << EndText;
584 for (iI = 0; iI < QUEST_OBJECTIVES_COUNT; iI++)
586 if (pQuest->ReqCreatureOrGOId[iI] < 0)
588 // client expected gameobject template id in form (id|0x80000000)
589 data << uint32((pQuest->ReqCreatureOrGOId[iI]*(-1))|0x80000000);
591 else
593 data << uint32(pQuest->ReqCreatureOrGOId[iI]);
595 data << uint32(pQuest->ReqCreatureOrGOCount[iI]);
596 data << uint32(pQuest->ReqItemId[iI]);
597 data << uint32(pQuest->ReqItemCount[iI]);
598 data << uint32(0); // added in WotLK, dunno if offset if correct
601 for (iI = 0; iI < QUEST_OBJECTIVES_COUNT; iI++)
602 data << ObjectiveText[iI];
604 pSession->SendPacket( &data );
605 sLog.outDebug( "WORLD: Sent SMSG_QUEST_QUERY_RESPONSE questid=%u", pQuest->GetQuestId() );
608 void PlayerMenu::SendQuestGiverOfferReward( Quest const* pQuest, uint64 npcGUID, bool EnbleNext )
610 std::string Title = pQuest->GetTitle();
611 std::string OfferRewardText = pQuest->GetOfferRewardText();
613 int loc_idx = pSession->GetSessionDbLocaleIndex();
614 if (loc_idx >= 0)
616 QuestLocale const *ql = objmgr.GetQuestLocale(pQuest->GetQuestId());
617 if (ql)
619 if (ql->Title.size() > loc_idx && !ql->Title[loc_idx].empty())
620 Title=ql->Title[loc_idx];
621 if (ql->OfferRewardText.size() > loc_idx && !ql->OfferRewardText[loc_idx].empty())
622 OfferRewardText=ql->OfferRewardText[loc_idx];
626 WorldPacket data( SMSG_QUESTGIVER_OFFER_REWARD, 50 ); // guess size
628 data << npcGUID;
629 data << pQuest->GetQuestId();
630 data << Title;
631 data << OfferRewardText;
633 data << uint32( EnbleNext );
634 data << uint32(0); // unk
636 uint32 EmoteCount = 0;
637 for (uint32 i = 0; i < QUEST_EMOTE_COUNT; i++)
639 if(pQuest->OfferRewardEmote[i] <= 0)
640 break;
641 ++EmoteCount;
644 data << EmoteCount; // Emote Count
645 for (uint32 i = 0; i < EmoteCount; i++)
647 data << uint32(0); // Delay Emote
648 data << pQuest->OfferRewardEmote[i];
651 ItemPrototype const *pItem;
653 data << uint32(pQuest->GetRewChoiceItemsCount());
654 for (uint32 i=0; i < pQuest->GetRewChoiceItemsCount(); i++)
656 pItem = objmgr.GetItemPrototype( pQuest->RewChoiceItemId[i] );
658 data << uint32(pQuest->RewChoiceItemId[i]);
659 data << uint32(pQuest->RewChoiceItemCount[i]);
661 if ( pItem )
662 data << uint32(pItem->DisplayInfoID);
663 else
664 data << uint32(0);
667 data << uint32(pQuest->GetRewItemsCount());
668 for (uint16 i=0; i < pQuest->GetRewItemsCount(); i++)
670 pItem = objmgr.GetItemPrototype(pQuest->RewItemId[i]);
671 data << uint32(pQuest->RewItemId[i]);
672 data << uint32(pQuest->RewItemCount[i]);
674 if ( pItem )
675 data << uint32(pItem->DisplayInfoID);
676 else
677 data << uint32(0);
680 data << uint32(pQuest->GetRewOrReqMoney());
682 // rewarded honor points. Multiply with 10 to satisfy client
683 data << uint32(10*MaNGOS::Honor::hk_honor_at_level(pSession->GetPlayer()->getLevel(), pQuest->GetRewHonorableKills()));
684 data << uint32(0x08); // unused by client?
685 data << uint32(pQuest->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0)
686 data << uint32(pQuest->GetRewSpellCast()); // casted spell
687 data << uint32(0); // unknown
688 data << uint32(pQuest->GetBonusTalents()); // bonus talents
689 pSession->SendPacket( &data );
690 sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_OFFER_REWARD NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId() );
693 void PlayerMenu::SendQuestGiverRequestItems( Quest const *pQuest, uint64 npcGUID, bool Completable, bool CloseOnCancel )
695 // We can always call to RequestItems, but this packet only goes out if there are actually
696 // items. Otherwise, we'll skip straight to the OfferReward
698 // We may wish a better check, perhaps checking the real quest requirements
699 if (pQuest->GetRequestItemsText().empty())
701 SendQuestGiverOfferReward(pQuest, npcGUID, true);
702 return;
705 std::string Title,RequestItemsText;
706 Title = pQuest->GetTitle();
707 RequestItemsText = pQuest->GetRequestItemsText();
709 int loc_idx = pSession->GetSessionDbLocaleIndex();
710 if (loc_idx >= 0)
712 QuestLocale const *ql = objmgr.GetQuestLocale(pQuest->GetQuestId());
713 if (ql)
715 if (ql->Title.size() > loc_idx && !ql->Title[loc_idx].empty())
716 Title=ql->Title[loc_idx];
717 if (ql->RequestItemsText.size() > loc_idx && !ql->RequestItemsText[loc_idx].empty())
718 RequestItemsText=ql->RequestItemsText[loc_idx];
722 WorldPacket data( SMSG_QUESTGIVER_REQUEST_ITEMS, 50 ); // guess size
723 data << npcGUID;
724 data << pQuest->GetQuestId();
725 data << Title;
726 data << RequestItemsText;
728 data << uint32(0x00); // unknown
730 if(Completable)
731 data << pQuest->GetCompleteEmote();
732 else
733 data << pQuest->GetIncompleteEmote();
735 // Close Window after cancel
736 if (CloseOnCancel)
737 data << uint32(0x01);
738 else
739 data << uint32(0x00);
741 data << uint32(0x00); // unknown
743 // Required Money
744 data << uint32(pQuest->GetRewOrReqMoney() < 0 ? -pQuest->GetRewOrReqMoney() : 0);
746 data << uint32( pQuest->GetReqItemsCount() );
747 ItemPrototype const *pItem;
748 for (int i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
750 if ( !pQuest->ReqItemId[i] ) continue;
751 pItem = objmgr.GetItemPrototype(pQuest->ReqItemId[i]);
752 data << uint32(pQuest->ReqItemId[i]);
753 data << uint32(pQuest->ReqItemCount[i]);
755 if ( pItem )
756 data << uint32(pItem->DisplayInfoID);
757 else
758 data << uint32(0);
761 if ( !Completable )
762 data << uint32(0x00);
763 else
764 data << uint32(0x03);
766 data << uint32(0x04);
767 data << uint32(0x08);
768 data << uint32(0x10);
770 pSession->SendPacket( &data );
771 sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_REQUEST_ITEMS NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId() );