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(Module/Eluna): Add Support for Multistate #21294

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ function(ConfigureElunaModule moduleName)
target_compile_options(game-interface
INTERFACE
-DAZEROTHCORE
-DWOTLK)
-DWOTLK
-DMOD_ELUNA)
endfunction()

# Set the MODULES_${SOURCE_MODULE} variables from the
Expand Down
15 changes: 15 additions & 0 deletions src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
#include "World.h"
#include "WorldPacket.h"

#if defined(MOD_ELUNA)
#include "LuaEngine.h"
#include "ElunaConfig.h"
#endif

/// @todo: this import is not necessary for compilation and marked as unused by the IDE
// however, for some reasons removing it would cause a damn linking issue
// there is probably some underlying problem with imports which should properly addressed
Expand Down Expand Up @@ -3231,3 +3236,13 @@ void WorldObject::RemoveAllowedLooter(ObjectGuid guid)
{
_allowedLooters.erase(guid);
}

#if defined(MOD_ELUNA)
Eluna* WorldObject::GetEluna() const
{
if (const Map * map = FindMap())
return map->GetEluna();

return nullptr;
}
#endif
7 changes: 7 additions & 0 deletions src/server/game/Entities/Object/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#include "UpdateFields.h"

class ElunaEventProcessor;
#if defined(MOD_ELUNA)
class Eluna;
#endif

