Skip to content

Commit

Permalink
[8968] Implement gossip menu options for GameObject
Browse files Browse the repository at this point in the history
Signed-off-by: NoFantasy <nofantasy@nf.no>
  • Loading branch information
NoFantasy committed Dec 11, 2009
1 parent 3c6e7b2 commit b3ff44a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
45 changes: 31 additions & 14 deletions src/game/NPCHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
15 changes: 7 additions & 8 deletions src/game/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "8967"
#define REVISION_NR "8968"
#endif // __REVISION_NR_H__

2 comments on commit b3ff44a

@VladimirMangos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what you will do with it if client not support... ?

@LordJZ
Copy link
Contributor

@LordJZ LordJZ commented on b3ff44a Dec 11, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If client not supports it, i'm wondering how it is implemented in ascent.

Please sign in to comment.