Skip to content

Commit

Permalink
chore. Allow decimal XP rates (#42)
Browse files Browse the repository at this point in the history
Co-authored-by: Denis Arnst <[email protected]>
  • Loading branch information
pangolp and Sapd authored Nov 2, 2024
1 parent 199d202 commit 7cf41eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
32 changes: 17 additions & 15 deletions src/individual_xp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Thanks to Rochet for the assistance
struct IndividualXpModule
{
bool Enabled, AnnounceModule, AnnounceRatesOnLogin;
uint32 MaxRate, DefaultRate;
float MaxRate, DefaultRate;
};

IndividualXpModule individualXp;
Expand Down Expand Up @@ -45,17 +45,17 @@ class IndividualXPConf : public WorldScript
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);
individualXp.MaxRate = sConfigMgr->GetOption<float>("IndividualXp.MaxXPRate", 10.0f);
individualXp.DefaultRate = sConfigMgr->GetOption<float>("IndividualXp.DefaultXPRate", 1.0f);
}
};

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
Expand All @@ -74,7 +74,7 @@ class IndividualXP : public PlayerScript
else
{
Field* fields = result->Fetch();
player->CustomData.Set("IndividualXP", new PlayerXpRate(fields[0].Get<uint32>()));
player->CustomData.Set("IndividualXP", new PlayerXpRate(fields[0].Get<float>()));
}

if (individualXp.Enabled)
Expand Down Expand Up @@ -114,10 +114,11 @@ class IndividualXP : public PlayerScript
if (individualXp.Enabled)
{
if (PlayerXpRate* data = player->CustomData.Get<PlayerXpRate>("IndividualXP"))
amount *= data->XPRate;
{
amount = static_cast<uint32>(std::round(static_cast<float>(amount) * data->XPRate));
}
}
}

};

class IndividualXPCommand : public CommandScript
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -249,25 +251,25 @@ class IndividualXPCommand : public CommandScript
{
handler->PSendSysMessage(ACORE_STRING_MODULE_DISABLED);
handler->SetSentErrorMessage(true);
return false;
return true;
}

Player* player = handler->GetSession()->GetPlayer();

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)
Expand Down

0 comments on commit 7cf41eb

Please sign in to comment.