[9579] Use ObjectGuid in some loot code.

Also use ObjectGuidSet instead std::set<ObjectGuid>
This commit is contained in:
VladimirMangos 2010-03-12 22:52:36 +03:00
parent acde81fc54
commit 8416702d7c
13 changed files with 447 additions and 428 deletions

View file

@ -94,7 +94,7 @@ VisibleNotifier::Notify()
// generate outOfRange for not iterate objects
i_data.AddOutOfRangeGUID(i_clientGUIDs);
for(Player::ClientGUIDs::iterator itr = i_clientGUIDs.begin();itr!=i_clientGUIDs.end();++itr)
for(ObjectGuidSet::iterator itr = i_clientGUIDs.begin();itr!=i_clientGUIDs.end();++itr)
{
i_player.m_clientGUIDs.erase(*itr);
@ -123,8 +123,8 @@ VisibleNotifier::Notify()
i_player.GetSession()->SendPacket(&packet);
// send out of range to other players if need
std::set<ObjectGuid> const& oor = i_data.GetOutOfRangeGUIDs();
for(std::set<ObjectGuid>::const_iterator iter = oor.begin(); iter != oor.end(); ++iter)
ObjectGuidSet const& oor = i_data.GetOutOfRangeGUIDs();
for(ObjectGuidSet::const_iterator iter = oor.begin(); iter != oor.end(); ++iter)
{
if(!iter->IsPlayer())
continue;

View file

@ -50,7 +50,7 @@ namespace MaNGOS
Player &i_player;
UpdateData i_data;
UpdateDataMapType i_data_updates;
Player::ClientGUIDs i_clientGUIDs;
ObjectGuidSet i_clientGUIDs;
std::set<WorldObject*> i_visibleNow;
explicit VisibleNotifier(Player &player) : i_player(player),i_clientGUIDs(player.m_clientGUIDs) {}

View file

@ -35,13 +35,15 @@ void WorldSession::HandleAutostoreLootItemOpcode( WorldPacket & recv_data )
{
sLog.outDebug("WORLD: CMSG_AUTOSTORE_LOOT_ITEM");
Player *player = GetPlayer();
uint64 lguid = player->GetLootGUID();
ObjectGuid lguid = player->GetLootGUID();
Loot *loot;
uint8 lootSlot;
recv_data >> lootSlot;
if (IS_GAMEOBJECT_GUID(lguid))
switch( lguid.GetHigh())
{
case HIGHGUID_GAMEOBJECT:
{
GameObject *go = player->GetMap()->GetGameObject(lguid);
@ -53,8 +55,9 @@ void WorldSession::HandleAutostoreLootItemOpcode( WorldPacket & recv_data )
}
loot = &go->loot;
break;
}
else if (IS_ITEM_GUID(lguid))
case HIGHGUID_ITEM:
{
Item *pItem = player->GetItemByGuid( lguid );
@ -65,8 +68,9 @@ void WorldSession::HandleAutostoreLootItemOpcode( WorldPacket & recv_data )
}
loot = &pItem->loot;
break;
}
else if (IS_CORPSE_GUID(lguid))
case HIGHGUID_CORPSE:
{
Corpse *bones = player->GetMap()->GetCorpse(lguid);
if (!bones)
@ -75,8 +79,9 @@ void WorldSession::HandleAutostoreLootItemOpcode( WorldPacket & recv_data )
return;
}
loot = &bones->loot;
break;
}
else
case HIGHGUID_UNIT:
{
Creature* pCreature = GetPlayer()->GetMap()->GetCreature(lguid);
@ -89,6 +94,13 @@ void WorldSession::HandleAutostoreLootItemOpcode( WorldPacket & recv_data )
}
loot = &pCreature->loot;
break;
}
default:
{
sLog.outError("%s is unsupported for looting.",lguid.GetString().c_str());
return;
}
}
QuestItem *qitem = NULL;
@ -162,13 +174,13 @@ void WorldSession::HandleLootMoneyOpcode( WorldPacket & /*recv_data*/ )
sLog.outDebug("WORLD: CMSG_LOOT_MONEY");
Player *player = GetPlayer();
uint64 guid = player->GetLootGUID();
if(!guid)
ObjectGuid guid = player->GetLootGUID();
if (guid.IsEmpty())
return;
Loot *pLoot = NULL;
switch(GUID_HIPART(guid))
switch(guid.GetHigh())
{
case HIGHGUID_GAMEOBJECT:
{
@ -210,9 +222,9 @@ void WorldSession::HandleLootMoneyOpcode( WorldPacket & /*recv_data*/ )
return; // unlootable type
}
if( pLoot )
if (pLoot)
{
if (!IS_ITEM_GUID(guid) && player->GetGroup()) //item can be looted only single player
if (!guid.IsItem() && player->GetGroup()) //item can be looted only single player
{
Group *group = player->GetGroup();
@ -274,7 +286,7 @@ void WorldSession::HandleLootReleaseOpcode( WorldPacket & recv_data )
DoLootRelease(lguid);
}
void WorldSession::DoLootRelease( uint64 lguid )
void WorldSession::DoLootRelease(ObjectGuid lguid)
{
Player *player = GetPlayer();
Loot *loot;
@ -287,7 +299,9 @@ void WorldSession::DoLootRelease( uint64 lguid )
if(!player->IsInWorld())
return;
if (IS_GAMEOBJECT_GUID(lguid))
switch(lguid.GetHigh())
{
case HIGHGUID_GAMEOBJECT:
{
GameObject *go = GetPlayer()->GetMap()->GetGameObject(lguid);
@ -366,8 +380,9 @@ void WorldSession::DoLootRelease( uint64 lguid )
else
// not fully looted object
go->SetLootState(GO_ACTIVATED);
break;
}
else if (IS_CORPSE_GUID(lguid)) // ONLY remove insignia at BG
case HIGHGUID_CORPSE: // ONLY remove insignia at BG
{
Corpse *corpse = _player->GetMap()->GetCorpse(lguid);
if (!corpse || !corpse->IsWithinDistInMap(_player,INTERACTION_DISTANCE) )
@ -380,8 +395,9 @@ void WorldSession::DoLootRelease( uint64 lguid )
loot->clear();
corpse->RemoveFlag(CORPSE_FIELD_DYNAMIC_FLAGS, CORPSE_DYNFLAG_LOOTABLE);
}
break;
}
else if (IS_ITEM_GUID(lguid))
case HIGHGUID_ITEM:
{
Item *pItem = player->GetItemByGuid(lguid );
if(!pItem)
@ -409,7 +425,7 @@ void WorldSession::DoLootRelease( uint64 lguid )
player->DestroyItem( pItem->GetBagSlot(),pItem->GetSlot(), true);
return; // item can be looted only single player
}
else
case HIGHGUID_UNIT:
{
Creature* pCreature = GetPlayer()->GetMap()->GetCreature(lguid);
@ -434,6 +450,13 @@ void WorldSession::DoLootRelease( uint64 lguid )
pCreature->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE);
loot->clear();
}
break;
}
default:
{
sLog.outError("%s is unsupported for looting.", lguid.GetString().c_str());
return;
}
}
//Player is not looking at loot list, he doesn't need to see updates on the loot list

