Gossip Item Script support (#124)

* Referencing latest SD3 commit

* Add support for Item script gosssip

* Modifying Gossip Method defnition
This commit is contained in:
Elmsroth 2020-12-28 20:03:29 +01:00 committed by GitHub
parent 27ed59195a
commit 7a1d09ed33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 8 deletions

View File

@ -41,7 +41,7 @@ GossipMenu::~GossipMenu()
ClearMenu(); ClearMenu();
} }
void GossipMenu::AddMenuItem(uint8 Icon, const std::string& Message, uint32 dtSender, uint32 dtAction, const std::string& BoxMessage, bool Coded) void GossipMenu::AddMenuItem(uint8 Icon, const std::string& Message, uint32 dtSender, uint32 dtAction, const std::string& BoxMessage, uint32 BoxMoney, bool Coded)
{ {
MANGOS_ASSERT(m_gItems.size() <= GOSSIP_MAX_MENU_ITEMS); MANGOS_ASSERT(m_gItems.size() <= GOSSIP_MAX_MENU_ITEMS);
@ -53,7 +53,7 @@ void GossipMenu::AddMenuItem(uint8 Icon, const std::string& Message, uint32 dtSe
gItem.m_gSender = dtSender; gItem.m_gSender = dtSender;
gItem.m_gOptionId = dtAction; gItem.m_gOptionId = dtAction;
gItem.m_gBoxMessage = BoxMessage; gItem.m_gBoxMessage = BoxMessage;
gItem.m_gBoxMoney = BoxMoney;
m_gItems.push_back(gItem); m_gItems.push_back(gItem);
} }
@ -78,9 +78,14 @@ void GossipMenu::AddMenuItem(uint8 Icon, char const* Message, bool Coded)
AddMenuItem(Icon, std::string(Message ? Message : ""), Coded); AddMenuItem(Icon, std::string(Message ? Message : ""), Coded);
} }
void GossipMenu::AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, uint32 dtAction, char const* BoxMessage, bool Coded) void GossipMenu::AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, uint32 dtAction, bool Coded)
{ {
AddMenuItem(Icon, std::string(Message ? Message : ""), dtSender, dtAction, std::string(BoxMessage ? BoxMessage : ""), Coded); AddMenuItem(Icon, std::string(Message ? Message : ""), dtSender, dtAction, "", 0,Coded);
}
void GossipMenu::AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, uint32 dtAction, char const* BoxMessage, uint32 BoxMoney, bool Coded)
{
AddMenuItem(Icon, std::string(Message ? Message : ""), dtSender, dtAction, std::string(BoxMessage ? BoxMessage : ""), BoxMoney, Coded);
} }
void GossipMenu::AddMenuItem(uint8 Icon, int32 itemText, uint32 dtSender, uint32 dtAction, int32 boxText, bool Coded) void GossipMenu::AddMenuItem(uint8 Icon, int32 itemText, uint32 dtSender, uint32 dtAction, int32 boxText, bool Coded)
@ -173,7 +178,9 @@ void PlayerMenu::SendGossipMenu(uint32 TitleTextId, ObjectGuid objectGuid)
data << uint32(iI); data << uint32(iI);
data << uint8(gItem.m_gIcon); data << uint8(gItem.m_gIcon);
data << uint8(gItem.m_gCoded); // makes pop up box password data << uint8(gItem.m_gCoded); // makes pop up box password
//data << uint32(gItem.m_gBoxMoney);
data << gItem.m_gMessage; // text for gossip item, max 0x800 data << gItem.m_gMessage; // text for gossip item, max 0x800
// data << gItem.m_gBoxMessage;
} }
data << uint32(mQuestMenu.MenuItemCount()); // max count 0x20 data << uint32(mQuestMenu.MenuItemCount()); // max count 0x20

View File

