From 7cf41eb32a3128bcb7738a0c68cf01d96e6abaa9 Mon Sep 17 00:00:00 2001 From: Walter Pagani Date: Sat, 2 Nov 2024 12:20:48 -0300 Subject: [PATCH] chore. Allow decimal XP rates (#42) Co-authored-by: Denis Arnst --- .../base/mod_individual_xp_IndividualXP.sql | 2 +- src/individual_xp.cpp | 32 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/data/sql/db-characters/base/mod_individual_xp_IndividualXP.sql b/data/sql/db-characters/base/mod_individual_xp_IndividualXP.sql index 04154c6..73e3058 100644 --- a/data/sql/db-characters/base/mod_individual_xp_IndividualXP.sql +++ b/data/sql/db-characters/base/mod_individual_xp_IndividualXP.sql @@ -14,7 +14,7 @@ -- Dumping structure for table acore_characters.individualxp CREATE TABLE IF NOT EXISTS `individualxp` ( `CharacterGUID` int(11) NOT NULL, - `XPRate` int(11) NOT NULL DEFAULT '0', + `XPRate` float NOT NULL, PRIMARY KEY (`CharacterGUID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/src/individual_xp.cpp b/src/individual_xp.cpp index eec9ed5..5172b37 100644 --- a/src/individual_xp.cpp +++ b/src/individual_xp.cpp @@ -16,7 +16,7 @@ Thanks to Rochet for the assistance struct IndividualXpModule { bool Enabled, AnnounceModule, AnnounceRatesOnLogin; - uint32 MaxRate, DefaultRate; + float MaxRate, DefaultRate; }; IndividualXpModule individualXp; @@ -45,8 +45,8 @@ class IndividualXPConf : public WorldScript 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); + individualXp.MaxRate = sConfigMgr->GetOption("IndividualXp.MaxXPRate", 10.0f); + individualXp.DefaultRate = sConfigMgr->GetOption("IndividualXp.DefaultXPRate", 1.0f); } }; @@ -54,8 +54,8 @@ class PlayerXpRate : public DataMap::Base { public: PlayerXpRate() {} - PlayerXpRate(uint32 XPRate) : XPRate(XPRate) {} - uint32 XPRate = 1; + PlayerXpRate(float XPRate) : XPRate(XPRate) {} + float XPRate = 1.0f; }; class IndividualXP : public PlayerScript @@ -74,7 +74,7 @@ class IndividualXP : public PlayerScript else { Field* fields = result->Fetch(); - player->CustomData.Set("IndividualXP", new PlayerXpRate(fields[0].Get())); + player->CustomData.Set("IndividualXP", new PlayerXpRate(fields[0].Get())); } if (individualXp.Enabled) @@ -114,10 +114,11 @@ class IndividualXP : public PlayerScript if (individualXp.Enabled) { if (PlayerXpRate* data = player->CustomData.Get("IndividualXP")) - amount *= data->XPRate; + { + amount = static_cast(std::round(static_cast(amount) * data->XPRate)); + } } } - }; class IndividualXPCommand : public CommandScript @@ -171,7 +172,7 @@ class IndividualXPCommand : public CommandScript return true; } - static bool HandleSetCommand(ChatHandler* handler, uint32 rate) + static bool HandleSetCommand(ChatHandler* handler, float rate) { if (!individualXp.Enabled) { @@ -202,7 +203,8 @@ class IndividualXPCommand : public CommandScript handler->SetSentErrorMessage(true); return false; } - else if (rate == 0) + + if (rate < 0.1f) { handler->PSendSysMessage(ACORE_STRING_MIN_RATE); handler->SetSentErrorMessage(true); @@ -249,7 +251,7 @@ class IndividualXPCommand : public CommandScript { handler->PSendSysMessage(ACORE_STRING_MODULE_DISABLED); handler->SetSentErrorMessage(true); - return false; + return true; } Player* player = handler->GetSession()->GetPlayer(); @@ -257,17 +259,17 @@ class IndividualXPCommand : public CommandScript if (!player) return false; - if (!player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN)) + 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; + ChatHandler(handler->GetSession()).PSendSysMessage(ACORE_STRING_RATES_DISABLED); } + + return true; } static bool HandleDefaultCommand(ChatHandler* handler)