From f157bc73ccd6fc8021768578d5bb767c2e14061a Mon Sep 17 00:00:00 2001 From: Pagani Walter Date: Thu, 31 Oct 2024 09:08:48 -0300 Subject: [PATCH] chore. update module --- .github/README.md | 20 +++-- .github/workflows/.gitkeep | 0 conf/.gitkeep | 0 conf/Individual-XP.conf.dist | 62 ++++++++++---- data/.gitkeep | 0 src/individual_xp.cpp | 152 ++++++++++++++++++++++------------- 6 files changed, 157 insertions(+), 77 deletions(-) create mode 100644 .github/workflows/.gitkeep create mode 100644 conf/.gitkeep create mode 100644 data/.gitkeep diff --git a/.github/README.md b/.github/README.md index 556410f..99a7954 100644 --- a/.github/README.md +++ b/.github/README.md @@ -6,7 +6,7 @@ [![Build Status](https://github.com/azerothcore/mod-individual-xp/workflows/core-build/badge.svg?branch=master&event=push)](https://github.com/azerothcore/mod-individual-xp) -Allows players to _View, Set, or Toggle_ the rate at which they gain experience individually. +This module allows each player to `view`, `enable`, `disable`, and `modify` their experience multiplier without having to modify the values of other players. This functionality can be accessed at any time through the use of commands. It is the player who decides how to play (`slow` or `fast`), rather than the server forcing them to decide for them. # How to install @@ -18,12 +18,18 @@ Allows players to _View, Set, or Toggle_ the rate at which they gain experience There are two variables to configure in the Config: -1. `Max XP Rate` -2. `Default XP Rate` - -The Max XP Rate variable dictates how high a player can set their XP rate. - -While the Default XP Rate variable dictates what XP rate players start with and the rate will be set to if the user does `.xp default` +- `IndividualXp.Enabled` + - Enable or Disable the IndividualXP Module. +- `IndividualXp.Announce` + - Announce the IndividualXP Module at logon. +- `IndividualXp.AnnounceRatesOnLogin` + - The player is shown the rates he has and the maximum value when he enters the chat. +- `IndividualXp.MaxXPRate` + - This is the max amount a player can set their xp to. +- `IndividualXp.DefaultXPRate` + - This is the default rate players start with. + +The Max XP Rate variable dictates how high a player can set their XP rate. While the Default XP Rate variable dictates what XP rate players start with and the rate will be set to if the user does `.xp default`. As a recommendation, it would be a good idea to set the default and maximum experience rates to match. In this way, all players would initially have the maximum experience on the server, and then, through the `.xp set` command, they could modify it. # Player Commands diff --git a/.github/workflows/.gitkeep b/.github/workflows/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/conf/.gitkeep b/conf/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/conf/Individual-XP.conf.dist b/conf/Individual-XP.conf.dist index ef2370b..e69020d 100644 --- a/conf/Individual-XP.conf.dist +++ b/conf/Individual-XP.conf.dist @@ -1,33 +1,63 @@ [worldserver] # -# IndividualXp.Enabled -# Description: Enable or Disable the IndividualXP Module. -# Default: IndividualXp.Enabled = 1 +# IndividualXp.Enabled +# +# Description: Enable or Disable the IndividualXP Module. +# Example: +# true (The module is active for use) +# false (No one can use the commands) +# +# Default: true +# + +IndividualXp.Enabled = true + +# +# IndividualXp.Announce +# +# Description: Announce the IndividualXP Module at logon. +# Example: +# true (The message is displayed in the chat when the player enters) +# false (The message does not appear) +# +# Default: true # -IndividualXp.Enabled = 1 +IndividualXp.Announce = true # -# IndividualXp.Announce -# Description: Announce the IndividualXP Module at logon. -# Default: IndividualXp.Announce = 1 +# IndividualXp.AnnounceRatesOnLogin +# +# Description: The player is shown the rates he has and the maximum value when he enters the chat +# Example: +# true (The message is displayed in the chat when the player enters) +# false (The message does not appear) +# +# Default: true # -IndividualXp.Announce = 1 +IndividualXp.AnnounceRatesOnLogin = true # -# MaxXPRate -# Description: This is the max amount a player can set their xp to. -# Default: Default = 1 +# IndividualXp.MaxXPRate +# +# Description: This is the max amount a player can set their xp to. +# Example: 1 or 2 or 3 or 4 (Any positive integer you want) +# +# Default: 10 # -MaxXPRate = 10 +IndividualXp.MaxXPRate = 10 # -# DefaultXPRate -# Description: This is the default rate players start with. -# Default: Default = 1 +# DefaultXPRate +# +# Description: This is the default rate players start with. +# Recommendation: It might be a good idea to set the default value to the maximum. +# Then each player can choose whether to lower it or not. Although it could also be 1. +# +# Default: 1 # -DefaultXPRate = 1 +IndividualXp.DefaultXPRate = 1 diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/individual_xp.cpp b/src/individual_xp.cpp index 12f395e..c062186 100644 --- a/src/individual_xp.cpp +++ b/src/individual_xp.cpp @@ -13,28 +13,17 @@ Coded by Talamortis - For Azerothcore Thanks to Rochet for the assistance */ -bool IndividualXpEnabled; -bool IndividualXpAnnounceModule; -uint32 MaxRate; -uint32 DefaultRate; - -class IndividualXPConf : public WorldScript +struct IndividualXpModule { -public: - IndividualXPConf() : WorldScript("IndividualXPConf") { } - - void OnBeforeConfigLoad(bool /*reload*/) override - { - IndividualXpAnnounceModule = sConfigMgr->GetOption("IndividualXp.Announce", 1); - IndividualXpEnabled = sConfigMgr->GetOption("IndividualXp.Enabled", 1); - MaxRate = sConfigMgr->GetOption("MaxXPRate", 10); - DefaultRate = sConfigMgr->GetOption("DefaultXPRate", 1); - } + bool Enabled, AnnounceModule, AnnounceRatesOnLogin; + uint32 MaxRate, DefaultRate; }; +IndividualXpModule individualXp; + enum IndividualXPAcoreString { - ACORE_STRING_CREDIT = 35411, + ACORE_STRING_CREDIT = 35411, ACORE_STRING_MODULE_DISABLED, ACORE_STRING_RATES_DISABLED, ACORE_STRING_COMMAND_VIEW, @@ -46,19 +35,18 @@ enum IndividualXPAcoreString ACORE_STRING_COMMAND_DEFAULT }; -class IndividualXpAnnounce : public PlayerScript +class IndividualXPConf : public WorldScript { public: + IndividualXPConf() : WorldScript("IndividualXPConf") { } - IndividualXpAnnounce() : PlayerScript("IndividualXpAnnounce") {} - - void OnLogin(Player* player) + void OnBeforeConfigLoad(bool /*reload*/) override { - // Announce Module - if ((IndividualXpEnabled) && (IndividualXpAnnounceModule)) - { - ChatHandler(player->GetSession()).SendSysMessage(ACORE_STRING_CREDIT); - } + individualXp.Enabled = sConfigMgr->GetOption("IndividualXp.Enabled", true); + individualXp.AnnounceModule = sConfigMgr->GetOption("IndividualXp.Announce", true); + individualXp.AnnounceRatesOnLogin = sConfigMgr->GetOption("IndividualXp.AnnounceRatesOnLogin", true); + individualXp.MaxRate = sConfigMgr->GetOption("IndividualXp.MaxXPRate", 10); + individualXp.DefaultRate = sConfigMgr->GetOption("IndividualXp.DefaultXPRate", 1); } }; @@ -81,13 +69,36 @@ class IndividualXP : public PlayerScript if (!result) { - player->CustomData.GetDefault("IndividualXP")->XPRate = DefaultRate; + player->CustomData.GetDefault("IndividualXP")->XPRate = individualXp.DefaultRate; } else { Field* fields = result->Fetch(); player->CustomData.Set("IndividualXP", new PlayerXpRate(fields[0].Get())); } + + if (individualXp.Enabled) + { + // Announce Module + if (individualXp.AnnounceModule) + { + ChatHandler(player->GetSession()).SendSysMessage(ACORE_STRING_CREDIT); + } + + // Announce Rates + if (individualXp.AnnounceRatesOnLogin) + { + if (player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN)) + { + ChatHandler(player->GetSession()).PSendSysMessage(ACORE_STRING_RATES_DISABLED); + } + else + { + ChatHandler(player->GetSession()).PSendSysMessage(ACORE_STRING_COMMAND_VIEW, player->CustomData.GetDefault("IndividualXP")->XPRate); + ChatHandler(player->GetSession()).PSendSysMessage(ACORE_STRING_COMMAND_DEFAULT, individualXp.DefaultRate); + } + } + } } void OnLogout(Player* player) override @@ -100,7 +111,7 @@ class IndividualXP : public PlayerScript void OnGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override { - if (IndividualXpEnabled) + if (individualXp.Enabled) { if (PlayerXpRate* data = player->CustomData.Get("IndividualXP")) amount *= data->XPRate; @@ -135,7 +146,7 @@ class IndividualXPCommand : public CommandScript static bool HandleViewCommand(ChatHandler* handler) { - if (!IndividualXpEnabled) + if (!individualXp.Enabled) { handler->PSendSysMessage(ACORE_STRING_MODULE_DISABLED); handler->SetSentErrorMessage(true); @@ -162,7 +173,7 @@ class IndividualXPCommand : public CommandScript static bool HandleSetCommand(ChatHandler* handler, uint32 rate) { - if (!IndividualXpEnabled) + if (!individualXp.Enabled) { handler->PSendSysMessage(ACORE_STRING_MODULE_DISABLED); handler->SetSentErrorMessage(true); @@ -177,27 +188,36 @@ class IndividualXPCommand : public CommandScript if (!player) return false; - if (rate > MaxRate) + if (player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN)) { - handler->PSendSysMessage(ACORE_STRING_MAX_RATE, MaxRate); + handler->PSendSysMessage(ACORE_STRING_RATES_DISABLED); handler->SetSentErrorMessage(true); return false; } - else if (rate == 0) + else { - handler->PSendSysMessage(ACORE_STRING_MIN_RATE); - handler->SetSentErrorMessage(true); - return false; + if (rate > individualXp.MaxRate) + { + handler->PSendSysMessage(ACORE_STRING_MAX_RATE, individualXp.MaxRate); + handler->SetSentErrorMessage(true); + return false; + } + else if (rate == 0) + { + handler->PSendSysMessage(ACORE_STRING_MIN_RATE); + handler->SetSentErrorMessage(true); + return false; + } + + player->CustomData.GetDefault("IndividualXP")->XPRate = rate; + ChatHandler(handler->GetSession()).PSendSysMessage(ACORE_STRING_COMMAND_SET, rate); + return true; } - - player->CustomData.GetDefault("IndividualXP")->XPRate = rate; - ChatHandler(handler->GetSession()).PSendSysMessage(ACORE_STRING_COMMAND_SET, rate); - return true; } static bool HandleDisableCommand(ChatHandler* handler) { - if (!IndividualXpEnabled) + if (!individualXp.Enabled) { handler->PSendSysMessage(ACORE_STRING_MODULE_DISABLED); handler->SetSentErrorMessage(true); @@ -209,15 +229,23 @@ class IndividualXPCommand : public CommandScript if (!player) return false; - // Turn Disabled On But Don't Change Value... - player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN); - player->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_DISABLED); - return true; + if (!player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN)) + { + // Turn Disabled On But Don't Change Value... + player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN); + ChatHandler(handler->GetSession()).PSendSysMessage(ACORE_STRING_COMMAND_DISABLED); + return true; + } + else + { + ChatHandler(handler->GetSession()).PSendSysMessage(ACORE_STRING_RATES_DISABLED); + return false; + } } static bool HandleEnableCommand(ChatHandler* handler) { - if (!IndividualXpEnabled) + if (!individualXp.Enabled) { handler->PSendSysMessage(ACORE_STRING_MODULE_DISABLED); handler->SetSentErrorMessage(true); @@ -229,14 +257,22 @@ class IndividualXPCommand : public CommandScript if (!player) return false; - player->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN); - player->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_ENABLED); - return true; + if (!player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN)) + { + player->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN); + ChatHandler(handler->GetSession()).PSendSysMessage(ACORE_STRING_COMMAND_ENABLED); + return true; + } + else + { + ChatHandler(handler->GetSession()).PSendSysMessage(ACORE_STRING_COMMAND_VIEW); + return false; + } } static bool HandleDefaultCommand(ChatHandler* handler) { - if (!IndividualXpEnabled) + if (!individualXp.Enabled) { handler->PSendSysMessage(ACORE_STRING_MODULE_DISABLED); handler->SetSentErrorMessage(true); @@ -248,16 +284,24 @@ class IndividualXPCommand : public CommandScript if (!player) return false; - player->CustomData.GetDefault("IndividualXP")->XPRate = DefaultRate; - ChatHandler(handler->GetSession()).PSendSysMessage(ACORE_STRING_COMMAND_DEFAULT, DefaultRate); - return true; + if (player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN)) + { + handler->PSendSysMessage(ACORE_STRING_RATES_DISABLED); + handler->SetSentErrorMessage(true); + return false; + } + else + { + player->CustomData.GetDefault("IndividualXP")->XPRate = individualXp.DefaultRate; + ChatHandler(handler->GetSession()).PSendSysMessage(ACORE_STRING_COMMAND_DEFAULT, individualXp.DefaultRate); + return true; + } } }; void AddIndividualXPScripts() { new IndividualXPConf(); - new IndividualXpAnnounce(); new IndividualXP(); new IndividualXPCommand(); }