View file

@ -75,9 +75,7 @@ enum HighGuid
#define IS_PLAYER_GUID(Guid) ( GUID_HIPART(Guid) == HIGHGUID_PLAYER && Guid!=0 )
#define IS_UNIT_GUID(Guid) ( IS_CREATURE_OR_PET_GUID(Guid) || IS_PLAYER_GUID(Guid) )
// special case for empty guid need check
#define IS_ITEM_GUID(Guid) ( GUID_HIPART(Guid) == HIGHGUID_ITEM )
#define IS_GAMEOBJECT_GUID(Guid) ( GUID_HIPART(Guid) == HIGHGUID_GAMEOBJECT )
#define IS_CORPSE_GUID(Guid) ( GUID_HIPART(Guid) == HIGHGUID_CORPSE )
#define IS_MO_TRANSPORT(Guid) ( GUID_HIPART(Guid) == HIGHGUID_MO_TRANSPORT )
// l - OBJECT_FIELD_GUID
@ -233,6 +231,8 @@ class ObjectGuid
uint64 m_guid;
};
typedef std::set<ObjectGuid> ObjectGuidSet;
class PackedGuid
{
friend ByteBuffer& operator<< (ByteBuffer& buf, PackedGuid const& guid);

View file

@ -7533,14 +7533,15 @@ void Player::RemovedInsignia(Player* looterPlr)
looterPlr->SendLoot(bones->GetGUID(), LOOT_INSIGNIA);
}
void Player::SendLootRelease( uint64 guid )
void Player::SendLootRelease(ObjectGuid guid)
{
WorldPacket data( SMSG_LOOT_RELEASE_RESPONSE, (8+1) );
data << uint64(guid) << uint8(1);
data << guid;
data << uint8(1);
SendDirectMessage( &data );
}
void Player::SendLoot(uint64 guid, LootType loot_type)
void Player::SendLoot(ObjectGuid guid, LootType loot_type)
{
if (uint64 lguid = GetLootGUID())
m_session->DoLootRelease(lguid);
@ -7549,7 +7550,9 @@ void Player::SendLoot(uint64 guid, LootType loot_type)
PermissionTypes permission = ALL_PERMISSION;
sLog.outDebug("Player::SendLoot");
if (IS_GAMEOBJECT_GUID(guid))
switch(guid.GetHigh())
{
case HIGHGUID_GAMEOBJECT:
{
sLog.outDebug(" IS_GAMEOBJECT_GUID(guid)");
GameObject *go = GetMap()->GetGameObject(guid);
@ -7588,8 +7591,9 @@ void Player::SendLoot(uint64 guid, LootType loot_type)
go->SetLootState(GO_ACTIVATED);
}
break;
}
else if (IS_ITEM_GUID(guid))
case HIGHGUID_ITEM:
{
Item *item = GetItemByGuid( guid );
@ -7623,8 +7627,9 @@ void Player::SendLoot(uint64 guid, LootType loot_type)
break;
}
}
break;
}
else if (IS_CORPSE_GUID(guid)) // remove insignia
case HIGHGUID_CORPSE: // remove insignia
{
Corpse *bones = GetMap()->GetCorpse(guid);
@ -7650,8 +7655,9 @@ void Player::SendLoot(uint64 guid, LootType loot_type)
if (bones->lootRecipient != this)
permission = NONE_PERMISSION;
break;
}
else
case HIGHGUID_UNIT:
{
Creature *creature = GetMap()->GetCreature(guid);
@ -7768,6 +7774,13 @@ void Player::SendLoot(uint64 guid, LootType loot_type)
permission = NONE_PERMISSION;
}
}
break;
}
default:
{
sLog.outError("%s is unsupported for looting.", guid.GetString().c_str());
return;
}
}
SetLootGUID(guid);
@ -7785,7 +7798,7 @@ void Player::SendLoot(uint64 guid, LootType loot_type)
WorldPacket data(SMSG_LOOT_RESPONSE, (9+50)); // we guess size
data << uint64(guid);
data << guid;
data << uint8(loot_type);
data << LootView(*loot, this, permission);
@ -7795,7 +7808,7 @@ void Player::SendLoot(uint64 guid, LootType loot_type)
if (permission != NONE_PERMISSION)
loot->AddLooter(GetGUID());
if (loot_type == LOOT_CORPSE && !IS_ITEM_GUID(guid))
if (loot_type == LOOT_CORPSE && !guid.IsItem())
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_LOOTING);
}
@ -8670,47 +8683,31 @@ Item* Player::GetItemByLimitedCategory(uint32 limitedCategory) const
return NULL;
}
Item* Player::GetItemByGuid( uint64 guid ) const
Item* Player::GetItemByGuid(ObjectGuid guid) const
{
for(int i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_ITEM_END; ++i)
{
Item *pItem = GetItemByPos( INVENTORY_SLOT_BAG_0, i );
if( pItem && pItem->GetGUID() == guid )
if (Item *pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
if (pItem->GetGUID() == guid.GetRawValue())
return pItem;
}
for(int i = KEYRING_SLOT_START; i < CURRENCYTOKEN_SLOT_END; ++i)
{
Item *pItem = GetItemByPos( INVENTORY_SLOT_BAG_0, i );
if( pItem && pItem->GetGUID() == guid )
if (Item *pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
if (pItem->GetGUID() == guid.GetRawValue())
return pItem;
}
for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
{
Bag *pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i );
if( pBag )
{
if (Bag *pBag = (Bag*)GetItemByPos(INVENTORY_SLOT_BAG_0, i))
for(uint32 j = 0; j < pBag->GetBagSize(); ++j)
{
Item* pItem = pBag->GetItemByPos( j );
if( pItem && pItem->GetGUID() == guid )
if (Item* pItem = pBag->GetItemByPos(j))
if (pItem->GetGUID() == guid.GetRawValue())
return pItem;
}
}
}
for(int i = BANK_SLOT_BAG_START; i < BANK_SLOT_BAG_END; ++i)
{
Bag *pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i );
if( pBag )
{
if (Bag *pBag = (Bag*)GetItemByPos(INVENTORY_SLOT_BAG_0, i))
for(uint32 j = 0; j < pBag->GetBagSize(); ++j)
{
Item* pItem = pBag->GetItemByPos( j );
if( pItem && pItem->GetGUID() == guid )
if (Item* pItem = pBag->GetItemByPos(j))
if (pItem->GetGUID() == guid.GetRawValue())
return pItem;
}
}
}
return NULL;
}
@ -18876,13 +18873,13 @@ void Player::UpdateVisibilityOf(WorldObject const* viewPoint, WorldObject* targe
}
template<class T>
inline void UpdateVisibilityOf_helper(std::set<ObjectGuid>& s64, T* target)
inline void UpdateVisibilityOf_helper(ObjectGuidSet& s64, T* target)
{
s64.insert(target->GetGUID());
}
template<>
inline void UpdateVisibilityOf_helper(std::set<ObjectGuid>& s64, GameObject* target)
inline void UpdateVisibilityOf_helper(ObjectGuidSet& s64, GameObject* target)
{
if(!target->IsTransport())
s64.insert(target->GetGUID());
@ -19529,7 +19526,7 @@ void Player::UpdateForQuestWorldObjects()
UpdateData udata;
WorldPacket packet;
for(ClientGUIDs::const_iterator itr=m_clientGUIDs.begin(); itr!=m_clientGUIDs.end(); ++itr)
for(ObjectGuidSet::const_iterator itr=m_clientGUIDs.begin(); itr!=m_clientGUIDs.end(); ++itr)
{
if (itr->IsGameobject())
{

View file

@ -1149,7 +1149,7 @@ class MANGOS_DLL_SPEC Player : public Unit
uint8 FindEquipSlot( ItemPrototype const* proto, uint32 slot, bool swap ) const;
uint32 GetItemCount( uint32 item, bool inBankAlso = false, Item* skipItem = NULL ) const;
uint32 GetItemCountWithLimitCategory(uint32 limitCategory) const;
Item* GetItemByGuid( uint64 guid ) const;
Item* GetItemByGuid(ObjectGuid uint64) const;
Item* GetItemByEntry(uint32 item) const; // only for special cases
Item* GetItemByLimitedCategory(uint32 limitedCategory) const;
Item* GetItemByPos( uint16 pos ) const;
@ -1789,8 +1789,8 @@ class MANGOS_DLL_SPEC Player : public Unit
void ApplyManaRegenBonus(int32 amount, bool apply);
void UpdateManaRegen();
const uint64& GetLootGUID() const { return m_lootGuid; }
void SetLootGUID(const uint64 &guid) { m_lootGuid = guid; }
const uint64& GetLootGUID() const { return m_lootGuid.GetRawValue(); }
void SetLootGUID(ObjectGuid const& guid) { m_lootGuid = guid; }
void RemovedInsignia(Player* looterPlr);
@ -1985,8 +1985,8 @@ class MANGOS_DLL_SPEC Player : public Unit
PlayerMenu* PlayerTalkClass;
std::vector<ItemSetEffect *> ItemSetEff;
void SendLoot(uint64 guid, LootType loot_type);
void SendLootRelease( uint64 guid );
void SendLoot(ObjectGuid guid, LootType loot_type);
void SendLootRelease(ObjectGuid guid );
void SendNotifyLootItemRemoved(uint8 lootSlot);
void SendNotifyLootMoneyRemoved();
@ -2178,8 +2178,7 @@ class MANGOS_DLL_SPEC Player : public Unit
Object* GetObjectByTypeMask(ObjectGuid guid, TypeMask typemask);
// currently visible objects at player client
typedef std::set<ObjectGuid> ClientGUIDs;
ClientGUIDs m_clientGUIDs;
ObjectGuidSet m_clientGUIDs;
bool HaveAtClient(WorldObject const* u) { return u==this || m_clientGUIDs.find(u->GetGUID())!=m_clientGUIDs.end(); }
@ -2375,7 +2374,7 @@ class MANGOS_DLL_SPEC Player : public Unit
time_t m_lastHonorUpdateTime;
void outDebugValues() const;
uint64 m_lootGuid;
ObjectGuid m_lootGuid;
uint32 m_team;
uint32 m_nextSave;

View file

@ -639,7 +639,7 @@ void WorldSession::HandleQuestgiverStatusMultipleQuery(WorldPacket& /*recvPacket
WorldPacket data(SMSG_QUESTGIVER_STATUS_MULTIPLE, 4);
data << uint32(count); // placeholder
for(Player::ClientGUIDs::const_iterator itr = _player->m_clientGUIDs.begin(); itr != _player->m_clientGUIDs.end(); ++itr)
for(ObjectGuidSet::const_iterator itr = _player->m_clientGUIDs.begin(); itr != _player->m_clientGUIDs.end(); ++itr)
{
uint8 questStatus = DIALOG_STATUS_NONE;
uint8 defstatus = DIALOG_STATUS_NONE;

View file

@ -192,7 +192,7 @@ void SpellCastTargets::Update(Unit* caster)
if(caster->GetTypeId() == TYPEID_PLAYER)
{
if(m_targetMask & TARGET_FLAG_ITEM)
m_itemTarget = ((Player*)caster)->GetItemByGuid(m_itemTargetGUID.GetRawValue());
m_itemTarget = ((Player*)caster)->GetItemByGuid(m_itemTargetGUID);
else if(m_targetMask & TARGET_FLAG_TRADE_ITEM)
{
Player* pTrader = ((Player*)caster)->GetTrader();

View file

@ -30,7 +30,7 @@ UpdateData::UpdateData() : m_blockCount(0)
{
}
void UpdateData::AddOutOfRangeGUID(std::set<ObjectGuid>& guids)
void UpdateData::AddOutOfRangeGUID(ObjectGuidSet& guids)
{
m_outOfRangeGUIDs.insert(guids.begin(),guids.end());
}
@ -115,7 +115,7 @@ bool UpdateData::BuildPacket(WorldPacket *packet)
buf << (uint8) UPDATETYPE_OUT_OF_RANGE_OBJECTS;
buf << (uint32) m_outOfRangeGUIDs.size();
for(std::set<ObjectGuid>::const_iterator i = m_outOfRangeGUIDs.begin(); i != m_outOfRangeGUIDs.end(); ++i)
for(ObjectGuidSet::const_iterator i = m_outOfRangeGUIDs.begin(); i != m_outOfRangeGUIDs.end(); ++i)
buf << i->WriteAsPacked();
}

View file

@ -20,9 +20,9 @@
#define __UPDATEDATA_H
#include "ByteBuffer.h"
#include "ObjectGuid.h"
class WorldPacket;
class ObjectGuid;
enum OBJECT_UPDATE_TYPE
{
@ -54,18 +54,18 @@ class UpdateData
public:
UpdateData();
void AddOutOfRangeGUID(std::set<ObjectGuid>& guids);
void AddOutOfRangeGUID(ObjectGuidSet& guids);
void AddOutOfRangeGUID(ObjectGuid const &guid);
void AddUpdateBlock(const ByteBuffer &block);
bool BuildPacket(WorldPacket *packet);
bool HasData() { return m_blockCount > 0 || !m_outOfRangeGUIDs.empty(); }
void Clear();
std::set<ObjectGuid> const& GetOutOfRangeGUIDs() const { return m_outOfRangeGUIDs; }
ObjectGuidSet const& GetOutOfRangeGUIDs() const { return m_outOfRangeGUIDs; }
protected:
uint32 m_blockCount;
std::set<ObjectGuid> m_outOfRangeGUIDs;
ObjectGuidSet m_outOfRangeGUIDs;
ByteBuffer m_data;
void Compress(void* dst, uint32 *dst_size, void* src, int src_size);

View file

@ -255,7 +255,7 @@ class MANGOS_DLL_SPEC WorldSession
void BuildPartyMemberStatsChangedPacket(Player *player, WorldPacket *data);
void DoLootRelease( uint64 lguid );
void DoLootRelease(ObjectGuid lguid);
// Account mute time
time_t m_muteTime;

View file

@ -692,7 +692,7 @@ bool ChatHandler::HandleDebugGetItemValueCommand(const char* args)
uint32 guid = (uint32)atoi(e);
uint32 index = (uint32)atoi(f);
Item *i = m_session->GetPlayer()->GetItemByGuid(MAKE_NEW_GUID(guid, 0, HIGHGUID_ITEM));
Item *i = m_session->GetPlayer()->GetItemByGuid(ObjectGuid(HIGHGUID_ITEM, guid));
if (!i)
return false;
@ -723,7 +723,7 @@ bool ChatHandler::HandleDebugSetItemValueCommand(const char* args)
uint32 index = (uint32)atoi(f);
uint32 value = (uint32)atoi(g);
Item *i = m_session->GetPlayer()->GetItemByGuid(MAKE_NEW_GUID(guid, 0, HIGHGUID_ITEM));
Item *i = m_session->GetPlayer()->GetItemByGuid(ObjectGuid(HIGHGUID_ITEM, guid));
if (!i)
return false;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9578"
#define REVISION_NR "9579"
#endif // __REVISION_NR_H__