2010-10-07 15:35:36 +02:00
/*
2015-01-01 00:27:46 +01:00
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
2010-10-07 15:35:36 +02:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "Common.h"
#include "Log.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "Opcodes.h"
#include "World.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "GossipDef.h"
#include "QuestDef.h"
#include "ObjectAccessor.h"
#include "Group.h"
2010-08-08 04:37:24 +02:00
#include "Battleground.h"
2010-01-19 11:36:05 +01:00
#include "ScriptMgr.h"
2010-10-27 21:01:47 +02:00
#include "GameObjectAI.h"
2014-11-19 00:30:31 +02:00
#include "QuestPackets.h"
2009-10-17 15:51:44 -07:00
2014-11-19 00:30:31 +02:00
void WorldSession :: HandleQuestgiverStatusQueryOpcode ( WorldPackets :: Quest :: QuestGiverStatusQuery & packet )
2008-10-02 16:23:55 -05:00
{
2011-12-22 15:00:06 +00:00
uint32 questStatus = DIALOG_STATUS_NONE ;
2009-10-17 15:51:44 -07:00
2014-11-19 00:30:31 +02:00
Object * questGiver = ObjectAccessor :: GetObjectByTypeMask ( * _player , packet . QuestGiverGUID , TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT );
2014-02-06 21:23:18 +01:00
if ( ! questGiver )
2008-10-02 16:23:55 -05:00
{
2014-11-19 00:30:31 +02:00
TC_LOG_INFO ( "network" , "Error in CMSG_QUESTGIVER_STATUS_QUERY, called for non-existing questgiver (%s)" , packet . QuestGiverGUID . ToString (). c_str ());
2008-10-02 16:23:55 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2014-02-06 21:23:18 +01:00
switch ( questGiver -> GetTypeId ())
2008-10-02 16:23:55 -05:00
{
case TYPEID_UNIT :
{
2014-10-22 22:18:21 +02:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTGIVER_STATUS_QUERY for npc, %s" , questGiver -> GetGUID (). ToString (). c_str ());
2014-02-06 21:23:18 +01:00
if ( ! questGiver -> ToCreature () -> IsHostileTo ( _player )) // do not show quest status to enemies
questStatus = _player -> GetQuestDialogStatus ( questGiver );
2008-10-02 16:23:55 -05:00
break ;
}
case TYPEID_GAMEOBJECT :
{
2014-10-22 22:18:21 +02:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTGIVER_STATUS_QUERY for GameObject %s" , questGiver -> GetGUID (). ToString (). c_str ());
2014-02-06 21:23:18 +01:00
questStatus = _player -> GetQuestDialogStatus ( questGiver );
2008-10-02 16:23:55 -05:00
break ;
}
default :
2014-02-06 21:23:18 +01:00
TC_LOG_ERROR ( "network" , "QuestGiver called for unexpected type %u" , questGiver -> GetTypeId ());
2008-10-02 16:23:55 -05:00
break ;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//inform client about status of quest
2014-11-19 00:30:31 +02:00
_player -> PlayerTalkClass -> SendQuestGiverStatus ( questStatus , packet . QuestGiverGUID );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2014-12-28 22:55:53 +02:00
void WorldSession :: HandleQuestgiverHelloOpcode ( WorldPackets :: Quest :: QuestGiverHello & packet )
2008-10-02 16:23:55 -05:00
{
2014-12-28 22:55:53 +02:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTGIVER_HELLO %s" , packet . QuestGiverGUID . ToString (). c_str ());
2009-10-17 15:51:44 -07:00
2014-12-28 22:55:53 +02:00
Creature * creature = GetPlayer () -> GetNPCIfCanInteractWith ( packet . QuestGiverGUID , UNIT_NPC_FLAG_NONE );
2011-10-07 11:08:09 -05:00
if ( ! creature )
2008-10-02 16:23:55 -05:00
{
2014-09-14 16:14:12 +02:00
TC_LOG_DEBUG ( "network" , "WORLD: HandleQuestgiverHelloOpcode - %s not found or you can't interact with him." ,
2014-12-28 22:55:53 +02:00
packet . QuestGiverGUID . ToString (). c_str ());
2008-10-02 16:23:55 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// remove fake death
2012-02-03 19:12:41 +02:00
if ( GetPlayer () -> HasUnitState ( UNIT_STATE_DIED ))
2009-04-06 13:31:14 +02:00
GetPlayer () -> RemoveAurasByType ( SPELL_AURA_FEIGN_DEATH );
2008-10-02 16:23:55 -05:00
// Stop the npc if moving
2011-10-07 11:08:09 -05:00
creature -> StopMoving ();
2009-10-17 15:51:44 -07:00
2011-10-07 11:08:09 -05:00
if ( sScriptMgr -> OnGossipHello ( _player , creature ))
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
_player -> PrepareGossipMenu ( creature , creature -> GetCreatureTemplate () -> GossipMenuId , true );
2011-10-07 11:08:09 -05:00
_player -> SendPreparedGossip ( creature );
2010-10-25 18:23:45 +02:00
2011-10-07 11:08:09 -05:00
creature -> AI () -> sGossipHello ( _player );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2015-03-14 18:04:25 +01:00
void WorldSession :: HandleQuestgiverAcceptQuestOpcode ( WorldPackets :: Quest :: QuestGiverAcceptQuest & packet )
2008-10-02 16:23:55 -05:00
{
2015-03-14 18:04:25 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTGIVER_ACCEPT_QUEST %s, quest = %u, startcheat = %u" , packet . QuestGiverGUID . ToString (). c_str (), packet . QuestID , packet . StartCheat );
2009-10-17 15:51:44 -07:00
2015-03-14 18:04:25 +01:00
Object * object = ObjectAccessor :: GetObjectByTypeMask ( * _player , packet . QuestGiverGUID , TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT | TYPEMASK_ITEM | TYPEMASK_PLAYER );
2009-10-17 15:51:44 -07:00
2013-07-11 21:45:14 +02:00
#define CLOSE_GOSSIP_CLEAR_DIVIDER() \
do { \
_player->PlayerTalkClass->SendCloseGossip(); \
2014-09-14 16:14:12 +02:00
_player->SetDivider(ObjectGuid::Empty); \
2013-07-11 21:45:14 +02:00
} while (0)
2008-10-02 16:23:55 -05:00
// no or incorrect quest giver
2013-07-11 21:45:14 +02:00
if ( ! object )
2008-10-02 16:23:55 -05:00
{
2013-07-11 21:45:14 +02:00
CLOSE_GOSSIP_CLEAR_DIVIDER ();
2008-10-02 16:23:55 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2013-07-11 21:45:14 +02:00
if ( Player * playerQuestObject = object -> ToPlayer ())
{
2015-03-14 18:04:25 +01:00
if (( ! _player -> GetDivider (). IsEmpty () && _player -> GetDivider () != packet . QuestGiverGUID ) ||
(( object != _player && ! playerQuestObject -> CanShareQuest ( packet . QuestID ))))
2013-07-11 21:45:14 +02:00
{
CLOSE_GOSSIP_CLEAR_DIVIDER ();
return ;
}
}
else
{
2015-03-14 18:04:25 +01:00
if ( ! object -> hasQuest ( packet . QuestID ))
2013-07-11 21:45:14 +02:00
{
CLOSE_GOSSIP_CLEAR_DIVIDER ();
return ;
}
}
2011-05-30 02:59:37 +07:00
// some kind of WPE protection
2012-05-30 08:01:02 +02:00
if ( ! _player -> CanInteractWithQuestGiver ( object ))
2011-05-30 02:59:37 +07:00
return ;
2015-03-14 18:04:25 +01:00
if ( Quest const * quest = sObjectMgr -> GetQuestTemplate ( packet . QuestID ))
2008-10-02 16:23:55 -05:00
{
// prevent cheating
2012-05-30 08:01:02 +02:00
if ( ! GetPlayer () -> CanTakeQuest ( quest , true ))
2008-10-02 16:23:55 -05:00
{
2013-07-11 21:45:14 +02:00
CLOSE_GOSSIP_CLEAR_DIVIDER ();
2008-10-02 16:23:55 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2014-09-14 16:14:12 +02:00
if ( ! _player -> GetDivider (). IsEmpty ())
2008-10-02 16:23:55 -05:00
{
2011-10-07 11:08:09 -05:00
Player * player = ObjectAccessor :: FindPlayer ( _player -> GetDivider ());
if ( player )
2008-10-02 16:23:55 -05:00
{
2011-10-07 11:08:09 -05:00
player -> SendPushToPartyResponse ( _player , QUEST_PARTY_MSG_ACCEPT_QUEST );
2014-09-14 16:14:12 +02:00
_player -> SetDivider ( ObjectGuid :: Empty );
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
if ( _player -> CanAddQuest ( quest , true ))
2008-10-02 16:23:55 -05:00
{
2014-02-06 21:23:18 +01:00
_player -> AddQuestAndCheckCompletion ( quest , object );
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
if ( quest -> HasFlag ( QUEST_FLAGS_PARTY_ACCEPT ))
2009-12-19 18:08:07 +01:00
{
2011-10-07 10:54:53 -05:00
if ( Group * group = _player -> GetGroup ())
2009-12-19 18:08:07 +01:00
{
2011-10-07 10:54:53 -05:00
for ( GroupReference * itr = group -> GetFirstMember (); itr != NULL ; itr = itr -> next ())
2009-12-19 18:08:07 +01:00
{
2013-06-11 21:25:12 -02:30
Player * player = itr -> GetSource ();
2009-12-19 18:08:07 +01:00
2011-10-07 11:08:09 -05:00
if ( ! player || player == _player ) // not self
2009-12-19 18:08:07 +01:00
continue ;
2012-05-30 08:01:02 +02:00
if ( player -> CanTakeQuest ( quest , true ))
2009-12-19 18:08:07 +01:00
{
2011-10-07 11:08:09 -05:00
player -> SetDivider ( _player -> GetGUID ());
2009-12-19 18:08:07 +01:00
2014-02-06 21:23:18 +01:00
// need confirmation that any gossip window will close
2011-10-07 11:08:09 -05:00
player -> PlayerTalkClass -> SendCloseGossip ();
2009-12-19 18:08:07 +01:00
2012-05-30 08:01:02 +02:00
_player -> SendQuestConfirmAccept ( quest , player );
2009-12-19 18:08:07 +01:00
}
}
}
}
2011-05-26 23:57:17 +02:00
_player -> PlayerTalkClass -> SendCloseGossip ();
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
if ( quest -> GetSrcSpell () > 0 )
_player -> CastSpell ( _player , quest -> GetSrcSpell (), true );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return ;
}
}
2009-10-17 15:51:44 -07:00
2011-05-26 23:57:17 +02:00
_player -> PlayerTalkClass -> SendCloseGossip ();
2013-07-11 21:45:14 +02:00
#undef CLOSE_GOSSIP_CLEAR_DIVIDER
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2014-12-29 23:01:50 +02:00
void WorldSession :: HandleQuestgiverQueryQuestOpcode ( WorldPackets :: Quest :: QuestGiverQueryQuest & packet )
2008-10-02 16:23:55 -05:00
{
2014-12-29 23:01:50 +02:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTGIVER_QUERY_QUEST QuestGiverGUID = %s, QuestID = %u, RespondToGiver = %u" , packet . QuestGiverGUID . ToString (). c_str (), packet . QuestID , packet . RespondToGiver );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Verify that the guid is valid and is a questgiver or involved in the requested quest
2014-12-29 23:01:50 +02:00
Object * object = ObjectAccessor :: GetObjectByTypeMask ( * _player , packet . QuestGiverGUID , TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT | TYPEMASK_ITEM );
if ( ! object || ( ! object -> hasQuest ( packet . QuestID ) && ! object -> hasInvolvedQuest ( packet . QuestID )))
2008-10-02 16:23:55 -05:00
{
2011-05-26 23:57:17 +02:00
_player -> PlayerTalkClass -> SendCloseGossip ();
2008-10-02 16:23:55 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2014-12-29 23:01:50 +02:00
if ( Quest const * quest = sObjectMgr -> GetQuestTemplate ( packet . QuestID ))
2008-10-02 16:23:55 -05:00
{
2011-06-28 20:16:15 +02:00
if ( ! _player -> CanTakeQuest ( quest , true ))
return ;
if ( quest -> IsAutoAccept () && _player -> CanAddQuest ( quest , true ))
2013-12-14 19:39:47 +01:00
_player -> AddQuestAndCheckCompletion ( quest , object );
2010-04-25 23:52:33 +02:00
2014-09-13 17:57:42 -05:00
if ( quest -> IsAutoComplete ())
2011-06-28 20:16:15 +02:00
_player -> PlayerTalkClass -> SendQuestGiverRequestItems ( quest , object -> GetGUID (), _player -> CanCompleteQuest ( quest -> GetQuestId ()), true );
2010-04-17 17:59:19 +02:00
else
2011-06-28 20:16:15 +02:00
_player -> PlayerTalkClass -> SendQuestGiverQuestDetails ( quest , object -> GetGUID (), true );
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
2014-12-28 22:55:53 +02:00
void WorldSession :: HandleQuestQueryOpcode ( WorldPackets :: Quest :: QueryQuestInfo & packet )
2008-10-02 16:23:55 -05:00
{
2010-09-03 20:30:29 -07:00
if ( ! _player )
return ;
2014-12-28 22:55:53 +02:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUEST_QUERY quest = %u" , packet . QuestID );
2009-10-17 15:51:44 -07:00
2014-12-28 22:55:53 +02:00
if ( Quest const * quest = sObjectMgr -> GetQuestTemplate ( packet . QuestID ))
2012-05-30 08:01:02 +02:00
_player -> PlayerTalkClass -> SendQuestQueryResponse ( quest );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2014-12-28 22:55:53 +02:00
void WorldSession :: HandleQuestgiverChooseRewardOpcode ( WorldPackets :: Quest :: QuestGiverChooseReward & packet )
2008-10-02 16:23:55 -05:00
{
2014-12-28 22:55:53 +02:00
if ( packet . ItemChoiceID >= QUEST_REWARD_CHOICES_COUNT )
2008-10-02 16:23:55 -05:00
{
2014-12-28 22:55:53 +02:00
TC_LOG_ERROR ( "network" , "Error in CMSG_QUESTGIVER_CHOOSE_REWARD: player %s (%s) tried to get invalid reward (%u) (possible packet-hacking detected)" , _player -> GetName (). c_str (), _player -> GetGUID (). ToString (). c_str (), packet . ItemChoiceID );
2008-10-02 16:23:55 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2014-12-28 22:55:53 +02:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTGIVER_CHOOSE_REWARD npc = %s, quest = %u, reward = %u" , packet . QuestGiverGUID . ToString (). c_str (), packet . QuestID , packet . ItemChoiceID );
2009-10-17 15:51:44 -07:00
2014-12-28 22:55:53 +02:00
Quest const * quest = sObjectMgr -> GetQuestTemplate ( packet . QuestID );
2012-09-13 16:16:33 +01:00
if ( ! quest )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2012-09-13 16:16:33 +01:00
Object * object = _player ;
2009-10-17 15:51:44 -07:00
2014-06-08 00:34:14 +02:00
if ( ! quest -> HasFlag ( QUEST_FLAGS_AUTOCOMPLETE ))
2008-10-02 16:23:55 -05:00
{
2014-12-28 22:55:53 +02:00
object = ObjectAccessor :: GetObjectByTypeMask ( * _player , packet . QuestGiverGUID , TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT );
if ( ! object || ! object -> hasInvolvedQuest ( packet . QuestID ))
2011-06-03 11:54:44 +06:00
return ;
2009-10-17 15:51:44 -07:00
2012-09-13 16:16:33 +01:00
// some kind of WPE protection
if ( ! _player -> CanInteractWithQuestGiver ( object ))
return ;
}
2014-12-28 22:55:53 +02:00
if (( ! _player -> CanSeeStartQuest ( quest ) && _player -> GetQuestStatus ( packet . QuestID ) == QUEST_STATUS_NONE ) ||
( _player -> GetQuestStatus ( packet . QuestID ) != QUEST_STATUS_COMPLETE && ! quest -> IsAutoComplete ()))
2012-09-13 16:16:33 +01:00
{
2014-10-22 22:18:21 +02:00
TC_LOG_ERROR ( "network" , "Error in QUEST_STATUS_COMPLETE: player %s (%s) tried to complete quest %u, but is not allowed to do so (possible packet-hacking or high latency)" ,
2014-12-28 22:55:53 +02:00
_player -> GetName (). c_str (), _player -> GetGUID (). ToString (). c_str (), packet . QuestID );
2012-09-13 16:16:33 +01:00
return ;
}
2014-12-28 22:55:53 +02:00
if ( _player -> CanRewardQuest ( quest , packet . ItemChoiceID , true ))
2012-09-13 16:16:33 +01:00
{
2014-12-28 22:55:53 +02:00
_player -> RewardQuest ( quest , packet . ItemChoiceID , object );
2012-09-13 16:16:33 +01:00
switch ( object -> GetTypeId ())
{
case TYPEID_UNIT :
case TYPEID_PLAYER :
2008-10-02 16:23:55 -05:00
{
2012-09-13 16:16:33 +01:00
//For AutoSubmition was added plr case there as it almost same exclute AI script cases.
2013-01-14 11:12:58 +01:00
Creature * creatureQGiver = object -> ToCreature ();
2014-12-28 22:55:53 +02:00
if ( ! creatureQGiver || ! sScriptMgr -> OnQuestReward ( _player , creatureQGiver , quest , packet . ItemChoiceID ))
2012-09-13 16:16:33 +01:00
{
// Send next quest
2014-12-28 22:55:53 +02:00
if ( Quest const * nextQuest = _player -> GetNextQuest ( packet . QuestGiverGUID , quest ))
2008-10-02 16:23:55 -05:00
{
2014-09-12 15:27:06 -05:00
// Only send the quest to the player if the conditions are met
2014-09-13 16:50:09 -05:00
if ( _player -> CanTakeQuest ( nextQuest , false ))
2011-06-18 17:15:52 +02:00
{
2014-09-12 15:27:06 -05:00
if ( nextQuest -> IsAutoAccept () && _player -> CanAddQuest ( nextQuest , true ))
_player -> AddQuestAndCheckCompletion ( nextQuest , object );
2010-10-25 18:23:45 +02:00
2014-12-28 22:55:53 +02:00
_player -> PlayerTalkClass -> SendQuestGiverQuestDetails ( nextQuest , packet . QuestGiverGUID , true );
2014-09-12 15:27:06 -05:00
}
2008-10-02 16:23:55 -05:00
}
2012-09-13 16:16:33 +01:00
if ( creatureQGiver )
2014-12-28 22:55:53 +02:00
creatureQGiver -> AI () -> sQuestReward ( _player , quest , packet . ItemChoiceID );
2012-09-13 16:16:33 +01:00
}
break ;
}
case TYPEID_GAMEOBJECT :
2014-04-05 20:43:05 +02:00
{
GameObject * questGiver = object -> ToGameObject ();
2014-12-28 22:55:53 +02:00
if ( ! sScriptMgr -> OnQuestReward ( _player , questGiver , quest , packet . ItemChoiceID ))
2012-09-13 16:16:33 +01:00
{
// Send next quest
2014-12-28 22:55:53 +02:00
if ( Quest const * nextQuest = _player -> GetNextQuest ( packet . QuestGiverGUID , quest ))
2008-10-02 16:23:55 -05:00
{
2014-09-12 15:27:06 -05:00
// Only send the quest to the player if the conditions are met
2014-09-13 16:50:09 -05:00
if ( _player -> CanTakeQuest ( nextQuest , false ))
2011-06-18 17:15:52 +02:00
{
2014-09-12 15:27:06 -05:00
if ( nextQuest -> IsAutoAccept () && _player -> CanAddQuest ( nextQuest , true ))
_player -> AddQuestAndCheckCompletion ( nextQuest , object );
2011-06-18 17:15:52 +02:00
2014-12-28 22:55:53 +02:00
_player -> PlayerTalkClass -> SendQuestGiverQuestDetails ( nextQuest , packet . QuestGiverGUID , true );
2014-09-12 15:27:06 -05:00
}
2008-10-02 16:23:55 -05:00
}
2012-09-13 16:16:33 +01:00
2014-12-28 22:55:53 +02:00
questGiver -> AI () -> QuestReward ( _player , quest , packet . ItemChoiceID );
2012-09-13 16:16:33 +01:00
}
break ;
2008-10-02 16:23:55 -05:00
}
2012-09-13 16:16:33 +01:00
default :
break ;
2008-10-02 16:23:55 -05:00
}
}
2012-09-13 16:16:33 +01:00
else
2014-12-28 22:55:53 +02:00
_player -> PlayerTalkClass -> SendQuestGiverOfferReward ( quest , packet . QuestGiverGUID , true );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2014-12-29 22:46:00 +02:00
void WorldSession :: HandleQuestgiverRequestRewardOpcode ( WorldPackets :: Quest :: QuestGiverRequestReward & packet )
2008-10-02 16:23:55 -05:00
{
2014-12-29 22:46:00 +02:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTGIVER_REQUEST_REWARD npc = %s, quest = %u" , packet . QuestGiverGUID . ToString (). c_str (), packet . QuestID );
2009-10-17 15:51:44 -07:00
2014-12-29 22:46:00 +02:00
Object * object = ObjectAccessor :: GetObjectByTypeMask ( * _player , packet . QuestGiverGUID , TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT );
if ( ! object || ! object -> hasInvolvedQuest ( packet . QuestID ))
2011-05-30 02:59:37 +07:00
return ;
// some kind of WPE protection
2012-05-30 08:01:02 +02:00
if ( ! _player -> CanInteractWithQuestGiver ( object ))
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2014-12-29 22:46:00 +02:00
if ( _player -> CanCompleteQuest ( packet . QuestID ))
_player -> CompleteQuest ( packet . QuestID );
2009-10-17 15:51:44 -07:00
2014-12-29 22:46:00 +02:00
if ( _player -> GetQuestStatus ( packet . QuestID ) != QUEST_STATUS_COMPLETE )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2014-12-29 22:46:00 +02:00
if ( Quest const * quest = sObjectMgr -> GetQuestTemplate ( packet . QuestID ))
_player -> PlayerTalkClass -> SendQuestGiverOfferReward ( quest , packet . QuestGiverGUID , true );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2012-08-05 19:40:30 -05:00
void WorldSession :: HandleQuestgiverCancel ( WorldPacket & /*recvData*/ )
2008-10-02 16:23:55 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTGIVER_CANCEL" );
2009-10-17 15:51:44 -07:00
2011-05-26 23:57:17 +02:00
_player -> PlayerTalkClass -> SendCloseGossip ();
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2012-08-05 19:40:30 -05:00
void WorldSession :: HandleQuestLogSwapQuest ( WorldPacket & recvData )
2008-10-02 16:23:55 -05:00
{
uint8 slot1 , slot2 ;
2012-08-05 19:40:30 -05:00
recvData >> slot1 >> slot2 ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( slot1 == slot2 || slot1 >= MAX_QUEST_LOG_SIZE || slot2 >= MAX_QUEST_LOG_SIZE )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTLOG_SWAP_QUEST slot 1 = %u, slot 2 = %u" , slot1 , slot2 );
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
GetPlayer () -> SwapQuestSlot ( slot1 , slot2 );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2015-03-14 23:53:41 +01:00
void WorldSession :: HandleQuestLogRemoveQuest ( WorldPackets :: Quest :: QuestLogRemoveQuest & packet )
2008-10-02 16:23:55 -05:00
{
2015-03-14 23:53:41 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTLOG_REMOVE_QUEST slot = %u" , packet . Entry );
2009-10-17 15:51:44 -07:00
2015-03-14 23:53:41 +01:00
if ( packet . Entry < MAX_QUEST_LOG_SIZE )
2008-10-02 16:23:55 -05:00
{
2015-03-14 23:53:41 +01:00
if ( uint32 questId = _player -> GetQuestSlotQuestId ( packet . Entry ))
2008-10-02 16:23:55 -05:00
{
2012-05-30 08:01:02 +02:00
if ( ! _player -> TakeQuestSourceItem ( questId , true ))
2008-10-02 16:23:55 -05:00
return ; // can't un-equip some items, reject quest cancel
2009-10-17 15:51:44 -07:00
2013-02-26 16:57:11 +01:00
if ( Quest const * quest = sObjectMgr -> GetQuestTemplate ( questId ))
2009-10-09 20:48:55 -07:00
{
2012-08-18 21:08:21 +01:00
if ( quest -> HasSpecialFlag ( QUEST_SPECIAL_FLAGS_TIMED ))
2012-05-30 08:01:02 +02:00
_player -> RemoveTimedQuest ( questId );
2013-02-26 17:14:13 +01:00
if ( quest -> HasFlag ( QUEST_FLAGS_FLAGS_PVP ))
{
_player -> pvpInfo . IsHostile = _player -> pvpInfo . IsInHostileArea || _player -> HasPvPForcingQuest ();
_player -> UpdatePvPState ();
}
2009-10-09 20:48:55 -07:00
}
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
_player -> TakeQuestSourceItem ( questId , true ); // remove quest src item from player
_player -> RemoveActiveQuest ( questId );
2012-09-18 14:29:53 +02:00
_player -> RemoveTimedAchievement ( ACHIEVEMENT_TIMED_TYPE_QUEST , questId );
2010-12-26 21:23:05 +01:00
2014-10-22 22:18:21 +02:00
TC_LOG_INFO ( "network" , "%s abandoned quest %u" , _player -> GetGUID (). ToString (). c_str (), questId );
2014-10-18 13:05:47 +02:00
if ( sWorld -> getBoolConfig ( CONFIG_QUEST_ENABLE_QUEST_TRACKER )) // check if Quest Tracker is enabled
{
// prepare Quest Tracker datas
PreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_QUEST_TRACK_ABANDON_TIME );
stmt -> setUInt32 ( 0 , questId );
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 1 , _player -> GetGUID (). GetCounter ());
2014-10-18 13:05:47 +02:00
// add to Quest Tracker
CharacterDatabase . Execute ( stmt );
}
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2015-03-14 23:53:41 +01:00
_player -> SetQuestSlot ( packet . Entry , 0 );
2009-10-17 15:51:44 -07:00
2012-07-09 11:08:33 +02:00
_player -> UpdateAchievementCriteria ( ACHIEVEMENT_CRITERIA_TYPE_QUEST_ABANDONED , 1 );
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
2011-12-22 04:34:26 +00:00
void WorldSession :: HandleQuestConfirmAccept ( WorldPacket & recvData )
2008-10-02 16:23:55 -05:00
{
2011-12-22 04:34:26 +00:00
uint32 questId ;
2012-01-14 19:27:14 +00:00
recvData >> questId ;
2009-10-17 15:51:44 -07:00
2013-11-08 11:12:17 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUEST_CONFIRM_ACCEPT questId = %u" , questId );
2011-12-22 04:34:26 +00:00
2014-02-06 21:23:18 +01:00
if ( Quest const * quest = sObjectMgr -> GetQuestTemplate ( questId ))
2009-12-19 18:08:07 +01:00
{
2011-12-22 04:34:26 +00:00
if ( ! quest -> HasFlag ( QUEST_FLAGS_PARTY_ACCEPT ))
2009-12-19 18:08:07 +01:00
return ;
2014-02-06 21:23:18 +01:00
Player * originalPlayer = ObjectAccessor :: FindPlayer ( _player -> GetDivider ());
if ( ! originalPlayer )
2009-12-19 18:08:07 +01:00
return ;
2014-02-06 21:23:18 +01:00
if ( ! _player -> IsInSameRaidWith ( originalPlayer ))
2012-12-24 19:53:28 +01:00
return ;
2009-12-19 18:08:07 +01:00
2014-12-29 22:46:00 +02:00
if ( ! originalPlayer -> CanShareQuest ( questId ))
2014-12-29 21:39:33 +02:00
return ;
if ( ! _player -> CanTakeQuest ( quest , true ))
return ;
2011-12-22 04:34:26 +00:00
if ( _player -> CanAddQuest ( quest , true ))
2013-12-14 19:41:54 +01:00
_player -> AddQuestAndCheckCompletion ( quest , NULL ); // NULL, this prevent DB script from duplicate running
2009-12-19 18:08:07 +01:00
2014-09-14 16:14:12 +02:00
_player -> SetDivider ( ObjectGuid :: Empty );
2009-12-19 18:08:07 +01:00
}
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2014-12-28 22:55:53 +02:00
void WorldSession :: HandleQuestgiverCompleteQuest ( WorldPackets :: Quest :: QuestGiverCompleteQuest & packet )
2008-10-02 16:23:55 -05:00
{
2014-12-28 22:55:53 +02:00
bool autoCompleteMode = packet . FromScript ; // 0 - standart complete quest mode with npc, 1 - auto-complete mode
2009-10-17 15:51:44 -07:00
2014-12-28 22:55:53 +02:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTGIVER_COMPLETE_QUEST npc = %s, questId = %u self-complete: %u" , packet . QuestGiverGUID . ToString (). c_str (), packet . QuestID , autoCompleteMode ? 1 : 0 );
2011-05-30 02:59:37 +07:00
2014-12-28 22:55:53 +02:00
Quest const * quest = sObjectMgr -> GetQuestTemplate ( packet . QuestID );
2013-08-07 10:31:13 +02:00
if ( ! quest )
return ;
2013-08-09 20:36:47 +02:00
2014-06-08 00:34:14 +02:00
if ( autoCompleteMode && ! quest -> HasFlag ( QUEST_FLAGS_AUTOCOMPLETE ))
return ;
Object * object = nullptr ;
if ( autoCompleteMode )
object = _player ;
else
2014-12-28 22:55:53 +02:00
object = ObjectAccessor :: GetObjectByTypeMask ( * _player , packet . QuestGiverGUID , TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT );
2014-07-11 10:22:27 +02:00
2014-06-08 00:34:14 +02:00
if ( ! object )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2012-09-13 16:16:33 +01:00
if ( autoCompleteMode == 0 )
{
2014-12-28 22:55:53 +02:00
if ( ! object -> hasInvolvedQuest ( packet . QuestID ))
2014-06-08 00:34:14 +02:00
return ;
2012-09-13 16:16:33 +01:00
// some kind of WPE protection
if ( ! _player -> CanInteractWithQuestGiver ( object ))
return ;
}
2014-06-08 00:34:14 +02:00
else
{
// Do not allow completing quests on other players.
2014-12-28 22:55:53 +02:00
if ( packet . QuestGiverGUID != _player -> GetGUID ())
2014-06-08 00:34:14 +02:00
return ;
}
2009-10-17 15:51:44 -07:00
2014-12-28 22:55:53 +02:00
if ( ! _player -> CanSeeStartQuest ( quest ) && _player -> GetQuestStatus ( packet . QuestID ) == QUEST_STATUS_NONE )
2008-10-02 16:23:55 -05:00
{
2014-10-22 22:18:21 +02:00
TC_LOG_ERROR ( "network" , "Possible hacking attempt: Player %s [%s] tried to complete quest [entry: %u] without being in possession of the quest!" ,
2014-12-28 22:55:53 +02:00
_player -> GetName (). c_str (), _player -> GetGUID (). ToString (). c_str (), packet . QuestID );
2013-08-07 10:31:13 +02:00
return ;
}
2012-09-13 16:16:33 +01:00
2013-08-07 10:31:13 +02:00
if ( Battleground * bg = _player -> GetBattleground ())
2014-12-28 22:55:53 +02:00
bg -> HandleQuestComplete ( packet . QuestID , _player );
2009-10-17 15:51:44 -07:00
2014-12-28 22:55:53 +02:00
if ( _player -> GetQuestStatus ( packet . QuestID ) != QUEST_STATUS_COMPLETE )
2013-08-07 10:31:13 +02:00
{
if ( quest -> IsRepeatable ())
2014-12-28 22:55:53 +02:00
_player -> PlayerTalkClass -> SendQuestGiverRequestItems ( quest , packet . QuestGiverGUID , _player -> CanCompleteRepeatableQuest ( quest ), false );
2008-10-02 16:23:55 -05:00
else
2014-12-28 22:55:53 +02:00
_player -> PlayerTalkClass -> SendQuestGiverRequestItems ( quest , packet . QuestGiverGUID , _player -> CanRewardQuest ( quest , false ), false );
2008-10-02 16:23:55 -05:00
}
2013-08-07 10:31:13 +02:00
else
{
2014-12-28 22:55:53 +02:00
if ( quest -> HasSpecialFlag ( QUEST_SPECIAL_FLAGS_DELIVER )) // some items required
_player -> PlayerTalkClass -> SendQuestGiverRequestItems ( quest , packet . QuestGiverGUID , _player -> CanRewardQuest ( quest , false ), false );
2013-08-07 10:31:13 +02:00
else // no items required
2014-12-28 22:55:53 +02:00
_player -> PlayerTalkClass -> SendQuestGiverOfferReward ( quest , packet . QuestGiverGUID , true );
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
void WorldSession :: HandleQuestgiverQuestAutoLaunch ( WorldPacket & /*recvPacket*/ )
2008-10-02 16:23:55 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTGIVER_QUEST_AUTOLAUNCH" );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
void WorldSession :: HandlePushQuestToParty ( WorldPacket & recvPacket )
2008-10-02 16:23:55 -05:00
{
2009-07-01 17:32:20 -05:00
uint32 questId ;
recvPacket >> questId ;
2009-10-17 15:51:44 -07:00
2013-07-11 21:45:14 +02:00
if ( ! _player -> CanShareQuest ( questId ))
return ;
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_PUSHQUESTTOPARTY questId = %u" , questId );
2009-10-17 15:51:44 -07:00
2013-08-07 10:31:13 +02:00
Quest const * quest = sObjectMgr -> GetQuestTemplate ( questId );
if ( ! quest )
return ;
Player * const sender = GetPlayer ();
Group * group = sender -> GetGroup ();
if ( ! group )
return ;
for ( GroupReference * itr = group -> GetFirstMember (); itr != NULL ; itr = itr -> next ())
2008-10-02 16:23:55 -05:00
{
2013-08-07 10:31:13 +02:00
Player * receiver = itr -> GetSource ();
2009-10-17 15:51:44 -07:00
2013-08-07 10:31:13 +02:00
if ( ! receiver || receiver == sender )
continue ;
2009-10-17 15:51:44 -07:00
2013-08-07 10:31:13 +02:00
if ( ! receiver -> SatisfyQuestStatus ( quest , false ))
{
sender -> SendPushToPartyResponse ( receiver , QUEST_PARTY_MSG_HAVE_QUEST );
continue ;
}
2009-10-17 15:51:44 -07:00
2013-08-07 10:31:13 +02:00
if ( receiver -> GetQuestStatus ( questId ) == QUEST_STATUS_COMPLETE )
{
sender -> SendPushToPartyResponse ( receiver , QUEST_PARTY_MSG_FINISH_QUEST );
continue ;
}
2009-10-17 15:51:44 -07:00
2013-08-07 10:31:13 +02:00
if ( ! receiver -> CanTakeQuest ( quest , false ))
{
sender -> SendPushToPartyResponse ( receiver , QUEST_PARTY_MSG_CANT_TAKE_QUEST );
continue ;
}
2009-10-17 15:51:44 -07:00
2013-08-07 10:31:13 +02:00
if ( ! receiver -> SatisfyQuestLog ( false ))
{
sender -> SendPushToPartyResponse ( receiver , QUEST_PARTY_MSG_LOG_FULL );
continue ;
}
2009-10-17 15:51:44 -07:00
2014-10-21 20:27:00 +02:00
if ( ! receiver -> GetDivider (). IsEmpty ())
2013-08-07 10:31:13 +02:00
{
sender -> SendPushToPartyResponse ( receiver , QUEST_PARTY_MSG_BUSY );
continue ;
}
2009-10-17 15:51:44 -07:00
2013-08-07 10:31:13 +02:00
sender -> SendPushToPartyResponse ( receiver , QUEST_PARTY_MSG_SHARING_QUEST );
2013-07-11 21:45:14 +02:00
2013-08-07 10:31:13 +02:00
if ( quest -> IsAutoAccept () && receiver -> CanAddQuest ( quest , true ) && receiver -> CanTakeQuest ( quest , true ))
2013-12-14 19:39:47 +01:00
receiver -> AddQuestAndCheckCompletion ( quest , sender );
2013-07-11 21:45:14 +02:00
2014-06-08 00:34:14 +02:00
if ( quest -> IsAutoComplete () && quest -> IsRepeatable () && ! quest -> IsDailyOrWeekly ())
2013-08-07 10:31:13 +02:00
receiver -> PlayerTalkClass -> SendQuestGiverRequestItems ( quest , sender -> GetGUID (), receiver -> CanCompleteRepeatableQuest ( quest ), true );
else
{
receiver -> SetDivider ( sender -> GetGUID ());
receiver -> PlayerTalkClass -> SendQuestGiverQuestDetails ( quest , sender -> GetGUID (), true );
2008-10-02 16:23:55 -05:00
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession :: HandleQuestPushResult ( WorldPacket & recvPacket )
{
2014-09-14 16:14:12 +02:00
ObjectGuid guid ;
2013-07-11 21:45:14 +02:00
uint32 questId ;
2008-10-02 16:23:55 -05:00
uint8 msg ;
2013-07-11 21:45:14 +02:00
recvPacket >> guid >> questId >> msg ;
2009-10-17 15:51:44 -07:00
2015-01-18 23:56:01 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUEST_PUSH_RESULT" );
2009-10-17 15:51:44 -07:00
2014-10-21 19:23:32 +02:00
if ( ! _player -> GetDivider (). IsEmpty () && _player -> GetDivider () == guid )
2008-10-02 16:23:55 -05:00
{
2011-10-07 11:08:09 -05:00
Player * player = ObjectAccessor :: FindPlayer ( _player -> GetDivider ());
if ( player )
2008-10-02 16:23:55 -05:00
{
2015-01-18 23:56:01 +01:00
player -> SendPushToPartyResponse ( _player , msg );
2014-09-14 16:14:12 +02:00
_player -> SetDivider ( ObjectGuid :: Empty );
2008-10-02 16:23:55 -05:00
}
}
}
2009-10-17 15:51:44 -07:00
2014-11-19 00:30:31 +02:00
void WorldSession :: HandleQuestgiverStatusMultipleQuery ( WorldPackets :: Quest :: QuestGiverStatusMultipleQuery & /*packet*/ )
2008-10-02 16:23:55 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Received CMSG_QUESTGIVER_STATUS_MULTIPLE_QUERY" );
2009-10-17 15:51:44 -07:00
2014-11-19 00:30:31 +02:00
WorldPackets :: Quest :: QuestGiverStatusMultiple response ;
2009-10-17 15:51:44 -07:00
2015-03-01 18:40:46 +01:00
for ( auto itr = _player -> m_clientGUIDs . begin (); itr != _player -> m_clientGUIDs . end (); ++ itr )
2008-10-02 16:23:55 -05:00
{
2014-09-14 16:14:12 +02:00
if ( itr -> IsAnyTypeCreature ())
2008-10-02 16:23:55 -05:00
{
2009-05-04 17:26:24 -05:00
// need also pet quests case support
2011-09-15 14:08:17 +02:00
Creature * questgiver = ObjectAccessor :: GetCreatureOrPetOrVehicle ( * GetPlayer (), * itr );
2010-04-07 19:14:10 +02:00
if ( ! questgiver || questgiver -> IsHostileTo ( _player ))
2008-10-02 16:23:55 -05:00
continue ;
2010-04-07 19:14:10 +02:00
if ( ! questgiver -> HasFlag ( UNIT_NPC_FLAGS , UNIT_NPC_FLAG_QUESTGIVER ))
2008-10-02 16:23:55 -05:00
continue ;
2013-12-25 02:08:05 +01:00
2014-11-19 21:09:30 +01:00
response . QuestGiver . emplace_back ( questgiver -> GetGUID (), _player -> GetQuestDialogStatus ( questgiver ));
2008-10-02 16:23:55 -05:00
}
2014-09-14 16:14:12 +02:00
else if ( itr -> IsGameObject ())
2008-10-02 16:23:55 -05:00
{
2011-09-15 14:08:17 +02:00
GameObject * questgiver = GetPlayer () -> GetMap () -> GetGameObject ( * itr );
2013-12-25 02:08:05 +01:00
if ( ! questgiver || questgiver -> GetGoType () != GAMEOBJECT_TYPE_QUESTGIVER )
2008-10-02 16:23:55 -05:00
continue ;
2013-12-25 02:08:05 +01:00
2014-11-19 21:09:30 +01:00
response . QuestGiver . emplace_back ( questgiver -> GetGUID (), _player -> GetQuestDialogStatus ( questgiver ));
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
2014-11-19 00:30:31 +02:00
SendPacket ( response . Write ());
2015-04-10 13:18:31 +02:00
}