2010-10-07 15:35:36 +02:00
/*
2014-01-01 00:07:53 +01:00
* Copyright (C) 2008-2014 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 "Corpse.h"
2012-11-20 14:54:33 +01:00
#include "Creature.h"
2008-10-02 16:23:55 -05:00
#include "GameObject.h"
2012-11-20 14:54:33 +01:00
#include "Group.h"
2008-10-02 16:23:55 -05:00
#include "LootMgr.h"
2012-11-20 14:54:33 +01:00
#include "ObjectAccessor.h"
2008-10-02 16:23:55 -05:00
#include "Object.h"
2012-11-20 14:54:33 +01:00
#include "Opcodes.h"
#include "Player.h"
2008-10-02 16:23:55 -05:00
#include "World.h"
2012-11-20 14:54:33 +01:00
#include "WorldPacket.h"
#include "WorldSession.h"
2009-10-17 15:51:44 -07:00
2012-11-27 13:02:04 +01:00
void WorldSession :: HandleAutostoreLootItemOpcode ( WorldPacket & recvData )
2008-10-02 16:23:55 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: CMSG_AUTOSTORE_LOOT_ITEM" );
2010-09-11 21:28:55 +02:00
Player * player = GetPlayer ();
uint64 lguid = player -> GetLootGUID ();
Loot * loot = NULL ;
uint8 lootSlot = 0 ;
2009-10-17 15:51:44 -07:00
2012-11-02 22:23:14 +01:00
recvData >> lootSlot ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if ( IS_GAMEOBJECT_GUID ( lguid ))
{
2011-09-15 14:08:17 +02:00
GameObject * go = player -> GetMap () -> GetGameObject ( lguid );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// not check distance for GO in case owned GO (fishing bobber case, for example) or Fishing hole GO
2011-04-29 20:47:02 +02:00
if ( ! go || (( go -> GetOwnerGUID () != _player -> GetGUID () && go -> GetGoType () != GAMEOBJECT_TYPE_FISHINGHOLE ) && ! go -> IsWithinDistInMap ( _player , INTERACTION_DISTANCE )))
2008-10-02 16:23:55 -05:00
{
player -> SendLootRelease ( lguid );
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
loot = & go -> loot ;
}
else if ( IS_ITEM_GUID ( lguid ))
{
2012-03-14 18:51:51 +01:00
Item * pItem = player -> GetItemByGuid ( lguid );
2009-10-17 15:51:44 -07:00
2012-03-14 18:51:51 +01:00
if ( ! pItem )
2008-10-02 16:23:55 -05:00
{
player -> SendLootRelease ( lguid );
return ;
}
2009-10-17 15:51:44 -07:00
2012-03-14 18:51:51 +01:00
loot = & pItem -> loot ;
2008-10-02 16:23:55 -05:00
}
2008-11-21 19:45:49 -06:00
else if ( IS_CORPSE_GUID ( lguid ))
{
2011-09-15 14:08:17 +02:00
Corpse * bones = ObjectAccessor :: GetCorpse ( * player , lguid );
2008-11-21 19:45:49 -06:00
if ( ! bones )
{
player -> SendLootRelease ( lguid );
return ;
}
2010-09-11 21:28:55 +02:00
2008-11-21 19:45:49 -06:00
loot = & bones -> loot ;
}
2008-10-02 16:23:55 -05:00
else
{
2011-10-07 11:08:09 -05:00
Creature * creature = GetPlayer () -> GetMap () -> GetCreature ( lguid );
2009-10-17 15:51:44 -07:00
2014-06-26 22:01:55 +02:00
bool lootAllowed = creature && creature -> IsAlive () == ( player -> getClass () == CLASS_ROGUE && creature -> loot . loot_type == LOOT_PICKPOCKETING );
2009-10-17 15:51:44 -07:00
2012-03-07 14:08:30 +01:00
if ( ! lootAllowed || ! creature -> IsWithinDistInMap ( _player , INTERACTION_DISTANCE ))
2008-10-02 16:23:55 -05:00
{
player -> SendLootRelease ( lguid );
return ;
}
2009-10-17 15:51:44 -07:00
2011-10-07 11:08:09 -05:00
loot = & creature -> loot ;
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2010-09-11 21:28:55 +02:00
player -> StoreLootItem ( lootSlot , loot );
2012-12-14 00:46:36 -05:00
// If player is removing the last LootItem, delete the empty container.
if ( loot -> isLooted () && IS_ITEM_GUID ( lguid ))
player -> GetSession () -> DoLootRelease ( lguid );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2013-01-30 10:34:18 +01:00
void WorldSession :: HandleLootMoneyOpcode ( WorldPacket & /*recvData*/ )
2008-10-02 16:23:55 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: CMSG_LOOT_MONEY" );
2009-10-17 15:51:44 -07:00
2011-05-29 14:32:46 +02:00
Player * player = GetPlayer ();
2008-10-02 16:23:55 -05:00
uint64 guid = player -> GetLootGUID ();
2010-04-07 19:14:10 +02:00
if ( ! guid )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2011-05-29 14:32:46 +02:00
Loot * loot = NULL ;
2011-05-11 20:39:26 +07:00
bool shareMoney = true ;
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
switch ( GUID_HIPART ( guid ))
2008-10-02 16:23:55 -05:00
{
case HIGHGUID_GAMEOBJECT :
{
2011-05-29 14:32:46 +02:00
GameObject * go = GetPlayer () -> GetMap () -> GetGameObject ( guid );
2009-10-17 15:51:44 -07:00
2011-05-29 14:32:46 +02:00
// do not check distance for GO if player is the owner of it (ex. fishing bobber)
if ( go && (( go -> GetOwnerGUID () == player -> GetGUID () || go -> IsWithinDistInMap ( player , INTERACTION_DISTANCE ))))
loot = & go -> loot ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
break ;
}
case HIGHGUID_CORPSE : // remove insignia ONLY in BG
{
2011-05-29 14:32:46 +02:00
Corpse * bones = ObjectAccessor :: GetCorpse ( * player , guid );
2009-10-17 15:51:44 -07:00
2011-05-29 14:32:46 +02:00
if ( bones && bones -> IsWithinDistInMap ( player , INTERACTION_DISTANCE ))
2011-05-11 20:39:26 +07:00
{
2011-05-29 14:32:46 +02:00
loot = & bones -> loot ;
2011-05-11 20:39:26 +07:00
shareMoney = false ;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
break ;
}
case HIGHGUID_ITEM :
{
2011-05-29 14:32:46 +02:00
if ( Item * item = player -> GetItemByGuid ( guid ))
2011-05-11 20:39:26 +07:00
{
2011-05-29 14:32:46 +02:00
loot = & item -> loot ;
2011-05-11 20:39:26 +07:00
shareMoney = false ;
}
2008-10-02 16:23:55 -05:00
break ;
}
case HIGHGUID_UNIT :
2011-06-28 23:08:09 +02:00
case HIGHGUID_VEHICLE :
2008-10-02 16:23:55 -05:00
{
2011-05-29 14:32:46 +02:00
Creature * creature = player -> GetMap () -> GetCreature ( guid );
2014-06-26 22:01:55 +02:00
bool lootAllowed = creature && creature -> IsAlive () == ( player -> getClass () == CLASS_ROGUE && creature -> loot . loot_type == LOOT_PICKPOCKETING );
2011-05-29 14:32:46 +02:00
if ( lootAllowed && creature -> IsWithinDistInMap ( player , INTERACTION_DISTANCE ))
2011-05-11 20:39:26 +07:00
{
2011-05-29 14:32:46 +02:00
loot = & creature -> loot ;
2013-06-11 19:54:27 -02:30
if ( creature -> IsAlive ())
2011-05-11 20:39:26 +07:00
shareMoney = false ;
}
2008-10-02 16:23:55 -05:00
break ;
}
default :
return ; // unlootable type
}
2009-10-17 15:51:44 -07:00
2011-05-29 14:32:46 +02:00
if ( loot )
2008-10-02 16:23:55 -05:00
{
2011-09-07 00:04:27 +02:00
loot -> NotifyMoneyRemoved ();
2011-05-11 20:39:26 +07:00
if ( shareMoney && player -> GetGroup ()) //item, pickpocket and players can be looted only single player
2008-10-02 16:23:55 -05:00
{
2011-05-29 14:32:46 +02:00
Group * group = player -> GetGroup ();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std :: vector < Player *> playersNear ;
2011-05-29 14:32:46 +02:00
for ( GroupReference * itr = group -> GetFirstMember (); itr != NULL ; itr = itr -> next ())
2008-10-02 16:23:55 -05:00
{
2013-06-11 21:25:12 -02:30
Player * member = itr -> GetSource ();
2011-05-29 14:32:46 +02:00
if ( ! member )
2008-10-02 16:23:55 -05:00
continue ;
2011-05-29 14:32:46 +02:00
if ( player -> IsWithinDistInMap ( member , sWorld -> getFloatConfig ( CONFIG_GROUP_XP_DISTANCE ), false ))
playersNear . push_back ( member );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2011-05-29 14:32:46 +02:00
uint32 goldPerPlayer = uint32 (( loot -> gold ) / ( playersNear . size ()));
2009-10-17 15:51:44 -07:00
2009-04-29 00:26:07 -05:00
for ( std :: vector < Player *>:: const_iterator i = playersNear . begin (); i != playersNear . end (); ++ i )
2008-10-02 16:23:55 -05:00
{
2011-09-07 00:04:27 +02:00
( * i ) -> ModifyMoney ( goldPerPlayer );
2012-09-18 14:29:53 +02:00
( * i ) -> UpdateAchievementCriteria ( ACHIEVEMENT_CRITERIA_TYPE_LOOT_MONEY , goldPerPlayer );
2011-09-07 00:04:27 +02:00
2011-07-08 11:15:00 +02:00
WorldPacket data ( SMSG_LOOT_MONEY_NOTIFY , 4 + 1 );
2011-05-29 14:32:46 +02:00
data << uint32 ( goldPerPlayer );
2013-01-30 10:34:18 +01:00
data << uint8 ( playersNear . size () <= 1 ); // Controls the text displayed in chat. 0 is "Your share is..." and 1 is "You loot..."
2010-04-07 22:59:46 +02:00
( * i ) -> GetSession () -> SendPacket ( & data );
2008-10-02 16:23:55 -05:00
}
}
else
2009-03-05 09:22:43 -06:00
{
2011-09-07 00:04:27 +02:00
player -> ModifyMoney ( loot -> gold );
2012-09-18 14:29:53 +02:00
player -> UpdateAchievementCriteria ( ACHIEVEMENT_CRITERIA_TYPE_LOOT_MONEY , loot -> gold );
2011-09-07 00:04:27 +02:00
2011-07-08 11:15:00 +02:00
WorldPacket data ( SMSG_LOOT_MONEY_NOTIFY , 4 + 1 );
2011-05-29 14:32:46 +02:00
data << uint32 ( loot -> gold );
2011-09-07 00:04:27 +02:00
data << uint8 ( 1 ); // "You loot..."
2011-05-29 14:32:46 +02:00
SendPacket ( & data );
2009-03-05 09:22:43 -06:00
}
2011-05-29 14:32:46 +02:00
loot -> gold = 0 ;
2012-12-14 00:46:36 -05:00
// Delete the money loot record from the DB
if ( loot -> containerID > 0 )
loot -> DeleteLootMoneyFromContainerItemDB ();
// Delete container if empty
if ( loot -> isLooted () && IS_ITEM_GUID ( guid ))
player -> GetSession () -> DoLootRelease ( guid );
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
2012-11-27 13:02:04 +01:00
void WorldSession :: HandleLootOpcode ( WorldPacket & recvData )
2008-10-02 16:23:55 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: CMSG_LOOT" );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
uint64 guid ;
2012-11-02 22:23:14 +01:00
recvData >> guid ;
2009-10-17 15:51:44 -07:00
2009-07-10 08:34:28 +08:00
// Check possible cheat
2014-01-23 20:09:13 +01:00
if ( ! GetPlayer () -> IsAlive () || ! IS_CRE_OR_VEH_GUID ( guid ))
2009-07-10 08:34:28 +08:00
return ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
GetPlayer () -> SendLoot ( guid , LOOT_CORPSE );
2010-09-13 04:02:57 +03:00
// interrupt cast
2013-12-25 14:16:55 -03:30
if ( GetPlayer () -> IsNonMeleeSpellCast ( false ))
2010-09-13 04:02:57 +03:00
GetPlayer () -> InterruptNonMeleeSpells ( false );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2012-06-05 13:14:15 +02:00
void WorldSession :: HandleLootReleaseOpcode ( WorldPacket & recvData )
2008-10-02 16:23:55 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: CMSG_LOOT_RELEASE" );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// cheaters can modify lguid to prevent correct apply loot release code and re-loot
// use internal stored guid
2012-06-05 13:14:15 +02:00
uint64 guid ;
recvData >> guid ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( uint64 lguid = GetPlayer () -> GetLootGUID ())
2012-06-05 13:14:15 +02:00
if ( lguid == guid )
DoLootRelease ( lguid );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2010-03-11 22:55:02 +01:00
void WorldSession :: DoLootRelease ( uint64 lguid )
2008-10-02 16:23:55 -05:00
{
Player * player = GetPlayer ();
Loot * loot ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
player -> SetLootGUID ( 0 );
player -> SendLootRelease ( lguid );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
player -> RemoveFlag ( UNIT_FIELD_FLAGS , UNIT_FLAG_LOOTING );
2009-10-17 15:51:44 -07:00
2010-03-11 22:55:02 +01:00
if ( ! player -> IsInWorld ())
2009-04-20 20:28:19 -05:00
return ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if ( IS_GAMEOBJECT_GUID ( lguid ))
{
2011-09-15 14:08:17 +02:00
GameObject * go = GetPlayer () -> GetMap () -> GetGameObject ( lguid );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// not check distance for GO in case owned GO (fishing bobber case, for example) or Fishing hole GO
2011-04-29 20:47:02 +02:00
if ( ! go || (( go -> GetOwnerGUID () != _player -> GetGUID () && go -> GetGoType () != GAMEOBJECT_TYPE_FISHINGHOLE ) && ! go -> IsWithinDistInMap ( _player , INTERACTION_DISTANCE )))
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
loot = & go -> loot ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if ( go -> GetGoType () == GAMEOBJECT_TYPE_DOOR )
{
// locked doors are opened with spelleffect openlock, prevent remove its as looted
go -> UseDoorOrButton ();
}
else if ( loot -> isLooted () || go -> GetGoType () == GAMEOBJECT_TYPE_FISHINGNODE )
{
2013-03-02 23:59:42 +01:00
if ( go -> GetGoType () == GAMEOBJECT_TYPE_FISHINGHOLE )
2008-10-02 16:23:55 -05:00
{ // The fishing hole used once more
go -> AddUse (); // if the max usage is reached, will be despawned in next tick
2013-03-02 23:59:42 +01:00
if ( go -> GetUseCount () >= go -> GetGOValue () -> FishingHole . MaxOpens )
2008-10-02 16:23:55 -05:00
go -> SetLootState ( GO_JUST_DEACTIVATED );
else
go -> SetLootState ( GO_READY );
}
2013-03-02 23:59:42 +01:00
else
2008-10-02 16:23:55 -05:00
go -> SetLootState ( GO_JUST_DEACTIVATED );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
loot -> clear ();
}
else
2010-03-11 22:55:02 +01:00
{
2008-10-02 16:23:55 -05:00
// not fully looted object
2012-01-22 20:36:01 -05:00
go -> SetLootState ( GO_ACTIVATED , player );
2010-03-11 22:55:02 +01:00
// if the round robin player release, reset it.
if ( player -> GetGUID () == loot -> roundRobinPlayer )
2014-03-16 19:12:01 +01:00
loot -> roundRobinPlayer = 0 ;
2010-03-11 22:55:02 +01:00
}
2008-10-02 16:23:55 -05:00
}
else if ( IS_CORPSE_GUID ( lguid )) // ONLY remove insignia at BG
{
2011-09-15 14:08:17 +02:00
Corpse * corpse = ObjectAccessor :: GetCorpse ( * player , lguid );
2011-04-29 20:47:02 +02:00
if ( ! corpse || ! corpse -> IsWithinDistInMap ( _player , INTERACTION_DISTANCE ))
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
loot = & corpse -> loot ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if ( loot -> isLooted ())
{
loot -> clear ();
corpse -> RemoveFlag ( CORPSE_FIELD_DYNAMIC_FLAGS , CORPSE_DYNFLAG_LOOTABLE );
}
}
else if ( IS_ITEM_GUID ( lguid ))
{
2012-03-14 18:51:51 +01:00
Item * pItem = player -> GetItemByGuid ( lguid );
if ( ! pItem )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2012-03-14 18:51:51 +01:00
ItemTemplate const * proto = pItem -> GetTemplate ();
2009-10-17 15:51:44 -07:00
2009-01-12 10:53:53 -06:00
// destroy only 5 items from stack in case prospecting and milling
2010-08-04 10:34:30 +02:00
if ( proto -> Flags & ( ITEM_PROTO_FLAG_PROSPECTABLE | ITEM_PROTO_FLAG_MILLABLE ))
2008-10-02 16:23:55 -05:00
{
2012-03-14 18:51:51 +01:00
pItem -> m_lootGenerated = false ;
pItem -> loot . clear ();
2009-10-17 15:51:44 -07:00
2012-03-14 18:51:51 +01:00
uint32 count = pItem -> GetCount ();
2009-10-17 15:51:44 -07:00
2009-01-12 10:53:53 -06:00
// >=5 checked in spell code, but will work for cheating cases also with removing from another stacks.
2010-03-11 22:55:02 +01:00
if ( count > 5 )
2009-01-12 10:53:53 -06:00
count = 5 ;
2009-10-17 15:51:44 -07:00
2012-03-14 18:51:51 +01:00
player -> DestroyItemCount ( pItem , count , true );
2008-10-02 16:23:55 -05:00
}
else
2012-12-21 22:22:36 +01:00
{
2014-06-22 21:47:30 +02:00
// Only delete item if no loot or money (unlooted loot is saved to db) or if it isn't an openable item
if ( pItem -> loot . isLooted () || ! ( proto -> Flags & ITEM_PROTO_FLAG_OPENABLE ))
2012-12-14 00:46:36 -05:00
player -> DestroyItem ( pItem -> GetBagSlot (), pItem -> GetSlot (), true );
2012-12-21 22:22:36 +01:00
}
2008-10-02 16:23:55 -05:00
return ; // item can be looted only single player
}
else
{
2011-10-07 11:08:09 -05:00
Creature * creature = GetPlayer () -> GetMap () -> GetCreature ( lguid );
2009-10-17 15:51:44 -07:00
2014-06-26 22:01:55 +02:00
bool lootAllowed = creature && creature -> IsAlive () == ( player -> getClass () == CLASS_ROGUE && creature -> loot . loot_type == LOOT_PICKPOCKETING );
2012-02-27 14:58:47 +01:00
if ( ! lootAllowed || ! creature -> IsWithinDistInMap ( _player , INTERACTION_DISTANCE ))
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2011-10-07 11:08:09 -05:00
loot = & creature -> loot ;
2008-10-02 16:23:55 -05:00
if ( loot -> isLooted ())
{
2014-06-24 20:04:07 -05:00
creature -> RemoveFlag ( UNIT_DYNAMIC_FLAGS , UNIT_DYNFLAG_LOOTABLE );
2011-05-25 19:54:17 +07:00
// skip pickpocketing loot for speed, skinning timer reduction is no-op in fact
2013-06-11 19:54:27 -02:30
if ( ! creature -> IsAlive ())
2011-10-07 11:08:09 -05:00
creature -> AllLootRemovedFromCorpse ();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
loot -> clear ();
}
2010-04-07 18:09:10 +02:00
else
2010-03-11 22:55:02 +01:00
{
// if the round robin player release, reset it.
if ( player -> GetGUID () == loot -> roundRobinPlayer )
{
2014-03-16 19:12:01 +01:00
loot -> roundRobinPlayer = 0 ;
2011-10-07 10:54:53 -05:00
if ( Group * group = player -> GetGroup ())
2010-03-11 22:55:02 +01:00
{
2014-03-16 19:12:01 +01:00
group -> SendLooter ( creature , NULL );
// force update of dynamic flags, otherwise other group's players still not able to loot.
creature -> ForceValuesUpdateAtIndex ( UNIT_DYNAMIC_FLAGS );
2010-03-11 22:55:02 +01:00
}
}
}
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Player is not looking at loot list, he doesn't need to see updates on the loot list
loot -> RemoveLooter ( player -> GetGUID ());
}
2009-10-17 15:51:44 -07:00
2012-11-27 13:02:04 +01:00
void WorldSession :: HandleLootMasterGiveOpcode ( WorldPacket & recvData )
2008-10-02 16:23:55 -05:00
{
uint8 slotid ;
uint64 lootguid , target_playerguid ;
2009-10-17 15:51:44 -07:00
2012-11-02 22:23:14 +01:00
recvData >> lootguid >> slotid >> target_playerguid ;
2009-10-17 15:51:44 -07:00
2014-03-16 19:12:01 +01:00
if ( ! _player -> GetGroup () || _player -> GetGroup () -> GetMasterLooterGuid () != _player -> GetGUID () || _player -> GetGroup () -> GetLootMethod () != MASTER_LOOT )
2008-10-02 16:23:55 -05:00
{
_player -> SendLootRelease ( GetPlayer () -> GetLootGUID ());
return ;
}
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
Player * target = ObjectAccessor :: FindPlayer ( MAKE_NEW_GUID ( target_playerguid , 0 , HIGHGUID_PLAYER ));
2010-04-07 19:14:10 +02:00
if ( ! target )
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" , "WorldSession::HandleLootMasterGiveOpcode (CMSG_LOOT_MASTER_GIVE, 0x02A3) Target = [%s]." , target -> GetName (). c_str ());
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( _player -> GetLootGUID () != lootguid )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2014-01-01 21:42:15 +01:00
if ( ! _player -> IsInRaidWith ( target ) || ! _player -> IsInMap ( target ))
{
TC_LOG_INFO ( "loot" , "MasterLootItem: Player %s tried to give an item to ineligible player %s !" , GetPlayer () -> GetName (). c_str (), target -> GetName (). c_str ());
return ;
}
2012-02-27 14:58:47 +01:00
Loot * loot = NULL ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( IS_CRE_OR_VEH_GUID ( GetPlayer () -> GetLootGUID ()))
2008-10-02 16:23:55 -05:00
{
2011-10-07 11:08:09 -05:00
Creature * creature = GetPlayer () -> GetMap () -> GetCreature ( lootguid );
if ( ! creature )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2012-02-27 14:58:47 +01:00
loot = & creature -> loot ;
2008-10-02 16:23:55 -05:00
}
2010-04-07 19:14:10 +02:00
else if ( IS_GAMEOBJECT_GUID ( GetPlayer () -> GetLootGUID ()))
2008-10-02 16:23:55 -05:00
{
2011-09-15 14:08:17 +02:00
GameObject * pGO = GetPlayer () -> GetMap () -> GetGameObject ( lootguid );
2010-04-07 19:14:10 +02:00
if ( ! pGO )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2012-02-27 14:58:47 +01:00
loot = & pGO -> loot ;
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2012-02-27 14:58:47 +01:00
if ( ! loot )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2012-07-06 10:26:37 -04:00
if ( slotid >= loot -> items . size () + loot -> quest_items . size ())
2008-10-02 16:23:55 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "loot" , "MasterLootItem: Player %s might be using a hack! (slot %d, size %lu)" ,
2012-10-24 13:29:34 +02:00
GetPlayer () -> GetName (). c_str (), slotid , ( unsigned long ) loot -> items . size ());
2008-10-02 16:23:55 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2012-07-06 10:23:27 -04:00
LootItem & item = slotid >= loot -> items . size () ? loot -> quest_items [ slotid - loot -> items . size ()] : loot -> items [ slotid ];
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
ItemPosCountVec dest ;
2011-04-29 16:48:15 +06:00
InventoryResult msg = target -> CanStoreNewItem ( NULL_BAG , NULL_SLOT , dest , item . itemid , item . count );
2012-07-05 12:59:42 -04:00
if ( item . follow_loot_rules && ! item . AllowedForPlayer ( target ))
msg = EQUIP_ERR_YOU_CAN_NEVER_USE_THAT_ITEM ;
2010-04-07 22:59:46 +02:00
if ( msg != EQUIP_ERR_OK )
2008-10-02 16:23:55 -05:00
{
2010-08-05 22:08:07 +06:00
target -> SendEquipError ( msg , NULL , NULL , item . itemid );
// send duplicate of error massage to master looter
_player -> SendEquipError ( msg , NULL , NULL , item . itemid );
2008-10-02 16:23:55 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2010-09-21 21:55:16 +02:00
// list of players allowed to receive this item in trade
2011-10-18 10:44:45 +02:00
AllowedLooterSet looters = item . GetAllowedLooters ();
2010-09-21 21:55:16 +02:00
2008-10-02 16:23:55 -05:00
// not move item from loot to target inventory
2011-10-18 10:44:45 +02:00
Item * newitem = target -> StoreNewItem ( dest , item . itemid , true , item . randomPropertyId , looters );
2010-04-07 22:59:46 +02:00
target -> SendNewItem ( newitem , uint32 ( item . count ), false , false , true );
2012-09-18 14:29:53 +02:00
target -> UpdateAchievementCriteria ( ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM , item . itemid , item . count );
target -> UpdateAchievementCriteria ( ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE , loot -> loot_type , item . count );
target -> UpdateAchievementCriteria ( ACHIEVEMENT_CRITERIA_TYPE_LOOT_EPIC_ITEM , item . itemid , item . count );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// mark as looted
item . count = 0 ;
item . is_looted = true ;
2012-02-27 14:58:47 +01:00
loot -> NotifyItemRemoved ( slotid );
-- loot -> unlootedCount ;
2008-10-02 16:23:55 -05:00
}