Skip to content

Commit

Permalink
Save instance ID in the Eluna state
Browse files Browse the repository at this point in the history
  • Loading branch information
Foereaper committed Jan 20, 2024
1 parent 042749e commit 4593003
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions LuaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ void Eluna::_ReloadEluna()
reload = false;
}

Eluna::Eluna(int32 mapId, bool compatMode) :
Eluna::Eluna(int32 mapId, uint32 instanceId, bool compatMode) :
event_level(0),
push_counter(0),
enabled(false),
boundMapId(mapId),
boundInstanceId(instanceId),
compatibilityMode(compatMode),

L(NULL),
Expand Down Expand Up @@ -234,7 +235,7 @@ void Eluna::DestroyBindStores()

void Eluna::RunScripts()
{
ELUNA_LOG_DEBUG("[Eluna]: Running scripts for map: %i", boundMapId);
ELUNA_LOG_DEBUG("[Eluna]: Running scripts for state: %i, instance: %u", boundMapId, boundInstanceId);

uint32 oldMSTime = ElunaUtil::GetCurrTime();
uint32 count = 0;
Expand Down Expand Up @@ -309,7 +310,7 @@ void Eluna::RunScripts()
}
// Stack: package, modules
lua_pop(L, 2);
ELUNA_LOG_INFO("[Eluna]: Executed %u Lua scripts in %u ms for map state %i", count, ElunaUtil::GetTimeDiff(oldMSTime), boundMapId);
ELUNA_LOG_INFO("[Eluna]: Executed %u Lua scripts in %u ms for map: %i, instance: %u", count, ElunaUtil::GetTimeDiff(oldMSTime), boundMapId, boundInstanceId);

OnLuaStateOpen();
}
Expand Down
6 changes: 5 additions & 1 deletion LuaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ class ELUNA_GAME_API Eluna
// The map id that this Eluna object is tied to. -1 is reserved for objects without a bound map id.
int32 boundMapId;

// The instance id that this Eluna object is tied to. -1 is reserved for objects without a bound map id.
uint32 boundInstanceId;

// Whether or not Eluna is in compatibility mode. Used in some method wrappers.
bool compatibilityMode;

Expand Down Expand Up @@ -360,9 +363,10 @@ class ELUNA_GAME_API Eluna
void FreeInstanceId(uint32 instanceId);

int32 GetBoundMapId() const { return boundMapId; }
uint32 GetBoundInstanceId() const { return boundInstanceId; }
bool GetCompatibilityMode() const { return compatibilityMode; }

Eluna(int32 mapId, bool compatMode = false);
Eluna(int32 mapId, uint32 instanceId, bool compatMode = false);
~Eluna();

// Prevent copy
Expand Down
12 changes: 12 additions & 0 deletions TrinityCore/GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ namespace LuaGlobalFunctions
return 1;
}

/**
* Returns the instance ID of the Lua state. Returns 0 for continent maps and the world state.
*
* @return uint32 instanceId
*/
int GetStateInstanceId(Eluna* E)
{
E->Push(E->GetBoundInstanceId());
return 1;
}

/**
* Returns [Quest] template
*
Expand Down Expand Up @@ -3096,6 +3107,7 @@ namespace LuaGlobalFunctions
{ "GetCoreVersion", &LuaGlobalFunctions::GetCoreVersion },
{ "GetCoreExpansion", &LuaGlobalFunctions::GetCoreExpansion },
{ "GetStateMapId", &LuaGlobalFunctions::GetStateMapId },
{ "GetStateInstanceId", &LuaGlobalFunctions::GetStateInstanceId },
{ "GetQuest", &LuaGlobalFunctions::GetQuest },
{ "GetPlayerByGUID", &LuaGlobalFunctions::GetPlayerByGUID, METHOD_REG_WORLD }, // World state method only in multistate
{ "GetPlayerByName", &LuaGlobalFunctions::GetPlayerByName, METHOD_REG_WORLD }, // World state method only in multistate
Expand Down

0 comments on commit 4593003

Please sign in to comment.