From dbe089b66daa5988d6c491099411be2f12a61e2a Mon Sep 17 00:00:00 2001 From: NoFantasy Date: Thu, 11 Mar 2010 15:34:37 +0100 Subject: [PATCH] [9572] Add script calls for GameObject GossipHello and GossipSelect Signed-off-by: NoFantasy --- src/bindings/universal/ScriptMgr.cpp | 40 ++++++++++++++++++++++++++++ src/bindings/universal/ScriptMgr.h | 6 ++++- src/game/GameObject.cpp | 15 ++++++++--- src/game/NPCHandler.cpp | 13 ++++++--- src/game/ScriptCalls.cpp | 3 +++ src/game/ScriptCalls.h | 6 +++++ src/shared/revision_nr.h | 2 +- 7 files changed, 76 insertions(+), 9 deletions(-) diff --git a/src/bindings/universal/ScriptMgr.cpp b/src/bindings/universal/ScriptMgr.cpp index ab8f5ed18..634cc8a9f 100644 --- a/src/bindings/universal/ScriptMgr.cpp +++ b/src/bindings/universal/ScriptMgr.cpp @@ -79,6 +79,18 @@ bool GossipHello ( Player * player, Creature *_Creature ) return tmpscript->pGossipHello(player,_Creature); } +MANGOS_DLL_EXPORT +bool GOGossipHello(Player *pPlayer, GameObject *pGo) +{ + Script *tmpscript = m_scripts[pGo->GetGOInfo()->ScriptId]; + if (!tmpscript || !tmpscript->pGOGossipHello) + return false; + + pPlayer->PlayerTalkClass->ClearMenus(); + + return tmpscript->pGOGossipHello(pPlayer, pGo); +} + MANGOS_DLL_EXPORT bool GossipSelect( Player *player, Creature *_Creature,uint32 sender, uint32 action ) { @@ -93,6 +105,20 @@ bool GossipSelect( Player *player, Creature *_Creature,uint32 sender, uint32 act return tmpscript->pGossipSelect(player,_Creature,sender,action); } +MANGOS_DLL_EXPORT +bool GOGossipSelect(Player *pPlayer, GameObject *pGo, uint32 sender, uint32 action) +{ + debug_log("DEBUG: GO Gossip selection, sender: %u, action: %u", sender, action); + + Script *tmpscript = m_scripts[pGo->GetGOInfo()->ScriptId]; + if (!tmpscript || !tmpscript->pGOGossipSelect) + return false; + + pPlayer->PlayerTalkClass->ClearMenus(); + + return tmpscript->pGOGossipSelect(pPlayer, pGo, sender, action); +} + MANGOS_DLL_EXPORT bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, uint32 action, const char* sCode ) { @@ -107,6 +133,20 @@ bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, u return tmpscript->pGossipSelectWithCode(player,_Creature,sender,action,sCode); } +MANGOS_DLL_EXPORT +bool GOGossipSelectWithCode(Player *pPlayer, GameObject *pGo, uint32 sender, uint32 action, const char* sCode) +{ + debug_log("DEBUG: GO Gossip selection, sender: %u, action: %u", sender, action); + + Script *tmpscript = m_scripts[pGo->GetGOInfo()->ScriptId]; + if (!tmpscript || !tmpscript->pGOGossipSelectWithCode) + return false; + + pPlayer->PlayerTalkClass->ClearMenus(); + + return tmpscript->pGOGossipSelectWithCode(pPlayer, pGo, sender, action, sCode); +} + MANGOS_DLL_EXPORT bool QuestAccept( Player *player, Creature *_Creature, Quest *_Quest ) { diff --git a/src/bindings/universal/ScriptMgr.h b/src/bindings/universal/ScriptMgr.h index c18bc5265..e5e27f216 100644 --- a/src/bindings/universal/ScriptMgr.h +++ b/src/bindings/universal/ScriptMgr.h @@ -39,7 +39,8 @@ class Aura; struct Script { Script() : - pGossipHello(NULL), pQuestAccept(NULL), pGossipSelect(NULL), pGossipSelectWithCode(NULL), + pGossipHello(NULL), pGOGossipHello(NULL), pQuestAccept(NULL), pGossipSelect(NULL), pGOGossipSelect(NULL), + pGossipSelectWithCode(NULL), pGOGossipSelectWithCode(NULL), pQuestSelect(NULL), pQuestComplete(NULL), pNPCDialogStatus(NULL), pGODialogStatus(NULL), pChooseReward(NULL), pItemHello(NULL), pGOHello(NULL), pAreaTrigger(NULL), pItemQuestAccept(NULL), pGOQuestAccept(NULL), pGOChooseReward(NULL), pItemUse(NULL), pEffectDummyGameObj(NULL), pEffectDummyCreature(NULL), @@ -50,9 +51,12 @@ struct Script // -- Quest/gossip Methods to be scripted -- bool (*pGossipHello )(Player *player, Creature *_Creature); + bool (*pGOGossipHello )(Player *player, GameObject *_GO); bool (*pQuestAccept )(Player *player, Creature *_Creature, Quest const*_Quest ); bool (*pGossipSelect )(Player *player, Creature *_Creature, uint32 sender, uint32 action ); + bool (*pGOGossipSelect )(Player *player, GameObject *_GO, uint32 sender, uint32 action ); bool (*pGossipSelectWithCode)(Player *player, Creature *_Creature, uint32 sender, uint32 action, const char* sCode ); + bool (*pGOGossipSelectWithCode)(Player *player, GameObject *_GO, uint32 sender, uint32 action, const char* sCode ); bool (*pQuestSelect )(Player *player, Creature *_Creature, Quest const*_Quest ); bool (*pQuestComplete )(Player *player, Creature *_Creature, Quest const*_Quest ); uint32 (*pNPCDialogStatus )(Player *player, Creature *_Creature ); diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index e146a0aa6..217690f84 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -930,8 +930,12 @@ void GameObject::Use(Unit* user) Player* player = (Player*)user; - player->PrepareGossipMenu(this, GetGOInfo()->questgiver.gossipID); - player->SendPreparedGossip(this); + if (!Script->GOGossipHello(player, this)) + { + player->PrepareGossipMenu(this, GetGOInfo()->questgiver.gossipID); + player->SendPreparedGossip(this); + } + return; } case GAMEOBJECT_TYPE_CHEST: @@ -1037,8 +1041,11 @@ void GameObject::Use(Unit* user) } else if (info->goober.gossipID) // ...or gossip, if page does not exist { - player->PrepareGossipMenu(this, info->goober.gossipID); - player->SendPreparedGossip(this); + if (!Script->GOGossipHello(player, this)) + { + player->PrepareGossipMenu(this, info->goober.gossipID); + player->SendPreparedGossip(this); + } } if (info->goober.eventId) diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp index cfdf7fa81..ffb3752a5 100644 --- a/src/game/NPCHandler.cpp +++ b/src/game/NPCHandler.cpp @@ -304,8 +304,6 @@ void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket & recv_data ) if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); - // TODO: determine if scriptCall is needed for GO and also if scriptCall can be same as current, with modified argument WorldObject* - // can vehicle have gossip? If so, need check for this also. if (IS_CREATURE_OR_PET_GUID(guid)) { @@ -338,7 +336,16 @@ void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket & recv_data ) return; } - _player->OnGossipSelect(pGo, gossipListId, menuId); + if (!code.empty()) + { + if (!Script->GOGossipSelectWithCode(_player, pGo, _player->PlayerTalkClass->GossipOptionSender(gossipListId), _player->PlayerTalkClass->GossipOptionAction(gossipListId), code.c_str())) + _player->OnGossipSelect(pGo, gossipListId, menuId); + } + else + { + if (!Script->GOGossipSelect(_player, pGo, _player->PlayerTalkClass->GossipOptionSender(gossipListId), _player->PlayerTalkClass->GossipOptionAction(gossipListId))) + _player->OnGossipSelect(pGo, gossipListId, menuId); + } } } diff --git a/src/game/ScriptCalls.cpp b/src/game/ScriptCalls.cpp index 0040a1617..c5f77ddde 100644 --- a/src/game/ScriptCalls.cpp +++ b/src/game/ScriptCalls.cpp @@ -58,10 +58,13 @@ bool LoadScriptingModule(char const* libName) ||!(testScript->ScriptsFree =(scriptCallScriptsFree )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsFree" )) ||!(testScript->ScriptsVersion =(scriptCallScriptsVersion )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsVersion" )) ||!(testScript->GossipHello =(scriptCallGossipHello )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GossipHello" )) + ||!(testScript->GOGossipHello =(scriptCallGOGossipHello )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GOGossipHello" )) ||!(testScript->GOChooseReward =(scriptCallGOChooseReward )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GOChooseReward" )) ||!(testScript->QuestAccept =(scriptCallQuestAccept )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"QuestAccept" )) ||!(testScript->GossipSelect =(scriptCallGossipSelect )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GossipSelect" )) + ||!(testScript->GOGossipSelect =(scriptCallGOGossipSelect )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GOGossipSelect" )) ||!(testScript->GossipSelectWithCode=(scriptCallGossipSelectWithCode)MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GossipSelectWithCode")) + ||!(testScript->GOGossipSelectWithCode=(scriptCallGOGossipSelectWithCode)MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GOGossipSelectWithCode")) ||!(testScript->QuestSelect =(scriptCallQuestSelect )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"QuestSelect" )) ||!(testScript->QuestComplete =(scriptCallQuestComplete )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"QuestComplete" )) ||!(testScript->NPCDialogStatus =(scriptCallNPCDialogStatus )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"NPCDialogStatus" )) diff --git a/src/game/ScriptCalls.h b/src/game/ScriptCalls.h index 281deb113..7747c917f 100644 --- a/src/game/ScriptCalls.h +++ b/src/game/ScriptCalls.h @@ -41,9 +41,12 @@ typedef void(MANGOS_IMPORT * scriptCallScriptsFree) (); typedef char const* (MANGOS_IMPORT * scriptCallScriptsVersion) (); typedef bool(MANGOS_IMPORT * scriptCallGossipHello) (Player *player, Creature *_Creature ); +typedef bool(MANGOS_IMPORT * scriptCallGOGossipHello) (Player *player, GameObject *_GO); typedef bool(MANGOS_IMPORT * scriptCallQuestAccept) (Player *player, Creature *_Creature, Quest const *); typedef bool(MANGOS_IMPORT * scriptCallGossipSelect)(Player *player, Creature *_Creature, uint32 sender, uint32 action); +typedef bool(MANGOS_IMPORT * scriptCallGOGossipSelect)(Player *player, GameObject *_GO, uint32 sender, uint32 action); typedef bool(MANGOS_IMPORT * scriptCallGossipSelectWithCode)( Player *player, Creature *_Creature, uint32 sender, uint32 action, const char* sCode ); +typedef bool(MANGOS_IMPORT * scriptCallGOGossipSelectWithCode)( Player *player, GameObject *_GO, uint32 sender, uint32 action, const char* sCode ); typedef bool(MANGOS_IMPORT * scriptCallQuestSelect)( Player *player, Creature *_Creature, Quest const* ); typedef bool(MANGOS_IMPORT * scriptCallQuestComplete)(Player *player, Creature *_Creature, Quest const*); typedef uint32(MANGOS_IMPORT * scriptCallNPCDialogStatus)( Player *player, Creature *_Creature); @@ -70,10 +73,13 @@ typedef struct scriptCallScriptsVersion ScriptsVersion; scriptCallGossipHello GossipHello; + scriptCallGOGossipHello GOGossipHello; scriptCallGOChooseReward GOChooseReward; scriptCallQuestAccept QuestAccept; scriptCallGossipSelect GossipSelect; + scriptCallGOGossipSelect GOGossipSelect; scriptCallGossipSelectWithCode GossipSelectWithCode; + scriptCallGOGossipSelectWithCode GOGossipSelectWithCode; scriptCallQuestSelect QuestSelect; scriptCallQuestComplete QuestComplete; scriptCallNPCDialogStatus NPCDialogStatus; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 70b7e3da2..7dd63a40a 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 "9571" + #define REVISION_NR "9572" #endif // __REVISION_NR_H__