From cfae767a8a22b0a423dbda3a287dfd71653ebfcb Mon Sep 17 00:00:00 2001 From: blkht01 <25400057+blkht01@users.noreply.github.com> Date: Sat, 3 Feb 2024 13:29:54 +0200 Subject: [PATCH] Allows for excluding spell id's from the module. (#12) * Modified to allow for excluding certain spells from the module * change of plans. let's load the spell ids from the config file instead, makes it a bit more versatile for others as well. * Update mod_account_mount.cpp * Update .gitignore ignore .conf file, only commit .dist * Update mod_account_mount.cpp * Handle scenarios where no spell IDs are to be excluded Modified the AccountMounts script to seamlessly handle scenarios where no spell IDs are to be excluded by interpreting "0" or an empty configuration string as no exclusion criteria. This update leverages the existing uint32 type for spell ID representation and enhances the script's flexibility in configuration management. The change ensures that the AccountMounts script is more adaptable to server administrators' needs, allowing for a straightforward way to toggle spell ID exclusions. Also added some code commenting * fatal error: 'GetStringDefault' is deprecated --------- Co-authored-by: Walter Pagani --- .gitignore | 1 + conf/mod_account_mount.conf.dist | 5 +++++ src/mod_account_mount.cpp | 38 ++++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index c6e1299..66b40c8 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ CMakeLists.txt.user *.BACKUP.* *.BASE.* *.LOCAL.* +*.conf # # IDE & other softwares diff --git a/conf/mod_account_mount.conf.dist b/conf/mod_account_mount.conf.dist index 3816e6b..02a2e28 100644 --- a/conf/mod_account_mount.conf.dist +++ b/conf/mod_account_mount.conf.dist @@ -11,3 +11,8 @@ Account.Mounts.Enable = 1 # Announce the module when the player logs in? Account.Mounts.Announce = 0 + +# Excluded Spell IDs (comma-separated, no space). See example below +# Account.Mounts.ExcludedSpellIDs = 470,578,6777 + +Account.Mounts.ExcludedSpellIDs = 0 \ No newline at end of file diff --git a/src/mod_account_mount.cpp b/src/mod_account_mount.cpp index 0eabf50..3223641 100644 --- a/src/mod_account_mount.cpp +++ b/src/mod_account_mount.cpp @@ -2,14 +2,34 @@ #include "ScriptMgr.h" #include "Chat.h" #include "Player.h" +#include // Required for std::set -- might be redundant +#include // Required for std::istringstream -- might be redundant +#include // Required for std::string -- might be redundant class AccountMounts : public PlayerScript { - static const bool limitrace = false; // This set to true will only learn mounts from chars on the same team, do what you want. + static const bool limitrace = true; // This set to true will only learn mounts from chars on the same team, do what you want. + std::set excludedSpellIds; // Set to hold the Spell IDs to be excluded public: - AccountMounts() : PlayerScript("AccountMounts") { } - + AccountMounts() : PlayerScript("AccountMounts") + { + // Retrieve the string of excluded Spell IDs from the config file + std::string excludedSpellsStr = sConfigMgr->GetOption("Account.Mounts.ExcludedSpellIDs", ""); + // Proceed only if the configuration is not "0" or empty, indicating exclusions are specified + if (excludedSpellsStr != "0" && !excludedSpellsStr.empty()) + { + std::istringstream spellStream(excludedSpellsStr); + std::string spellIdStr; + while (std::getline(spellStream, spellIdStr, ',')) { + uint32 spellId = static_cast(std::stoul(spellIdStr)); + if (spellId != 0) { // Ensure the spell ID is not 0, as 0 is used to indicate no exclusions + excludedSpellIds.insert(spellId); // Add the Spell ID to the set of exclusions + } + } + } + } + void OnLogin(Player* pPlayer) { if (sConfigMgr->GetOption("Account.Mounts.Enable", true)) @@ -32,7 +52,7 @@ public: uint32 race = fields[1].Get(); if ((Player::TeamIdForRace(race) == Player::TeamIdForRace(pPlayer->getRace())) || !limitrace) - Guids.push_back(result1->Fetch()[0].Get()); + Guids.push_back(fields[0].Get()); } while (result1->NextRow()); @@ -52,9 +72,13 @@ public: for (auto& i : Spells) { - auto sSpell = sSpellStore.LookupEntry(i); - if (sSpell->Effect[0] == SPELL_EFFECT_APPLY_AURA && sSpell->EffectApplyAuraName[0] == SPELL_AURA_MOUNTED) - pPlayer->learnSpell(sSpell->Id); + // Check if the spell is in the excluded list before learning it + if (excludedSpellIds.find(i) == excludedSpellIds.end()) + { + auto sSpell = sSpellStore.LookupEntry(i); + if (sSpell->Effect[0] == SPELL_EFFECT_APPLY_AURA && sSpell->EffectApplyAuraName[0] == SPELL_AURA_MOUNTED) + pPlayer->learnSpell(sSpell->Id); + } } } }