@ -138,6 +138,7 @@ struct GossipMenuItem
uint32 m_gSender; uint32 m_gSender;
uint32 m_gOptionId; uint32 m_gOptionId;
std::string m_gBoxMessage; std::string m_gBoxMessage;
uint32 m_gBoxMoney;
}; };
typedef std::vector<GossipMenuItem> GossipMenuItemList; typedef std::vector<GossipMenuItem> GossipMenuItemList;
@ -166,12 +167,12 @@ class GossipMenu
~GossipMenu(); ~GossipMenu();
void AddMenuItem(uint8 Icon, const std::string& Message, bool Coded = false); void AddMenuItem(uint8 Icon, const std::string& Message, bool Coded = false);
void AddMenuItem(uint8 Icon, const std::string& Message, uint32 dtSender, uint32 dtAction, const std::string& BoxMessage, bool Coded = false); void AddMenuItem(uint8 Icon, const std::string& Message, uint32 dtSender, uint32 dtAction, const std::string& BoxMessage, uint32 BoxMoney = 0, bool Coded = false);
// for using from scripts, don't must be inlined // for using from scripts, don't must be inlined
void AddMenuItem(uint8 Icon, char const* Message, bool Coded = false); void AddMenuItem(uint8 Icon, char const* Message, bool Coded = false);
void AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, uint32 dtAction, char const* BoxMessage, bool Coded = false); void AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, uint32 dtAction, bool Coded = false);
void AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, uint32 dtAction, char const* BoxMessage, uint32 BoxMoney = 0, bool Coded =false);
void AddMenuItem(uint8 Icon, int32 itemText, uint32 dtSender, uint32 dtAction, int32 boxText, bool Coded = false); void AddMenuItem(uint8 Icon, int32 itemText, uint32 dtSender, uint32 dtAction, int32 boxText, bool Coded = false);
void SetMenuId(uint32 menu_id) { m_gMenuId = menu_id; } void SetMenuId(uint32 menu_id) { m_gMenuId = menu_id; }

View File

@ -490,6 +490,13 @@ void WorldSession::HandleGossipSelectOptionOpcode(WorldPacket& recv_data)
return; return;
} }
if (!sScriptMgr.OnGossipSelect(_player, item, sender, action, code.empty() ? NULL : code.c_str()))
{
DEBUG_LOG("WORLD: HandleGossipSelectOptionOpcode - item script for %s not found or you can't interact with it.", item->GetProto()->Name1);
return;
}
// Used by Eluna // Used by Eluna
#ifdef ENABLE_ELUNA #ifdef ENABLE_ELUNA
sEluna->HandleGossipSelectOption(GetPlayer(), item, GetPlayer()->PlayerTalkClass->GossipOptionSender(gossipListId), GetPlayer()->PlayerTalkClass->GossipOptionAction(gossipListId), code); sEluna->HandleGossipSelectOption(GetPlayer(), item, GetPlayer()->PlayerTalkClass->GossipOptionSender(gossipListId), GetPlayer()->PlayerTalkClass->GossipOptionAction(gossipListId), code);

View File

@ -2600,6 +2600,20 @@ bool ScriptMgr::OnGossipHello(Player* pPlayer, GameObject* pGameObject)
#endif #endif
} }
bool ScriptMgr::OnGossipHello(Player* pPlayer, Item* pItem)
{
// Used by Eluna
#ifdef ENABLE_ELUNA
// TODO ELUNA handler
#endif /* ENABLE_ELUNA */
#ifdef ENABLE_SD3
return SD3::ItemGossipHello(pPlayer, pItem);
#else
return false;
#endif
}
bool ScriptMgr::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code) bool ScriptMgr::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code)
{ {
#ifdef ENABLE_ELUNA #ifdef ENABLE_ELUNA
@ -2669,6 +2683,27 @@ bool ScriptMgr::OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32
#endif #endif
} }
bool ScriptMgr::OnGossipSelect(Player* pPlayer, Item* pItem, uint32 sender, uint32 action, const char* code)
{
// Used by Eluna
#ifdef ENABLE_ELUNA
// TODO Add Eluna handlers
#endif /* ENABLE_ELUNA */
#ifdef ENABLE_SD3
if (code)
{
return SD3::ItemGossipSelectWithCode(pPlayer, pItem, sender, action, code);
}
else
{
return SD3::ItemGossipSelect(pPlayer, pItem, sender, action);
}
#else
return false;
#endif
}
bool ScriptMgr::OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest) bool ScriptMgr::OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest)
{ {
// Used by Eluna // Used by Eluna

View File

@ -664,8 +664,10 @@ class ScriptMgr
char const* GetScriptLibraryVersion() const; char const* GetScriptLibraryVersion() const;
bool OnGossipHello(Player* pPlayer, Creature* pCreature); bool OnGossipHello(Player* pPlayer, Creature* pCreature);
bool OnGossipHello(Player* pPlayer, GameObject* pGameObject); bool OnGossipHello(Player* pPlayer, GameObject* pGameObject);
bool OnGossipHello(Player* pPlayer, Item* pItem);
bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code); bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code);
bool OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code); bool OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code);
bool OnGossipSelect(Player* pPlayer, Item* pItem, uint32 sender, uint32 action, const char* code);
bool OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest); bool OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest);
bool OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest); bool OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest);
bool OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest); bool OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest);

@ -1 +1 @@
Subproject commit ee5ee41c913c4935e9d1ec8ced7508c93b942f2b Subproject commit b4fea426319568b0eeb50a551aacbdb826ce758d