Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(LuaEngine/GlobalMethods): add GetGossipMenuOptionLocale, GetMapEntrance #233

Merged
merged 9 commits into from
Feb 5, 2025
2 changes: 2 additions & 0 deletions src/LuaEngine/LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ luaL_Reg GlobalMethods[] =
{ "PrintError", &LuaGlobalFunctions::PrintError },
{ "PrintDebug", &LuaGlobalFunctions::PrintDebug },
{ "GetActiveGameEvents", &LuaGlobalFunctions::GetActiveGameEvents },
{ "GetGossipMenuOptionLocale", &LuaGlobalFunctions::GetGossipMenuOptionLocale },
{ "GetMapEntrance", &LuaGlobalFunctions::GetMapEntrance },

// Boolean
{ "IsCompatibilityMode", &LuaGlobalFunctions::IsCompatibilityMode },
Expand Down
79 changes: 79 additions & 0 deletions src/LuaEngine/methods/GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -3231,6 +3231,85 @@ namespace LuaGlobalFunctions
}

/**
* Gets the localized OptionText and BoxText for a specific gossip menu option.
* If the text for the specified locale is not found, it returns the default text.
*
* @param uint32 menuId : The ID of the gossip menu.
* @param uint32 optionId : The ID of the gossip menu option.
* @param uint8 locale : The locale to retrieve the text for. 0 represents the default locale.
*
* @return string, string : The localized OptionText and BoxText for the gossip menu option, or the default text if no localization is found.
*/
int GetGossipMenuOptionLocale(lua_State* L)
{
uint32 menuId = Eluna::CHECKVAL<uint32>(L, 1);
uint32 optionId = Eluna::CHECKVAL<uint32>(L, 2);
uint8 locale = Eluna::CHECKVAL<uint8>(L, 3);

std::string strOptionText;
std::string strBoxText;

if (locale != DEFAULT_LOCALE)
{
if (GossipMenuItemsLocale const* gossipMenuLocale = sObjectMgr->GetGossipMenuItemsLocale(MAKE_PAIR32(menuId, optionId)))
{
ObjectMgr::GetLocaleString(gossipMenuLocale->OptionText, LocaleConstant(locale), strOptionText);
ObjectMgr::GetLocaleString(gossipMenuLocale->BoxText, LocaleConstant(locale), strBoxText);
}
}

if (strOptionText.empty() || strBoxText.empty())
{
GossipMenuItemsMapBounds bounds = sObjectMgr->GetGossipMenuItemsMapBounds(menuId);
for (auto itr = bounds.first; itr != bounds.second; ++itr)
{
if (itr->second.OptionID == optionId)
{
if (strOptionText.empty())
strOptionText = itr->second.OptionText;
if (strBoxText.empty())
strBoxText = itr->second.BoxText;
break;
}
}
}

Eluna::Push(L, strOptionText);
Eluna::Push(L, strBoxText);
return 2; // 2 values returned to Lua
iThorgrim marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Return the entrance position (x, y, z, o) of the specified dungeon map id
*
* @param uint32 mapId
*
* return uint32 pos_x
* return uint32 pos_y
* return uint32 pos_z
* return uint32 pos_o
*
*/
int GetMapEntrance(lua_State* L)
{
uint32 mapId = Eluna::CHECKVAL<uint32>(L, 1);
AreaTriggerTeleport const* at = sObjectMgr->GetMapEntranceTrigger(mapId);

if (!at)
{
lua_pushnil(L);
return 1;
}

Eluna::Push(L, at->target_X);
Eluna::Push(L, at->target_Y);
Eluna::Push(L, at->target_Z);
Eluna::Push(L, at->target_Orientation);

return 5;
}

/**
* Returns the instance of the specified DBC (DatabaseClient) store.
*
* This function retrieves the DBC store associated with the provided name
Expand Down