enum TempSummonType
{
Expand Down Expand Up @@ -630,6 +633,10 @@ class WorldObject : public Object, public WorldLocation

std::string GetDebugInfo() const override;

#if defined(MOD_ELUNA)
Eluna* GetEluna() const;
#endif

// Event handler
ElunaEventProcessor* elunaEvents;
EventProcessor m_Events;
Expand Down
41 changes: 41 additions & 0 deletions src/server/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
#include "VMapMgr2.h"
#include "Weather.h"

#if defined(MOD_ELUNA)
#include "LuaEngine.h"
#include "ElunaConfig.h"
#include "ElunaLoader.h"
#endif

union u_map_magic
{
char asChar[4];
Expand All @@ -64,6 +70,11 @@ ZoneDynamicInfo::ZoneDynamicInfo() : MusicId(0), WeatherId(WEATHER_STATE_FINE),

Map::~Map()
{
#if defined(MOD_ELUNA)
delete eluna;
eluna = nullptr;
#endif

// UnloadAll must be called before deleting the map

sScriptMgr->OnDestroyMap(this);
Expand Down Expand Up @@ -242,6 +253,16 @@ Map::Map(uint32 id, uint32 InstanceId, uint8 SpawnMode, Map* _parent) :
_transportsUpdateIter(_transports.end()), i_scriptLock(false), _defaultLight(GetDefaultMapLight(id))
{
m_parentMap = (_parent ? _parent : this);

// lua state begins uninitialized
#if defined(MOD_ELUNA)
eluna = nullptr;

if (sElunaConfig->IsElunaEnabled() && !sElunaConfig->IsElunaCompatibilityMode() && sElunaConfig->ShouldMapLoadEluna(id))
if (!IsParentMap() || (IsParentMap() && !Instanceable()))
eluna = new Eluna(this);
#endif

for (unsigned int idx = 0; idx < MAX_NUMBER_OF_GRIDS; ++idx)
{
for (unsigned int j = 0; j < MAX_NUMBER_OF_GRIDS; ++j)
Expand Down Expand Up @@ -2655,6 +2676,16 @@ void Map::AddObjectToRemoveList(WorldObject* obj)
{
ASSERT(obj->GetMapId() == GetId() && obj->GetInstanceId() == GetInstanceId());

#if defined(MOD_ELUNA)
if (Eluna* E = GetEluna())
{
if (Creature* creature = obj->ToCreature())
E->OnRemove(creature);
else if (GameObject* gameobject = obj->ToGameObject())
E->OnRemove(gameobject);
}
#endif

obj->CleanupsBeforeDelete(false); // remove or simplify at least cross referenced links

i_objectsToRemove.insert(obj);
Expand Down Expand Up @@ -4088,3 +4119,13 @@ std::string InstanceMap::GetDebugInfo() const
<< "ScriptId: " << GetScriptId() << " ScriptName: " << GetScriptName();
return sstr.str();
}

#if defined(MOD_ELUNA)
Eluna *Map::GetEluna() const
{
if (sElunaConfig->IsElunaCompatibilityMode())
return sWorld->GetEluna();

return eluna;
}
#endif
13 changes: 13 additions & 0 deletions src/server/game/Maps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#include <memory>
#include <shared_mutex>

#if defined(MOD_ELUNA)
class Eluna;
#endif

class Unit;
class WorldPacket;
class InstanceScript;
Expand Down Expand Up @@ -380,6 +384,7 @@ class Map : public GridRefMgr<NGridType>
static bool ExistVMap(uint32 mapid, int gx, int gy);

[[nodiscard]] Map const* GetParent() const { return m_parentMap; }
bool IsParentMap() const { return GetParent() == this; }

// pussywizard: movemaps, mmaps
[[nodiscard]] std::shared_mutex& GetMMapLock() const { return *(const_cast<std::shared_mutex*>(&MMapLock)); }
Expand Down Expand Up @@ -656,6 +661,10 @@ class Map : public GridRefMgr<NGridType>

virtual std::string GetDebugInfo() const;

#if defined(MOD_ELUNA)
Eluna* GetEluna() const;
#endif

private:
void LoadMapAndVMap(int gx, int gy);
void LoadVMap(int gx, int gy);
Expand Down Expand Up @@ -802,6 +811,10 @@ class Map : public GridRefMgr<NGridType>
std::unordered_set<Corpse*> _corpseBones;

std::unordered_set<Object*> _updateObjects;

#if defined(MOD_ELUNA)
Eluna* eluna;
Copy link
Member

Choose a reason for hiding this comment

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

std::unique_ptr

#endif
};

enum InstanceResetMethod
Expand Down
9 changes: 9 additions & 0 deletions src/server/game/World/IWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "SharedDefines.h"
#include <unordered_map>

#if defined(MOD_ELUNA)
class Eluna;
#endif

class WorldPacket;
class WorldSession;
class Player;
Expand Down Expand Up @@ -612,6 +616,11 @@ class IWorld
virtual void SetRealmName(std::string name) = 0;
virtual void RemoveOldCorpses() = 0;
virtual void DoForAllOnlinePlayers(std::function<void(Player*)> exec) = 0;

#if defined(MOD_ELUNA)
Eluna* GetEluna() const { return eluna; }
Eluna* eluna;
#endif
};

#endif //AZEROTHCORE_IWORLD_H
6 changes: 3 additions & 3 deletions src/server/game/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,11 @@ void World::LoadConfigSettings(bool reload)
LOG_ERROR("server.loading", "World settings reload fail: can't read settings.");
return;
}

sLog->LoadFromConfig();
sMetric->LoadFromConfigs();
}

sLog->LoadFromConfig();
sMetric->LoadFromConfigs();

// Set realm id and enable db logging
sLog->SetRealmId(realm.Id.Realm);

Expand Down
9 changes: 9 additions & 0 deletions src/server/game/World/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include <map>
#include <unordered_map>

#if defined(MOD_ELUNA)
class Eluna;
#endif

class Object;
class WorldPacket;
class WorldSocket;
Expand Down Expand Up @@ -344,6 +348,11 @@ class World: public IWorld

void DoForAllOnlinePlayers(std::function<void(Player*)> exec) override;

#if defined(MOD_ELUNA)
Eluna* GetEluna() const { return eluna; }
Eluna* eluna;
#endif

protected:
void _UpdateGameTime();
// callback for UpdateRealmCharacters
Expand Down
Loading