Skip to content

Commit

Permalink
chore. correct module format (#38)
Browse files Browse the repository at this point in the history
* chore. command writing format

* More changes
  • Loading branch information
pangolp authored Apr 30, 2024
1 parent 48d9890 commit f061cbc
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 92 deletions.
7 changes: 4 additions & 3 deletions src/IXP_loader.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
void AddIndividual_XPScripts();
void AddIndividualXPScripts();

void Addmod_individual_xpScripts() {
AddIndividual_XPScripts();
void Addmod_individual_xpScripts()
{
AddIndividualXPScripts();
}
160 changes: 71 additions & 89 deletions src/Individual_XP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include "Object.h"
#include "DataMap.h"

#if AC_COMPILER == AC_COMPILER_GNU
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

using namespace Acore::ChatCommands;

/*
Expand All @@ -22,21 +18,21 @@ bool IndividualXpAnnounceModule;
uint32 MaxRate;
uint32 DefaultRate;

class Individual_XP_conf : public WorldScript
class IndividualXPConf : public WorldScript
{
public:
Individual_XP_conf() : WorldScript("Individual_XP_conf_conf") { }
IndividualXPConf() : WorldScript("IndividualXPConf") { }

void OnBeforeConfigLoad(bool /*reload*/) override
{
IndividualXpAnnounceModule = sConfigMgr->GetOption<bool>("IndividualXp.Announce", 1);
IndividualXpEnabled = sConfigMgr->GetBoolDefault("IndividualXp.Enabled", 1);
MaxRate = sConfigMgr->GetIntDefault("MaxXPRate", 10);
DefaultRate = sConfigMgr->GetIntDefault("DefaultXPRate", 1);
IndividualXpEnabled = sConfigMgr->GetOption<bool>("IndividualXp.Enabled", 1);
MaxRate = sConfigMgr->GetOption<uint32>("MaxXPRate", 10);
DefaultRate = sConfigMgr->GetOption<uint32>("DefaultXPRate", 1);
}
};

enum IndividualXP
enum IndividualXPAcoreString
{
ACORE_STRING_CREDIT = 35411,
ACORE_STRING_MODULE_DISABLED,
Expand All @@ -50,16 +46,16 @@ enum IndividualXP
ACORE_STRING_COMMAND_DEFAULT
};

