From 2711418bb3cb7cd7909b1e26fe6bd36f680c3f73 Mon Sep 17 00:00:00 2001 From: Carey Brooks Date: Mon, 1 Mar 2021 13:27:59 -0600 Subject: [PATCH] Fix Config Errors --- CMakeLists.txt | 5 +--- src/mod_learnspells.cpp | 63 +++++++++++++++-------------------------- 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3396cba..aeb556e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,4 @@ -CU_SET_PATH("CMAKE_MOD_LEARNSPELLS_DIR" "${CMAKE_CURRENT_LIST_DIR}") - AC_ADD_SCRIPT("${CMAKE_CURRENT_LIST_DIR}/src/mod_learnspells.cpp") - AC_ADD_SCRIPT_LOADER("LearnAllSpells" "${CMAKE_CURRENT_LIST_DIR}/src/loader.h") -CU_ADD_HOOK(AFTER_WORLDSERVER_CMAKE "${CMAKE_CURRENT_LIST_DIR}/src/cmake/after_ws_install.cmake") \ No newline at end of file +AC_ADD_CONFIG_FILE("${CMAKE_CURRENT_LIST_DIR}/conf/mod_learnspells.conf.dist") \ No newline at end of file diff --git a/src/mod_learnspells.cpp b/src/mod_learnspells.cpp index b3a5969..d77b52b 100644 --- a/src/mod_learnspells.cpp +++ b/src/mod_learnspells.cpp @@ -5,7 +5,23 @@ #include "ScriptMgr.h" #include "SpellInfo.h" -uint32 MaxLevel; +static bool learnlpells_announce; +static bool learnspells_enable; +static bool learnspells_onfirstlogin; +static uint32 learnspells_maxlevel; + +class LearnAllSpellseBeforeConfigLoad : public WorldScript { +public: + + LearnAllSpellseBeforeConfigLoad() : WorldScript("LearnAllSpellseBeforeConfigLoad") { } + + void OnBeforeConfigLoad(bool /*reload*/) override { + learnlpells_announce = sConfigMgr->GetBoolDefault("LearnSpells.Announce", 1); + learnspells_enable = sConfigMgr->GetBoolDefault("LearnSpells.Enable", 1); + learnspells_onfirstlogin = sConfigMgr->GetBoolDefault("LearnSpells.OnFirstLogin", 0); + learnspells_maxlevel = sConfigMgr->GetIntDefault("learnspells_maxlevel", 80); + } +}; class LearnSpellsOnLevelUp : public PlayerScript { @@ -16,29 +32,22 @@ class LearnSpellsOnLevelUp : public PlayerScript void OnLogin(Player* player) override { - if (sConfigMgr->GetBoolDefault("LearnSpells.Enable", true)) - { - if (sConfigMgr->GetBoolDefault("LearnSpells.Announce", true)) - { - ChatHandler(player->GetSession()).SendSysMessage("This server is running the |cff4CFF00LearnAllSpells |rmodule."); - } + if (learnspells_enable && learnlpells_announce){ + ChatHandler(player->GetSession()).SendSysMessage("This server is running the |cff4CFF00LearnAllSpells |rmodule."); } } void OnFirstLogin(Player* player) override { - if (sConfigMgr->GetBoolDefault("LearnSpells.LearnAllOnFirstLogin", false)) - { + if (learnspells_onfirstlogin){ LearnSpellsForNewLevel(player, 1); } } void OnLevelChanged(Player* player, uint8 oldLevel) override { - if (sConfigMgr->GetBoolDefault("LearnSpells.Enable", true)) - { - if (player->getLevel() <= MaxLevel) - { + if (sConfigMgr->GetBoolDefault("LearnSpells.Enable", true)){ + if (player->getLevel() <= learnspells_maxlevel){ if (oldLevel < player->getLevel()) LearnSpellsForNewLevel(player, oldLevel); } @@ -319,34 +328,8 @@ class LearnSpellsOnLevelUp : public PlayerScript } }; -class LearnAllSpellsWorld : public WorldScript -{ - public: - LearnAllSpellsWorld() : WorldScript("LearnAllSpellsWorld") - { - } - - void OnBeforeConfigLoad(bool reload) override - { - if (!reload) - { - std::string conf_path = _CONF_DIR; - std::string cfg_file = conf_path + "/mod_learnspells.conf"; -#ifdef WIN32 - cfg_file = "mod_learnspells.conf"; -#endif - std::string cfg_def_file = cfg_file + ".dist"; - sConfigMgr->LoadMore(cfg_def_file.c_str()); - - sConfigMgr->LoadMore(cfg_file.c_str()); - - MaxLevel = sConfigMgr->GetIntDefault("MaxLevel", 80); - } - } -}; - void AddLearnAllSpellsScripts() { - new LearnAllSpellsWorld(); + new LearnAllSpellseBeforeConfigLoad(); new LearnSpellsOnLevelUp(); }