From f0e7f01a7b13b3403b10c7cdbb4f2637a83eda9b Mon Sep 17 00:00:00 2001 From: NoFantasy Date: Fri, 11 Dec 2009 11:07:34 +0100 Subject: [PATCH] [8968] Implement gossip menu options for GameObject Signed-off-by: NoFantasy --- src/game/NPCHandler.cpp | 45 +++++++++++++++++++++++++++------------- src/game/Player.cpp | 15 +++++++------- src/game/Player.h | 2 +- src/shared/revision_nr.h | 2 +- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp index d0451cd0d..80a049303 100644 --- a/src/game/NPCHandler.cpp +++ b/src/game/NPCHandler.cpp @@ -300,27 +300,44 @@ void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket & recv_data ) sLog.outBasic("string read: %s", code.c_str()); } - Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE); - - if (!pCreature) - { - sLog.outDebug( "WORLD: HandleGossipSelectOptionOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); - return; - } - // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); - if (!code.empty()) + // TODO: determine if scriptCall is needed for GO and also if scriptCall can be same as current, with modified argument WorldObject* + + if (IS_CREATURE_GUID(guid)) { - if (!Script->GossipSelectWithCode(_player, pCreature, _player->PlayerTalkClass->GossipOptionSender(gossipListId), _player->PlayerTalkClass->GossipOptionAction(gossipListId), code.c_str())) - _player->OnGossipSelect(pCreature, gossipListId, menuId); + 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))); + return; + } + + if (!code.empty()) + { + if (!Script->GossipSelectWithCode(_player, pCreature, _player->PlayerTalkClass->GossipOptionSender(gossipListId), _player->PlayerTalkClass->GossipOptionAction(gossipListId), code.c_str())) + _player->OnGossipSelect(pCreature, gossipListId, menuId); + } + else + { + if (!Script->GossipSelect(_player, pCreature, _player->PlayerTalkClass->GossipOptionSender(gossipListId), _player->PlayerTalkClass->GossipOptionAction(gossipListId))) + _player->OnGossipSelect(pCreature, gossipListId, menuId); + } } - else + else if (IS_GAMEOBJECT_GUID(guid)) { - if (!Script->GossipSelect(_player, pCreature, _player->PlayerTalkClass->GossipOptionSender(gossipListId), _player->PlayerTalkClass->GossipOptionAction(gossipListId))) - _player->OnGossipSelect(pCreature, gossipListId, menuId); + 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))); + return; + } + + _player->OnGossipSelect(pGo, gossipListId, menuId); } } diff --git a/src/game/Player.cpp b/src/game/Player.cpp index e89b34f9c..61b06b0ea 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -2117,14 +2117,14 @@ Creature* Player::GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask) return unit; } -GameObject* Player::GetGameObjectIfCanInteractWith(uint64 guid, GameobjectTypes type) const +GameObject* Player::GetGameObjectIfCanInteractWith(uint64 guid, uint32 gameobject_type) const { - if(GameObject *go = GetMap()->GetGameObject(guid)) + if (GameObject *go = GetMap()->GetGameObject(guid)) { - if(go->GetGoType() == type) + if (uint32(go->GetGoType()) == gameobject_type || gameobject_type == MAX_GAMEOBJECT_TYPE) { float maxdist; - switch(type) + switch(go->GetGoType()) { // TODO: find out how the client calculates the maximal usage distance to spellless working // gameobjects like guildbanks and mailboxes - 10.0 is a just an abitrary choosen number @@ -2140,10 +2140,10 @@ GameObject* Player::GetGameObjectIfCanInteractWith(uint64 guid, GameobjectTypes break; } - if (go->IsWithinDistInMap(this, maxdist)) + if (go->IsWithinDistInMap(this, maxdist) && go->isSpawned()) return go; - sLog.outError("IsGameObjectOfTypeInRange: GameObject '%s' [GUID: %u] is too far away from player %s [GUID: %u] to be used by him (distance=%f, maximal 10 is allowed)", go->GetGOInfo()->name, + sLog.outError("GetGameObjectIfCanInteractWith: GameObject '%s' [GUID: %u] is too far away from player %s [GUID: %u] to be used by him (distance=%f, maximal 10 is allowed)", go->GetGOInfo()->name, go->GetGUIDLow(), GetName(), GetGUIDLow(), go->GetDistance(this)); } } @@ -12287,11 +12287,10 @@ void Player::PrepareGossipMenu(WorldObject *pSource, uint32 menuId) bCanTalk = false; break; case GOSSIP_OPTION_GOSSIP: - if (pGo->GetGoType() != GAMEOBJECT_TYPE_QUESTGIVER || pGo->GetGoType() != GAMEOBJECT_TYPE_GOOBER) + if (pGo->GetGoType() != GAMEOBJECT_TYPE_QUESTGIVER && pGo->GetGoType() != GAMEOBJECT_TYPE_GOOBER) bCanTalk = false; break; default: - sLog.outErrorDb("GameObject entry %u are using invalid gossip option %u for menu %u", pGo->GetEntry(), itr->second.option_id, itr->second.menu_id); bCanTalk = false; break; } diff --git a/src/game/Player.h b/src/game/Player.h index e1b4a271e..a9a00479f 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -1066,7 +1066,7 @@ class MANGOS_DLL_SPEC Player : public Unit void SendInstanceResetWarning(uint32 mapid, Difficulty difficulty, uint32 time); Creature* GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask); - GameObject* GetGameObjectIfCanInteractWith(uint64 guid, GameobjectTypes type) const; + GameObject* GetGameObjectIfCanInteractWith(uint64 guid, uint32 gameobject_type = MAX_GAMEOBJECT_TYPE) const; void UpdateVisibilityForPlayer(); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 1de986d24..9cf4f2bc5 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "8967" + #define REVISION_NR "8968" #endif // __REVISION_NR_H__