mod: renamed config file

fix: only apply cooldown if mod is enabled
mod: refactored code
mod: read enabled state only when the world-config is loaded
add: config option to switch mod announcement
This commit is contained in:
BytesGalore
2021-10-06 20:10:13 +02:00
parent 6500b8cc87
commit e9978b92b9
3 changed files with 48 additions and 26 deletions

View File

@@ -3,7 +3,7 @@
### This is a module for [AzerothCore](http://www.azerothcore.org) ### This is a module for [AzerothCore](http://www.azerothcore.org)
#### Features: #### Features:
- It disables the Hearthstone cooldown - It resets the Hearthstone cooldown immediatly
### This module currently requires: ### This module currently requires:
- AzerothCore v4.0.0+ - AzerothCore v4.0.0+
@@ -11,14 +11,13 @@
### How to install ### How to install
1. Simply place the module under the `modules` folder of your AzerothCore source folder. 1. Simply place the module under the `modules` folder of your AzerothCore source folder.
2. Re-run cmake and launch a clean build of AzerothCore 2. Re-run cmake and launch a clean build of AzerothCore
3. that's all
### (Optional) Edit module configuration ### (Optional) Edit module configuration
You can turn the module **on** and **off**, default it is **on**. - You can turn the module **on** and **off**, default it is **on**
If you want to disable it, go to your server configuration folder (e.g. **etc**), copy `no-hearthstone-cooldown.conf.dist` to `no-hearthstone-cooldown.conf` and change - You can also turn the announcement of the module on player-login **on** and **off**, default it is **on**
`NoHearthstoneCooldown.Enable = 1` - If you want change the settings, go to your server configuration folder (e.g. **etc**), copy `mod_no_hearthstone_cooldown.conf.dist` to `mod_no_hearthstone_cooldown.conf` and edit the settings
to
`NoHearthstoneCooldown.Enable = 0`
## Credits ## Credits
* BytesGalore * [BytesGalore](https://github.com/BytesGalore) (author of the module)
* AzerothCore: [repository](https://github.com/azerothcore) - [website](http://azerothcore.org/) - [discord chat community](https://discord.gg/PaqQRkd) * AzerothCore: [repository](https://github.com/azerothcore) - [website](http://azerothcore.org/) - [discord chat community](https://discord.gg/PaqQRkd)

View File

@@ -13,5 +13,12 @@
# Default: 1 - Enabled # Default: 1 - Enabled
# 0 - Disabled # 0 - Disabled
# #
# NoHearthstoneCooldownConfig.Announce
# Description: Inform the player about the loaded module
# Default: 1 - Enabled
# 0 - Disabled
#
NoHearthstoneCooldown.Enable = 1 NoHearthstoneCooldown.Enable = 1
NoHearthstoneCooldown.Announce = 1

View File

@@ -6,40 +6,56 @@
#include "Player.h" #include "Player.h"
#include "Config.h" #include "Config.h"
#include "Chat.h" #include "Chat.h"
#include "Item.h"
// Add player scripts // Add player scripts
class NoHearthstoneCooldown : public PlayerScript class NoHearthstoneCooldown : public PlayerScript, public WorldScript
{ {
public: public:
NoHearthstoneCooldown(): PlayerScript("NoHearthstoneCooldown") {} NoHearthstoneCooldown(): PlayerScript("NoHearthstoneCooldown"), WorldScript("NoHearthstoneCooldown") {}
bool OnBeforeTeleport(Player* player, uint32 /*mapid*/, float /*x*/, float /*y*/, float /*z*/, float /*orientation*/, uint32 /*options*/, Unit* /*target*/) override bool OnBeforeTeleport(Player* player, uint32 /*mapid*/, float /*x*/, float /*y*/, float /*z*/, float /*orientation*/, uint32 /*options*/, Unit* /*target*/) override
{ {
auto* spell = player->FindCurrentSpellBySpellId(8690); ClearHearthstoneCooldown(player);
if (spell)
{
player->RemoveSpellCooldown(8690, true);
player->RemoveSpellCooldown(39937, true);
player->SendClearCooldown(8690, player);
player->SendClearCooldown(39937, player);
}
return true; return true;
} }
void OnLogin(Player* player) override void OnLogin(Player* player) override
{ {
if (sConfigMgr->GetOption<bool>("NoHearthstoneCooldown.Enable", false)) if (sConfigMgr->GetOption<bool>("NoHearthstoneCooldown.Announce", true))
{ {
ChatHandler(player->GetSession()).SendSysMessage("This server is running the |cff4CFF00No Hearthstone cooldown|rmodule!"); ChatHandler(player->GetSession()).SendSysMessage("This server is running the |cff4CFF00No Hearthstone cooldown|r module.");
player->RemoveSpellCooldown(8690, true);
player->RemoveSpellCooldown(39937, true);
player->SendClearCooldown(8690, player);
player->SendClearCooldown(39937, player);
} }
ClearHearthstoneCooldown(player);
} }
void OnAfterConfigLoad(bool /*reload*/) override
{
m_bNHCModuleEnabled = sConfigMgr->GetOption<bool>("NoHearthstoneCooldown.Enable", true);
}
private:
void ClearHearthstoneCooldown(Player* player)
{
if (m_bNHCModuleEnabled)
{
// only clear the cooldown if the player actually casted the Hearthstone spell
if (player->FindCurrentSpellBySpellId(m_nSpellIDHearthstone))
{
// we remove the cooldown from the list of the player current cooldowns
player->RemoveSpellCooldown(m_nSpellIDHearthstone, true);
player->RemoveSpellCooldown(m_nSpellIDNoPlaceLikeHome, true);
// then we clear the cooldown and send an update to the player client
player->SendClearCooldown(m_nSpellIDHearthstone, player);
player->SendClearCooldown(m_nSpellIDNoPlaceLikeHome, player);
}
}
}
bool m_bNHCModuleEnabled = false;
// https://www.wowhead.com/spell=8690/hearthstone
const uint32 m_nSpellIDHearthstone = 8690;
// https://tbc.wowhead.com/spell=39937/theres-no-place-like-home
const uint32 m_nSpellIDNoPlaceLikeHome = 39937;
}; };
// Add all scripts in one // Add all scripts in one