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 316d3e98e..03a6d278f 100644 --- a/src/game/BattleGround/BattleGround.cpp +++ b/src/game/BattleGround/BattleGround.cpp @@ -454,6 +454,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); @@ -774,7 +781,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(); @@ -1281,7 +1291,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 21260881b..602329a6f 100644 --- a/src/game/BattleGround/BattleGroundMgr.cpp +++ b/src/game/BattleGround/BattleGroundMgr.cpp @@ -1231,10 +1231,6 @@ uint32 BattleGroundMgr::CreateBattleGround(BattleGroundTypeId bgTypeId, uint32 M // 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 7d0df045b..49af8dba5 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=0 ELUNA_MANGOS> ) target_link_libraries(game diff --git a/src/game/Object/Creature.cpp b/src/game/Object/Creature.cpp index c748c83a5..229c204c0 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 5e3828e82..1eb9a66e5 100644 --- a/src/game/Object/GameObject.cpp +++ b/src/game/Object/GameObject.cpp @@ -124,7 +124,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 @@ -248,7 +254,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 @@ -282,7 +291,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) @@ -2310,7 +2322,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(); } @@ -2319,7 +2334,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 74832ed5d..2212c77b5 100644 --- a/src/game/Object/Guild.cpp +++ b/src/game/Object/Guild.cpp @@ -159,7 +159,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); @@ -264,7 +267,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; @@ -280,7 +286,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 */ } @@ -294,7 +303,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 */ } @@ -619,7 +631,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(); @@ -823,7 +838,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 bda0a3659..c10f1781e 100644 --- a/src/game/Object/Item.cpp +++ b/src/game/Object/Item.cpp @@ -331,7 +331,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 4455fe1ef..71ba96969 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 */ @@ -908,7 +909,7 @@ void Object::MarkForClientUpdate() WorldObject::WorldObject() : #ifdef ENABLE_ELUNA - elunaEvents(NULL), + elunaEvents(nullptr), #endif /* ENABLE_ELUNA */ m_currMap(NULL), m_mapId(0), m_InstanceId(0), @@ -920,7 +921,7 @@ WorldObject::~WorldObject() { #ifdef ENABLE_ELUNA delete elunaEvents; - elunaEvents = NULL; + elunaEvents = nullptr; #endif /* ENABLE_ELUNA */ } @@ -932,7 +933,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 */ } @@ -1578,13 +1582,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() @@ -1644,7 +1641,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 */ @@ -2060,3 +2060,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 5877067a1..152305c8f 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 @@ -78,7 +81,9 @@ class UpdateMask; class InstanceData; class TerrainInfo; #ifdef ENABLE_ELUNA +class Eluna; class ElunaEventProcessor; +class LuaVal; #endif /* ENABLE_ELUNA */ struct MangosStringLocale; @@ -689,6 +694,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 e96f4ee54..205649f70 100644 --- a/src/game/Object/Player.cpp +++ b/src/game/Object/Player.cpp @@ -1452,7 +1452,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()); @@ -2634,7 +2637,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 @@ -2748,7 +2754,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 */ } @@ -2757,7 +2766,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); @@ -3974,7 +3986,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 @@ -4826,7 +4841,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) @@ -7384,7 +7402,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; @@ -7555,7 +7576,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 @@ -11601,10 +11625,13 @@ InventoryResult Player::CanUseItem(ItemPrototype const* pProto, bool direct_acti } #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 @@ -11945,14 +11972,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; @@ -12179,7 +12214,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) @@ -17874,7 +17912,10 @@ InstancePlayerBind* Player::BindToInstance(DungeonPersistentState* state, bool p GetName(), GetGUIDLow(), state->GetMapId(), state->GetInstanceId()); // 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; @@ -18113,9 +18154,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 */ @@ -19140,7 +19184,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); @@ -22864,7 +22911,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*/ } @@ -22975,7 +23025,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 4a67f9c56..8b0f28ab4 100644 --- a/src/game/Object/ReputationMgr.cpp +++ b/src/game/Object/ReputationMgr.cpp @@ -256,7 +256,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 e25767ed3..be48a3050 100644 --- a/src/game/Object/Totem.cpp +++ b/src/game/Object/Totem.cpp @@ -114,7 +114,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 8611dcf9f..17b14fcc4 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 */ @@ -312,10 +313,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. @@ -836,9 +833,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 */ @@ -905,7 +905,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 */ } @@ -1156,7 +1159,10 @@ void Unit::JustKilledCreature(Creature* victim, Player* responsiblePlayer) } // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnCreatureKill(responsiblePlayer, victim); + if (Eluna* e = responsiblePlayer->GetEluna()) + { + e->OnCreatureKill(responsiblePlayer, victim); + } #endif /* ENABLE_ELUNA */ } @@ -7687,9 +7693,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 */ @@ -7707,9 +7716,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 */ @@ -9374,6 +9386,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() @@ -9390,6 +9412,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 2b28df4be..80cfca683 100644 --- a/src/game/Server/WorldSession.cpp +++ b/src/game/Server/WorldSession.cpp @@ -628,7 +628,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 @@ -877,9 +880,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 ebdc8aac1..0f1049d5c 100644 --- a/src/game/Server/WorldSocket.cpp +++ b/src/game/Server/WorldSocket.cpp @@ -543,9 +543,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); @@ -553,7 +556,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 f038e7fde..ae1a50e2c 100644 --- a/src/game/WorldHandlers/AuctionHouseHandler.cpp +++ b/src/game/WorldHandlers/AuctionHouseHandler.cpp @@ -388,7 +388,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 */ } @@ -559,7 +562,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 a1690ded9..7d87b768a 100644 --- a/src/game/WorldHandlers/CharacterHandler.cpp +++ b/src/game/WorldHandlers/CharacterHandler.cpp @@ -498,7 +498,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() @@ -550,7 +553,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 @@ -869,9 +875,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 */ @@ -924,7 +933,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 99b625334..cb9de7dfb 100644 --- a/src/game/WorldHandlers/Chat.cpp +++ b/src/game/WorldHandlers/Chat.cpp @@ -1353,9 +1353,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); @@ -1366,9 +1369,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 ef891b32d..37b1e0781 100644 --- a/src/game/WorldHandlers/ChatHandler.cpp +++ b/src/game/WorldHandlers/ChatHandler.cpp @@ -214,9 +214,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); @@ -224,9 +227,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); @@ -234,9 +240,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); @@ -292,9 +301,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 @@ -347,9 +359,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 */ @@ -402,9 +417,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 */ @@ -458,9 +476,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 */ @@ -507,9 +528,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 */ @@ -568,9 +592,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 89cc20a06..87b6a2d98 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 /* ENABLE_ELUNA */ } @@ -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 /* ENABLE_ELUNA */ } diff --git a/src/game/WorldHandlers/Group.cpp b/src/game/WorldHandlers/Group.cpp index b3ec17449..d397e552c 100644 --- a/src/game/WorldHandlers/Group.cpp +++ b/src/game/WorldHandlers/Group.cpp @@ -156,7 +156,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; @@ -262,7 +265,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; @@ -343,7 +349,10 @@ bool Group::AddMember(ObjectGuid guid, const char* name, uint8 joinMethod) // 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 @@ -453,7 +462,10 @@ uint32 Group::RemoveMember(ObjectGuid guid, uint8 removeMethod) // Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnRemoveMember(this, guid, removeMethod); // 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(); @@ -469,7 +481,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); @@ -569,7 +584,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 e194eafda..e654d39fc 100644 --- a/src/game/WorldHandlers/LootHandler.cpp +++ b/src/game/WorldHandlers/LootHandler.cpp @@ -218,7 +218,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 @@ -269,7 +272,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; @@ -354,7 +360,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; @@ -718,7 +727,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 8f12f3035..bded65ec5 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; @@ -117,6 +126,16 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId) 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()); @@ -142,7 +161,10 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId) m_weatherSystem = new WeatherSystem(this); i_transports.clear(); #ifdef ENABLE_ELUNA - sEluna->OnCreate(this); + if (Eluna* e = GetEluna()) + { + e->OnCreate(this); + } #endif /* ENABLE_ELUNA */ } @@ -356,8 +378,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) @@ -677,7 +702,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) @@ -691,7 +724,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) @@ -1155,13 +1191,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 */ @@ -1377,7 +1416,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 = 0; @@ -2576,3 +2618,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 f03e9d268..fa0845a0d 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; @@ -300,6 +306,12 @@ class Map : public GridRefManager void LoadLocalTransports(); +#ifdef ENABLE_ELUNA + Eluna* GetEluna() const; + + LuaVal lua_data = LuaVal({}); +#endif /* ENABLE_ELUNA */ + private: void LoadMapAndVMap(int gx, int gy); @@ -394,6 +406,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 1badd76b9..e13a1ed88 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); @@ -62,6 +66,16 @@ void 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) { @@ -481,3 +495,10 @@ void MapManager::LoadActiveEntities(Map* m) } } +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 013bdff2e..5da17d556 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 edc22433b..d88a9fe66 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 b33e5ceaa..3ff8e458e 100644 --- a/src/game/WorldHandlers/NPCHandler.cpp +++ b/src/game/WorldHandlers/NPCHandler.cpp @@ -499,7 +499,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()) @@ -512,7 +515,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 8b4122f10..31f087800 100644 --- a/src/game/WorldHandlers/QuestHandler.cpp +++ b/src/game/WorldHandlers/QuestHandler.cpp @@ -399,7 +399,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 b1ecdb900..78afe48f6 100644 --- a/src/game/WorldHandlers/Spell.cpp +++ b/src/game/WorldHandlers/Spell.cpp @@ -3294,12 +3294,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 e06959312..ecd063c12 100644 --- a/src/game/WorldHandlers/SpellEffects.cpp +++ b/src/game/WorldHandlers/SpellEffects.cpp @@ -2724,12 +2724,18 @@ void Spell::EffectSummon(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 */ } @@ -3116,7 +3122,10 @@ void Spell::EffectSummonWild(SpellEffectIndex eff_idx) 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 */ } @@ -3246,12 +3255,18 @@ void Spell::EffectSummonGuardian(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 /* ENABLE_ELUNA */ } @@ -4738,7 +4753,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 */ } @@ -5037,7 +5055,10 @@ void Spell::EffectSummonPossessed(SpellEffectIndex eff_idx) #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 */ } @@ -5750,12 +5771,18 @@ void Spell::EffectSummonCritter(SpellEffectIndex eff_idx) #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 2bce400e8..d82344019 100644 --- a/src/game/WorldHandlers/Weather.cpp +++ b/src/game/WorldHandlers/Weather.cpp @@ -268,7 +268,10 @@ bool Weather::SendWeatherForPlayersInZone(Map const* _map) ///- Log the event LogWeatherState(GetWeatherState()); #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 cdff7f634..f0601dadc 100644 --- a/src/game/WorldHandlers/World.cpp +++ b/src/game/WorldHandlers/World.cpp @@ -79,6 +79,8 @@ #ifdef ENABLE_ELUNA #include "LuaEngine.h" +#include "ElunaConfig.h" +#include "ElunaLoader.h" #endif /* ENABLE_ELUNA */ #ifdef ENABLE_PLAYERBOTS @@ -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 @@ -953,12 +958,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(); @@ -1052,8 +1058,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..."); @@ -1339,6 +1356,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 @@ -1496,8 +1524,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 @@ -1739,7 +1769,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 @@ -2147,7 +2181,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 */ } @@ -2197,7 +2234,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 ce77b6927..fcb4f6bc3 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; @@ -349,7 +352,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_AUTOPOOLING_MINING_ENABLE, CONFIG_BOOL_ENABLE_QUEST_TRACKER, @@ -628,6 +630,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 9114cd226..e037282b4 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=0 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 eed0471de..480ccdce3 100644 --- a/src/mangosd/mangosd.conf.dist.in +++ b/src/mangosd/mangosd.conf.dist.in @@ -1770,13 +1770,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. @@ -1789,8 +1801,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..e5f206b9b 160000 --- a/src/modules/Eluna +++ b/src/modules/Eluna @@ -1 +1 @@ -Subproject commit 058ffa1cb7f81bb111e3022d572a6311558c1d5f +Subproject commit e5f206b9bc54445f2d54e446469c9b7a7f2392ae diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 73d4e174c..9df3c2003 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=0 ELUNA_MANGOS> ) target_link_libraries(shared diff --git a/src/shared/Common/Common.h b/src/shared/Common/Common.h index 178492a67..65971a85b 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"