2010-10-07 15:35:36 +02:00
/*
2020-01-02 06:44:10 +01:00
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
2010-10-07 15:35:36 +02:00
*
* 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
2017-05-18 23:52:58 +02:00
#include "WorldSession.h"
#include "CellImpl.h"
2008-10-02 16:23:55 -05:00
#include "Common.h"
#include "Corpse.h"
2012-11-20 14:54:33 +01:00
#include "Creature.h"
2017-06-04 01:00:45 +02:00
#include "DB2Stores.h"
2008-10-02 16:23:55 -05:00
#include "GameObject.h"
2016-12-28 01:12:01 +01:00
#include "GridNotifiersImpl.h"
2012-11-20 14:54:33 +01:00
#include "Group.h"
2017-05-18 23:52:58 +02:00
#include "Guild.h"
2012-11-20 16:01:31 +01:00
#include "GuildMgr.h"
2017-06-04 01:00:45 +02:00
#include "Item.h"
2017-05-18 23:52:58 +02:00
#include "Log.h"
2017-04-12 03:22:50 +02:00
#include "LootItemStorage.h"
2008-10-02 16:23:55 -05:00
#include "LootMgr.h"
2017-05-18 23:52:58 +02:00
#include "LootPackets.h"
2008-10-02 16:23:55 -05:00
#include "Object.h"
2017-05-18 23:52:58 +02:00
#include "ObjectAccessor.h"
2012-11-20 14:54:33 +01:00
#include "Player.h"
#include "WorldPacket.h"
2009-10-17 15:51:44 -07:00
2016-12-31 20:50:39 +01:00
class AELootCreatureCheck
{
public :
static float constexpr LootDistance = 30.0f ;
AELootCreatureCheck ( Player * looter , ObjectGuid mainLootTarget ) : _looter ( looter ), _mainLootTarget ( mainLootTarget ) { }
bool operator ()( Creature * creature ) const
{
if ( creature -> IsAlive ())
return false ;
if ( creature -> GetGUID () == _mainLootTarget )
return false ;
if ( ! _looter -> IsWithinDist ( creature , LootDistance ))
return false ;
return _looter -> isAllowedToLoot ( creature );
}
Player * _looter ;
ObjectGuid _mainLootTarget ;
};
2015-04-01 01:44:10 +02:00
void WorldSession :: HandleAutostoreLootItemOpcode ( WorldPackets :: Loot :: LootItem & packet )
2008-10-02 16:23:55 -05:00
{
2010-09-11 21:28:55 +02:00
Player * player = GetPlayer ();
2016-12-28 01:12:01 +01:00
AELootResult aeResult ;
AELootResult * aeResultPtr = player -> GetAELootView (). size () > 1 ? & aeResult : nullptr ;
2009-10-17 15:51:44 -07:00
2014-12-30 02:23:37 +02:00
/// @todo Implement looting by LootObject guid
for ( WorldPackets :: Loot :: LootRequest const & req : packet . Loot )
2008-10-02 16:23:55 -05:00
{
2016-12-28 01:12:01 +01:00
Loot * loot = nullptr ;
ObjectGuid lguid = player -> GetLootWorldObjectGUID ( req . Object );
2009-10-17 15:51:44 -07:00
2014-12-30 02:23:37 +02:00
if ( lguid . IsGameObject ())
2008-10-02 16:23:55 -05:00
{
2014-12-30 02:23:37 +02:00
GameObject * go = player -> GetMap () -> GetGameObject ( lguid );
2009-10-17 15:51:44 -07:00
2014-12-30 02:23:37 +02:00
// not check distance for GO in case owned GO (fishing bobber case, for example) or Fishing hole GO
2019-05-02 21:53:12 +02:00
if ( ! go || (( go -> GetOwnerGUID () != _player -> GetGUID () && go -> GetGoType () != GAMEOBJECT_TYPE_FISHINGHOLE ) && ! go -> IsWithinDistInMap ( _player )))
2014-12-30 02:23:37 +02:00
{
player -> SendLootRelease ( lguid );
continue ;
}
2009-10-17 15:51:44 -07:00
2014-12-30 02:23:37 +02:00
loot = & go -> loot ;
2008-10-02 16:23:55 -05:00
}
2014-12-30 02:23:37 +02:00
else if ( lguid . IsItem ())
2008-11-21 19:45:49 -06:00
{
2014-12-30 02:23:37 +02:00
Item * pItem = player -> GetItemByGuid ( lguid );
2010-09-11 21:28:55 +02:00
2014-12-30 02:23:37 +02:00
if ( ! pItem )
{
player -> SendLootRelease ( lguid );
continue ;
}
2009-10-17 15:51:44 -07:00
2014-12-30 02:23:37 +02:00
loot = & pItem -> loot ;
}
else if ( lguid . IsCorpse ())
2008-10-02 16:23:55 -05:00
{
2014-12-30 02:23:37 +02:00
Corpse * bones = ObjectAccessor :: GetCorpse ( * player , lguid );
if ( ! bones )
{
player -> SendLootRelease ( lguid );
continue ;
}
loot = & bones -> loot ;
2008-10-02 16:23:55 -05:00
}
2014-12-30 02:23:37 +02:00
else
{
Creature * creature = GetPlayer () -> GetMap () -> GetCreature ( lguid );
2009-10-17 15:51:44 -07:00
2019-07-01 21:36:32 +02:00
bool lootAllowed = creature && creature -> IsAlive () == ( player -> GetClass () == CLASS_ROGUE && creature -> loot . loot_type == LOOT_PICKPOCKETING );
2016-12-31 20:50:39 +01:00
if ( ! lootAllowed || ! creature -> IsWithinDistInMap ( _player , AELootCreatureCheck :: LootDistance ))
2014-12-30 02:23:37 +02:00
{
2016-12-31 20:50:39 +01:00
player -> SendLootError ( req . Object , lguid , lootAllowed ? LOOT_ERROR_TOO_FAR : LOOT_ERROR_DIDNT_KILL );
2014-12-30 02:23:37 +02:00
continue ;
}
loot = & creature -> loot ;
}
2009-10-17 15:51:44 -07:00
2016-12-28 01:12:01 +01:00
player -> StoreLootItem ( req . LootListID - 1 , loot , aeResultPtr );
2012-12-14 00:46:36 -05:00
2014-12-30 02:23:37 +02:00
// If player is removing the last LootItem, delete the empty container.
if ( loot -> isLooted () && lguid . IsItem ())
player -> GetSession () -> DoLootRelease ( lguid );
}
2016-12-28 01:12:01 +01:00
if ( aeResultPtr )
{
for ( AELootResult :: ResultValue const & resultValue : aeResult )
{
player -> SendNewItem ( resultValue . item , resultValue . count , false , false , true );
2021-09-08 22:07:01 +02:00
player -> UpdateCriteria ( CriteriaType :: LootItem , resultValue . item -> GetEntry (), resultValue . count );
player -> UpdateCriteria ( CriteriaType :: GetLootByType , resultValue . item -> GetEntry (), resultValue . count , resultValue . lootType );
player -> UpdateCriteria ( CriteriaType :: LootAnyItem , resultValue . item -> GetEntry (), resultValue . count );
2016-12-28 01:12:01 +01:00
}
}
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2015-01-16 12:50:09 +03:00
void WorldSession :: HandleLootMoneyOpcode ( WorldPackets :: Loot :: LootMoney & /*packet*/ )
2008-10-02 16:23:55 -05:00
{
2011-05-29 14:32:46 +02:00
Player * player = GetPlayer ();
2019-05-18 22:21:17 +02:00
for ( std :: pair < ObjectGuid const , ObjectGuid > const & lootView : player -> GetAELootView ())
2008-10-02 16:23:55 -05:00
{
2016-12-28 01:12:01 +01:00
ObjectGuid guid = lootView . second ;
Loot * loot = nullptr ;
bool shareMoney = true ;
2009-10-17 15:51:44 -07:00
2016-12-28 01:12:01 +01:00
switch ( guid . GetHigh ())
2008-10-02 16:23:55 -05:00
{
2016-12-28 01:12:01 +01:00
case HighGuid :: GameObject :
2011-05-11 20:39:26 +07:00
{
2016-12-28 01:12:01 +01:00
GameObject * go = GetPlayer () -> GetMap () -> GetGameObject ( guid );
2009-10-17 15:51:44 -07:00
2016-12-28 01:12:01 +01:00
// do not check distance for GO if player is the owner of it (ex. fishing bobber)
2019-05-02 21:53:12 +02:00
if ( go && (( go -> GetOwnerGUID () == player -> GetGUID () || go -> IsWithinDistInMap ( player ))))
2016-12-28 01:12:01 +01:00
loot = & go -> loot ;
break ;
}
case HighGuid :: Corpse : // remove insignia ONLY in BG
2011-05-11 20:39:26 +07:00
{
2016-12-28 01:12:01 +01:00
Corpse * bones = ObjectAccessor :: GetCorpse ( * player , guid );
if ( bones && bones -> IsWithinDistInMap ( player , INTERACTION_DISTANCE ))
{
loot = & bones -> loot ;
shareMoney = false ;
}
break ;
2011-05-11 20:39:26 +07:00
}
2016-12-28 01:12:01 +01:00
case HighGuid :: Item :
2011-05-11 20:39:26 +07:00
{
2016-12-28 01:12:01 +01:00
if ( Item * item = player -> GetItemByGuid ( guid ))
{
loot = & item -> loot ;
2011-05-11 20:39:26 +07:00
shareMoney = false ;
2016-12-28 01:12:01 +01:00
}
break ;
2011-05-11 20:39:26 +07:00
}
2016-12-28 01:12:01 +01:00
case HighGuid :: Creature :
case HighGuid :: Vehicle :
{
Creature * creature = player -> GetMap () -> GetCreature ( guid );
2019-07-01 21:36:32 +02:00
bool lootAllowed = creature && creature -> IsAlive () == ( player -> GetClass () == CLASS_ROGUE && creature -> loot . loot_type == LOOT_PICKPOCKETING );
2016-12-31 20:50:39 +01:00
if ( lootAllowed && creature -> IsWithinDistInMap ( player , AELootCreatureCheck :: LootDistance ))
2016-12-28 01:12:01 +01:00
{
loot = & creature -> loot ;
if ( creature -> IsAlive ())
shareMoney = false ;
}
else
2016-12-31 20:50:39 +01:00
player -> SendLootError ( lootView . first , lootView . second , lootAllowed ? LOOT_ERROR_TOO_FAR : LOOT_ERROR_DIDNT_KILL );
2016-12-28 01:12:01 +01:00
break ;
}
default :
continue ; // unlootable type
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2016-12-28 01:12:01 +01:00
if ( ! loot )
continue ;
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 ;
2020-08-14 17:06:03 +02:00
for ( GroupReference * itr = group -> GetFirstMember (); itr != nullptr ; 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
2015-06-24 22:40:57 +02:00
if ( player -> IsAtGroupRewardDistance ( member ))
2011-05-29 14:32:46 +02:00
playersNear . push_back ( member );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2019-05-18 22:21:17 +02:00
uint64 goldPerPlayer = uint64 ( 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
{
2019-05-18 22:21:17 +02:00
uint64 goldMod = CalculatePct ( goldPerPlayer , ( * i ) -> GetTotalAuraModifierByMiscValue ( SPELL_AURA_MOD_MONEY_GAIN , 1 ));
2011-09-07 00:04:27 +02:00
2019-05-18 22:21:17 +02:00
( * i ) -> ModifyMoney ( goldPerPlayer + goldMod );
2021-09-08 22:07:01 +02:00
( * i ) -> UpdateCriteria ( CriteriaType :: MoneyLootedFromCreatures , goldPerPlayer );
2012-09-10 18:43:06 -05:00
2015-01-16 12:50:09 +03:00
WorldPackets :: Loot :: LootMoneyNotify packet ;
packet . Money = goldPerPlayer ;
2019-05-18 22:21:17 +02:00
packet . MoneyMod = goldMod ;
2015-01-16 12:50:09 +03:00
packet . SoleLooter = playersNear . size () <= 1 ? true : false ;
( * i ) -> SendDirectMessage ( packet . Write ());
2008-10-02 16:23:55 -05:00
}
}
else
2009-03-05 09:22:43 -06:00
{
2019-05-18 22:21:17 +02:00
uint64 goldMod = CalculatePct ( loot -> gold , player -> GetTotalAuraModifierByMiscValue ( SPELL_AURA_MOD_MONEY_GAIN , 1 ));
2011-09-07 00:04:27 +02:00
2019-05-18 22:21:17 +02:00
player -> ModifyMoney ( loot -> gold + goldMod );
2021-09-08 22:07:01 +02:00
player -> UpdateCriteria ( CriteriaType :: MoneyLootedFromCreatures , loot -> gold );
2012-09-10 18:43:06 -05:00
2015-01-16 12:50:09 +03:00
WorldPackets :: Loot :: LootMoneyNotify packet ;
packet . Money = loot -> gold ;
2019-05-18 22:21:17 +02:00
packet . MoneyMod = goldMod ;
2015-01-16 12:50:09 +03:00
packet . SoleLooter = true ; // "You loot..."
SendPacket ( packet . Write ());
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
2014-10-22 19:33:06 +02:00
if ( ! loot -> containerID . IsEmpty ())
2017-04-12 03:22:50 +02:00
sLootItemStorage -> RemoveStoredMoneyForContainer ( loot -> containerID . GetCounter ());
2012-12-14 00:46:36 -05:00
// Delete container if empty
2014-09-14 16:14:12 +02:00
if ( loot -> isLooted () && guid . IsItem ())
2012-12-14 00:46:36 -05:00
player -> GetSession () -> DoLootRelease ( guid );
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
2014-12-29 02:54:44 +02:00
void WorldSession :: HandleLootOpcode ( WorldPackets :: Loot :: LootUnit & packet )
2008-10-02 16:23:55 -05:00
{
2009-07-10 08:34:28 +08:00
// Check possible cheat
2014-12-29 02:54:44 +02:00
if ( ! GetPlayer () -> IsAlive () || ! packet . Unit . IsCreatureOrVehicle ())
2009-07-10 08:34:28 +08:00
return ;
2009-10-17 15:51:44 -07:00
2016-12-28 01:12:01 +01:00
std :: list < Creature *> corpses ;
AELootCreatureCheck check ( _player , packet . Unit );
Trinity :: CreatureListSearcher < AELootCreatureCheck > searcher ( _player , corpses , check );
2017-05-13 19:37:33 +02:00
Cell :: VisitGridObjects ( _player , searcher , AELootCreatureCheck :: LootDistance );
2016-12-28 01:12:01 +01:00
if ( ! corpses . empty ())
SendPacket ( WorldPackets :: Loot :: AELootTargets ( uint32 ( corpses . size () + 1 )). Write ());
2014-12-29 02:54:44 +02:00
GetPlayer () -> SendLoot ( packet . Unit , LOOT_CORPSE );
2010-09-13 04:02:57 +03:00
2016-12-28 01:12:01 +01:00
if ( ! corpses . empty ())
{
// main target
SendPacket ( WorldPackets :: Loot :: AELootTargetsAck (). Write ());
for ( Creature * creature : corpses )
{
GetPlayer () -> SendLoot ( creature -> GetGUID (), LOOT_CORPSE , true );
SendPacket ( WorldPackets :: Loot :: AELootTargetsAck (). Write ());
}
}
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 );
2021-03-21 12:05:32 +01:00
GetPlayer () -> RemoveAurasWithInterruptFlags ( SpellAuraInterruptFlags :: Looting );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2015-01-16 12:50:09 +03:00
void WorldSession :: HandleLootReleaseOpcode ( WorldPackets :: Loot :: LootRelease & packet )
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
2016-12-28 01:12:01 +01:00
if ( GetPlayer () -> HasLootWorldObjectGUID ( packet . Unit ))
DoLootRelease ( packet . Unit );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2014-09-14 16:14:12 +02:00
void WorldSession :: DoLootRelease ( ObjectGuid lguid )
2008-10-02 16:23:55 -05:00
{
Player * player = GetPlayer ();
Loot * loot ;
2009-10-17 15:51:44 -07:00
2016-12-28 01:12:01 +01:00
if ( player -> GetLootGUID () == lguid )
player -> SetLootGUID ( ObjectGuid :: Empty );
2021-03-28 14:18:34 +02:00
2008-10-02 16:23:55 -05:00
player -> SendLootRelease ( lguid );
2021-03-28 14:18:34 +02:00
player -> RemoveAELootedWorldObject ( lguid );
2009-10-17 15:51:44 -07:00
2019-06-03 20:40:34 +02:00
player -> RemoveUnitFlag ( 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
2014-09-14 16:14:12 +02:00
if ( lguid . IsGameObject ())
2008-10-02 16:23:55 -05:00
{
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
2019-05-02 21:53:12 +02:00
if ( ! go || (( go -> GetOwnerGUID () != _player -> GetGUID () && go -> GetGoType () != GAMEOBJECT_TYPE_FISHINGHOLE ) && ! go -> IsWithinDistInMap ( _player )))
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-09-14 16:14:12 +02:00
loot -> roundRobinPlayer . Clear ();
2010-03-11 22:55:02 +01:00
}
2008-10-02 16:23:55 -05:00
}
2014-09-14 16:14:12 +02:00
else if ( lguid . IsCorpse ()) // ONLY remove insignia at BG
2008-10-02 16:23:55 -05:00
{
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 ();
2019-06-03 20:40:34 +02:00
corpse -> RemoveCorpseDynamicFlag ( CORPSE_DYNFLAG_LOOTABLE );
2008-10-02 16:23:55 -05:00
}
}
2014-09-14 16:14:12 +02:00
else if ( lguid . IsItem ())
2008-10-02 16:23:55 -05:00
{
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
2021-03-28 14:18:34 +02:00
if ( pItem -> loot . loot_type == LOOT_PROSPECTING || pItem -> loot . loot_type == LOOT_MILLING )
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
2020-02-01 17:45:58 +04:00
if ( pItem -> loot . isLooted () || ! proto -> HasFlag ( ITEM_FLAG_HAS_LOOT ))
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
2019-07-01 21:36:32 +02:00
bool lootAllowed = creature && creature -> IsAlive () == ( player -> GetClass () == CLASS_ROGUE && creature -> loot . loot_type == LOOT_PICKPOCKETING );
2016-12-31 20:50:39 +01:00
if ( ! lootAllowed || ! creature -> IsWithinDistInMap ( _player , AELootCreatureCheck :: LootDistance ))
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 ())
{
2019-06-03 20:40:34 +02:00
creature -> RemoveDynamicFlag ( UNIT_DYNFLAG_LOOTABLE );
2014-06-24 20:04:07 -05:00
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-09-14 16:14:12 +02:00
loot -> roundRobinPlayer . Clear ();
2014-03-16 19:12:01 +01:00
2011-10-07 10:54:53 -05:00
if ( Group * group = player -> GetGroup ())
2020-08-14 17:06:03 +02:00
group -> SendLooter ( creature , nullptr );
2010-03-11 22:55:02 +01:00
}
2016-06-17 12:46:13 +02:00
// force dynflag update to update looter and lootable info
2019-06-03 20:40:34 +02:00
creature -> ForceUpdateFieldChange ( creature -> m_values . ModifyValue ( & Object :: m_objectData ). ModifyValue ( & UF :: ObjectData :: DynamicFlags ));
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 ());
2016-12-28 01:12:01 +01:00
}
void WorldSession :: DoLootReleaseAll ()
{
std :: unordered_map < ObjectGuid , ObjectGuid > lootView = _player -> GetAELootView ();
2019-05-18 22:21:17 +02:00
for ( std :: pair < ObjectGuid const , ObjectGuid > const & lootPair : lootView )
2016-12-28 01:12:01 +01:00
DoLootRelease ( lootPair . second );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2020-07-02 00:07:38 +02:00
void WorldSession :: HandleLootMasterGiveOpcode ( WorldPackets :: Loot :: MasterLootItem & masterLootItem )
2008-10-02 16:23:55 -05:00
{
2020-07-02 00:07:38 +02:00
AELootResult aeResult ;
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
{
2020-07-02 00:07:38 +02:00
_player -> SendLootError ( ObjectGuid :: Empty , ObjectGuid :: Empty , LOOT_ERROR_DIDNT_KILL );
2008-10-02 16:23:55 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2017-02-05 23:42:31 +01:00
// player on other map
2020-07-02 00:07:38 +02:00
Player * target = ObjectAccessor :: GetPlayer ( * _player , masterLootItem . Target );
2010-04-07 19:14:10 +02:00
if ( ! target )
2014-07-31 21:41:41 +02:00
{
2020-07-02 00:07:38 +02:00
_player -> SendLootError ( ObjectGuid :: Empty , ObjectGuid :: Empty , LOOT_ERROR_PLAYER_NOT_FOUND );
2008-10-02 16:23:55 -05:00
return ;
2014-07-31 21:41:41 +02:00
}
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
2020-07-02 00:07:38 +02:00
for ( WorldPackets :: Loot :: LootRequest const & req : masterLootItem . Loot )
2014-07-31 21:41:41 +02:00
{
2020-07-02 00:07:38 +02:00
Loot * loot = nullptr ;
ObjectGuid lootguid = _player -> GetLootWorldObjectGUID ( req . Object );
2009-10-17 15:51:44 -07:00
2020-07-02 00:07:38 +02:00
if ( ! _player -> IsInRaidWith ( target ) || ! _player -> IsInMap ( target ))
{
_player -> SendLootError ( req . Object , ObjectGuid :: Empty , LOOT_ERROR_MASTER_OTHER );
TC_LOG_INFO ( "entities.player.cheat" , "MasterLootItem: Player %s tried to give an item to ineligible player %s !" , GetPlayer () -> GetName (). c_str (), target -> GetName (). c_str ());
return ;
}
2014-01-01 21:42:15 +01:00
2020-07-02 00:07:38 +02:00
if ( GetPlayer () -> GetLootGUID (). IsCreatureOrVehicle ())
{
Creature * creature = GetPlayer () -> GetMap () -> GetCreature ( lootguid );
if ( ! creature )
return ;
2009-10-17 15:51:44 -07:00
2020-07-02 00:07:38 +02:00
loot = & creature -> loot ;
}
else if ( GetPlayer () -> GetLootGUID (). IsGameObject ())
{
GameObject * pGO = GetPlayer () -> GetMap () -> GetGameObject ( lootguid );
if ( ! pGO )
return ;
loot = & pGO -> loot ;
}
if ( ! loot )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2020-07-02 00:07:38 +02:00
uint8 slotid = req . LootListID - 1 ;
if ( slotid >= loot -> items . size () + loot -> quest_items . size ())
{
TC_LOG_DEBUG ( "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 ;
2020-07-02 00:07:38 +02:00
}
2009-10-17 15:51:44 -07:00
2020-07-02 00:07:38 +02: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
2020-07-02 00:07:38 +02:00
ItemPosCountVec dest ;
InventoryResult msg = target -> CanStoreNewItem ( NULL_BAG , NULL_SLOT , dest , item . itemid , item . count );
2019-06-15 14:17:29 +02:00
if ( ! item . AllowedForPlayer ( target , true ))
2020-07-02 00:07:38 +02:00
msg = EQUIP_ERR_CANT_EQUIP_EVER ;
if ( msg != EQUIP_ERR_OK )
{
if ( msg == EQUIP_ERR_ITEM_MAX_COUNT )
_player -> SendLootError ( req . Object , ObjectGuid :: Empty , LOOT_ERROR_MASTER_UNIQUE_ITEM );
else if ( msg == EQUIP_ERR_INV_FULL )
_player -> SendLootError ( req . Object , ObjectGuid :: Empty , LOOT_ERROR_MASTER_INV_FULL );
else
_player -> SendLootError ( req . Object , ObjectGuid :: Empty , LOOT_ERROR_MASTER_OTHER );
return ;
}
2009-10-17 15:51:44 -07:00
2020-07-02 00:07:38 +02:00
// now move item from loot to target inventory
Item * newitem = target -> StoreNewItem ( dest , item . itemid , true , item . randomBonusListId , item . GetAllowedLooters (), item . context , item . BonusListIDs );
aeResult . Add ( newitem , item . count , loot -> loot_type );
2009-10-17 15:51:44 -07:00
2020-07-02 00:07:38 +02:00
// mark as looted
item . count = 0 ;
item . is_looted = true ;
2014-07-31 21:41:41 +02:00
2020-07-02 00:07:38 +02:00
loot -> NotifyItemRemoved ( slotid );
-- loot -> unlootedCount ;
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2020-07-02 00:07:38 +02:00
for ( AELootResult :: ResultValue const & resultValue : aeResult )
{
target -> SendNewItem ( resultValue . item , resultValue . count , false , false , true );
2021-09-08 22:07:01 +02:00
target -> UpdateCriteria ( CriteriaType :: LootItem , resultValue . item -> GetEntry (), resultValue . count );
target -> UpdateCriteria ( CriteriaType :: GetLootByType , resultValue . item -> GetEntry (), resultValue . count , resultValue . lootType );
target -> UpdateCriteria ( CriteriaType :: LootAnyItem , resultValue . item -> GetEntry (), resultValue . count );
2020-07-02 00:07:38 +02:00
}
2008-10-02 16:23:55 -05:00
}
2015-08-08 18:10:02 +02:00
void WorldSession :: HandleSetLootSpecialization ( WorldPackets :: Loot :: SetLootSpecialization & packet )
{
if ( packet . SpecID )
{
if ( ChrSpecializationEntry const * chrSpec = sChrSpecializationStore . LookupEntry ( packet . SpecID ))
2019-07-01 21:36:32 +02:00
if ( chrSpec -> ClassID == GetPlayer () -> GetClass ())
2015-08-08 18:10:02 +02:00
GetPlayer () -> SetLootSpecId ( packet . SpecID );
}
else
2017-06-04 01:00:45 +02:00
GetPlayer () -> SetLootSpecId ( 0 );
2015-08-08 18:10:02 +02:00
}