diff --git a/CMakeLists.txt b/CMakeLists.txt index 138a2f0f8..a5c28839c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -cmake_minimum_required(VERSION 3.18 FATAL_ERROR) +cmake_minimum_required(VERSION 3.22 FATAL_ERROR) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -27,9 +27,9 @@ cmake_policy(SET CMP0042 NEW) cmake_policy(SET CMP0048 NEW) cmake_policy(SET CMP0063 NEW) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) +#set(CMAKE_CXX_STANDARD 17) +#set(CMAKE_CXX_STANDARD_REQUIRED ON) +#set(CMAKE_CXX_EXTENSIONS OFF) set_property(GLOBAL PROPERTY USE_FOLDERS ON diff --git a/cmake/PCHSupport.cmake b/cmake/PCHSupport.cmake index 7b1f6c78a..9726f46f2 100644 --- a/cmake/PCHSupport.cmake +++ b/cmake/PCHSupport.cmake @@ -79,7 +79,7 @@ function(ADD_CXX_PCH TARGET_NAME PRECOMPILED_HEADER PRECOMPILED_SOURCE) set(COMPILER_FLAGS "${${CXX_FLAGS}} ${CMAKE_CXX_FLAGS}") separate_arguments(COMPILER_FLAGS) - set(CXX_STD c++11) + set(CXX_STD c++17) add_custom_command( OUTPUT ${OUTPUT_NAME} diff --git a/dep b/dep index a6901739e..5e87639de 160000 --- a/dep +++ b/dep @@ -1 +1 @@ -Subproject commit a6901739e4ad37bfb9a178a6320e4d6969c00b53 +Subproject commit 5e87639deddcf5052e73940f346ab28e3aceb3b2 diff --git a/src/game/BattleGround/BattleGround.cpp b/src/game/BattleGround/BattleGround.cpp index 316d3e98e..76de5675b 100644 --- a/src/game/BattleGround/BattleGround.cpp +++ b/src/game/BattleGround/BattleGround.cpp @@ -774,7 +774,8 @@ 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 +1282,8 @@ void BattleGround::StartBattleGround() sBattleGroundMgr.AddBattleGround(GetInstanceID(), GetTypeID(), this); #ifdef ENABLE_ELUNA - sEluna->OnBGStart(this, GetTypeID(), GetInstanceID()); + if (Eluna* e = GetBgMap()->GetEluna()) + e->OnBGStart(this, GetTypeID(), GetInstanceID()); #endif /* ENABLE_ELUNA */ } diff --git a/src/game/BattleGround/BattleGroundMgr.cpp b/src/game/BattleGround/BattleGroundMgr.cpp index 21260881b..1987aa4e9 100644 --- a/src/game/BattleGround/BattleGroundMgr.cpp +++ b/src/game/BattleGround/BattleGroundMgr.cpp @@ -1232,7 +1232,8 @@ uint32 BattleGroundMgr::CreateBattleGround(BattleGroundTypeId bgTypeId, uint32 M AddBattleGround(bg->GetInstanceID(), bg->GetTypeID(), bg); #ifdef ENABLE_ELUNA - sEluna->OnBGCreate(bg, bgTypeId, bg->GetInstanceID()); + if (Eluna* e = bg->GetBgMap()->GetEluna()) + e->OnBGCreate(bg, bgTypeId, bg->GetInstanceID()); #endif /* ENABLE_ELUNA */ // return some not-null value, bgTypeId is good enough for me diff --git a/src/game/Object/Creature.cpp b/src/game/Object/Creature.cpp index e1109e337..335db682f 100644 --- a/src/game/Object/Creature.cpp +++ b/src/game/Object/Creature.cpp @@ -211,9 +211,8 @@ void Creature::AddToWorld() #ifdef ENABLE_ELUNA if (!inWorld) - { - sEluna->OnAddToWorld(this); - } + if (Eluna* e = GetEluna()) + e->OnAddToWorld(this); #endif /* ENABLE_ELUNA */ } @@ -222,9 +221,8 @@ void Creature::RemoveFromWorld() { #ifdef ENABLE_ELUNA if (IsInWorld()) - { - sEluna->OnRemoveFromWorld(this); - } + if (Eluna* e = GetEluna()) + e->OnRemoveFromWorld(this); #endif /* ENABLE_ELUNA */ ///- Remove the creature from the accessor diff --git a/src/game/Object/GameObject.cpp b/src/game/Object/GameObject.cpp index 5e3828e82..761eda598 100644 --- a/src/game/Object/GameObject.cpp +++ b/src/game/Object/GameObject.cpp @@ -123,9 +123,8 @@ void GameObject::AddToWorld() #ifdef ENABLE_ELUNA if (!inWorld) - { - sEluna->OnAddToWorld(this); - } + if (Eluna* e = GetEluna()) + e->OnAddToWorld(this); #endif /* ENABLE_ELUNA */ } @@ -136,7 +135,8 @@ 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 +248,8 @@ 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 +283,8 @@ 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 +2312,8 @@ 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 +2322,8 @@ 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..24078fcb5 100644 --- a/src/game/Object/Guild.cpp +++ b/src/game/Object/Guild.cpp @@ -159,7 +159,8 @@ 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 +265,8 @@ 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 +282,8 @@ 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 +297,8 @@ 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 +623,8 @@ 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 +828,8 @@ 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..6ef152f48 100644 --- a/src/game/Object/Item.cpp +++ b/src/game/Object/Item.cpp @@ -331,7 +331,8 @@ 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 9e9fe4f4d..2c775c68a 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 */ @@ -932,7 +933,8 @@ 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 */ } @@ -1580,8 +1582,19 @@ void WorldObject::SetMap(Map* map) m_InstanceId = map->GetInstanceId(); #ifdef ENABLE_ELUNA - if (!elunaEvents) - elunaEvents = new ElunaEventProcessor(&Eluna::GEluna, this); + //@todo: possibly look into cleanly clearing all pending events from previous map's event mgr. + + // 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 + } + + if (Eluna* e = map->GetEluna()) + if (!elunaEvents) + elunaEvents = new ElunaEventProcessor(e, this); #endif } @@ -1640,10 +1653,9 @@ 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()) + if (Unit* summoner = ToUnit()) + e->OnSummoned(pCreature, summoner); #endif /* ENABLE_ELUNA */ // Creature Linking, Initial load is handled like respawn @@ -2058,3 +2070,13 @@ void WorldObject::SetActiveObjectState(bool active) } m_isActiveObject = active; } + +#ifdef ENABLE_ELUNA +Eluna* WorldObject::GetEluna() const +{ + if (IsInWorld()) + return GetMap()->GetEluna(); + + return nullptr; +} +#endif \ No newline at end of file diff --git a/src/game/Object/Object.h b/src/game/Object/Object.h index 5877067a1..0edbabe98 100644 --- a/src/game/Object/Object.h +++ b/src/game/Object/Object.h @@ -35,6 +35,10 @@ #include +#ifdef ENABLE_ELUNA +#include "LuaValue.h" +#endif + #define CONTACT_DISTANCE 0.5f #define INTERACTION_DISTANCE 5.0f #define ATTACK_DISTANCE 5.0f @@ -78,7 +82,9 @@ class UpdateMask; class InstanceData; class TerrainInfo; #ifdef ENABLE_ELUNA +class Eluna; class ElunaEventProcessor; +class LuaVal; #endif /* ENABLE_ELUNA */ struct MangosStringLocale; @@ -689,6 +695,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 52487b45e..858d951f3 100644 --- a/src/game/Object/Player.cpp +++ b/src/game/Object/Player.cpp @@ -1452,7 +1452,8 @@ 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 +2635,8 @@ 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 +2750,8 @@ 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 +2760,8 @@ 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); @@ -3973,7 +3977,8 @@ 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 @@ -4823,7 +4828,8 @@ 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) @@ -7381,7 +7387,8 @@ 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; @@ -7552,7 +7559,8 @@ 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 @@ -11598,10 +11606,11 @@ 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 @@ -11942,14 +11951,16 @@ 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); #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); #endif /* ENABLE_ELUNA */ return pItem; @@ -12176,7 +12187,8 @@ 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) @@ -17871,7 +17883,8 @@ 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; @@ -18110,10 +18123,9 @@ void Player::SaveToDB() #ifdef ENABLE_ELUNA // Hack to check that this is not on create save - if (!HasAtLoginFlag(AT_LOGIN_FIRST)) - { - sEluna->OnSave(this); - } + if(Eluna* e = GetEluna()) + if (!HasAtLoginFlag(AT_LOGIN_FIRST)) + e->OnSave(this); #endif /* ENABLE_ELUNA */ static SqlStatementID delChar ; @@ -19137,7 +19149,8 @@ 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); @@ -21066,7 +21079,7 @@ void Player::SendTransferAbortedByLockStatus(MapEntry const* mapEntry, AreaTrigg // ToDo: SendAreaTriggerMessage or Transfer Abort for these cases! break; case AREA_LOCKSTATUS_MISSING_ITEM: - if (AreaTrigger const* at = sObjectMgr.GetMapEntranceTrigger(mapEntry->MapID)) + if (AreaTrigger const* areatrigger = sObjectMgr.GetMapEntranceTrigger(mapEntry->MapID)) { GetSession()->SendAreaTriggerMessage(GetSession()->GetMangosString(LANG_REQUIRED_ITEM), sObjectMgr.GetItemPrototype(miscRequirement)->Name1); } @@ -22859,7 +22872,8 @@ 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*/ } @@ -22970,7 +22984,8 @@ 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..5cdff5a87 100644 --- a/src/game/Object/ReputationMgr.cpp +++ b/src/game/Object/ReputationMgr.cpp @@ -256,7 +256,8 @@ 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..130a3acc7 100644 --- a/src/game/Object/Totem.cpp +++ b/src/game/Object/Totem.cpp @@ -114,7 +114,8 @@ 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..4536d54ab 100644 --- a/src/game/Object/Unit.cpp +++ b/src/game/Object/Unit.cpp @@ -312,10 +312,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,10 +832,9 @@ uint32 Unit::DealDamage(Unit* pVictim, uint32 damage, CleanDamage const* cleanDa { // Used by Eluna #ifdef ENABLE_ELUNA - if (Player* killed = pVictim->ToPlayer()) - { - sEluna->OnPlayerKilledByCreature(killer, killed); - } + if (Eluna* e = killer->GetEluna()) + if (Player* killed = pVictim->ToPlayer()) + e->OnPlayerKilledByCreature(killer, killed); #endif /* ENABLE_ELUNA */ } @@ -905,7 +900,8 @@ 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 +1152,8 @@ 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,10 +7684,9 @@ void Unit::SetInCombatState(bool PvP, Unit* enemy) // Used by Eluna #ifdef ENABLE_ELUNA - if (GetTypeId() == TYPEID_PLAYER) - { - sEluna->OnPlayerEnterCombat(ToPlayer(), enemy); - } + if (Eluna* e = GetEluna()) + if (GetTypeId() == TYPEID_PLAYER) + e->OnPlayerEnterCombat(ToPlayer(), enemy); #endif /* ENABLE_ELUNA */ } @@ -7707,10 +7703,9 @@ void Unit::ClearInCombat() // Used by Eluna #ifdef ENABLE_ELUNA - if (GetTypeId() == TYPEID_PLAYER) - { - sEluna->OnPlayerLeaveCombat(ToPlayer()); - } + if (Eluna* e = GetEluna()) + if (GetTypeId() == TYPEID_PLAYER) + e->OnPlayerLeaveCombat(ToPlayer()); #endif /* ENABLE_ELUNA */ // Player's state will be cleared in Player::UpdateContestedPvP diff --git a/src/game/Server/WorldSession.cpp b/src/game/Server/WorldSession.cpp index 942729f5f..9f54f29e3 100644 --- a/src/game/Server/WorldSession.cpp +++ b/src/game/Server/WorldSession.cpp @@ -622,7 +622,8 @@ 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 @@ -871,10 +872,9 @@ 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)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnPacketReceive(this, *packet)) + return; #endif /* ENABLE_ELUNA */ // need prevent do internal far teleports in handlers because some handlers do lot steps diff --git a/src/game/Server/WorldSocket.cpp b/src/game/Server/WorldSocket.cpp index 7a9978340..85eac1a22 100644 --- a/src/game/Server/WorldSocket.cpp +++ b/src/game/Server/WorldSocket.cpp @@ -543,17 +543,17 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct) } #ifdef ENABLE_ELUNA - if (!sEluna->OnPacketReceive(m_Session, *new_pct)) - { - return 0; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnPacketReceive(m_Session, *new_pct)) + return 0; #endif /* ENABLE_ELUNA */ return HandleAuthSession(*new_pct); case CMSG_KEEP_ALIVE: DEBUG_LOG("CMSG_KEEP_ALIVE ,size: " SIZEFMTD " ", 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/Tools/PlayerDump.cpp b/src/game/Tools/PlayerDump.cpp index 1ca3279b3..6818ebc4a 100644 --- a/src/game/Tools/PlayerDump.cpp +++ b/src/game/Tools/PlayerDump.cpp @@ -388,7 +388,6 @@ void PlayerDumpWriter::DumpTableContent(std::string& dump, uint32 guid, char con } // remove last character of tableColumnNamesStr = "," tableColumnNamesStr.pop_back(); - namesMap.empty(); // fetch results of the table QueryResult* result = CharacterDatabase.PQuery("SELECT %s FROM `%s` WHERE %s", tableColumnNamesStr.c_str(), tableFrom, wherestr.c_str()); diff --git a/src/game/WorldHandlers/AuctionHouseHandler.cpp b/src/game/WorldHandlers/AuctionHouseHandler.cpp index f038e7fde..6e79ca2b3 100644 --- a/src/game/WorldHandlers/AuctionHouseHandler.cpp +++ b/src/game/WorldHandlers/AuctionHouseHandler.cpp @@ -388,7 +388,8 @@ 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 +560,8 @@ 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..8cbd21159 100644 --- a/src/game/WorldHandlers/CharacterHandler.cpp +++ b/src/game/WorldHandlers/CharacterHandler.cpp @@ -498,7 +498,8 @@ 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 +551,8 @@ 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,10 +871,9 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder) // Used by Eluna #ifdef ENABLE_ELUNA - if (pCurrChar->HasAtLoginFlag(AT_LOGIN_FIRST)) - { - sEluna->OnFirstLogin(pCurrChar); - } + if (Eluna* e = pCurrChar->GetEluna()) + if (pCurrChar->HasAtLoginFlag(AT_LOGIN_FIRST)) + e->OnFirstLogin(pCurrChar); #endif /* ENABLE_ELUNA */ @@ -924,7 +925,8 @@ 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..440c9e927 100644 --- a/src/game/WorldHandlers/Chat.cpp +++ b/src/game/WorldHandlers/Chat.cpp @@ -1353,10 +1353,9 @@ 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())) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnCommand(m_session ? m_session->GetPlayer() : NULL, fullcmd.c_str())) + return; #endif /* ENABLE_ELUNA */ SendSysMessage(LANG_NO_SUBCMD); ShowHelpForCommand(command->ChildCommands, text); @@ -1366,10 +1365,9 @@ 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())) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnCommand(m_session ? m_session->GetPlayer() : NULL, fullcmd.c_str())) + return; #endif /* ENABLE_ELUNA */ SendSysMessage(LANG_NO_CMD); SetSentErrorMessage(true); diff --git a/src/game/WorldHandlers/ChatHandler.cpp b/src/game/WorldHandlers/ChatHandler.cpp index ef891b32d..19d493604 100644 --- a/src/game/WorldHandlers/ChatHandler.cpp +++ b/src/game/WorldHandlers/ChatHandler.cpp @@ -214,30 +214,27 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) if (type == CHAT_MSG_SAY) { #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg)) + return; #endif /* ENABLE_ELUNA */ GetPlayer()->Say(msg, lang); } else if (type == CHAT_MSG_EMOTE) { #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, LANG_UNIVERSAL, msg)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, LANG_UNIVERSAL, msg)) + return; #endif /* ENABLE_ELUNA */ GetPlayer()->TextEmote(msg); } else if (type == CHAT_MSG_YELL) { #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg)) + return; #endif /* ENABLE_ELUNA */ GetPlayer()->Yell(msg, lang); } @@ -292,10 +289,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, player)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg, player)) + return; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_PLAYERBOTS if (player->GetPlayerbotAI()) @@ -347,10 +343,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + return; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_PLAYERBOTS @@ -402,10 +397,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) { // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, guild)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg, guild)) + return; #endif /* ENABLE_ELUNA */ guild->BroadcastToGuild(this, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL); @@ -458,10 +452,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) { // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, guild)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg, guild)) + return; #endif /* ENABLE_ELUNA */ guild->BroadcastToOfficers(this, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL); @@ -507,10 +500,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + return; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_PLAYERBOTS @@ -568,10 +560,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + return; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_PLAYERBOTS @@ -616,10 +607,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + return; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_PLAYERBOTS @@ -665,10 +655,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + return; #endif /* ENABLE_ELUNA */ WorldPacket data; @@ -700,10 +689,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, group)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg, group)) + return; #endif /* ENABLE_ELUNA */ WorldPacket data; @@ -733,10 +721,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) { // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg, chn)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg, chn)) + return; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_PLAYERBOTS if (_player->GetPlayerbotMgr() && chn->GetFlags() & 0x18) @@ -781,10 +768,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) } // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg)) + return; #endif /* ENABLE_ELUNA */ } break; @@ -818,10 +804,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data) } // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnChat(GetPlayer(), type, lang, msg)) - { - return; - } + if (Eluna* e = sWorld.GetEluna()) + if (!e->OnChat(GetPlayer(), type, lang, msg)) + return; #endif /* ENABLE_ELUNA */ break; @@ -845,7 +830,8 @@ 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 +895,8 @@ 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/GMTicketHandler.cpp b/src/game/WorldHandlers/GMTicketHandler.cpp index 7e6c752aa..c5ef41251 100644 --- a/src/game/WorldHandlers/GMTicketHandler.cpp +++ b/src/game/WorldHandlers/GMTicketHandler.cpp @@ -75,7 +75,10 @@ void WorldSession::HandleGMTicketUpdateTextOpcode(WorldPacket& recv_data) stripLineInvisibleChars(ticketText); // Since invisible char are replaced with a ' ' if any leading space is added we remove it : - ltrim(ticketText); + + ticketText.erase(ticketText.begin(), std::find_if(ticketText.begin(), ticketText.end(), [](unsigned char ch) { + return !std::isspace(ch); + })); GMTicketResponse responce = GMTICKET_RESPONSE_UPDATE_SUCCESS; if (GMTicket* ticket = sTicketMgr.GetGMTicket(GetPlayer()->GetObjectGuid())) diff --git a/src/game/WorldHandlers/GameEventMgr.cpp b/src/game/WorldHandlers/GameEventMgr.cpp index 265d122e7..1f8b2be4e 100644 --- a/src/game/WorldHandlers/GameEventMgr.cpp +++ b/src/game/WorldHandlers/GameEventMgr.cpp @@ -105,10 +105,9 @@ void GameEventMgr::StartEvent(uint16 event_id, bool overwrite /*=false*/, bool r } } #ifdef ENABLE_ELUNA - if (IsActiveEvent(event_id)) - { - sEluna->OnGameEventStart(event_id); - } + if (Eluna* e = sWorld.GetEluna()) + if (IsActiveEvent(event_id)) + e->OnGameEventStart(event_id); #endif /* ENABLE_ELUNA */ } @@ -124,10 +123,9 @@ void GameEventMgr::StopEvent(uint16 event_id, bool overwrite) } } #ifdef ENABLE_ELUNA - if (!IsActiveEvent(event_id)) - { - sEluna->OnGameEventStop(event_id); - } + if (Eluna* e = sWorld.GetEluna()) + 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..6744f35a1 100644 --- a/src/game/WorldHandlers/Group.cpp +++ b/src/game/WorldHandlers/Group.cpp @@ -156,7 +156,8 @@ 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 +263,8 @@ 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 +345,8 @@ 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 +456,8 @@ 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 +473,8 @@ 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 +574,8 @@ 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 31faa6290..fb613c7d3 100644 --- a/src/game/WorldHandlers/LootHandler.cpp +++ b/src/game/WorldHandlers/LootHandler.cpp @@ -218,7 +218,8 @@ 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 @@ -267,10 +268,10 @@ void WorldSession::HandleLootMoneyOpcode(WorldPacket& /*recv_data*/) pLoot->NotifyMoneyRemoved(); player->ModifyMoney(pLoot->gold); - // Used by Eluna - #ifdef ENABLE_ELUNA - sEluna->OnLootMoney(player, pLoot->gold); - #endif /* ENABLE_ELUNA */ +#ifdef ENABLE_ELUNA + if (Eluna* e = player->GetEluna()) + e->OnLootMoney(player, pLoot->gold); +#endif /* ENABLE_ELUNA */ pLoot->gold = 0; return; @@ -354,7 +355,8 @@ 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 +720,8 @@ 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..88e46e95a 100644 --- a/src/game/WorldHandlers/Map.cpp +++ b/src/game/WorldHandlers/Map.cpp @@ -47,13 +47,23 @@ #ifdef ENABLE_ELUNA #include "LuaEngine.h" +#include "ElunaConfig.h" +#include "ElunaLoader.h" #endif /* ENABLE_ELUNA */ Map::~Map() { #ifdef ENABLE_ELUNA - sEluna->OnDestroy(this); -#endif /* ENABLE_ELUNA */ + if (Eluna* e = GetEluna()) + e->OnDestroy(this); + + if (Eluna* e = GetEluna()) + if (Instanceable()) + e->FreeInstanceId(GetInstanceId()); + + delete eluna; + eluna = nullptr; +#endif UnloadAll(true); @@ -67,13 +77,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 +120,13 @@ 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() && sElunaLoader->ShouldMapLoadEluna(id)) + eluna = new Eluna(this); +#endif m_CreatureGuids.Set(sObjectMgr.GetFirstTemporaryCreatureLowGuid()); m_GameObjectGuids.Set(sObjectMgr.GetFirstTemporaryGameObjectLowGuid()); @@ -141,9 +151,11 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId) m_weatherSystem = new WeatherSystem(this); i_transports.clear(); + #ifdef ENABLE_ELUNA - sEluna->OnCreate(this); -#endif /* ENABLE_ELUNA */ + if (Eluna* e = GetEluna()) + e->OnCreate(this); +#endif } void Map::InitVisibilityDistance() @@ -356,8 +368,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 +692,13 @@ 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 +712,8 @@ 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 +1177,12 @@ void Map::AddObjectToRemoveList(WorldObject* obj) MANGOS_ASSERT(obj->GetMapId() == GetId() && obj->GetInstanceId() == GetInstanceId()); #ifdef ENABLE_ELUNA - if (Creature* creature = obj->ToCreature()) + if (Eluna* e = GetEluna()) { - sEluna->OnRemove(creature); - } - else if (GameObject* gameobject = obj->ToGameObject()) - { - 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 +1398,8 @@ 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 +2598,13 @@ 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 \ No newline at end of file diff --git a/src/game/WorldHandlers/Map.h b/src/game/WorldHandlers/Map.h index f50dd463b..4c6bbe09e 100644 --- a/src/game/WorldHandlers/Map.h +++ b/src/game/WorldHandlers/Map.h @@ -44,9 +44,15 @@ #include "DynamicTree.h" #include +#ifdef ENABLE_ELUNA +#include "LuaValue.h" +#endif struct CreatureInfo; class Creature; +#ifdef ENABLE_ELUNA +class Eluna; +#endif 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 + 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 }; class WorldMap : public Map diff --git a/src/game/WorldHandlers/MapManager.cpp b/src/game/WorldHandlers/MapManager.cpp index 1badd76b9..f4d2bae1d 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 + #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 + // Start mtmaps if needed. if (num_threads > 0 && m_updater.activate(num_threads) == -1) { @@ -481,3 +495,8 @@ 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); +} \ No newline at end of file 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..c7798d78b 100644 --- a/src/game/WorldHandlers/MiscHandler.cpp +++ b/src/game/WorldHandlers/MiscHandler.cpp @@ -73,7 +73,8 @@ 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..29768be0e 100644 --- a/src/game/WorldHandlers/NPCHandler.cpp +++ b/src/game/WorldHandlers/NPCHandler.cpp @@ -499,7 +499,8 @@ 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 +513,8 @@ 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..c7a9804b1 100644 --- a/src/game/WorldHandlers/QuestHandler.cpp +++ b/src/game/WorldHandlers/QuestHandler.cpp @@ -399,7 +399,8 @@ 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..ab4fd686d 100644 --- a/src/game/WorldHandlers/ScriptMgr.cpp +++ b/src/game/WorldHandlers/ScriptMgr.cpp @@ -2664,10 +2664,9 @@ CreatureAI* ScriptMgr::GetCreatureAI(Creature* pCreature) { // Used by Eluna #ifdef ENABLE_ELUNA - if (CreatureAI* luaAI = sEluna->GetAI(pCreature)) - { - return luaAI; - } + if (Eluna* e = pCreature->GetEluna()) + if (CreatureAI* luaAI = e->GetAI(pCreature)) + return luaAI; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2700,10 +2699,9 @@ bool ScriptMgr::OnGossipHello(Player* pPlayer, Creature* pCreature) { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnGossipHello(pPlayer, pCreature)) - { - return true; - } + if (Eluna* e = pPlayer->GetEluna()) + if (e->OnGossipHello(pPlayer, pCreature)) + return true; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2717,10 +2715,9 @@ bool ScriptMgr::OnGossipHello(Player* pPlayer, GameObject* pGameObject) { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnGossipHello(pPlayer, pGameObject)) - { - return true; - } + if (Eluna* e = pPlayer->GetEluna()) + if (e->OnGossipHello(pPlayer, pGameObject)) + return true; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2747,20 +2744,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; + // Used by Eluna + if (e->OnGossipSelectCode(pPlayer, pCreature, sender, action, code)) + return true; } - } - else - { - // Used by Eluna - if (sEluna->OnGossipSelect(pPlayer, pCreature, sender, action)) + else { - return true; + // Used by Eluna + if (e->OnGossipSelect(pPlayer, pCreature, sender, action)) + return true; } } #endif /* ENABLE_ELUNA */ @@ -2783,18 +2779,17 @@ 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)) + else { - return true; + if (e->OnGossipSelect(pPlayer, pGameObject, sender, action)) + return true; } } #endif /* ENABLE_ELUNA */ @@ -2838,10 +2833,9 @@ bool ScriptMgr::OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnQuestAccept(pPlayer, pCreature, pQuest)) - { - return true; - } + if (Eluna* e = pPlayer->GetEluna()) + if (e->OnQuestAccept(pPlayer, pCreature, pQuest)) + return true; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2855,10 +2849,9 @@ bool ScriptMgr::OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest co { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnQuestAccept(pPlayer, pGameObject, pQuest)) - { - return true; - } + if (Eluna* e = pPlayer->GetEluna()) + if (e->OnQuestAccept(pPlayer, pGameObject, pQuest)) + return true; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2872,10 +2865,9 @@ bool ScriptMgr::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest) { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnQuestAccept(pPlayer, pItem, pQuest)) - { - return true; - } + if (Eluna* e = pPlayer->GetEluna()) + if (e->OnQuestAccept(pPlayer, pItem, pQuest)) + return true; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2889,10 +2881,9 @@ bool ScriptMgr::OnQuestRewarded(Player* pPlayer, Creature* pCreature, Quest cons { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnQuestReward(pPlayer, pCreature, pQuest, reward)) - { - return true; - } + if (Eluna* e = pPlayer->GetEluna()) + if (e->OnQuestReward(pPlayer, pCreature, pQuest, reward)) + return true; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2906,10 +2897,9 @@ bool ScriptMgr::OnQuestRewarded(Player* pPlayer, GameObject* pGameObject, Quest { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnQuestReward(pPlayer, pGameObject, pQuest, reward)) - { - return true; - } + if (Eluna* e = pPlayer->GetEluna()) + if (e->OnQuestReward(pPlayer, pGameObject, pQuest, reward)) + return true; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2923,7 +2913,8 @@ 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 +2928,8 @@ 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,10 +2942,9 @@ uint32 ScriptMgr::GetDialogStatus(Player* pPlayer, GameObject* pGameObject) bool ScriptMgr::OnGameObjectUse(Player* pPlayer, GameObject* pGameObject) { #ifdef ENABLE_ELUNA - if (sEluna->OnGameObjectUse(pPlayer, pGameObject)) - { - return true; - } + if (Eluna* e = pPlayer->GetEluna()) + if (e->OnGameObjectUse(pPlayer, pGameObject)) + return true; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2978,10 +2969,9 @@ bool ScriptMgr::OnItemUse(Player* pPlayer, Item* pItem, SpellCastTargets const& { // Used by Eluna #ifdef ENABLE_ELUNA - if (!sEluna->OnUse(pPlayer, pItem, targets)) - { - return true; - } + if (Eluna* e = pPlayer->GetEluna()) + if (!e->OnUse(pPlayer, pItem, targets)) + return true; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -2995,10 +2985,9 @@ bool ScriptMgr::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* atEntry) { // Used by Eluna #ifdef ENABLE_ELUNA - if (sEluna->OnAreaTrigger(pPlayer, atEntry)) - { - return true; - } + if (Eluna* e = pPlayer->GetEluna()) + if (e->OnAreaTrigger(pPlayer, atEntry)) + return true; #endif /* ENABLE_ELUNA */ #ifdef ENABLE_SD3 @@ -3030,10 +3019,9 @@ bool ScriptMgr::OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectIndex ef { // Used by Eluna #ifdef ENABLE_ELUNA - if (Creature* creature = pTarget->ToCreature()) - { - sEluna->OnDummyEffect(pCaster, spellId, effIndex, creature); - } + if (Eluna* e = pCaster->GetEluna()) + if (Creature* creature = pTarget->ToCreature()) + e->OnDummyEffect(pCaster, spellId, effIndex, creature); #endif /* ENABLE_ELUNA */ @@ -3048,7 +3036,8 @@ 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 +3051,8 @@ 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 8cb5f400b..614544bb3 100644 --- a/src/game/WorldHandlers/Spell.cpp +++ b/src/game/WorldHandlers/Spell.cpp @@ -1699,7 +1699,7 @@ bool Spell::IsAliveUnitPresentInTargetList() // Spell target first // Raidmates then descending by injury suffered (MaxHealth - Health) // Other players/mobs then descending by injury suffered (MaxHealth - Health) -struct ChainHealingOrder : public std::binary_function +struct ChainHealingOrder { const Unit* MainTarget; ChainHealingOrder(Unit const* Target) : MainTarget(Target) {}; @@ -1733,7 +1733,7 @@ struct ChainHealingOrder : public std::binary_function +class ChainHealingFullHealth { public: const Unit* MainTarget; @@ -1747,7 +1747,7 @@ class ChainHealingFullHealth: std::unary_function // Helper for targets nearest to the spell target // The spell target is always first unless there is a target at _completely_ the same position (unbelievable case) -struct TargetDistanceOrderNear : public std::binary_function +struct TargetDistanceOrderNear { const Unit* MainTarget; TargetDistanceOrderNear(const Unit* Target) : MainTarget(Target) {}; @@ -3279,10 +3279,9 @@ void Spell::cast(bool skipCheck) // Used by Eluna #ifdef ENABLE_ELUNA - if (m_caster->GetTypeId() == TYPEID_PLAYER) - { - sEluna->OnSpellCast(m_caster->ToPlayer(), this, skipCheck); - } + 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..f58bf5d65 100644 --- a/src/game/WorldHandlers/SpellEffects.cpp +++ b/src/game/WorldHandlers/SpellEffects.cpp @@ -2723,14 +2723,12 @@ 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 */ } @@ -3113,11 +3111,10 @@ void Spell::EffectSummonWild(SpellEffectIndex eff_idx) ((Creature*)m_originalCaster)->AI()->JustSummoned(summon); } #ifdef ENABLE_ELUNA - if (m_originalCaster) - if (Unit* summoner = m_originalCaster->ToUnit()) - { - sEluna->OnSummoned(summon, summoner); - } + if (m_originalCaster) + if (Unit* summoner = m_originalCaster->ToUnit()) + if (Eluna* e = summoner->GetEluna()) + e->OnSummoned(summon, summoner); #endif /* ENABLE_ELUNA */ } } @@ -3244,15 +3241,15 @@ void Spell::EffectSummonGuardian(SpellEffectIndex eff_idx) ((Creature*)m_originalCaster)->AI()->JustSummoned(spawnCreature); } #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 +4735,8 @@ 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 */ } @@ -5036,9 +5034,8 @@ 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 */ } @@ -5749,14 +5746,12 @@ 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..99652a283 100644 --- a/src/game/WorldHandlers/Weather.cpp +++ b/src/game/WorldHandlers/Weather.cpp @@ -268,7 +268,8 @@ 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 cc054b9be..b0e36fc9b 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 + ///- 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 @@ -945,12 +950,11 @@ 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(); @@ -1044,9 +1048,20 @@ void World::SetInitialWorldSettings() #ifdef ENABLE_ELUNA ///- Initialize Lua Engine - sLog.outString("Initialize Eluna Lua Engine..."); - Eluna::Initialize(); -#endif /* ENABLE_ELUNA */ + + // 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 sLog.outString("Loading Page Texts..."); sObjectMgr.LoadPageTexts(); @@ -1331,6 +1346,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 + ///- 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 @@ -1488,8 +1514,8 @@ 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 @@ -1731,7 +1757,12 @@ void World::Update(uint32 diff) ///- Used by Eluna #ifdef ENABLE_ELUNA - sEluna->OnWorldUpdate(diff); + ///- used by eluna + if (Eluna* e = GetEluna()) + { + e->UpdateEluna(diff); + e->OnWorldUpdate(diff); + } #endif /* ENABLE_ELUNA */ ///- Delete all characters which have been deleted X days before @@ -2139,7 +2170,8 @@ 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 */ } @@ -2189,7 +2221,8 @@ 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 a8e4a2b85..492821cef 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 class Object; class ObjectGuid; class WorldPacket; @@ -346,7 +349,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, @@ -620,7 +622,10 @@ class World * Access: public **/ void InvalidatePlayerDataToAllClient(ObjectGuid guid); - +#ifdef ENABLE_ELUNA + Eluna* GetEluna() const { return eluna; } + Eluna* eluna; +#endif protected: void _UpdateGameTime(); // callback for UpdateRealmCharacters diff --git a/src/mangosd/CMakeLists.txt b/src/mangosd/CMakeLists.txt index 9114cd226..5785a26df 100644 --- a/src/mangosd/CMakeLists.txt +++ b/src/mangosd/CMakeLists.txt @@ -49,7 +49,6 @@ if(WIN32) configure_file(${CMAKE_SOURCE_DIR}/cmake/win/VersionInfo.h.in ${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.h) endif() - add_executable(mangosd ${SRC_GRP_MAIN} $<$:${SRC_GRP_SOAP}> @@ -59,6 +58,9 @@ add_executable(mangosd > ) +target_compile_features(mangosd PUBLIC cxx_std_17) +set_target_properties(mangosd PROPERTIES CXX_EXTENSIONS OFF) + target_include_directories(mangosd PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/src/mangosd/WorldThread.cpp b/src/mangosd/WorldThread.cpp index 6658656ce..33807b061 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,13 @@ 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 9120ea38b..06559d02b 100644 --- a/src/mangosd/mangosd.conf.dist.in +++ b/src/mangosd/mangosd.conf.dist.in @@ -1738,10 +1738,22 @@ Warden.DBLogLevel = 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. @@ -1754,8 +1766,9 @@ Warden.DBLogLevel = 0 # The path can be relative or absolute. # Default: "lua_scripts" # -################################################################################################################### -Eluna.Enabled = 1 -Eluna.TraceBack = false +Eluna.Enabled = true +Eluna.CompatibilityMode = true +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..a6df4ee31 160000 --- a/src/modules/Eluna +++ b/src/modules/Eluna @@ -1 +1 @@ -Subproject commit 058ffa1cb7f81bb111e3022d572a6311558c1d5f +Subproject commit a6df4ee312b9cab4b55e6d8ec5f2059c306b2f00 diff --git a/src/modules/SD3 b/src/modules/SD3 index 5b28cf687..6ee2d2121 160000 --- a/src/modules/SD3 +++ b/src/modules/SD3 @@ -1 +1 @@ -Subproject commit 5b28cf6878a6e55f9e746e5d2c881d873441c3b2 +Subproject commit 6ee2d212187682273551934e1a13d1252797a92e diff --git a/src/realmd b/src/realmd index 8c08d47a9..70ab1cad4 160000 --- a/src/realmd +++ b/src/realmd @@ -1 +1 @@ -Subproject commit 8c08d47a9a3e6c64007be67074e7c587a5e63e5e +Subproject commit 70ab1cad4b9f87ee486c3903352e96fddfbc5aa5 diff --git a/src/shared/Utilities/Util.h b/src/shared/Utilities/Util.h index 891def7fc..07c3d1e06 100644 --- a/src/shared/Utilities/Util.h +++ b/src/shared/Utilities/Util.h @@ -121,28 +121,6 @@ inline uint32 secsToTimeBitFields(time_t secs) return (lt->tm_year - 100) << 24 | lt->tm_mon << 20 | (lt->tm_mday - 1) << 14 | lt->tm_wday << 11 | lt->tm_hour << 6 | lt->tm_min; } - -inline std::string& ltrim(std::string& s) -{ - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) - { - return !std::isspace(ch); - })); - - return s; -} - -inline std::string& rtrim(std::string& s) -{ - s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); - return s; -} - -inline std::string& trim(std::string& s) -{ - return ltrim(rtrim(s)); -} - /** * @brief Return a random number in the range min..max; (max-min) must be smaller than 32768. *