From 2bf75e7a10efe4cc2a9019befdd20406f176e527 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sat, 13 Mar 2010 16:12:13 +0300 Subject: [PATCH] 111 --- src/game/ItemHandler.cpp | 5 ++--- src/game/LootHandler.cpp | 16 ++++++++-------- src/game/NPCHandler.cpp | 10 +++++----- src/game/ObjectGuid.h | 3 +-- src/game/Player.cpp | 12 ++++++++---- src/game/Player.h | 4 ++-- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/game/ItemHandler.cpp b/src/game/ItemHandler.cpp index 2e454418c..19b2c13cc 100644 --- a/src/game/ItemHandler.cpp +++ b/src/game/ItemHandler.cpp @@ -470,12 +470,11 @@ void WorldSession::HandlePageQuerySkippedOpcode( WorldPacket & recv_data ) sLog.outDebug( "WORLD: Received CMSG_PAGE_TEXT_QUERY" ); uint32 itemid; - uint64 guid; + ObjectGuid guid; recv_data >> itemid >> guid; - sLog.outDetail( "Packet Info: itemid: %u guidlow: %u guidentry: %u guidhigh: %u", - itemid, GUID_LOPART(guid), GUID_ENPART(guid), GUID_HIPART(guid)); + sLog.outDetail( "Packet Info: itemid: %u guid: %s", itemid, guid.GetString().c_str()); } void WorldSession::HandleSellItemOpcode( WorldPacket & recv_data ) diff --git a/src/game/LootHandler.cpp b/src/game/LootHandler.cpp index d090e0aca..944e9e821 100644 --- a/src/game/LootHandler.cpp +++ b/src/game/LootHandler.cpp @@ -466,7 +466,8 @@ void WorldSession::DoLootRelease(ObjectGuid lguid) void WorldSession::HandleLootMasterGiveOpcode( WorldPacket & recv_data ) { uint8 slotid; - uint64 lootguid, target_playerguid; + ObjectGuid lootguid; + ObjectGuid target_playerguid; recv_data >> lootguid >> slotid >> target_playerguid; @@ -476,18 +477,18 @@ void WorldSession::HandleLootMasterGiveOpcode( WorldPacket & recv_data ) return; } - Player *target = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, target_playerguid)); + Player *target = ObjectAccessor::FindPlayer(target_playerguid); if(!target) return; - sLog.outDebug("WorldSession::HandleLootMasterGiveOpcode (CMSG_LOOT_MASTER_GIVE, 0x02A3) Target = [%s].", target->GetName()); + sLog.outDebug("WorldSession::HandleLootMasterGiveOpcode (CMSG_LOOT_MASTER_GIVE, 0x02A3) Target = %s [%s].", target_playerguid.GetString().c_str(), target->GetName()); - if(_player->GetLootGUID() != lootguid) + if(_player->GetLootGUID() != lootguid.GetRawValue()) return; Loot *pLoot = NULL; - if(IS_CREATURE_GUID(GetPlayer()->GetLootGUID())) + if(lootguid.IsCreature()) { Creature *pCreature = GetPlayer()->GetMap()->GetCreature(lootguid); if(!pCreature) @@ -495,7 +496,7 @@ void WorldSession::HandleLootMasterGiveOpcode( WorldPacket & recv_data ) pLoot = &pCreature->loot; } - else if(IS_GAMEOBJECT_GUID(GetPlayer()->GetLootGUID())) + else if(lootguid.IsGameobject()) { GameObject *pGO = GetPlayer()->GetMap()->GetGameObject(lootguid); if(!pGO) @@ -503,8 +504,7 @@ void WorldSession::HandleLootMasterGiveOpcode( WorldPacket & recv_data ) pLoot = &pGO->loot; } - - if(!pLoot) + else return; if (slotid > pLoot->items.size()) diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp index ffb3752a5..5519f22b0 100644 --- a/src/game/NPCHandler.cpp +++ b/src/game/NPCHandler.cpp @@ -288,7 +288,7 @@ void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket & recv_data ) uint32 gossipListId; uint32 menuId; - uint64 guid; + ObjectGuid guid; std::string code = ""; recv_data >> guid >> menuId >> gossipListId; @@ -305,13 +305,13 @@ void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket & recv_data ) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); // can vehicle have gossip? If so, need check for this also. - if (IS_CREATURE_OR_PET_GUID(guid)) + if (guid.IsCreatureOrPet()) { Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE); if (!pCreature) { - sLog.outDebug("WORLD: HandleGossipSelectOptionOpcode - Creature (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid))); + sLog.outDebug("WORLD: HandleGossipSelectOptionOpcode - %s not found or you can't interact with it.", guid.GetString().c_str()); return; } @@ -326,13 +326,13 @@ void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket & recv_data ) _player->OnGossipSelect(pCreature, gossipListId, menuId); } } - else if (IS_GAMEOBJECT_GUID(guid)) + else if (guid.IsGameobject()) { GameObject *pGo = GetPlayer()->GetGameObjectIfCanInteractWith(guid); if (!pGo) { - sLog.outDebug("WORLD: HandleGossipSelectOptionOpcode - GameObject (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid))); + sLog.outDebug("WORLD: HandleGossipSelectOptionOpcode - %s not found or you can't interact with it.", guid.GetString().c_str()); return; } diff --git a/src/game/ObjectGuid.h b/src/game/ObjectGuid.h index ed649af37..91c66e04b 100644 --- a/src/game/ObjectGuid.h +++ b/src/game/ObjectGuid.h @@ -71,9 +71,8 @@ enum HighGuid //*** Must be replaced by ObjectGuid use *** #define IS_CREATURE_GUID(Guid) ( GUID_HIPART(Guid) == HIGHGUID_UNIT ) #define IS_PET_GUID(Guid) ( GUID_HIPART(Guid) == HIGHGUID_PET ) -#define IS_CREATURE_OR_PET_GUID(Guid)( IS_CREATURE_GUID(Guid) || IS_PET_GUID(Guid) ) #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) ) +#define IS_UNIT_GUID(Guid) ( IS_CREATURE_GUID(Guid) || IS_PET_GUID(Guid) || IS_PLAYER_GUID(Guid) ) // special case for empty guid need check #define IS_GAMEOBJECT_GUID(Guid) ( GUID_HIPART(Guid) == HIGHGUID_GAMEOBJECT ) #define IS_MO_TRANSPORT(Guid) ( GUID_HIPART(Guid) == HIGHGUID_MO_TRANSPORT ) diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 2e5f72d31..eae66fc43 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -2124,10 +2124,10 @@ void Player::RegenerateHealth(uint32 diff) ModifyHealth(int32(addvalue)); } -Creature* Player::GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask) +Creature* Player::GetNPCIfCanInteractWith(ObjectGuid guid, uint32 npcflagmask) { - // unit checks - if (!guid || !IsInWorld() || isInFlight()) + // some basic checks + if (guid.IsEmpty() || !IsInWorld() || isInFlight()) return NULL; // exist (we need look pets also for some interaction (quest/etc) @@ -2174,8 +2174,12 @@ Creature* Player::GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask) return unit; } -GameObject* Player::GetGameObjectIfCanInteractWith(uint64 guid, uint32 gameobject_type) const +GameObject* Player::GetGameObjectIfCanInteractWith(ObjectGuid guid, uint32 gameobject_type) const { + // some basic checks + if (guid.IsEmpty() || !IsInWorld() || isInFlight()) + return NULL; + if (GameObject *go = GetMap()->GetGameObject(guid)) { if (uint32(go->GetGoType()) == gameobject_type || gameobject_type == MAX_GAMEOBJECT_TYPE) diff --git a/src/game/Player.h b/src/game/Player.h index cb67f1b7e..159d8c591 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -1048,8 +1048,8 @@ class MANGOS_DLL_SPEC Player : public Unit void SendTransferAborted(uint32 mapid, uint8 reason, uint8 arg = 0); void SendInstanceResetWarning(uint32 mapid, Difficulty difficulty, uint32 time); - Creature* GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask); - GameObject* GetGameObjectIfCanInteractWith(uint64 guid, uint32 gameobject_type = MAX_GAMEOBJECT_TYPE) const; + Creature* GetNPCIfCanInteractWith(ObjectGuid guid, uint32 npcflagmask); + GameObject* GetGameObjectIfCanInteractWith(ObjectGuid guid, uint32 gameobject_type = MAX_GAMEOBJECT_TYPE) const; void UpdateVisibilityForPlayer();