Skip to content

Commit

Permalink
chore. update module
Browse files Browse the repository at this point in the history
  • Loading branch information
pangolp committed Oct 31, 2024
1 parent 24be9fa commit f157bc7
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 77 deletions.
20 changes: 13 additions & 7 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
Empty file added .github/workflows/.gitkeep
Empty file.
Empty file added conf/.gitkeep
Empty file.
62 changes: 46 additions & 16 deletions conf/Individual-XP.conf.dist
Original file line number Diff line number Diff line change
@@ -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
Empty file added data/.gitkeep
Empty file.
152 changes: 98 additions & 54 deletions src/individual_xp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("IndividualXp.Announce", 1);
IndividualXpEnabled = sConfigMgr->GetOption<bool>("IndividualXp.Enabled", 1);
MaxRate = sConfigMgr->GetOption<uint32>("MaxXPRate", 10);
DefaultRate = sConfigMgr->GetOption<uint32>("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,
Expand All @@ -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<bool>("IndividualXp.Enabled", true);
individualXp.AnnounceModule = sConfigMgr->GetOption<bool>("IndividualXp.Announce", true);
individualXp.AnnounceRatesOnLogin = sConfigMgr->GetOption<bool>("IndividualXp.AnnounceRatesOnLogin", true);
individualXp.MaxRate = sConfigMgr->GetOption<uint32>("IndividualXp.MaxXPRate", 10);
individualXp.DefaultRate = sConfigMgr->GetOption<uint32>("IndividualXp.DefaultXPRate", 1);
}
};

Expand All @@ -81,13 +69,36 @@ class IndividualXP : public PlayerScript

if (!result)
{
player->CustomData.GetDefault<PlayerXpRate>("IndividualXP")->XPRate = DefaultRate;
player->CustomData.GetDefault<PlayerXpRate>("IndividualXP")->XPRate = individualXp.DefaultRate;
}
else
{
Field* fields = result->Fetch();
player->CustomData.Set("IndividualXP", new PlayerXpRate(fields[0].Get<uint32>()));
}

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<PlayerXpRate>("IndividualXP")->XPRate);
ChatHandler(player->GetSession()).PSendSysMessage(ACORE_STRING_COMMAND_DEFAULT, individualXp.DefaultRate);
}
}
}
}

void OnLogout(Player* player) override
Expand All @@ -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<PlayerXpRate>("IndividualXP"))
amount *= data->XPRate;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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<PlayerXpRate>("IndividualXP")->XPRate = rate;
ChatHandler(handler->GetSession()).PSendSysMessage(ACORE_STRING_COMMAND_SET, rate);
return true;
}

player->CustomData.GetDefault<PlayerXpRate>("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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -248,16 +284,24 @@ class IndividualXPCommand : public CommandScript
if (!player)
return false;

player->CustomData.GetDefault<PlayerXpRate>("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<PlayerXpRate>("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();
}

0 comments on commit f157bc7

Please sign in to comment.