diff --git a/.github/workflows/core_windows_build.yml b/.github/workflows/core_windows_build.yml index 2b7967ebc..89d8e5e99 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=1 -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=1 -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 fa32d075d..a8669e58c 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=1 -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=1 -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 c3232b205..55d3f9c22 100644 --- a/src/game/BattleGround/BattleGround.cpp +++ b/src/game/BattleGround/BattleGround.cpp @@ -451,6 +451,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); @@ -793,7 +800,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(); @@ -1428,7 +1438,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 2c198e160..ab06af17d 100644 --- a/src/game/BattleGround/BattleGroundMgr.cpp +++ b/src/game/BattleGround/BattleGroundMgr.cpp @@ -1716,10 +1716,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 b82d2750a..4d9001640 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,8 +260,9 @@ 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 ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot @@ -272,7 +275,7 @@ target_compile_definitions(game $<$:ENABLE_SOAP> $<$:ENABLE_SD3> $<$:ENABLE_PLAYERBOTS> - $<$:ENABLE_ELUNA> + $<$:ENABLE_ELUNA ELUNA_EXPANSION=1 ELUNA_MANGOS> ) target_link_libraries(game diff --git a/src/game/Object/Creature.cpp b/src/game/Object/Creature.cpp index de9d9bad8..6761d374b 100644 --- a/src/game/Object/Creature.cpp +++ b/src/game/Object/Creature.cpp @@ -211,7 +211,10 @@ void Creature::AddToWorld() #ifdef ENABLE_ELUNA if (!inWorld) { - sEluna->OnAddToWorld(this); + if (Eluna* e = GetEluna()) + { + e->OnAddToWorld(this); + } } #endif /* ENABLE_ELUNA */ @@ -222,7 +225,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 4c40215d6..9b1fb4538 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 @@ -253,7 +259,10 @@ bool GameObject::Create(uint32 guidlow, uint32 name_id, Map* map, float x, float // 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 @@ -287,7 +296,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) @@ -2342,7 +2354,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(); } @@ -2351,7 +2366,10 @@ void GameObject::SetGoState(GOState state) { SetByteValue(GAMEOBJECT_STATE, 0, state); #ifdef ENABLE_ELUNA - sEluna->OnGameObjectStateChanged(this, state); + if (Eluna* e = GetEluna()) + { + e->OnGameObjectStateChanged(this, state); + } #endif /* ENABLE_ELUNA */ UpdateCollisionState(); } diff --git a/src/game/Object/Guild.cpp b/src/game/Object/Guild.cpp index 300216244..aed3cfdc9 100644 --- a/src/game/Object/Guild.cpp +++ b/src/game/Object/Guild.cpp @@ -168,7 +168,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); @@ -281,7 +284,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; @@ -297,7 +303,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 */ } @@ -311,7 +320,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 */ } @@ -659,7 +671,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(); @@ -879,7 +894,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); diff --git a/src/game/Object/Item.cpp b/src/game/Object/Item.cpp index 578c56769..a37ece58b 100644 --- a/src/game/Object/Item.cpp +++ b/src/game/Object/Item.cpp @@ -350,7 +350,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 */ owner->DestroyItem(GetBagSlot(), GetSlot(), true); return; diff --git a/src/game/Object/Object.cpp b/src/game/Object/Object.cpp index af82db4c9..2bfdbca6f 100644 --- a/src/game/Object/Object.cpp +++ b/src/game/Object/Object.cpp @@ -48,6 +48,7 @@ #ifdef ENABLE_ELUNA #include "LuaEngine.h" +#include "ElunaConfig.h" #include "ElunaEventMgr.h" #endif /* ENABLE_ELUNA */ @@ -1002,7 +1003,7 @@ void Object::MarkForClientUpdate() WorldObject::WorldObject() : #ifdef ENABLE_ELUNA - elunaEvents(NULL), + elunaEvents(nullptr), #endif /* ENABLE_ELUNA */ m_transportInfo(NULL), m_currMap(NULL), @@ -1015,7 +1016,7 @@ WorldObject::~WorldObject() { #ifdef ENABLE_ELUNA delete elunaEvents; - elunaEvents = NULL; + elunaEvents = nullptr; #endif /* ENABLE_ELUNA */ } @@ -1027,7 +1028,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 */ } @@ -1675,13 +1679,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() @@ -1748,7 +1745,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 */ @@ -2182,3 +2182,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 ca0c9489e..2ae03d8fe 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 @@ -76,7 +79,9 @@ class UpdateMask; class InstanceData; class TerrainInfo; #ifdef ENABLE_ELUNA +class Eluna; class ElunaEventProcessor; +class LuaVal; #endif /* ENABLE_ELUNA */ class TransportInfo; struct MangosStringLocale; @@ -695,6 +700,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 abf6b8c21..659ecd8c1 100644 --- a/src/game/Object/Player.cpp +++ b/src/game/Object/Player.cpp @@ -1504,7 +1504,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()); @@ -2719,7 +2722,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 @@ -2840,7 +2846,10 @@ void Player::GiveLevel(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())) @@ -2853,7 +2862,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); @@ -4106,7 +4118,10 @@ bool Player::resetTalents(bool no_cost) { // 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 @@ -4983,7 +4998,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) @@ -7685,7 +7703,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; @@ -7844,7 +7865,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 */ // Remove Duel Flag object @@ -11972,10 +11996,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 @@ -12340,14 +12367,22 @@ 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; } // 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; @@ -12605,7 +12640,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) @@ -18687,7 +18725,10 @@ InstancePlayerBind* Player::BindToInstance(DungeonPersistentState* state, bool p GetName(), GetGUIDLow(), state->GetMapId(), state->GetInstanceId(), state->GetDifficulty()); // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnBindToInstance(this, (Difficulty)0, state->GetMapId(), permanent); + if (Eluna* e = GetEluna()) + { + e->OnBindToInstance(this, (Difficulty)0, state->GetMapId(), permanent); + } #endif /* ENABLE_ELUNA */ return &bind; @@ -18942,9 +18983,12 @@ void Player::SaveToDB() #ifdef ENABLE_ELUNA // Hack to check that this is not on create save - if (!HasAtLoginFlag(AT_LOGIN_FIRST)) + if (Eluna* e = GetEluna()) { - sEluna->OnSave(this); + if (!HasAtLoginFlag(AT_LOGIN_FIRST)) + { + e->OnSave(this); + } } #endif /* ENABLE_ELUNA */ @@ -20004,7 +20048,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); @@ -24135,7 +24182,10 @@ void Player::LearnTalent(uint32 talentId, uint32 talentRank) learnSpell(spellid, false); 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*/ } @@ -24246,7 +24296,10 @@ void Player::ModifyMoney(int32 d) { // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnMoneyChanged(this, d); + 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 58ccb9fb9..92bf24bb1 100644 --- a/src/game/Object/ReputationMgr.cpp +++ b/src/game/Object/ReputationMgr.cpp @@ -251,7 +251,10 @@ bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standi { // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnReputationChange(m_player, factionEntry->ID, standing, incremental); + if (Eluna* e = m_player->GetEluna()) + { + e->OnReputationChange(m_player, factionEntry->ID, standing, incremental); + } #endif /* ENABLE_ELUNA */ bool res = false; diff --git a/src/game/Object/Totem.cpp b/src/game/Object/Totem.cpp index b591e2508..ff98227c0 100644 --- a/src/game/Object/Totem.cpp +++ b/src/game/Object/Totem.cpp @@ -123,7 +123,10 @@ void Totem::Summon(Unit* owner) ((Creature*)owner)->AI()->JustSummoned((Creature*)this); } #ifdef ENABLE_ELUNA - sEluna->OnSummoned(this, owner); + if (Eluna* e = this->GetEluna()) + { + e->OnSummoned(this, owner); + } #endif /* ENABLE_ELUNA */ // there are some totems, which exist just for their visual appeareance diff --git a/src/game/Object/Unit.cpp b/src/game/Object/Unit.cpp index 6f36d5fe0..d4006b30b 100644 --- a/src/game/Object/Unit.cpp +++ b/src/game/Object/Unit.cpp @@ -55,6 +55,7 @@ #include "GameTime.h" #ifdef ENABLE_ELUNA #include "LuaEngine.h" +#include "ElunaConfig.h" #include "ElunaEventMgr.h" #endif /* ENABLE_ELUNA */ @@ -322,10 +323,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. @@ -906,9 +903,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 */ } @@ -974,7 +974,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 */ } } @@ -1223,9 +1226,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 */ } @@ -8217,9 +8223,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 */ } @@ -8236,9 +8245,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 */ @@ -10032,6 +10044,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() @@ -10048,6 +10070,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/Server/WorldSession.cpp b/src/game/Server/WorldSession.cpp index 4b642f9c2..8cf613d00 100644 --- a/src/game/Server/WorldSession.cpp +++ b/src/game/Server/WorldSession.cpp @@ -631,7 +631,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 @@ -891,9 +894,12 @@ void WorldSession::SendTransferAborted(uint32 mapid, uint8 reason, uint8 arg) 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 f9b2bc582..d4580f13b 100644 --- a/src/game/Server/WorldSocket.cpp +++ b/src/game/Server/WorldSocket.cpp @@ -571,9 +571,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); @@ -581,7 +584,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 fba0c9f3f..e13424bec 100644 --- a/src/game/WorldHandlers/AuctionHouseHandler.cpp +++ b/src/game/WorldHandlers/AuctionHouseHandler.cpp @@ -362,7 +362,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 */ } @@ -533,7 +536,10 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recv_data) // 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 33a4fdf31..2f9f66b00 100644 --- a/src/game/WorldHandlers/CharacterHandler.cpp +++ b/src/game/WorldHandlers/CharacterHandler.cpp @@ -527,7 +527,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() @@ -588,7 +591,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 @@ -922,9 +928,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 */ @@ -977,7 +986,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 */ /* Used for movement */ diff --git a/src/game/WorldHandlers/Chat.cpp b/src/game/WorldHandlers/Chat.cpp index 053634164..d6ab38bc6 100644 --- a/src/game/WorldHandlers/Chat.cpp +++ b/src/game/WorldHandlers/Chat.cpp @@ -1377,9 +1377,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); @@ -1390,9 +1393,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 04d278435..6d457f011 100644 --- a/src/game/WorldHandlers/ChatHandler.cpp +++ b/src/game/WorldHandlers/ChatHandler.cpp @@ -218,9 +218,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); @@ -228,9 +231,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); @@ -238,9 +244,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); @@ -296,9 +305,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 */ #ifdef ENABLE_PLAYERBOTS @@ -351,9 +363,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 */ @@ -405,9 +420,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 */ @@ -460,9 +478,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 */ @@ -509,9 +530,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 */ @@ -569,9 +593,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 */ @@ -616,9 +643,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 */ @@ -665,9 +695,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 */ @@ -700,9 +733,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 */ @@ -733,9 +769,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 */ #ifdef ENABLE_PLAYERBOTS @@ -781,9 +820,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 */ } @@ -818,9 +860,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 */ @@ -845,7 +890,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); } @@ -909,7 +957,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 ae5832f0b..b5979bd0b 100644 --- a/src/game/WorldHandlers/GameEventMgr.cpp +++ b/src/game/WorldHandlers/GameEventMgr.cpp @@ -105,9 +105,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 } @@ -124,9 +127,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 } diff --git a/src/game/WorldHandlers/Group.cpp b/src/game/WorldHandlers/Group.cpp index 1996da9db..f5668d243 100644 --- a/src/game/WorldHandlers/Group.cpp +++ b/src/game/WorldHandlers/Group.cpp @@ -160,7 +160,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; @@ -273,7 +276,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; @@ -360,7 +366,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 @@ -373,7 +382,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 @@ -390,7 +399,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); @@ -428,7 +437,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(); @@ -444,7 +456,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); @@ -534,7 +549,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/LootHandler.cpp b/src/game/WorldHandlers/LootHandler.cpp index a3e3c65cf..d24293209 100644 --- a/src/game/WorldHandlers/LootHandler.cpp +++ b/src/game/WorldHandlers/LootHandler.cpp @@ -215,7 +215,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 */ } else @@ -259,6 +262,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; @@ -332,7 +343,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; @@ -714,7 +728,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 996d98d46..f5f17ab98 100644 --- a/src/game/WorldHandlers/Map.cpp +++ b/src/game/WorldHandlers/Map.cpp @@ -47,12 +47,28 @@ #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); @@ -67,13 +83,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; @@ -111,6 +120,16 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode) i_gridExpiry(expiry), m_TerrainData(sTerrainMgr.LoadTerrain(id)), i_data(NULL) { +#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()); @@ -136,7 +155,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 */ } @@ -350,8 +372,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) @@ -639,7 +664,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) @@ -653,7 +686,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) @@ -1101,13 +1137,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 */ @@ -1323,7 +1362,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(); @@ -2501,3 +2543,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 521cd217d..07d1125c3 100644 --- a/src/game/WorldHandlers/Map.h +++ b/src/game/WorldHandlers/Map.h @@ -42,11 +42,17 @@ #include "ScriptMgr.h" #include "CreatureLinkingMgr.h" #include "DynamicTree.h" +#ifdef ENABLE_ELUNA +#include "LuaValue.h" +#endif /* ENABLE_ELUNA */ #include struct CreatureInfo; class Creature; +#ifdef ENABLE_ELUNA +class Eluna; +#endif /* ENABLE_ELUNA */ class Unit; class WorldPacket; class InstanceData; @@ -316,6 +322,12 @@ class Map : public GridRefManager bool GetRandomPointInTheAir(float& x, float& y, float& z, float radius); bool GetRandomPointUnderWater(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); @@ -406,6 +418,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 efd8288a0..9b3df1980 100644 --- a/src/game/WorldHandlers/MapManager.cpp +++ b/src/game/WorldHandlers/MapManager.cpp @@ -33,6 +33,10 @@ #include "CellImpl.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); @@ -63,6 +67,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(); @@ -432,3 +446,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 d091ffa4a..a9004e853 100644 --- a/src/game/WorldHandlers/MapManager.h +++ b/src/game/WorldHandlers/MapManager.h @@ -161,8 +161,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 df2fe7de0..3ea3fd5cd 100644 --- a/src/game/WorldHandlers/MiscHandler.cpp +++ b/src/game/WorldHandlers/MiscHandler.cpp @@ -73,7 +73,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 6447dd205..534f6691b 100644 --- a/src/game/WorldHandlers/NPCHandler.cpp +++ b/src/game/WorldHandlers/NPCHandler.cpp @@ -451,7 +451,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()) @@ -464,7 +467,10 @@ void WorldSession::HandleGossipSelectOptionOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->HandleGossipSelectOption(GetPlayer(), GetPlayer()->PlayerTalkClass->GetGossipMenu().GetMenuId(), GetPlayer()->PlayerTalkClass->GossipOptionSender(gossipListId), GetPlayer()->PlayerTalkClass->GossipOptionAction(gossipListId), code); + if (Eluna* e = GetPlayer()->GetEluna()) + { + e->HandleGossipSelectOption(GetPlayer(), GetPlayer()->PlayerTalkClass->GetGossipMenu().GetMenuId(), 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 8c2d4a803..a78ea8798 100644 --- a/src/game/WorldHandlers/QuestHandler.cpp +++ b/src/game/WorldHandlers/QuestHandler.cpp @@ -411,7 +411,10 @@ void WorldSession::HandleQuestLogRemoveQuest(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnQuestAbandon(_player, quest); + if (Eluna* e = _player->GetEluna()) + { + e->OnQuestAbandon(_player, quest); + } #endif /* ENABLE_ELUNA */ } diff --git a/src/game/WorldHandlers/ScriptMgr.cpp b/src/game/WorldHandlers/ScriptMgr.cpp index a99308e0d..58c54cf9b 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 93f92beac..9cc164ede 100644 --- a/src/game/WorldHandlers/Spell.cpp +++ b/src/game/WorldHandlers/Spell.cpp @@ -3467,12 +3467,15 @@ void Spell::cast(bool skipCheck) // set to real guid to be sent later to the client m_targets.updateTradeSlotItem(); - if (m_caster->GetTypeId() == TYPEID_PLAYER) - { #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 f11401cb0..3e1c55919 100644 --- a/src/game/WorldHandlers/SpellEffects.cpp +++ b/src/game/WorldHandlers/SpellEffects.cpp @@ -4306,12 +4306,18 @@ void Spell::DoSummon(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); + } } else if (m_originalCaster) if (Unit* summoner = m_originalCaster->ToUnit()) { - sEluna->OnSummoned(spawnCreature, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(spawnCreature, summoner); + } } #endif /* ENABLE_ELUNA */ } @@ -4701,7 +4707,10 @@ void Spell::DoSummonWild(SpellEffectIndex eff_idx, uint32 forceFaction) if (m_originalCaster) if (Unit* summoner = m_originalCaster->ToUnit()) { - sEluna->OnSummoned(summon, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(summon, summoner); + } } #endif /* ENABLE_ELUNA */ } @@ -4818,12 +4827,18 @@ void Spell::DoSummonGuardian(SpellEffectIndex eff_idx, uint32 forceFaction) #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 /* ENABLE_ELUNA */ } @@ -6973,7 +6988,10 @@ void Spell::EffectDuel(SpellEffectIndex eff_idx) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnDuelRequest(target, caster); + if (Eluna* e = caster->GetEluna()) + { + e->OnDuelRequest(target, caster); + } #endif /* ENABLE_ELUNA */ } @@ -7321,7 +7339,10 @@ bool Spell::DoSummonPossessed(SpellEffectIndex eff_idx, uint32 forceFaction) #ifdef ENABLE_ELUNA if (Unit* summoner = m_originalCaster->ToUnit()) { - sEluna->OnSummoned(spawnCreature, summoner); + if (Eluna* e = summoner->GetEluna()) + { + e->OnSummoned(spawnCreature, summoner); + } } #endif /* ENABLE_ELUNA */ return true; @@ -8074,12 +8095,18 @@ void Spell::DoSummonCritter(SpellEffectIndex eff_idx, uint32 forceFaction) #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 /* ENABLE_ELUNA */ } diff --git a/src/game/WorldHandlers/Weather.cpp b/src/game/WorldHandlers/Weather.cpp index 5cf9a72bf..021a85cc6 100644 --- a/src/game/WorldHandlers/Weather.cpp +++ b/src/game/WorldHandlers/Weather.cpp @@ -253,7 +253,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 03a7038fe..a8117226e 100644 --- a/src/game/WorldHandlers/World.cpp +++ b/src/game/WorldHandlers/World.cpp @@ -80,6 +80,8 @@ #ifdef ENABLE_ELUNA #include "LuaEngine.h" +#include "ElunaConfig.h" +#include "ElunaLoader.h" #endif /* ENABLE_ELUNA */ #ifdef ENABLE_PLAYERBOTS @@ -157,6 +159,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()) { @@ -187,9 +195,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 @@ -977,12 +982,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(); @@ -1082,8 +1088,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..."); @@ -1366,6 +1383,17 @@ void World::SetInitialWorldSettings() sLog.outString("Loading GM tickets..."); sTicketMgr.LoadGMTickets(); +#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 @@ -1521,8 +1549,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 @@ -1769,7 +1799,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 @@ -2162,7 +2196,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 */ } @@ -2212,7 +2249,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 0ad444350..4d1706e8f 100644 --- a/src/game/WorldHandlers/World.h +++ b/src/game/WorldHandlers/World.h @@ -37,6 +37,9 @@ #include #include +#ifdef ENABLE_ELUNA +class Eluna; +#endif /* ENABLE_ELUNA */ class Object; class ObjectGuid; class WorldPacket; @@ -358,7 +361,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 ae5bc7530..0f2435125 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=1 ELUNA_MANGOS> ) target_link_libraries(mangosd diff --git a/src/mangosd/WorldThread.cpp b/src/mangosd/WorldThread.cpp index 6658656ce..f8bd02d09 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 f01ba282c..de5dc51e4 100644 --- a/src/mangosd/mangosd.conf.dist.in +++ b/src/mangosd/mangosd.conf.dist.in @@ -1820,13 +1820,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. @@ -1839,8 +1851,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 8355e1da8..fcd938b72 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 058ffa1cb..38f1f7c73 160000 --- a/src/modules/Eluna +++ b/src/modules/Eluna @@ -1 +1 @@ -Subproject commit 058ffa1cb7f81bb111e3022d572a6311558c1d5f +Subproject commit 38f1f7c73355f1f63a125020498d4fe79895089f diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 7ba6b6a6d..7be005450 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=1 ELUNA_MANGOS> ) target_link_libraries(shared diff --git a/src/shared/Common/Common.h b/src/shared/Common/Common.h index 457ed09d5..33c9cfa11 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"