class Individual_Xp_Announce : public PlayerScript
class IndividualXpAnnounce : public PlayerScript
{
public:

Individual_Xp_Announce() : PlayerScript("Individual_Xp_Announce") {}
IndividualXpAnnounce() : PlayerScript("IndividualXpAnnounce") {}

void OnLogin(Player* player)
{
// Announce Module
if (IndividualXpEnabled & IndividualXpAnnounceModule)
if ((IndividualXpEnabled) && (IndividualXpAnnounceModule))
{
ChatHandler(player->GetSession()).SendSysMessage(ACORE_STRING_CREDIT);
}
Expand All @@ -74,69 +70,70 @@ class PlayerXpRate : public DataMap::Base
uint32 XPRate = 1;
};

class Individual_XP : public PlayerScript
class IndividualXP : public PlayerScript
{
public:
Individual_XP() : PlayerScript("Individual_XP") { }
IndividualXP() : PlayerScript("IndividualXP") {}

void OnLogin(Player* p) override
void OnLogin(Player* player) override
{
QueryResult result = CharacterDatabase.Query("SELECT `XPRate` FROM `individualxp` WHERE `CharacterGUID` = '{}'", p->GetGUID().GetCounter());
QueryResult result = CharacterDatabase.Query("SELECT `XPRate` FROM `individualxp` WHERE `CharacterGUID`='{}'", player->GetGUID().GetCounter());

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

void OnLogout(Player* p) override
void OnLogout(Player* player) override
{
if (PlayerXpRate* data = p->CustomData.Get<PlayerXpRate>("Individual_XP"))
if (PlayerXpRate* data = player->CustomData.Get<PlayerXpRate>("IndividualXP"))
{
uint32 rate = data->XPRate;
CharacterDatabase.DirectExecute("REPLACE INTO `individualxp` (`CharacterGUID`, `XPRate`) VALUES ('{}', '{}');", p->GetGUID().GetCounter(), rate);
CharacterDatabase.DirectExecute("REPLACE INTO `individualxp` (`CharacterGUID`, `XPRate`) VALUES ('{}', '{}');", player->GetGUID().GetCounter(), data->XPRate);
}
}

void OnGiveXP(Player* p, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override
void OnGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override
{
if (IndividualXpEnabled) {
if (PlayerXpRate* data = p->CustomData.Get<PlayerXpRate>("Individual_XP"))
if (IndividualXpEnabled)
{
if (PlayerXpRate* data = player->CustomData.Get<PlayerXpRate>("IndividualXP"))
amount *= data->XPRate;
}
}

};

class Individual_XP_command : public CommandScript
class IndividualXPCommand : public CommandScript
{
public:
Individual_XP_command() : CommandScript("Individual_XP_command") { }
std::vector<ChatCommand> GetCommands() const override
IndividualXPCommand() : CommandScript("IndividualXPCommand") {}

ChatCommandTable GetCommands() const override
{
static std::vector<ChatCommand> IndividualXPCommandTable =
static ChatCommandTable IndividualXPCommandTable =
{
{ "enable", SEC_PLAYER, false, &HandleEnableCommand, "" },
{ "disable", SEC_PLAYER, false, &HandleDisableCommand, "" },
{ "view", SEC_PLAYER, false, &HandleViewCommand, "" },
{ "set", SEC_PLAYER, false, &HandleSetCommand, "" },
{ "default", SEC_PLAYER, false, &HandleDefaultCommand, "" },
{ "", SEC_PLAYER, false, &HandleXPCommand, "" }
{ "enable", HandleEnableCommand, SEC_PLAYER, Console::No },
{ "disable", HandleDisableCommand, SEC_PLAYER, Console::No },
{ "view", HandleViewCommand, SEC_PLAYER, Console::No },
{ "set", HandleSetCommand, SEC_PLAYER, Console::No },
{ "default", HandleDefaultCommand, SEC_PLAYER, Console::No }
};

static std::vector<ChatCommand> IndividualXPBaseTable =
static ChatCommandTable IndividualXPBaseTable =
{
{ "xp", SEC_PLAYER, false, nullptr, "", IndividualXPCommandTable }
{ "xp", IndividualXPCommandTable }
};

return IndividualXPBaseTable;
return IndividualXPBaseTable;
}

static bool HandleXPCommand(ChatHandler* handler, char const* args)
static bool HandleViewCommand(ChatHandler* handler)
{
if (!IndividualXpEnabled)
{
Expand All @@ -145,40 +142,25 @@ class Individual_XP_command : public CommandScript
return false;
}

if (!*args)
return false;

return true;
}

static bool HandleViewCommand(ChatHandler* handler, char const* /*args*/)
{
if (!IndividualXpEnabled)
{
handler->PSendSysMessage(ACORE_STRING_MODULE_DISABLED);
handler->SetSentErrorMessage(true);
return false;
}
Player* player = handler->GetSession()->GetPlayer();

Player* me = handler->GetSession()->GetPlayer();
if (!me)
if (!player)
return false;

if (me->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN))
if (player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN))
{
handler->PSendSysMessage(ACORE_STRING_RATES_DISABLED);
handler->SetSentErrorMessage(true);
return false;
}
else
{
me->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_VIEW, me->CustomData.GetDefault<PlayerXpRate>("Individual_XP")->XPRate);
player->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_VIEW, player->CustomData.GetDefault<PlayerXpRate>("IndividualXP")->XPRate);
}
return true;
}

// Set Command
static bool HandleSetCommand(ChatHandler* handler, char const* args)
static bool HandleSetCommand(ChatHandler* handler, uint32 rate)
{
if (!IndividualXpEnabled)
{
Expand All @@ -187,14 +169,14 @@ class Individual_XP_command : public CommandScript
return false;
}

if (!*args)
if (!rate)
return false;

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

if (!player)
return false;

uint32 rate = (uint32)atol(args);
if (rate > MaxRate)
{
handler->PSendSysMessage(ACORE_STRING_MAX_RATE, MaxRate);
Expand All @@ -208,13 +190,12 @@ class Individual_XP_command : public CommandScript
return false;
}

me->CustomData.GetDefault<PlayerXpRate>("Individual_XP")->XPRate = rate;
me->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_SET, rate);
player->CustomData.GetDefault<PlayerXpRate>("IndividualXP")->XPRate = rate;
player->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_SET, rate);
return true;
}

// Disable Command
static bool HandleDisableCommand(ChatHandler* handler, char const* /*args*/)
static bool HandleDisableCommand(ChatHandler* handler)
{
if (!IndividualXpEnabled)
{
Expand All @@ -223,18 +204,18 @@ class Individual_XP_command : public CommandScript
return false;
}

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

if (!player)
return false;

// Turn Disabled On But Don't Change Value...
me->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
me->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_DISABLED);
player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
player->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_DISABLED);
return true;
}

// Enable Command
static bool HandleEnableCommand(ChatHandler* handler, char const* /*args*/)
static bool HandleEnableCommand(ChatHandler* handler)
{
if (!IndividualXpEnabled)
{
Expand All @@ -243,17 +224,17 @@ class Individual_XP_command : public CommandScript
return false;
}

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

if (!player)
return false;

me->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
me->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_ENABLED);
player->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
player->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_ENABLED);
return true;
}

// Default Command
static bool HandleDefaultCommand(ChatHandler* handler, char const* /*args*/)
static bool HandleDefaultCommand(ChatHandler* handler)
{
if (!IndividualXpEnabled)
{
Expand All @@ -262,20 +243,21 @@ class Individual_XP_command : public CommandScript
return false;
}

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

if (!player)
return false;

me->CustomData.GetDefault<PlayerXpRate>("Individual_XP")->XPRate = DefaultRate;
me->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_DEFAULT, DefaultRate);
player->CustomData.GetDefault<PlayerXpRate>("IndividualXP")->XPRate = DefaultRate;
player->GetSession()->SendAreaTriggerMessage(ACORE_STRING_COMMAND_DEFAULT, DefaultRate);
return true;
}
};

void AddIndividual_XPScripts()
void AddIndividualXPScripts()
{
new Individual_XP_conf();
new Individual_Xp_Announce();
new Individual_XP();
new Individual_XP_command();
new IndividualXPConf();
new IndividualXpAnnounce();
new IndividualXP();
new IndividualXPCommand();
}

0 comments on commit f061cbc

Please sign in to comment.