From 390d8c092a2e63a5fbe6b2245b2e6f026c079abc Mon Sep 17 00:00:00 2001 From: Niam5 Date: Thu, 29 Aug 2024 17:01:55 -0700 Subject: [PATCH] [Eluna] Update Eluna to latest and reenable Eluna tests (#204) * [Eluna] Update to latest Eluna Adds multistate support and defaults it to on Co-Authored-By: Foe * [Eluna] Fix BG crash * [Eluna] Fix elunaEvent init and de-init Co-Authored-By: Foe * Enable Eluna tests --------- Co-authored-by: Foe --- .github/workflows/core_windows_build.yml | 2 +- apps/ci/ci-compile.sh | 2 +- src/game/BattleGround/BattleGround.cpp | 17 ++- src/game/BattleGround/BattleGroundMgr.cpp | 4 - src/game/CMakeLists.txt | 11 +- src/game/Object/Creature.cpp | 10 +- src/game/Object/GameObject.cpp | 40 ++++-- src/game/Object/Guild.cpp | 40 ++++-- src/game/Object/Item.cpp | 5 +- src/game/Object/Object.cpp | 34 +++-- src/game/Object/Object.h | 9 ++ src/game/Object/Player.cpp | 99 +++++++++++--- src/game/Object/ReputationMgr.cpp | 7 +- src/game/Object/Totem.cpp | 7 +- src/game/Object/Unit.cpp | 58 ++++++-- src/game/Object/Vehicle.cpp | 21 ++- src/game/Server/WorldSession.cpp | 12 +- src/game/Server/WorldSocket.cpp | 24 +++- .../WorldHandlers/AuctionHouseHandler.cpp | 10 +- src/game/WorldHandlers/CharacterHandler.cpp | 22 ++- src/game/WorldHandlers/Chat.cpp | 14 +- src/game/WorldHandlers/ChatHandler.cpp | 115 +++++++++++----- src/game/WorldHandlers/GameEventMgr.cpp | 14 +- src/game/WorldHandlers/Group.cpp | 34 +++-- src/game/WorldHandlers/GuildHandler.cpp | 6 +- src/game/WorldHandlers/LootHandler.cpp | 23 +++- src/game/WorldHandlers/Map.cpp | 94 ++++++++++--- src/game/WorldHandlers/Map.h | 16 +++ src/game/WorldHandlers/MapManager.cpp | 22 +++ src/game/WorldHandlers/MapManager.h | 9 ++ src/game/WorldHandlers/MiscHandler.cpp | 5 +- src/game/WorldHandlers/NPCHandler.cpp | 10 +- src/game/WorldHandlers/QuestHandler.cpp | 7 +- src/game/WorldHandlers/ScriptMgr.cpp | 127 +++++++++++++----- src/game/WorldHandlers/Spell.cpp | 10 +- src/game/WorldHandlers/SpellEffects.cpp | 77 +++++++++-- src/game/WorldHandlers/Weather.cpp | 5 +- src/game/WorldHandlers/World.cpp | 66 +++++++-- src/game/WorldHandlers/World.h | 9 +- src/mangosd/CMakeLists.txt | 2 +- src/mangosd/WorldThread.cpp | 12 -- src/mangosd/mangosd.conf.dist.in | 30 +++-- src/modules/CMakeLists.txt | 4 + src/modules/Eluna | 2 +- src/shared/CMakeLists.txt | 2 +- src/shared/Common/Common.h | 2 + 46 files changed, 883 insertions(+), 268 deletions(-) diff --git a/.github/workflows/core_windows_build.yml b/.github/workflows/core_windows_build.yml index 369de97937..62c13859ca 100644 --- a/.github/workflows/core_windows_build.yml +++ b/.github/workflows/core_windows_build.yml @@ -33,5 +33,5 @@ jobs: shell: bash run: | mkdir -p build && cd build - cmake .. -DCMAKE_SYSTEM_VERSION=10.0.22621.0 -DBUILD_TOOLS:BOOL=1 -DBUILD_MANGOSD:BOOL=1 -DBUILD_REALMD:BOOL=1 -DSOAP:BOOL=1 -DSCRIPT_LIB_ELUNA:BOOL=0 -DSCRIPT_LIB_SD3:BOOL=1 -DPLAYERBOTS:BOOL=0 -DUSE_STORMLIB:BOOL=1 + cmake .. -DCMAKE_SYSTEM_VERSION=10.0.22621.0 -DBUILD_TOOLS:BOOL=1 -DBUILD_MANGOSD:BOOL=1 -DBUILD_REALMD:BOOL=1 -DSOAP:BOOL=1 -DSCRIPT_LIB_ELUNA:BOOL=1 -DSCRIPT_LIB_SD3:BOOL=1 -DPLAYERBOTS:BOOL=0 -DUSE_STORMLIB:BOOL=1 cmake --build . --config Release --parallel 4 diff --git a/apps/ci/ci-compile.sh b/apps/ci/ci-compile.sh index 517738fee4..9917e785b9 100644 --- a/apps/ci/ci-compile.sh +++ b/apps/ci/ci-compile.sh @@ -10,7 +10,7 @@ time test -d _install || mkdir _install time cd _build # Run CMake Configurations -time cmake .. -DCMAKE_INSTALL_PREFIX=../_install -DBUILD_TOOLS:BOOL=1 -DBUILD_MANGOSD:BOOL=1 -DBUILD_REALMD:BOOL=1 -DSOAP:BOOL=1 -DSCRIPT_LIB_ELUNA:BOOL=0 -DSCRIPT_LIB_SD3:BOOL=1 -DPLAYERBOTS:BOOL=0 -DUSE_STORMLIB:BOOL=1 +time cmake .. -DCMAKE_INSTALL_PREFIX=../_install -DBUILD_TOOLS:BOOL=1 -DBUILD_MANGOSD:BOOL=1 -DBUILD_REALMD:BOOL=1 -DSOAP:BOOL=1 -DSCRIPT_LIB_ELUNA:BOOL=1 -DSCRIPT_LIB_SD3:BOOL=1 -DPLAYERBOTS:BOOL=0 -DUSE_STORMLIB:BOOL=1 # Compile the Project time make -j 6 diff --git a/src/game/BattleGround/BattleGround.cpp b/src/game/BattleGround/BattleGround.cpp index a926ee2525..18e9a153ad 100644 --- a/src/game/BattleGround/BattleGround.cpp +++ b/src/game/BattleGround/BattleGround.cpp @@ -458,6 +458,13 @@ void BattleGround::Update(uint32 diff) { m_Events |= BG_STARTING_EVENT_4; +#ifdef ENABLE_ELUNA + if (Eluna* e = this->GetBgMap()->GetEluna()) + { + e->OnBGCreate(this, GetTypeID(), GetInstanceID()); + } +#endif /* ENABLE_ELUNA */ + StartingEventOpenDoors(); SendMessageToAll(m_StartMessageIds[BG_STARTING_EVENT_FOURTH], CHAT_MSG_BG_SYSTEM_NEUTRAL); @@ -850,7 +857,10 @@ void BattleGround::UpdateWorldStateForPlayer(uint32 Field, uint32 Value, Player* void BattleGround::EndBattleGround(Team winner) { #ifdef ENABLE_ELUNA - sEluna->OnBGEnd(this, GetTypeID(), GetInstanceID(), winner); + if (Eluna* e = GetBgMap()->GetEluna()) + { + e->OnBGEnd(this, GetTypeID(), GetInstanceID(), winner); + } #endif /* ENABLE_ELUNA */ this->RemoveFromBGFreeSlotQueue(); @@ -1466,7 +1476,10 @@ void BattleGround::StartBattleGround() sBattleGroundMgr.AddBattleGround(GetInstanceID(), GetTypeID(), this); #ifdef ENABLE_ELUNA - sEluna->OnBGStart(this, GetTypeID(), GetInstanceID()); + if (Eluna* e = GetBgMap()->GetEluna()) + { + e->OnBGCreate(this, GetTypeID(), GetInstanceID()); + } #endif /* ENABLE_ELUNA */ } diff --git a/src/game/BattleGround/BattleGroundMgr.cpp b/src/game/BattleGround/BattleGroundMgr.cpp index 5cb642331d..01cd1c8e00 100644 --- a/src/game/BattleGround/BattleGroundMgr.cpp +++ b/src/game/BattleGround/BattleGroundMgr.cpp @@ -1791,10 +1791,6 @@ uint32 BattleGroundMgr::CreateBattleGround(BattleGroundTypeId bgTypeId, bool IsA // add bg to update list AddBattleGround(bg->GetInstanceID(), bg->GetTypeID(), bg); -#ifdef ENABLE_ELUNA - sEluna->OnBGCreate(bg, bgTypeId, bg->GetInstanceID()); -#endif /* ENABLE_ELUNA */ - // return some not-null value, bgTypeId is good enough for me return bgTypeId; } diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt index e1ee09b293..5196890ab9 100644 --- a/src/game/CMakeLists.txt +++ b/src/game/CMakeLists.txt @@ -86,8 +86,10 @@ if(SCRIPT_LIB_ELUNA) file(GLOB SRC_GRP_ELUNA ${CMAKE_SOURCE_DIR}/src/modules/Eluna/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Eluna/*.h - ${CMAKE_SOURCE_DIR}/src/modules/Eluna/Mangos/*.cpp - ${CMAKE_SOURCE_DIR}/src/modules/Eluna/Mangos/*.h + ${CMAKE_SOURCE_DIR}/src/modules/Eluna/hooks/*.cpp + ${CMAKE_SOURCE_DIR}/src/modules/Eluna/hooks/*.h + ${CMAKE_SOURCE_DIR}/src/modules/Eluna/methods/Mangos/*.cpp + ${CMAKE_SOURCE_DIR}/src/modules/Eluna/methods/Mangos/*.h ) source_group("Eluna" FILES ${SRC_GRP_ELUNA}) endif() @@ -258,7 +260,8 @@ target_include_directories(game WorldHandlers $<$: ${CMAKE_SOURCE_DIR}/src/modules/Eluna - ${CMAKE_SOURCE_DIR}/src/modules/Eluna/Mangos + ${CMAKE_SOURCE_DIR}/src/modules/Eluna/hooks + ${CMAKE_SOURCE_DIR}/src/modules/Eluna/methods/Mangos > $<$: ${CMAKE_SOURCE_DIR}/src/modules/Bots @@ -272,7 +275,7 @@ target_compile_definitions(game $<$:ENABLE_SOAP> $<$:ENABLE_SD3> $<$:ENABLE_PLAYERBOTS> - $<$:ENABLE_ELUNA> + $<$:ENABLE_ELUNA ELUNA_EXPANSION=2 ELUNA_MANGOS> ) target_link_libraries(game diff --git a/src/game/Object/Creature.cpp b/src/game/Object/Creature.cpp index ee21029fef..fc8e46a4d4 100644 --- a/src/game/Object/Creature.cpp +++ b/src/game/Object/Creature.cpp @@ -212,7 +212,10 @@ void Creature::AddToWorld() #ifdef ENABLE_ELUNA if (!inWorld) { - sEluna->OnAddToWorld(this); + if (Eluna* e = GetEluna()) + { + e->OnAddToWorld(this); + } } #endif /* ENABLE_ELUNA */ @@ -223,7 +226,10 @@ void Creature::RemoveFromWorld() #ifdef ENABLE_ELUNA if (IsInWorld()) { - sEluna->OnRemoveFromWorld(this); + if (Eluna* e = GetEluna()) + { + e->OnRemoveFromWorld(this); + } } #endif /* ENABLE_ELUNA */ diff --git a/src/game/Object/GameObject.cpp b/src/game/Object/GameObject.cpp index 8da141effe..70623803a7 100644 --- a/src/game/Object/GameObject.cpp +++ b/src/game/Object/GameObject.cpp @@ -125,7 +125,10 @@ void GameObject::AddToWorld() #ifdef ENABLE_ELUNA if (!inWorld) { - sEluna->OnAddToWorld(this); + if (Eluna* e = GetEluna()) + { + e->OnAddToWorld(this); + } } #endif /* ENABLE_ELUNA */ } @@ -136,7 +139,10 @@ void GameObject::RemoveFromWorld() if (IsInWorld()) { #ifdef ENABLE_ELUNA - sEluna->OnRemoveFromWorld(this); + if (Eluna* e = GetEluna()) + { + e->OnRemoveFromWorld(this); + } #endif /* ENABLE_ELUNA */ // Notify the outdoor pvp script @@ -252,7 +258,10 @@ bool GameObject::Create(uint32 guidlow, uint32 name_id, Map* map, uint32 phaseMa // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnSpawn(this); + if (Eluna* e = GetEluna()) + { + e->OnSpawn(this); + } #endif /* ENABLE_ELUNA */ // Notify the battleground or outdoor pvp script @@ -286,7 +295,10 @@ void GameObject::Update(uint32 update_diff, uint32 p_time) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->UpdateAI(this, update_diff); + if (Eluna* e = GetEluna()) + { + e->UpdateAI(this, update_diff); + } #endif /* ENABLE_ELUNA */ switch (m_lootState) @@ -2262,7 +2274,10 @@ void GameObject::SetLootState(LootState state) { m_lootState = state; #ifdef ENABLE_ELUNA - sEluna->OnLootStateChanged(this, state); + if (Eluna* e = GetEluna()) + { + e->OnLootStateChanged(this, state); + } #endif /* ENABLE_ELUNA */ UpdateCollisionState(); } @@ -2271,7 +2286,10 @@ void GameObject::SetGoState(GOState state) { SetByteValue(GAMEOBJECT_BYTES_1, 0, state); #ifdef ENABLE_ELUNA - sEluna->OnGameObjectStateChanged(this, state); + if (Eluna* e = GetEluna()) + { + e->OnGameObjectStateChanged(this, state); + } #endif /* ENABLE_ELUNA */ UpdateCollisionState(); } @@ -2782,7 +2800,10 @@ void GameObject::ForceGameObjectHealth(int32 diff, Unit* caster) #ifdef ENABLE_ELUNA if (caster && caster->ToPlayer()) { - sEluna->OnDamaged(this, caster->ToPlayer()); + if (Eluna* e = caster->GetEluna()) + { + e->OnDamaged(this, caster->ToPlayer()); + } } #endif if (m_useTimes > uint32(-diff)) @@ -2835,7 +2856,10 @@ void GameObject::ForceGameObjectHealth(int32 diff, Unit* caster) #ifdef ENABLE_ELUNA if(caster && caster->ToPlayer()) { - sEluna->OnDestroyed(this, caster->ToPlayer()); + if (Eluna* e = caster->GetEluna()) + { + e->OnDestroyed(this, caster->ToPlayer()); + } } #endif RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_UNK_9 | GO_FLAG_UNK_10); diff --git a/src/game/Object/Guild.cpp b/src/game/Object/Guild.cpp index 67562b7b32..bd21bb2a4a 100644 --- a/src/game/Object/Guild.cpp +++ b/src/game/Object/Guild.cpp @@ -161,7 +161,10 @@ bool Guild::Create(Player* leader, std::string gname) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnCreate(this, leader, gname.c_str()); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnCreate(this, leader, gname.c_str()); + } #endif /* ENABLE_ELUNA */ return AddMember(m_LeaderGuid, (uint32)GR_GUILDMASTER); @@ -274,7 +277,10 @@ bool Guild::AddMember(ObjectGuid plGuid, uint32 plRank) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnAddMember(this, pl, newmember.RankId); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnAddMember(this, pl, newmember.RankId); + } #endif /* ENABLE_ELUNA */ return true; @@ -290,7 +296,10 @@ void Guild::SetMOTD(std::string motd) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnMOTDChanged(this, motd); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnMOTDChanged(this, motd); + } #endif /* ENABLE_ELUNA */ } @@ -304,7 +313,10 @@ void Guild::SetGINFO(std::string ginfo) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnInfoChanged(this, ginfo); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnInfoChanged(this, ginfo); + } #endif /* ENABLE_ELUNA */ } @@ -644,7 +656,10 @@ bool Guild::DelMember(ObjectGuid guid, bool isDisbanding) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnRemoveMember(this, player, isDisbanding); // IsKicked not a part of Mangos, implement? + if (Eluna* e = sWorld.GetEluna()) + { + e->OnRemoveMember(this, player, isDisbanding); // IsKicked not a part of Mangos, implement? + } #endif /* ENABLE_ELUNA */ return members.empty(); @@ -897,7 +912,10 @@ void Guild::Disband() // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnDisband(this); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnDisband(this); + } #endif /* ENABLE_ELUNA */ sGuildMgr.RemoveGuild(m_Id); @@ -1466,7 +1484,10 @@ bool Guild::MemberMoneyWithdraw(uint32 amount, uint32 LowGuid) #ifdef ENABLE_ELUNA Player* player = sObjectMgr.GetPlayer(ObjectGuid(HIGHGUID_PLAYER, LowGuid)); - sEluna->OnMemberWitdrawMoney(this, player, amount, false); // IsRepair not a part of Mangos, implement? + if (Eluna* e = sWorld.GetEluna()) + { + e->OnMemberWitdrawMoney(this, player, amount, false); // IsRepair not a part of Mangos, implement? + } #endif return true; @@ -1918,7 +1939,10 @@ void Guild::LogBankEvent(uint8 EventType, uint8 TabId, uint32 PlayerGuidLow, uin } #ifdef ENABLE_ELUNA - sEluna->OnBankEvent(this, EventType, TabId, PlayerGuidLow, ItemOrMoney, ItemStackCount, DestTabId); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnBankEvent(this, EventType, TabId, PlayerGuidLow, ItemOrMoney, ItemStackCount, DestTabId); + } #endif // save event to database diff --git a/src/game/Object/Item.cpp b/src/game/Object/Item.cpp index 1e6b284422..efb05e6c98 100644 --- a/src/game/Object/Item.cpp +++ b/src/game/Object/Item.cpp @@ -356,7 +356,10 @@ void Item::UpdateDuration(Player* owner, uint32 diff) { // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnExpire(owner, GetProto()); + if (Eluna* e = owner->GetEluna()) + { + e->OnExpire(owner, GetProto()); + } #endif /* ENABLE_ELUNA */ if (uint32 newItemId = sObjectMgr.GetItemExpireConvert(GetEntry())) diff --git a/src/game/Object/Object.cpp b/src/game/Object/Object.cpp index 938afb376d..4155dce736 100644 --- a/src/game/Object/Object.cpp +++ b/src/game/Object/Object.cpp @@ -54,6 +54,7 @@ #ifdef ENABLE_ELUNA #include "LuaEngine.h" +#include "ElunaConfig.h" #include "ElunaEventMgr.h" #endif /* ENABLE_ELUNA */ @@ -1063,7 +1064,7 @@ void Object::MarkForClientUpdate() WorldObject::WorldObject() : #ifdef ENABLE_ELUNA - elunaEvents(NULL), + elunaEvents(nullptr), #endif /* ENABLE_ELUNA */ m_transportInfo(NULL), m_currMap(NULL), @@ -1076,7 +1077,7 @@ WorldObject::~WorldObject() { #ifdef ENABLE_ELUNA delete elunaEvents; - elunaEvents = NULL; + elunaEvents = nullptr; #endif /* ENABLE_ELUNA */ } @@ -1088,7 +1089,10 @@ void WorldObject::CleanupsBeforeDelete() void WorldObject::Update(uint32 update_diff, uint32 time_diff) { #ifdef ENABLE_ELUNA - elunaEvents->Update(update_diff); + if (elunaEvents) // can be null on maps without eluna + { + elunaEvents->Update(update_diff); + } #endif /* ENABLE_ELUNA */ } @@ -1752,13 +1756,6 @@ void WorldObject::SetMap(Map* map) // lets save current map's Id/instanceId m_mapId = map->GetId(); m_InstanceId = map->GetInstanceId(); - -#ifdef ENABLE_ELUNA - if (!elunaEvents) - { - elunaEvents = new ElunaEventProcessor(&Eluna::GEluna, this); - } -#endif } void WorldObject::ResetMap() @@ -1825,7 +1822,10 @@ Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, floa #ifdef ENABLE_ELUNA if (Unit* summoner = ToUnit()) { - sEluna->OnSummoned(pCreature, summoner); + if (Eluna* e = GetEluna()) + { + e->OnSummoned(pCreature, summoner); + } } #endif /* ENABLE_ELUNA */ @@ -2269,3 +2269,15 @@ void WorldObject::SetActiveObjectState(bool active) } m_isActiveObject = active; } + +#ifdef ENABLE_ELUNA +Eluna* WorldObject::GetEluna() const +{ + if (IsInWorld()) + { + return GetMap()->GetEluna(); + } + + return nullptr; +} +#endif /* ENABLE_ELUNA */ diff --git a/src/game/Object/Object.h b/src/game/Object/Object.h index cebea0d04f..46b57bad98 100644 --- a/src/game/Object/Object.h +++ b/src/game/Object/Object.h @@ -32,6 +32,9 @@ #include "ObjectGuid.h" #include "Camera.h" #include "GameTime.h" +#ifdef ENABLE_ELUNA +#include "LuaValue.h" +#endif /* ENABLE_ELUNA */ #include #include @@ -83,7 +86,9 @@ class UpdateMask; class InstanceData; class TerrainInfo; #ifdef ENABLE_ELUNA +class Eluna; class ElunaEventProcessor; +class LuaVal; #endif /* ENABLE_ELUNA */ class TransportInfo; struct MangosStringLocale; @@ -711,6 +716,10 @@ class WorldObject : public Object #ifdef ENABLE_ELUNA ElunaEventProcessor* elunaEvents; + + Eluna* GetEluna() const; + + LuaVal lua_data = LuaVal({}); #endif /* ENABLE_ELUNA */ protected: diff --git a/src/game/Object/Player.cpp b/src/game/Object/Player.cpp index 65f6a68426..d80dff2cc1 100644 --- a/src/game/Object/Player.cpp +++ b/src/game/Object/Player.cpp @@ -1550,7 +1550,10 @@ void Player::Update(uint32 update_diff, uint32 p_time) // m_nextSave reseted in SaveToDB call // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnSave(this); + if (Eluna* e = GetEluna()) + { + e->OnSave(this); + } #endif /* ENABLE_ELUNA */ SaveToDB(); DETAIL_LOG("Player '%s' (GUID: %u) saved", GetName(), GetGUIDLow()); @@ -2852,7 +2855,10 @@ void Player::GiveXP(uint32 xp, Unit* victim) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnGiveXP(this, xp, victim); + if (Eluna* e = GetEluna()) + { + e->OnGiveXP(this, xp, victim); + } #endif /* ENABLE_ELUNA */ // XP to money conversion processed in Player::RewardQuest @@ -2997,7 +3003,10 @@ void Player::SetLevel(uint32 level) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnLevelChanged(this, oldLevel); + if (Eluna* e = GetEluna()) + { + e->OnLevelChanged(this, oldLevel); + } #endif /* ENABLE_ELUNA */ if (MailLevelReward const* mailReward = sObjectMgr.GetMailLevelReward(level, getRaceMask())) @@ -3012,7 +3021,10 @@ void Player::SetFreeTalentPoints(uint32 points) { // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnFreeTalentPointsChanged(this, points); + if (Eluna* e = GetEluna()) + { + e->OnFreeTalentPointsChanged(this, points); + } #endif /* ENABLE_ELUNA */ SetUInt32Value(PLAYER_CHARACTER_POINTS1, points); @@ -4369,7 +4381,10 @@ bool Player::resetTalents(bool no_cost, bool all_specs) { // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnTalentsReset(this, no_cost); + if (Eluna* e = GetEluna()) + { + e->OnTalentsReset(this, no_cost); + } #endif /* ENABLE_ELUNA */ // not need after this call @@ -5309,7 +5324,10 @@ void Player::ResurrectPlayer(float restore_percent, bool applySickness) UpdateObjectVisibility(); #ifdef ENABLE_ELUNA - sEluna->OnResurrect(this); + if (Eluna* e = GetEluna()) + { + e->OnResurrect(this); + } #endif /* ENABLE_ELUNA */ if (!applySickness) @@ -8119,7 +8137,10 @@ void Player::UpdateZone(uint32 newZone, uint32 newArea) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnUpdateZone(this, newZone, newArea); + if (Eluna* e = GetEluna()) + { + e->OnUpdateZone(this, newZone, newArea); + } #endif /* ENABLE_ELUNA */ m_zoneUpdateId = newZone; @@ -8274,7 +8295,10 @@ void Player::DuelComplete(DuelCompleteType type) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnDuelEnd(duel->opponent, this, type); + if (Eluna* e = GetEluna()) + { + e->OnDuelEnd(duel->opponent, this, type); + } #endif /* ENABLE_ELUNA */ if (type == DUEL_WON) @@ -13002,10 +13026,13 @@ InventoryResult Player::CanUseItem(ItemPrototype const* pProto) const } #ifdef ENABLE_ELUNA - InventoryResult eres = sEluna->OnCanUseItem(this, pProto->ItemId); - if (eres != EQUIP_ERR_OK) + if (Eluna* e = GetEluna()) { - return eres; + InventoryResult eres = e->OnCanUseItem(this, pProto->ItemId); + if (eres != EQUIP_ERR_OK) + { + return eres; + } } #endif @@ -13375,7 +13402,11 @@ Item* Player::EquipItem(uint16 pos, Item* pItem, bool update) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnEquip(this, pItem2, bag, slot); + if (Eluna* e = GetEluna()) + { + e->OnEquip(this, pItem2, bag, slot); // This is depricated and will be removed in the future + e->OnItemEquip(this, pItem2, slot); + } #endif /* ENABLE_ELUNA */ return pItem2; @@ -13391,7 +13422,11 @@ Item* Player::EquipItem(uint16 pos, Item* pItem, bool update) GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM, slot + 1); // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnEquip(this, pItem, bag, slot); + if (Eluna* e = GetEluna()) + { + e->OnEquip(this, pItem, bag, slot); // This is depricated and will be removed in the future + e->OnItemEquip(this, pItem, slot); + } #endif /* ENABLE_ELUNA */ return pItem; @@ -13648,7 +13683,10 @@ void Player::DestroyItem(uint8 bag, uint8 slot, bool update) ItemRemovedQuestCheck(pItem->GetEntry(), pItem->GetCount()); #ifdef ENABLE_ELUNA - sEluna->OnRemove(this, pItem); + if (Eluna* e = GetEluna()) + { + e->OnRemove(this, pItem); + } #endif /* ENABLE_ELUNA */ if (bag == INVENTORY_SLOT_BAG_0) @@ -19983,7 +20021,10 @@ InstancePlayerBind* Player::BindToInstance(DungeonPersistentState* state, bool p // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnBindToInstance(this, state->GetDifficulty(), state->GetMapId(), permanent); + if (Eluna* e = GetEluna()) + { + e->OnBindToInstance(this, state->GetDifficulty(), state->GetMapId(), permanent); + } #endif /* ENABLE_ELUNA */ return &bind; } @@ -20236,6 +20277,17 @@ void Player::SaveToDB() CharacterDatabase.BeginTransaction(); +#ifdef ENABLE_ELUNA + // Hack to check that this is not on create save + if (Eluna* e = GetEluna()) + { + if (!HasAtLoginFlag(AT_LOGIN_FIRST)) + { + e->OnSave(this); + } + } +#endif /* ENABLE_ELUNA */ + static SqlStatementID delChar ; static SqlStatementID insChar ; @@ -21442,7 +21494,10 @@ void Player::UpdateDuelFlag(time_t currTime) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnDuelStart(this, duel->opponent); + if (Eluna* e = GetEluna()) + { + e->OnDuelStart(this, duel->opponent); + } #endif /* ENABLE_ELUNA */ SetUInt32Value(PLAYER_DUEL_TEAM, 1); @@ -26023,7 +26078,10 @@ void Player::LearnTalent(uint32 talentId, uint32 talentRank) DETAIL_LOG("TalentID: %u Rank: %u Spell: %u\n", talentId, talentRank, spellid); #ifdef ENABLE_ELUNA - sEluna->OnLearnTalents(this, talentId, talentRank, spellid); + if (Eluna* e = GetEluna()) + { + e->OnLearnTalents(this, talentId, talentRank, spellid); + } #endif /*ENABLE_ELUNA*/ } @@ -26878,8 +26936,11 @@ void Player::UpdateSpecCount(uint8 count) void Player::ModifyMoney(int32 d) { #ifdef ENABLE_ELUNA - sEluna->OnMoneyChanged(this, d); -#endif + if (Eluna* e = GetEluna()) + { + e->OnMoneyChanged(this, d); + } +#endif /* ENABLE_ELUNA */ if (d < 0) { diff --git a/src/game/Object/ReputationMgr.cpp b/src/game/Object/ReputationMgr.cpp index e5fd18804b..160407da26 100644 --- a/src/game/Object/ReputationMgr.cpp +++ b/src/game/Object/ReputationMgr.cpp @@ -261,8 +261,11 @@ void ReputationMgr::Initialize() void ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standing, bool incremental) { #ifdef ENABLE_ELUNA - sEluna->OnReputationChange(m_player, factionEntry->ID, standing, incremental); -#endif + if (Eluna* e = m_player->GetEluna()) + { + e->OnReputationChange(m_player, factionEntry->ID, standing, incremental); + } +#endif /* ENABLE_ELUNA */ bool anyRankIncreased = false; // if spillover definition exists in DB, override DBC diff --git a/src/game/Object/Totem.cpp b/src/game/Object/Totem.cpp index eb45bca75a..e088509bef 100644 --- a/src/game/Object/Totem.cpp +++ b/src/game/Object/Totem.cpp @@ -120,8 +120,11 @@ void Totem::Summon(Unit* owner) ((Creature*)owner)->AI()->JustSummoned((Creature*)this); } #ifdef ENABLE_ELUNA - sEluna->OnSummoned(this, owner); -#endif + if (Eluna* e = this->GetEluna()) + { + e->OnSummoned(this, owner); + } +#endif /* ENABLE_ELUNA */ // there are some totems, which exist just for their visual appeareance if (!GetSpell()) diff --git a/src/game/Object/Unit.cpp b/src/game/Object/Unit.cpp index 99195c65ae..54b8343323 100644 --- a/src/game/Object/Unit.cpp +++ b/src/game/Object/Unit.cpp @@ -60,6 +60,7 @@ #include "GameTime.h" #ifdef ENABLE_ELUNA #include "LuaEngine.h" +#include "ElunaConfig.h" #include "ElunaEventMgr.h" #endif /* ENABLE_ELUNA */ @@ -337,10 +338,6 @@ void Unit::Update(uint32 update_diff, uint32 p_time) }else m_AurasCheck -= p_time;*/ -#ifdef ENABLE_ELUNA - elunaEvents->Update(update_diff); -#endif /* ENABLE_ELUNA */ - // WARNING! Order of execution here is important, do not change. // Spells must be processed with event system BEFORE they go to _UpdateSpells. // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad. @@ -928,9 +925,12 @@ uint32 Unit::DealDamage(Unit* pVictim, uint32 damage, CleanDamage const* cleanDa { // Used by Eluna #ifdef ENABLE_ELUNA - if (Player* killed = pVictim->ToPlayer()) + if (Eluna* e = killer->GetEluna()) { - sEluna->OnPlayerKilledByCreature(killer, killed); + if (Player* killed = pVictim->ToPlayer()) + { + e->OnPlayerKilledByCreature(killer, killed); + } } #endif /* ENABLE_ELUNA */ } @@ -1011,7 +1011,10 @@ uint32 Unit::DealDamage(Unit* pVictim, uint32 damage, CleanDamage const* cleanDa // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnPVPKill(player_tap, playerVictim); + if (Eluna* e = player_tap->GetEluna()) + { + e->OnPVPKill(player_tap, playerVictim); + } #endif /* ENABLE_ELUNA */ } } @@ -1241,9 +1244,12 @@ void Unit::JustKilledCreature(Creature* victim, Player* responsiblePlayer) bg->HandleKillUnit(victim, responsiblePlayer); } - // Used by Eluna + // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnCreatureKill(responsiblePlayer, victim); + if (Eluna* e = responsiblePlayer->GetEluna()) + { + e->OnCreatureKill(responsiblePlayer, victim); + } #endif /* ENABLE_ELUNA */ } @@ -9546,9 +9552,12 @@ void Unit::SetInCombatState(bool PvP, Unit* enemy) // Used by Eluna #ifdef ENABLE_ELUNA - if (GetTypeId() == TYPEID_PLAYER) + if (Eluna* e = GetEluna()) { - sEluna->OnPlayerEnterCombat(ToPlayer(), enemy); + if (GetTypeId() == TYPEID_PLAYER) + { + e->OnPlayerEnterCombat(ToPlayer(), enemy); + } } #endif /* ENABLE_ELUNA */ } @@ -9565,9 +9574,12 @@ void Unit::ClearInCombat() // Used by Eluna #ifdef ENABLE_ELUNA - if (GetTypeId() == TYPEID_PLAYER) + if (Eluna* e = GetEluna()) { - sEluna->OnPlayerLeaveCombat(ToPlayer()); + if (GetTypeId() == TYPEID_PLAYER) + { + e->OnPlayerLeaveCombat(ToPlayer()); + } } #endif /* ENABLE_ELUNA */ @@ -11456,6 +11468,16 @@ void Unit::AddToWorld() { Object::AddToWorld(); ScheduleAINotify(0); + +#ifdef ENABLE_ELUNA + if (Eluna* e = GetEluna()) + { + if (!elunaEvents) + { + elunaEvents = new ElunaEventProcessor(e, this); + } + } +#endif } void Unit::RemoveFromWorld() @@ -11474,6 +11496,16 @@ void Unit::RemoveFromWorld() GetViewPoint().Event_RemovedFromWorld(); } +#ifdef ENABLE_ELUNA + // if multistate, delete elunaEvents and set to nullptr. events shouldn't move across states. + // in single state, the timed events should move across maps + if (!sElunaConfig->IsElunaCompatibilityMode()) + { + delete elunaEvents; + elunaEvents = nullptr; // set to null in case map doesn't use eluna + } +#endif + Object::RemoveFromWorld(); } diff --git a/src/game/Object/Vehicle.cpp b/src/game/Object/Vehicle.cpp index 76a16086f1..2f3e97ec31 100644 --- a/src/game/Object/Vehicle.cpp +++ b/src/game/Object/Vehicle.cpp @@ -154,7 +154,10 @@ void VehicleInfo::Initialize() int32 basepoint0 = itr->seatId + 1; summoned->CastCustomSpell((Unit*)m_owner, SPELL_RIDE_VEHICLE_HARDCODED, &basepoint0, NULL, NULL, true); #ifdef ENABLE_ELUNA - sEluna->OnInstallAccessory(this, summoned); + if (Eluna* e = summoned->GetEluna()) + { + e->OnInstallAccessory(this, summoned); + } #endif } } @@ -195,9 +198,9 @@ void VehicleInfo::Initialize() m_isInitialized = true; -#ifdef ENABLE_ELUNA - sEluna->OnInstall(this); -#endif +//#ifdef ENABLE_ELUNA +// sEluna->OnInstall(this); +//#endif } /* @@ -277,7 +280,10 @@ void VehicleInfo::Board(Unit* passenger, uint8 seat) ApplySeatMods(passenger, seatEntry->m_flags); #ifdef ENABLE_ELUNA - sEluna->OnAddPassenger(this, passenger, seat); + if (Eluna* e = passenger->GetEluna()) + { + e->OnAddPassenger(this, passenger, seat); + } #endif } @@ -405,7 +411,10 @@ void VehicleInfo::UnBoard(Unit* passenger, bool changeVehicle) RemoveSeatMods(passenger, seatEntry->m_flags); #ifdef ENABLE_ELUNA - sEluna->OnRemovePassenger(this, passenger); + if (Eluna* e = passenger->GetEluna()) + { + e->OnRemovePassenger(this, passenger); + } #endif // Some creature vehicles get despawned after passenger unboarding diff --git a/src/game/Server/WorldSession.cpp b/src/game/Server/WorldSession.cpp index 29f67e45a6..e5a4050bc0 100644 --- a/src/game/Server/WorldSession.cpp +++ b/src/game/Server/WorldSession.cpp @@ -560,7 +560,10 @@ void WorldSession::LogoutPlayer(bool Save) ///- Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnLogout(_player); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnLogout(_player); + } #endif /* ENABLE_ELUNA */ ///- Remove the player from the world @@ -1105,9 +1108,12 @@ void WorldSession::SendGmResurrectSuccessResponse() void WorldSession::ExecuteOpcode(OpcodeHandler const& opHandle, WorldPacket* packet) { #ifdef ENABLE_ELUNA - if (!sEluna->OnPacketReceive(this, *packet)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnPacketReceive(this, *packet)) + { + return; + } } #endif /* ENABLE_ELUNA */ diff --git a/src/game/Server/WorldSocket.cpp b/src/game/Server/WorldSocket.cpp index cdb7835ad6..0bc7834156 100644 --- a/src/game/Server/WorldSocket.cpp +++ b/src/game/Server/WorldSocket.cpp @@ -179,10 +179,14 @@ int WorldSocket::SendPacket(const WorldPacket& pkt) sLog.outWorldPacketDump(uint32(get_handle()), pct.GetOpcode(), pct.GetOpcodeName(), &pct, false); #ifdef ENABLE_ELUNA - if (!sEluna->OnPacketSend(m_Session, pct)) - { - return 0; - } + // TODO: ELUNAFIX NEEDED + //if (Eluna* e = pkt>GetEluna()) + //{ + // if (!e->OnPacketSend(m_Session, pct)) + // { + // return 0; + // } + //} #endif ServerPktHeader header(pct.size() + 2, pct.GetOpcode()); @@ -749,9 +753,12 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct) } #ifdef ENABLE_ELUNA - if (!sEluna->OnPacketReceive(m_Session, *new_pct)) + if (Eluna* e = sWorld.GetEluna()) { - return 0; + if (!e->OnPacketReceive(m_Session, *new_pct)) + { + return 0; + } } #endif /* ENABLE_ELUNA */ return HandleAuthSession(*new_pct); @@ -759,7 +766,10 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct) DEBUG_LOG("CMSG_KEEP_ALIVE ,size: %zu ", new_pct->size()); #ifdef ENABLE_ELUNA - sEluna->OnPacketReceive(m_Session, *new_pct); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnPacketReceive(m_Session, *new_pct); + } #endif /* ENABLE_ELUNA */ return 0; default: diff --git a/src/game/WorldHandlers/AuctionHouseHandler.cpp b/src/game/WorldHandlers/AuctionHouseHandler.cpp index ec03ef07f8..b6c1f91b85 100644 --- a/src/game/WorldHandlers/AuctionHouseHandler.cpp +++ b/src/game/WorldHandlers/AuctionHouseHandler.cpp @@ -412,7 +412,10 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnAdd(auctionHouse, AH); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnAdd(auctionHouse, AH); + } #endif /* ENABLE_ELUNA */ } } @@ -590,7 +593,10 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recv_data) auctionHouse->RemoveAuction(auction->Id); // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnRemove(auctionHouse, auction); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnRemove(auctionHouse, auction); + } #endif /* ENABLE_ELUNA */ delete auction; } diff --git a/src/game/WorldHandlers/CharacterHandler.cpp b/src/game/WorldHandlers/CharacterHandler.cpp index 9a1cbbc848..8dc3b6f645 100644 --- a/src/game/WorldHandlers/CharacterHandler.cpp +++ b/src/game/WorldHandlers/CharacterHandler.cpp @@ -528,7 +528,10 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnCreate(pNewChar); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnCreate(pNewChar); + } #endif /* ENABLE_ELUNA */ delete pNewChar; // created only to call SaveToDB() @@ -589,7 +592,10 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnDelete(lowguid); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnDelete(lowguid); + } #endif /* ENABLE_ELUNA */ if (sLog.IsOutCharDump()) // optimize GetPlayerDump call @@ -919,9 +925,12 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder) // Used by Eluna #ifdef ENABLE_ELUNA - if (pCurrChar->HasAtLoginFlag(AT_LOGIN_FIRST)) + if (Eluna* e = pCurrChar->GetEluna()) { - sEluna->OnFirstLogin(pCurrChar); + if (pCurrChar->HasAtLoginFlag(AT_LOGIN_FIRST)) + { + e->OnFirstLogin(pCurrChar); + } } #endif /* ENABLE_ELUNA */ @@ -974,7 +983,10 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnLogin(pCurrChar); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnLogin(pCurrChar); + } #endif /* ENABLE_ELUNA */ // Handle Login-Achievements (should be handled after loading) diff --git a/src/game/WorldHandlers/Chat.cpp b/src/game/WorldHandlers/Chat.cpp index 440ec68b2c..8d3cca797f 100644 --- a/src/game/WorldHandlers/Chat.cpp +++ b/src/game/WorldHandlers/Chat.cpp @@ -1411,9 +1411,12 @@ void ChatHandler::ExecuteCommand(const char* text) case CHAT_COMMAND_UNKNOWN_SUBCOMMAND: { #ifdef ENABLE_ELUNA - if (!sEluna->OnCommand(m_session ? m_session->GetPlayer() : NULL, fullcmd.c_str())) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnCommand(m_session ? m_session->GetPlayer() : NULL, fullcmd.c_str())) + { + return; + } } #endif /* ENABLE_ELUNA */ SendSysMessage(LANG_NO_SUBCMD); @@ -1424,9 +1427,12 @@ void ChatHandler::ExecuteCommand(const char* text) case CHAT_COMMAND_UNKNOWN: { #ifdef ENABLE_ELUNA - if (!sEluna->OnCommand(m_session ? m_session->GetPlayer() : NULL, fullcmd.c_str())) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnCommand(m_session ? m_session->GetPlayer() : NULL, fullcmd.c_str())) + { + return; + } } #endif /* ENABLE_ELUNA */ SendSysMessage(LANG_NO_CMD); diff --git a/src/game/WorldHandlers/ChatHandler.cpp b/src/game/WorldHandlers/ChatHandler.cpp index 2121b20d22..30fb27d1f6 100644 --- a/src/game/WorldHandlers/ChatHandler.cpp +++ b/src/game/WorldHandlers/ChatHandler.cpp @@ -215,9 +215,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) if (type == CHAT_MSG_SAY) { #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg)) + { + return; + } } #endif /* ENABLE_ELUNA */ GetPlayer()->Say(msg, lang); @@ -225,9 +228,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) else if (type == CHAT_MSG_EMOTE) { #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, LANG_UNIVERSAL, msg)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, LANG_UNIVERSAL, msg)) + { + return; + } } #endif /* ENABLE_ELUNA */ GetPlayer()->TextEmote(msg); @@ -235,9 +241,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) else if (type == CHAT_MSG_YELL) { #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg)) + { + return; + } } #endif /* ENABLE_ELUNA */ GetPlayer()->Yell(msg, lang); @@ -293,9 +302,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, player)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg, player)) + { + return; + } } #endif /* ENABLE_ELUNA */ GetPlayer()->Whisper(msg, lang, player->GetObjectGuid()); @@ -345,9 +357,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + { + return; + } } #endif /* ENABLE_ELUNA */ @@ -387,9 +402,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) { // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, guild)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg, guild)) + { + return; + } } #endif /* ENABLE_ELUNA */ @@ -428,9 +446,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) { // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, guild)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg, guild)) + { + return; + } } #endif /* ENABLE_ELUNA */ @@ -477,9 +498,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + { + return; + } } #endif /* ENABLE_ELUNA */ @@ -525,9 +549,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + { + return; + } } #endif /* ENABLE_ELUNA */ @@ -560,9 +587,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + { + return; + } } #endif /* ENABLE_ELUNA */ @@ -596,9 +626,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + { + return; + } } #endif /* ENABLE_ELUNA */ @@ -631,9 +664,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + { + return; + } } #endif /* ENABLE_ELUNA */ @@ -664,9 +700,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) { // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, chn)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg, chn)) + { + return; + } } #endif /* ENABLE_ELUNA */ @@ -706,9 +745,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) } // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg)) + { + return; + } } #endif /* ENABLE_ELUNA */ } @@ -743,9 +785,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) } // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg)) + if (Eluna* e = sWorld.GetEluna()) { - return; + if (!e->OnChat(GetPlayer(), type, lang, msg)) + { + return; + } } #endif /* ENABLE_ELUNA */ @@ -770,7 +815,10 @@ void WorldSession::HandleEmoteOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnEmote(GetPlayer(), emote); + if (Eluna* e = GetPlayer()->GetEluna()) + { + e->OnEmote(GetPlayer(), emote); + } #endif /* ENABLE_ELUNA */ GetPlayer()->HandleEmoteCommand(emote); } @@ -834,7 +882,10 @@ void WorldSession::HandleTextEmoteOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnTextEmote(GetPlayer(), text_emote, emoteNum, guid); + if (Eluna* e = GetPlayer()->GetEluna()) + { + e->OnTextEmote(GetPlayer(), text_emote, emoteNum, guid); + } #endif /* ENABLE_ELUNA */ EmotesTextEntry const* em = sEmotesTextStore.LookupEntry(text_emote); diff --git a/src/game/WorldHandlers/GameEventMgr.cpp b/src/game/WorldHandlers/GameEventMgr.cpp index ee7cab7b4b..cfb6eadab8 100644 --- a/src/game/WorldHandlers/GameEventMgr.cpp +++ b/src/game/WorldHandlers/GameEventMgr.cpp @@ -106,9 +106,12 @@ void GameEventMgr::StartEvent(uint16 event_id, bool overwrite /*=false*/, bool r } } #ifdef ENABLE_ELUNA - if (IsActiveEvent(event_id)) + if (Eluna* e = sWorld.GetEluna()) { - sEluna->OnGameEventStart(event_id); + if (IsActiveEvent(event_id)) + { + e->OnGameEventStart(event_id); + } } #endif /* ENABLE_ELUNA */ } @@ -125,9 +128,12 @@ void GameEventMgr::StopEvent(uint16 event_id, bool overwrite) } } #ifdef ENABLE_ELUNA - if (!IsActiveEvent(event_id)) + if (Eluna* e = sWorld.GetEluna()) { - sEluna->OnGameEventStop(event_id); + if (!IsActiveEvent(event_id)) + { + e->OnGameEventStop(event_id); + } } #endif /* ENABLE_ELUNA */ } diff --git a/src/game/WorldHandlers/Group.cpp b/src/game/WorldHandlers/Group.cpp index a083bccb25..963d704550 100644 --- a/src/game/WorldHandlers/Group.cpp +++ b/src/game/WorldHandlers/Group.cpp @@ -199,7 +199,10 @@ bool Group::Create(ObjectGuid guid, const char* name) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnCreate(this, m_leaderGuid, m_groupType); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnCreate(this, m_leaderGuid, m_groupType); + } #endif /* ENABLE_ELUNA */ return true; @@ -318,7 +321,10 @@ bool Group::AddInvite(Player* player) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnInviteMember(this, player->GetObjectGuid()); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnInviteMember(this, player->GetObjectGuid()); + } #endif /* ENABLE_ELUNA */ return true; @@ -414,7 +420,10 @@ bool Group::AddMember(ObjectGuid guid, const char* name) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnAddMember(this, player->GetObjectGuid()); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnAddMember(this, player->GetObjectGuid()); + } #endif /* ENABLE_ELUNA */ // quest related GO state dependent from raid membership @@ -427,7 +436,7 @@ bool Group::AddMember(ObjectGuid guid, const char* name) return true; } -uint32 Group::RemoveMember(ObjectGuid guid, uint8 method) +uint32 Group::RemoveMember(ObjectGuid guid, uint8 removeMethod) { // remove member and change leader (if need) only if strong more 2 members _before_ member remove if (GetMembersCount() > uint32(isBGGroup() ? 1 : 2)) // in BG group case allow 1 members group @@ -444,7 +453,7 @@ uint32 Group::RemoveMember(ObjectGuid guid, uint8 method) WorldPacket data; - if (method == 1) + if (removeMethod == 1) { data.Initialize(SMSG_GROUP_UNINVITE, 0); player->GetSession()->SendPacket(&data); @@ -483,7 +492,10 @@ uint32 Group::RemoveMember(ObjectGuid guid, uint8 method) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnRemoveMember(this, guid, method); // Kicker and Reason not a part of Mangos, implement? + if (Eluna* e = sWorld.GetEluna()) + { + e->OnRemoveMember(this, guid, removeMethod); // Kicker and Reason not a part of Mangos, implement? + } #endif /* ENABLE_ELUNA */ return m_memberSlots.size(); @@ -499,7 +511,10 @@ void Group::ChangeLeader(ObjectGuid guid) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnChangeLeader(this, guid, GetLeaderGuid()); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnChangeLeader(this, guid, GetLeaderGuid()); + } #endif /* ENABLE_ELUNA */ _setLeader(guid); @@ -591,7 +606,10 @@ void Group::Disband(bool hideDestroy) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnDisband(this); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnDisband(this); + } #endif /* ENABLE_ELUNA */ m_leaderGuid.Clear(); diff --git a/src/game/WorldHandlers/GuildHandler.cpp b/src/game/WorldHandlers/GuildHandler.cpp index 3d928dbd83..9fdb3d5705 100644 --- a/src/game/WorldHandlers/GuildHandler.cpp +++ b/src/game/WorldHandlers/GuildHandler.cpp @@ -1003,7 +1003,11 @@ void WorldSession::HandleGuildBankDepositMoney(WorldPacket& recv_data) pGuild->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_MONEY, uint8(0), GetPlayer()->GetGUIDLow(), money); #ifdef ENABLE_ELUNA - sEluna->OnMemberDepositMoney(pGuild, GetPlayer(), money); + // TODO: ELUNAFIX NEEDED + //if (Eluna* e = xxx->GetEluna()) + //{ + // e->OnMemberDepositMoney(pGuild, GetPlayer(), money); + //} #endif pGuild->DisplayGuildBankTabsInfo(this); diff --git a/src/game/WorldHandlers/LootHandler.cpp b/src/game/WorldHandlers/LootHandler.cpp index ef6370fca9..ea1b0e8b5a 100644 --- a/src/game/WorldHandlers/LootHandler.cpp +++ b/src/game/WorldHandlers/LootHandler.cpp @@ -187,7 +187,10 @@ void WorldSession::HandleAutostoreLootItemOpcode(WorldPacket& recv_data) player->SendNewItem(newitem, uint32(item->count), false, false, true); #ifdef ENABLE_ELUNA - sEluna->OnLootItem(player, newitem, item->count, lguid); + if (Eluna* e = player->GetEluna()) + { + e->OnLootItem(player, newitem, item->count, lguid); + } #endif /* ENABLE_ELUNA */ player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM, item->itemid, item->count); @@ -235,6 +238,14 @@ void WorldSession::HandleLootMoneyOpcode(WorldPacket& /*recv_data*/) if (bones && bones->IsWithinDistInMap(_player, INTERACTION_DISTANCE)) { pLoot = &bones->loot; + + // Used by Eluna + #ifdef ENABLE_ELUNA + if (Eluna* e = player->GetEluna()) + { + e->OnLootMoney(player, pLoot->gold); + } + #endif /* ENABLE_ELUNA */ } break; @@ -317,7 +328,10 @@ void WorldSession::HandleLootMoneyOpcode(WorldPacket& /*recv_data*/) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnLootMoney(player, pLoot->gold); + if (Eluna* e = player->GetEluna()) + { + e->OnLootMoney(player, pLoot->gold); + } #endif /* ENABLE_ELUNA */ pLoot->gold = 0; @@ -676,7 +690,10 @@ void WorldSession::HandleLootMasterGiveOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnLootItem(target, newitem, item.count, lootguid); + if (Eluna* e = target->GetEluna()) + { + e->OnLootItem(target, newitem, item.count, lootguid); + } #endif /* ENABLE_ELUNA */ // mark as looted diff --git a/src/game/WorldHandlers/Map.cpp b/src/game/WorldHandlers/Map.cpp index f2fc9906bc..b22b809fbd 100644 --- a/src/game/WorldHandlers/Map.cpp +++ b/src/game/WorldHandlers/Map.cpp @@ -48,12 +48,28 @@ #include "Weather.h" #ifdef ENABLE_ELUNA #include "LuaEngine.h" +#include "ElunaConfig.h" +#include "ElunaLoader.h" #endif /* ENABLE_ELUNA */ Map::~Map() { #ifdef ENABLE_ELUNA - sEluna->OnDestroy(this); + if (Eluna* e = GetEluna()) + { + e->OnDestroy(this); + } + + if (Eluna* e = GetEluna()) + { + if (Instanceable()) + { + e->FreeInstanceId(GetInstanceId()); + } + } + + delete eluna; + eluna = nullptr; #endif /* ENABLE_ELUNA */ UnloadAll(true); @@ -68,13 +84,6 @@ Map::~Map() m_persistentState->SetUsedByMapState(NULL); // field pointer can be deleted after this } -#ifdef ENABLE_ELUNA - if (Instanceable()) - { - sEluna->FreeInstanceId(GetInstanceId()); - } -#endif /* ENABLE_ELUNA */ - delete i_data; i_data = NULL; @@ -112,6 +121,16 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode) i_gridExpiry(expiry), m_TerrainData(sTerrainMgr.LoadTerrain(id)), i_data(NULL), i_script_id(0) { +#ifdef ENABLE_ELUNA + // lua state begins uninitialized + eluna = nullptr; + + if (sElunaConfig->IsElunaEnabled() && !sElunaConfig->IsElunaCompatibilityMode() && sElunaConfig->ShouldMapLoadEluna(id)) + { + eluna = new Eluna(this); + } +#endif + m_CreatureGuids.Set(sObjectMgr.GetFirstTemporaryCreatureLowGuid()); m_GameObjectGuids.Set(sObjectMgr.GetFirstTemporaryGameObjectLowGuid()); @@ -137,7 +156,10 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode) m_weatherSystem = new WeatherSystem(this); #ifdef ENABLE_ELUNA - sEluna->OnCreate(this); + if (Eluna* e = GetEluna()) + { + e->OnCreate(this); + } #endif /* ENABLE_ELUNA */ } @@ -361,8 +383,11 @@ bool Map::Add(Player* player) UpdateObjectVisibility(player, cell, p); #ifdef ENABLE_ELUNA - sEluna->OnMapChanged(player); - sEluna->OnPlayerEnter(this, player); + if (Eluna* e = GetEluna()) + { + e->OnMapChanged(player); + e->OnPlayerEnter(this, player); + } #endif /* ENABLE_ELUNA */ if (i_data) @@ -650,7 +675,15 @@ void Map::Update(const uint32& t_diff) } #ifdef ENABLE_ELUNA - sEluna->OnUpdate(this, t_diff); + if (Eluna* e = GetEluna()) + { + if (!sElunaConfig->IsElunaCompatibilityMode()) + { + e->UpdateEluna(t_diff); + } + + e->OnUpdate(this, t_diff); + } #endif /* ENABLE_ELUNA */ if (i_data) @@ -664,7 +697,10 @@ void Map::Update(const uint32& t_diff) void Map::Remove(Player* player, bool remove) { #ifdef ENABLE_ELUNA - sEluna->OnPlayerLeave(this, player); + if (Eluna* e = GetEluna()) + { + e->OnPlayerLeave(this, player); + } #endif /* ENABLE_ELUNA */ if (i_data) @@ -1120,13 +1156,16 @@ void Map::AddObjectToRemoveList(WorldObject* obj) MANGOS_ASSERT(obj->GetMapId() == GetId() && obj->GetInstanceId() == GetInstanceId()); #ifdef ENABLE_ELUNA - if (Creature* creature = obj->ToCreature()) - { - sEluna->OnRemove(creature); - } - else if (GameObject* gameobject = obj->ToGameObject()) + if (Eluna* e = GetEluna()) { - sEluna->OnRemove(gameobject); + if (Creature* creature = obj->ToCreature()) + { + e->OnRemove(creature); + } + else if (GameObject* gameobject = obj->ToGameObject()) + { + e->OnRemove(gameobject); + } } #endif /* ENABLE_ELUNA */ @@ -1342,7 +1381,10 @@ void Map::CreateInstanceData(bool load) } #ifdef ENABLE_ELUNA - i_data = sEluna->GetInstanceData(this); + if (Eluna* e = GetEluna()) + { + i_data = e->GetInstanceData(this); + } #endif /* ENABLE_ELUNA */ uint32 i_script_id = GetScriptId(); @@ -2519,3 +2561,15 @@ bool Map::GetReachableRandomPosition(Unit* unit, float& x, float& y, float& z, f return false; } + +#ifdef ENABLE_ELUNA +Eluna* Map::GetEluna() const +{ + if (sElunaConfig->IsElunaCompatibilityMode()) + { + return sWorld.GetEluna(); + } + + return eluna; +} +#endif /* ENABLE_ELUNA */ diff --git a/src/game/WorldHandlers/Map.h b/src/game/WorldHandlers/Map.h index 42a5b25e55..98d024c84a 100644 --- a/src/game/WorldHandlers/Map.h +++ b/src/game/WorldHandlers/Map.h @@ -44,12 +44,18 @@ #include "ScriptMgr.h" #include "CreatureLinkingMgr.h" #include "DynamicTree.h" +#ifdef ENABLE_ELUNA +#include "LuaValue.h" +#endif /* ENABLE_ELUNA */ #include #include struct CreatureInfo; class Creature; +#ifdef ENABLE_ELUNA +class Eluna; +#endif /* ENABLE_ELUNA */ class Unit; class WorldPacket; class InstanceData; @@ -321,6 +327,12 @@ class Map : public GridRefManager bool GetRandomPointInTheAir(uint32 phaseMask, float& x, float& y, float& z, float radius); bool GetRandomPointUnderWater(uint32 phaseMask, float& x, float& y, float& z, float radius, GridMapLiquidData& liquid_status); +#ifdef ENABLE_ELUNA + Eluna* GetEluna() const; + + LuaVal lua_data = LuaVal({}); +#endif /* ENABLE_ELUNA */ + private: void LoadMapAndVMap(int gx, int gy); @@ -417,6 +429,10 @@ class Map : public GridRefManager // WeatherSystem WeatherSystem* m_weatherSystem; + +#ifdef ENABLE_ELUNA + Eluna* eluna; +#endif /* ENABLE_ELUNA */ }; class WorldMap : public Map diff --git a/src/game/WorldHandlers/MapManager.cpp b/src/game/WorldHandlers/MapManager.cpp index fdc1c92558..936a89a152 100644 --- a/src/game/WorldHandlers/MapManager.cpp +++ b/src/game/WorldHandlers/MapManager.cpp @@ -34,6 +34,10 @@ #include "Corpse.h" #include "ObjectMgr.h" +#ifdef ENABLE_ELUNA +#include "ElunaConfig.h" +#endif /* ENABLE_ELUNA */ + #define CLASS_LOCK MaNGOS::ClassLevelLockable INSTANTIATE_SINGLETON_2(MapManager, CLASS_LOCK); INSTANTIATE_CLASS_MUTEX(MapManager, ACE_Recursive_Thread_Mutex); @@ -64,6 +68,16 @@ MapManager::Initialize() { int num_threads(sWorld.getConfig(CONFIG_UINT32_NUMTHREADS)); +#ifdef ENABLE_ELUNA + if (sElunaConfig->IsElunaEnabled() && sElunaConfig->IsElunaCompatibilityMode() && num_threads > 1) + { + // Force 1 thread for Eluna if compatibility mode is enabled. Compatibility mode is single state and does not allow more update threads. + sLog.outError("Map update threads set to %i, when Eluna in compatibility mode only allows 1, changing to 1", num_threads); + num_threads = 1; + } +#endif /* ENABLE_ELUNA */ + + // Start mtmaps if needed. if (num_threads > 0 && m_updater.activate(num_threads) == -1) { abort(); @@ -426,3 +440,11 @@ BattleGroundMap* MapManager::CreateBattleGroundMap(uint32 id, uint32 InstanceId, return map; } + +void MapManager::DoForAllMaps(const std::function& worker) +{ + for (MapMapType::const_iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr) + { + worker(itr->second); + } +} diff --git a/src/game/WorldHandlers/MapManager.h b/src/game/WorldHandlers/MapManager.h index f7bb6018b4..e75076eefc 100644 --- a/src/game/WorldHandlers/MapManager.h +++ b/src/game/WorldHandlers/MapManager.h @@ -160,8 +160,17 @@ class MapManager : public MaNGOS::Singleton void DoForAllMaps(Do& _do) + { + for (auto& mapData : i_maps) + { + _do(mapData.second); + } + } + template void DoForAllMapsWithMapId(uint32 mapId, Do& _do); + void DoForAllMaps(const std::function& worker); private: diff --git a/src/game/WorldHandlers/MiscHandler.cpp b/src/game/WorldHandlers/MiscHandler.cpp index f021104ec5..62be91d8ad 100644 --- a/src/game/WorldHandlers/MiscHandler.cpp +++ b/src/game/WorldHandlers/MiscHandler.cpp @@ -81,7 +81,10 @@ void WorldSession::HandleRepopRequestOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnRepop(GetPlayer()); + if (Eluna* e = GetPlayer()->GetEluna()) + { + e->OnRepop(GetPlayer()); + } #endif /* ENABLE_ELUNA */ // this is spirit release confirm? diff --git a/src/game/WorldHandlers/NPCHandler.cpp b/src/game/WorldHandlers/NPCHandler.cpp index c9b74eea8b..8a0a9712ff 100644 --- a/src/game/WorldHandlers/NPCHandler.cpp +++ b/src/game/WorldHandlers/NPCHandler.cpp @@ -459,7 +459,10 @@ void WorldSession::HandleGossipSelectOptionOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->HandleGossipSelectOption(GetPlayer(), item, GetPlayer()->PlayerTalkClass->GossipOptionSender(gossipListId), GetPlayer()->PlayerTalkClass->GossipOptionAction(gossipListId), code); + if (Eluna* e = GetPlayer()->GetEluna()) + { + e->HandleGossipSelectOption(GetPlayer(), item, GetPlayer()->PlayerTalkClass->GossipOptionSender(gossipListId), GetPlayer()->PlayerTalkClass->GossipOptionAction(gossipListId), code); + } #endif /* ENABLE_ELUNA */ } else if (guid.IsPlayer()) @@ -472,7 +475,10 @@ void WorldSession::HandleGossipSelectOptionOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->HandleGossipSelectOption(GetPlayer(), menuId, GetPlayer()->PlayerTalkClass->GossipOptionSender(gossipListId), GetPlayer()->PlayerTalkClass->GossipOptionAction(gossipListId), code); + if (Eluna* e = GetPlayer()->GetEluna()) + { + e->HandleGossipSelectOption(GetPlayer(), menuId, GetPlayer()->PlayerTalkClass->GossipOptionSender(gossipListId), GetPlayer()->PlayerTalkClass->GossipOptionAction(gossipListId), code); + } #endif /* ENABLE_ELUNA */ } } diff --git a/src/game/WorldHandlers/QuestHandler.cpp b/src/game/WorldHandlers/QuestHandler.cpp index ad86273ae6..283908d77b 100644 --- a/src/game/WorldHandlers/QuestHandler.cpp +++ b/src/game/WorldHandlers/QuestHandler.cpp @@ -414,8 +414,11 @@ void WorldSession::HandleQuestLogRemoveQuest(WorldPacket& recv_data) } #ifdef ENABLE_ELUNA - sEluna->OnQuestAbandon(_player, quest); -#endif + if (Eluna* e = _player->GetEluna()) + { + e->OnQuestAbandon(_player, quest); + } +#endif /* ENABLE_ELUNA */ } _player->SetQuestSlot(slot, 0); diff --git a/src/game/WorldHandlers/ScriptMgr.cpp b/src/game/WorldHandlers/ScriptMgr.cpp index a99308e0d4..58c54cf9b3 100644 --- a/src/game/WorldHandlers/ScriptMgr.cpp +++ b/src/game/WorldHandlers/ScriptMgr.cpp @@ -2664,9 +2664,12 @@ CreatureAI* ScriptMgr::GetCreatureAI(Creature* pCreature) { // Used by Eluna #ifdef ENABLE_ELUNA - if (CreatureAI* luaAI = sEluna->GetAI(pCreature)) + if (Eluna* e = pCreature->GetEluna()) { - return luaAI; + if (CreatureAI* luaAI = e->GetAI(pCreature)) + { + return luaAI; + } } #endif /* ENABLE_ELUNA */ @@ -2700,9 +2703,12 @@ bool ScriptMgr::OnGossipHello(Player* pPlayer, Creature* pCreature) { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnGossipHello(pPlayer, pCreature)) + if (Eluna* e = pPlayer->GetEluna()) { - return true; + if (e->OnGossipHello(pPlayer, pCreature)) + { + return true; + } } #endif /* ENABLE_ELUNA */ @@ -2717,9 +2723,12 @@ bool ScriptMgr::OnGossipHello(Player* pPlayer, GameObject* pGameObject) { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnGossipHello(pPlayer, pGameObject)) + if (Eluna* e = pPlayer->GetEluna()) { - return true; + if (e->OnGossipHello(pPlayer, pGameObject)) + { + return true; + } } #endif /* ENABLE_ELUNA */ @@ -2747,18 +2756,19 @@ bool ScriptMgr::OnGossipHello(Player* pPlayer, Item* pItem) bool ScriptMgr::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code) { #ifdef ENABLE_ELUNA - if (code) + if (Eluna* e = pPlayer->GetEluna()) { - // Used by Eluna - if (sEluna->OnGossipSelectCode(pPlayer, pCreature, sender, action, code)) + if (code) { - return true; + if (e->OnGossipSelectCode(pPlayer, pCreature, sender, action, code)) + { + return true; + } } } else { - // Used by Eluna - if (sEluna->OnGossipSelect(pPlayer, pCreature, sender, action)) + if (e->OnGossipSelect(pPlayer, pCreature, sender, action)) { return true; } @@ -2783,16 +2793,20 @@ bool ScriptMgr::OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 { // Used by Eluna #ifdef ENABLE_ELUNA - if (code) + if (Eluna* e = pPlayer->GetEluna()) { - if (sEluna->OnGossipSelectCode(pPlayer, pGameObject, sender, action, code)) + + if (code) { - return true; + if (e->OnGossipSelectCode(pPlayer, pGameObject, sender, action, code)) + { + return true; + } } } else { - if (sEluna->OnGossipSelect(pPlayer, pGameObject, sender, action)) + if (e->OnGossipSelect(pPlayer, pGameObject, sender, action)) { return true; } @@ -2838,9 +2852,12 @@ bool ScriptMgr::OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnQuestAccept(pPlayer, pCreature, pQuest)) + if (Eluna* e = pPlayer->GetEluna()) { - return true; + if (e->OnQuestAccept(pPlayer, pCreature, pQuest)) + { + return true; + } } #endif /* ENABLE_ELUNA */ @@ -2855,9 +2872,12 @@ bool ScriptMgr::OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest co { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnQuestAccept(pPlayer, pGameObject, pQuest)) + if (Eluna* e = pPlayer->GetEluna()) { - return true; + if (e->OnQuestAccept(pPlayer, pGameObject, pQuest)) + { + return true; + } } #endif /* ENABLE_ELUNA */ @@ -2872,9 +2892,12 @@ bool ScriptMgr::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest) { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnQuestAccept(pPlayer, pItem, pQuest)) + if (Eluna* e = pPlayer->GetEluna()) { - return true; + if (e->OnQuestAccept(pPlayer, pItem, pQuest)) + { + return true; + } } #endif /* ENABLE_ELUNA */ @@ -2889,9 +2912,12 @@ bool ScriptMgr::OnQuestRewarded(Player* pPlayer, Creature* pCreature, Quest cons { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnQuestReward(pPlayer, pCreature, pQuest, reward)) + if (Eluna* e = pPlayer->GetEluna()) { - return true; + if (e->OnQuestReward(pPlayer, pCreature, pQuest, reward)) + { + return true; + } } #endif /* ENABLE_ELUNA */ @@ -2906,9 +2932,12 @@ bool ScriptMgr::OnQuestRewarded(Player* pPlayer, GameObject* pGameObject, Quest { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnQuestReward(pPlayer, pGameObject, pQuest, reward)) + if (Eluna* e = pPlayer->GetEluna()) { - return true; + if (e->OnQuestReward(pPlayer, pGameObject, pQuest, reward)) + { + return true; + } } #endif /* ENABLE_ELUNA */ @@ -2923,7 +2952,10 @@ uint32 ScriptMgr::GetDialogStatus(Player* pPlayer, Creature* pCreature) { // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->GetDialogStatus(pPlayer, pCreature); + if (Eluna* e = pPlayer->GetEluna()) + { + e->GetDialogStatus(pPlayer, pCreature); + } #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2937,7 +2969,10 @@ uint32 ScriptMgr::GetDialogStatus(Player* pPlayer, GameObject* pGameObject) { // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->GetDialogStatus(pPlayer, pGameObject); + if (Eluna* e = pPlayer->GetEluna()) + { + e->GetDialogStatus(pPlayer, pGameObject); + } #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2950,9 +2985,12 @@ uint32 ScriptMgr::GetDialogStatus(Player* pPlayer, GameObject* pGameObject) bool ScriptMgr::OnGameObjectUse(Player* pPlayer, GameObject* pGameObject) { #ifdef ENABLE_ELUNA - if (sEluna->OnGameObjectUse(pPlayer, pGameObject)) + if (Eluna* e = pPlayer->GetEluna()) { - return true; + if (e->OnGameObjectUse(pPlayer, pGameObject)) + { + return true; + } } #endif /* ENABLE_ELUNA */ @@ -2978,9 +3016,12 @@ bool ScriptMgr::OnItemUse(Player* pPlayer, Item* pItem, SpellCastTargets const& { // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnUse(pPlayer, pItem, targets)) + if (Eluna* e = pPlayer->GetEluna()) { - return true; + if (!e->OnUse(pPlayer, pItem, targets)) + { + return true; + } } #endif /* ENABLE_ELUNA */ @@ -2995,9 +3036,12 @@ bool ScriptMgr::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* atEntry) { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnAreaTrigger(pPlayer, atEntry)) + if (Eluna* e = pPlayer->GetEluna()) { - return true; + if (e->OnAreaTrigger(pPlayer, atEntry)) + { + return true; + } } #endif /* ENABLE_ELUNA */ @@ -3032,7 +3076,10 @@ bool ScriptMgr::OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectIndex ef #ifdef ENABLE_ELUNA if (Creature* creature = pTarget->ToCreature()) { - sEluna->OnDummyEffect(pCaster, spellId, effIndex, creature); + if (Eluna* e = pCaster->GetEluna()) + { + e->OnDummyEffect(pCaster, spellId, effIndex, creature); + } } #endif /* ENABLE_ELUNA */ @@ -3048,7 +3095,10 @@ bool ScriptMgr::OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectIndex ef { // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnDummyEffect(pCaster, spellId, effIndex, pTarget); + if (Eluna* e = pCaster->GetEluna()) + { + e->OnDummyEffect(pCaster, spellId, effIndex, pTarget); + } #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -3062,7 +3112,10 @@ bool ScriptMgr::OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectIndex ef { // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnDummyEffect(pCaster, spellId, effIndex, pTarget); + if (Eluna* e = pCaster->GetEluna()) + { + e->OnDummyEffect(pCaster, spellId, effIndex, pTarget); + } #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 diff --git a/src/game/WorldHandlers/Spell.cpp b/src/game/WorldHandlers/Spell.cpp index a565efb7a4..e7935dccff 100644 --- a/src/game/WorldHandlers/Spell.cpp +++ b/src/game/WorldHandlers/Spell.cpp @@ -3946,11 +3946,17 @@ void Spell::cast(bool skipCheck) } ((Player*)m_caster)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL, m_spellInfo->Id); + } #ifdef ENABLE_ELUNA - sEluna->OnSpellCast(m_caster->ToPlayer(), this, skipCheck); -#endif /* ENABLE_ELUNA */ + if (Eluna* e = m_caster->GetEluna()) + { + if (m_caster->GetTypeId() == TYPEID_PLAYER) + { + e->OnSpellCast(m_caster->ToPlayer(), this, skipCheck); + } } +#endif /* ENABLE_ELUNA */ FillTargetMap(); diff --git a/src/game/WorldHandlers/SpellEffects.cpp b/src/game/WorldHandlers/SpellEffects.cpp index 96ce2f9feb..7ce997af35 100644 --- a/src/game/WorldHandlers/SpellEffects.cpp +++ b/src/game/WorldHandlers/SpellEffects.cpp @@ -6534,13 +6534,21 @@ void Spell::EffectSummonType(SpellEffectIndex eff_idx) #ifdef ENABLE_ELUNA if (Unit* summoner = m_caster->ToUnit()) { - sEluna->OnSummoned(itr->creature, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(itr->creature, summoner); + } } else if (m_originalCaster) + { if (Unit* summoner = m_originalCaster->ToUnit()) { - sEluna->OnSummoned(itr->creature, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(itr->creature, summoner); + } } + } #endif } } @@ -6578,7 +6586,10 @@ bool Spell::DoSummonWild(CreatureSummonPositions& list, SummonPropertiesEntry co #ifdef ENABLE_ELUNA if (Unit* summoner = m_originalCaster->ToUnit()) { - sEluna->OnSummoned(summon, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(summon, summoner); + } } #endif } @@ -6660,12 +6671,18 @@ bool Spell::DoSummonCritter(CreatureSummonPositions& list, SummonPropertiesEntry #ifdef ENABLE_ELUNA if (Unit* summoner = m_caster->ToUnit()) { - sEluna->OnSummoned(critter, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(critter, summoner); + } } if (m_originalCaster) if (Unit* summoner = m_originalCaster->ToUnit()) { - sEluna->OnSummoned(critter, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(critter, summoner); + } } #endif @@ -6751,13 +6768,21 @@ bool Spell::DoSummonGuardian(CreatureSummonPositions& list, SummonPropertiesEntr #ifdef ENABLE_ELUNA if (Unit* summoner = m_caster->ToUnit()) { - sEluna->OnSummoned(spawnCreature, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(spawnCreature, summoner); + } } if (m_originalCaster) + { if (Unit* summoner = m_originalCaster->ToUnit()) { - sEluna->OnSummoned(spawnCreature, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(spawnCreature, summoner); + } } + } #endif } @@ -6910,7 +6935,10 @@ bool Spell::DoSummonPossessed(CreatureSummonPositions& list, SummonPropertiesEnt #ifdef ENABLE_ELUNA if (Unit* summoner = m_originalCaster->ToUnit()) { - sEluna->OnSummoned(spawnCreature, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(spawnCreature, summoner); + } } #endif } @@ -7028,12 +7056,18 @@ bool Spell::DoSummonPet(SpellEffectIndex eff_idx) #ifdef ENABLE_ELUNA if (Unit* summoner = m_caster->ToUnit()) { - sEluna->OnSummoned(spawnCreature, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(spawnCreature, summoner); + } } if (m_originalCaster) if (Unit* summoner = m_originalCaster->ToUnit()) { - sEluna->OnSummoned(spawnCreature, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(spawnCreature, summoner); + } } #endif @@ -7096,7 +7130,10 @@ bool Spell::DoSummonVehicle(CreatureSummonPositions& list, SummonPropertiesEntry if (m_originalCaster) if (Unit* summoner = m_originalCaster->ToUnit()) { - sEluna->OnSummoned(spawnCreature, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(spawnCreature, summoner); + } } #endif @@ -11943,8 +11980,11 @@ void Spell::EffectDuel(SpellEffectIndex eff_idx) target->SetGuidValue(PLAYER_DUEL_ARBITER, pGameObj->GetObjectGuid()); #ifdef ENABLE_ELUNA - sEluna->OnDuelRequest(target, caster); -#endif + if (Eluna* e = caster->GetEluna()) + { + e->OnDuelRequest(target, caster); + } +#endif /* ENABLE_ELUNA */ } void Spell::EffectStuck(SpellEffectIndex /*eff_idx*/) @@ -12197,6 +12237,17 @@ void Spell::EffectApplyGlyph(SpellEffectIndex eff_idx) player->SendTalentsInfoData(false); } } +// TODO: ELUNAFIX NEEDED +//#ifdef ENABLE_ELUNA +// if (Unit* summoner = m_originalCaster->ToUnit()) +// { +// if (Eluna* e = player->GetEluna()) +// { +// e->OnSummoned(spawnCreature, summoner); +// } +// } +//#endif /* ENABLE_ELUNA */ + } void Spell::EffectEnchantHeldItem(SpellEffectIndex eff_idx) diff --git a/src/game/WorldHandlers/Weather.cpp b/src/game/WorldHandlers/Weather.cpp index 1b7d9ac86d..fa0cef2ef0 100644 --- a/src/game/WorldHandlers/Weather.cpp +++ b/src/game/WorldHandlers/Weather.cpp @@ -250,7 +250,10 @@ bool Weather::SendWeatherForPlayersInZone(Map const* _map) ///- Log the event LogWeatherState(state); #ifdef ENABLE_ELUNA - sEluna->OnChange(this, m_zone, GetWeatherState(), m_grade); + if (Eluna* e = sWorld.GetEluna()) + { + e->OnChange(this, m_zone, GetWeatherState(), m_grade); + } #endif /* ENABLE_ELUNA */ return true; diff --git a/src/game/WorldHandlers/World.cpp b/src/game/WorldHandlers/World.cpp index 004a93db12..016b64ab58 100644 --- a/src/game/WorldHandlers/World.cpp +++ b/src/game/WorldHandlers/World.cpp @@ -84,6 +84,8 @@ #ifdef ENABLE_ELUNA #include "LuaEngine.h" +#include "ElunaConfig.h" +#include "ElunaLoader.h" #endif /* ENABLE_ELUNA */ // WARDEN @@ -156,6 +158,12 @@ World::World() /// World destructor World::~World() { +#ifdef ENABLE_ELUNA + // Delete world Eluna state + delete eluna; + eluna = nullptr; +#endif /* ENABLE_ELUNA */ + ///- Empty the kicked session set while (!m_sessions.empty()) { @@ -186,9 +194,6 @@ void World::CleanupsBeforeStop() KickAll(); // save and kick all players UpdateSessions(1); // real players unload required UpdateSessions call sBattleGroundMgr.DeleteAllBattleGrounds(); // unload battleground templates before different singletons destroyed -#ifdef ENABLE_ELUNA - Eluna::Uninitialize(); -#endif } /// Find a session by its id @@ -1003,12 +1008,13 @@ void World::LoadConfigSettings(bool reload) MMAP::MMapFactory::preventPathfindingOnMaps(ignoreMapIds.c_str()); sLog.outString("WORLD: MMap pathfinding %sabled", getConfig(CONFIG_BOOL_MMAP_ENABLED) ? "en" : "dis"); - setConfig(CONFIG_BOOL_ELUNA_ENABLED, "Eluna.Enabled", true); - #ifdef ENABLE_ELUNA if (reload) { - sEluna->OnConfigLoad(reload); + if (Eluna* e = GetEluna()) + { + e->OnConfigLoad(reload); + } } #endif /* ENABLE_ELUNA */ sLog.outString(); @@ -1110,8 +1116,19 @@ void World::SetInitialWorldSettings() #ifdef ENABLE_ELUNA ///- Initialize Lua Engine - sLog.outString("Initialize Eluna Lua Engine..."); - Eluna::Initialize(); + + // lua state begins uninitialized + eluna = nullptr; + + sLog.outString("Loading Eluna config..."); + sElunaConfig->Initialize(); + + if (sElunaConfig->IsElunaEnabled()) + { + ///- Initialize Lua Engine + sLog.outString("Loading Lua scripts..."); + sElunaLoader->LoadScripts(); + } #endif /* ENABLE_ELUNA */ sLog.outString("Loading Page Texts..."); @@ -1429,6 +1446,17 @@ void World::SetInitialWorldSettings() sLog.outString("Returning old mails..."); sObjectMgr.ReturnOrDeleteOldMails(false); +#ifdef ENABLE_ELUNA + if (sElunaConfig->IsElunaEnabled()) + { + ///- Run eluna scripts. + sLog.outString("Starting Eluna world state..."); + // use map id -1 for the global Eluna state + eluna = new Eluna(nullptr, sElunaConfig->IsElunaCompatibilityMode()); + sLog.outString(); + } +#endif /*ENABLE_ELUNA*/ + ///- Load and initialize DBScripts Engine sLog.outString("Loading DB-Scripts Engine..."); sScriptMgr.LoadDbScripts(DBS_ON_QUEST_START); // must be after load Creature/Gameobject(Template/Data) and QuestTemplate @@ -1595,8 +1623,10 @@ void World::SetInitialWorldSettings() #ifdef ENABLE_ELUNA ///- Run eluna scripts. // in multithread foreach: run scripts - sEluna->RunScripts(); - sEluna->OnConfigLoad(false); // Must be done after Eluna is initialized and scripts have run. + if (Eluna* e = GetEluna()) + { + e->OnConfigLoad(false); // Must be done after Eluna is initialized and scripts have run. + } #endif #ifdef ENABLE_PLAYERBOTS @@ -1864,7 +1894,11 @@ void World::Update(uint32 diff) ///- Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnWorldUpdate(diff); + if (Eluna* e = GetEluna()) + { + e->UpdateEluna(diff); + e->OnWorldUpdate(diff); + } #endif /* ENABLE_ELUNA */ ///- Delete all characters which have been deleted X days before @@ -2253,7 +2287,10 @@ void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode) ///- Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnShutdownInitiate(ShutdownExitCode(exitcode), ShutdownMask(options)); + if (Eluna* e = GetEluna()) + { + e->OnShutdownInitiate(ShutdownExitCode(exitcode), ShutdownMask(options)); + } #endif /* ENABLE_ELUNA */ } @@ -2303,7 +2340,10 @@ void World::ShutdownCancel() ///- Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnShutdownCancel(); + if (Eluna* e = GetEluna()) + { + e->OnShutdownCancel(); + } #endif /* ENABLE_ELUNA */ } diff --git a/src/game/WorldHandlers/World.h b/src/game/WorldHandlers/World.h index 712cc09c9c..c8113d301a 100644 --- a/src/game/WorldHandlers/World.h +++ b/src/game/WorldHandlers/World.h @@ -38,6 +38,9 @@ #include #include +#ifdef ENABLE_ELUNA +class Eluna; +#endif /* ENABLE_ELUNA */ class Object; class ObjectGuid; class WorldPacket; @@ -370,7 +373,6 @@ enum eConfigBoolValues CONFIG_BOOL_VMAP_INDOOR_CHECK, CONFIG_BOOL_PET_UNSUMMON_AT_MOUNT, CONFIG_BOOL_MMAP_ENABLED, - CONFIG_BOOL_ELUNA_ENABLED, CONFIG_BOOL_PLAYER_COMMANDS, CONFIG_BOOL_ENABLE_QUEST_TRACKER, @@ -646,6 +648,11 @@ class World **/ void InvalidatePlayerDataToAllClient(ObjectGuid guid); +#ifdef ENABLE_ELUNA + Eluna* GetEluna() const { return eluna; } + Eluna* eluna; +#endif /* ENABLE_ELUNA */ + protected: void _UpdateGameTime(); // callback for UpdateRealmCharacters diff --git a/src/mangosd/CMakeLists.txt b/src/mangosd/CMakeLists.txt index ae5bc7530e..be5f35959a 100644 --- a/src/mangosd/CMakeLists.txt +++ b/src/mangosd/CMakeLists.txt @@ -68,7 +68,7 @@ target_include_directories(mangosd target_compile_definitions(mangosd PUBLIC - $<$:ENABLE_ELUNA> + $<$:ENABLE_ELUNA ELUNA_EXPANSION=2 ELUNA_MANGOS> ) target_link_libraries(mangosd diff --git a/src/mangosd/WorldThread.cpp b/src/mangosd/WorldThread.cpp index 6658656ce0..f8bd02d091 100644 --- a/src/mangosd/WorldThread.cpp +++ b/src/mangosd/WorldThread.cpp @@ -63,9 +63,6 @@ int WorldThread::open(void* unused) World::StopNow(ERROR_EXIT_CODE); return -1; } -#ifdef ENABLE_ELUNA - sEluna->OnStartup(); -#endif /* ENABLE_ELUNA */ activate(); return 0; @@ -106,21 +103,12 @@ int WorldThread::svc() Sleep(1000); #endif } -#ifdef ENABLE_ELUNA - sEluna->OnShutdown(); -#endif /* ENABLE_ELUNA */ sWorld.KickAll(); // save and kick all players sWorld.UpdateSessions(1); // real players unload required UpdateSessions call sWorldSocketMgr->StopNetwork(); sMapMgr.UnloadAll(); // unload all grids (including locked in memory) -#ifdef ENABLE_ELUNA - // Eluna must be unloaded after Maps, since ~Map calls sEluna->OnDestroy, - // and must be unloaded before the DB, since it can access the DB. - Eluna::Uninitialize(); -#endif /* ENABLE_ELUNA */ - sLog.outString("World Updater Thread stopped"); return 0; } diff --git a/src/mangosd/mangosd.conf.dist.in b/src/mangosd/mangosd.conf.dist.in index 94705489c0..917e284489 100644 --- a/src/mangosd/mangosd.conf.dist.in +++ b/src/mangosd/mangosd.conf.dist.in @@ -1903,13 +1903,25 @@ Warden.DBLogLevel = 0 Realm.RecommendedOrNew.Enabled = 0 Realm.RecommendedOrNew = 0 -################################################################################################################### +################################################################################################### # ELUNA SETTINGS # -# Eluna.Enabled -# Enable Eluna LuaEngine -# Default: 1 (Enabled) -# 0 (Disabled) +# Eluna.Enabled +# Description: Enable or disable Eluna LuaEngine +# Default: true - (enabled) +# false - (disabled) +# +# Eluna.CompatibilityMode +# Description: Toggles Eluna between compatibility mode (single-threaded) or multistate mode. +# Compatibility mode limits the core to a single map update thread. +# Default: true - (enabled) +# false - (disabled) +# +# Eluna.OnlyOnMaps +# Description: When Eluna is enabled, a state will only be created for a list of specified maps +# This only works for multistate mode. +# Default: "" - (enabled on all maps) +# "0,1,2,..." - (enabled on specific maps only) # # Eluna.TraceBack # Description: Sets whether to use debug.traceback function on a lua error or not. @@ -1922,8 +1934,10 @@ Realm.RecommendedOrNew = 0 # The path can be relative or absolute. # Default: "lua_scripts" # -################################################################################################################### +################################################################################################### -Eluna.Enabled = 1 -Eluna.TraceBack = false +Eluna.Enabled = true +Eluna.CompatibilityMode = false +Eluna.OnlyOnMaps = "" +Eluna.TraceBack = false Eluna.ScriptPath = "lua_scripts" diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 8355e1da8a..fcd938b72d 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -21,3 +21,7 @@ if(SCRIPT_LIB_SD3) add_subdirectory(SD3) endif() + +if(SCRIPT_LIB_ELUNA) + add_subdirectory(Eluna) +endif() \ No newline at end of file diff --git a/src/modules/Eluna b/src/modules/Eluna index 058ffa1cb7..5fd63aae9b 160000 --- a/src/modules/Eluna +++ b/src/modules/Eluna @@ -1 +1 @@ -Subproject commit 058ffa1cb7f81bb111e3022d572a6311558c1d5f +Subproject commit 5fd63aae9b2877b7bd1c444f35247c6578e06b95 diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 7ba6b6a6d1..0790860039 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -226,7 +226,7 @@ target_compile_definitions(shared $<$:MANGOS_DEBUG> MANGOS_ENDIAN=${ENDIAN_VALUE} $<$:ARCH_IS_BIG_ENDIAN> - $<$:ENABLE_ELUNA> + $<$:ENABLE_ELUNA ELUNA_EXPANSION=2 ELUNA_MANGOS> ) target_link_libraries(shared diff --git a/src/shared/Common/Common.h b/src/shared/Common/Common.h index 457ed09d5c..33c9cfa113 100644 --- a/src/shared/Common/Common.h +++ b/src/shared/Common/Common.h @@ -97,6 +97,8 @@ #include #include #include +#include +#include #include "Utilities/Errors.h" #include "LockedQueue/LockedQueue.h"