2010-10-07 15:35:36 +02:00
/*
2012-01-01 00:32:13 +01:00
* Copyright (C) 2008-2012 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 "WorldPacket.h"
#include "Log.h"
#include "Corpse.h"
#include "GameObject.h"
#include "Player.h"
#include "ObjectAccessor.h"
#include "WorldSession.h"
#include "LootMgr.h"
#include "Object.h"
#include "Group.h"
#include "World.h"
2012-11-20 12:30:30 +01:00
#include "Creature.h"
2009-10-17 15:51:44 -07:00
2012-11-02 22:23:14 +01:00
void WorldSession :: HandleAutostoreLootItemOpcode ( WorldPacket & recvData )
2008-10-02 16:23:55 -05:00
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "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
2012-03-07 14:08:30 +01:00
bool lootAllowed = creature && creature -> isAlive () == ( player -> getClass () == CLASS_ROGUE && creature -> lootForPickPocketed );
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 );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2012-11-02 22:23:14 +01:00
void WorldSession :: HandleLootMoneyOpcode ( WorldPacket & /*recvData*/ )
2008-10-02 16:23:55 -05:00
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "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 );
bool lootAllowed = creature && creature -> isAlive () == ( player -> getClass () == CLASS_ROGUE && creature -> lootForPickPocketed );
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 ;
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
{
2011-05-29 14:32:46 +02:00
Player * member = itr -> getSource ();
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 );
2011-09-07 00:04:27 +02:00
data << uint8 ( playersNear . size () > 1 ? 0 : 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 ;
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
2012-11-02 22:23:14 +01:00
void WorldSession :: HandleLootOpcode ( WorldPacket & recvData )
2008-10-02 16:23:55 -05:00
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "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
2010-04-07 19:14:10 +02:00
if ( ! _player -> isAlive ())
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
if ( GetPlayer () -> IsNonMeleeSpellCasted ( false ))
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
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "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 )
{
// GO is mineral vein? so it is not removed after its looted
2010-04-07 19:14:10 +02:00
if ( go -> GetGoType () == GAMEOBJECT_TYPE_CHEST )
2008-10-02 16:23:55 -05:00
{
uint32 go_min = go -> GetGOInfo () -> chest . minSuccessOpens ;
uint32 go_max = go -> GetGOInfo () -> chest . maxSuccessOpens ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// only vein pass this check
2010-04-07 19:14:10 +02:00
if ( go_min != 0 && go_max > go_min )
2008-10-02 16:23:55 -05:00
{
2010-12-23 23:25:44 +01:00
float amount_rate = sWorld -> getRate ( RATE_MINING_AMOUNT );
2008-10-02 16:23:55 -05:00
float min_amount = go_min * amount_rate ;
float max_amount = go_max * amount_rate ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
go -> AddUse ();
float uses = float ( go -> GetUseCount ());
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( uses < max_amount )
2008-10-02 16:23:55 -05:00
{
2010-04-07 19:14:10 +02:00
if ( uses >= min_amount )
2008-10-02 16:23:55 -05:00
{
2010-12-23 23:25:44 +01:00
float chance_rate = sWorld -> getRate ( RATE_MINING_NEXT );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
int32 ReqValue = 175 ;
2011-09-15 14:08:17 +02:00
LockEntry const * lockInfo = sLockStore . LookupEntry ( go -> GetGOInfo () -> chest . lockId );
2010-04-07 19:14:10 +02:00
if ( lockInfo )
2008-12-24 09:58:26 -06:00
ReqValue = lockInfo -> Skill [ 0 ];
2008-10-02 16:23:55 -05:00
float skill = float ( player -> GetSkillValue ( SKILL_MINING )) / ( ReqValue + 25 );
2011-04-29 20:47:02 +02:00
double chance = pow ( 0.8 * chance_rate , 4 * ( 1 / double ( max_amount )) * double ( uses ));
2010-08-22 12:39:39 -07:00
if ( roll_chance_f (( float )( 100 * chance + skill )))
2008-10-02 16:23:55 -05:00
{
go -> SetLootState ( GO_READY );
}
else // not have more uses
go -> SetLootState ( GO_JUST_DEACTIVATED );
}
else // 100% chance until min uses
go -> SetLootState ( GO_READY );
}
else // max uses already
go -> SetLootState ( GO_JUST_DEACTIVATED );
}
else // not vein
go -> SetLootState ( GO_JUST_DEACTIVATED );
}
else if ( go -> GetGoType () == GAMEOBJECT_TYPE_FISHINGHOLE )
{ // The fishing hole used once more
go -> AddUse (); // if the max usage is reached, will be despawned in next tick
2010-08-26 15:54:56 +06:00
if ( go -> GetUseCount () >= urand ( go -> GetGOInfo () -> fishinghole . minSuccessOpens , go -> GetGOInfo () -> fishinghole . maxSuccessOpens ))
2008-10-02 16:23:55 -05:00
{
go -> SetLootState ( GO_JUST_DEACTIVATED );
}
else
go -> SetLootState ( GO_READY );
}
else // not chest (or vein/herb/etc)
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 )
{
2011-10-07 10:54:53 -05:00
if ( Group * group = player -> GetGroup ())
2010-03-11 22:55:02 +01:00
{
2011-10-07 10:54:53 -05:00
if ( group -> GetLootMethod () != MASTER_LOOT )
2010-03-11 22:55:02 +01:00
{
loot -> roundRobinPlayer = 0 ;
}
}
else
loot -> roundRobinPlayer = 0 ;
}
}
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
2010-03-11 22:55:02 +01:00
// FIXME: item must not be deleted in case not fully looted state. But this pre-request implement loot saving in DB at item save. Or cheating possible.
2012-03-14 18:51:51 +01:00
player -> DestroyItem ( pItem -> GetBagSlot (), pItem -> GetSlot (), true );
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
2012-02-27 14:58:47 +01:00
bool lootAllowed = creature && creature -> isAlive () == ( player -> getClass () == CLASS_ROGUE && creature -> lootForPickPocketed );
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 ())
{
2011-05-25 19:54:17 +07:00
// skip pickpocketing loot for speed, skinning timer reduction is no-op in fact
2011-10-07 11:08:09 -05:00
if ( ! creature -> isAlive ())
creature -> AllLootRemovedFromCorpse ();
2009-10-17 15:51:44 -07:00
2011-10-07 11:08:09 -05:00
creature -> RemoveFlag ( UNIT_DYNAMIC_FLAGS , UNIT_DYNFLAG_LOOTABLE );
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 )
{
2011-10-07 10:54:53 -05:00
if ( Group * group = player -> GetGroup ())
2010-03-11 22:55:02 +01:00
{
2011-10-07 10:54:53 -05:00
if ( group -> GetLootMethod () != MASTER_LOOT )
2010-03-11 22:55:02 +01:00
{
loot -> roundRobinPlayer = 0 ;
2011-10-07 11:08:09 -05:00
group -> SendLooter ( creature , NULL );
2010-03-11 22:55:02 +01:00
// force update of dynamic flags, otherwise other group's players still not able to loot.
2011-10-07 11:08:09 -05:00
creature -> ForceValuesUpdateAtIndex ( UNIT_DYNAMIC_FLAGS );
2010-03-11 22:55:02 +01:00
}
}
else
loot -> roundRobinPlayer = 0 ;
}
}
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-02 22:23:14 +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
2010-04-07 19:14:10 +02:00
if ( ! _player -> GetGroup () || _player -> GetGroup () -> GetLooterGuid () != _player -> GetGUID ())
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
2012-10-24 13:29:34 +02:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "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
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
{
2012-10-24 13:29:34 +02:00
sLog -> outDebug ( LOG_FILTER_LOOT , "MasterLootItem: Player %s might be using a hack! (slot %d, size %lu)" ,
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
}