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