mirror of
https://github.com/araxiaonline/mod-individual-xp.git
synced 2026-06-13 02:32:23 -04:00
Refactor & Update (#4)
* Refactor & Update Based For Issue: https://github.com/azerothcore/mod-individual-XP/issues/3 * XP Disable Fix Fixing .xp Disable command. Adding .xp Enable command. Fixing small spelling errors. Defaulting XP Rate to 1 from 5 Adding comments for Handles
This commit is contained in:
@@ -4,5 +4,9 @@
|
||||
# MaxXPRate
|
||||
# Description: This is the max amount a player can set their xp to.
|
||||
# Default: Default = 1
|
||||
#
|
||||
MaxXPRate = 10
|
||||
# DefaultXPRate
|
||||
# Description: This is the default rate players start with.
|
||||
# Default: Default = 1
|
||||
#
|
||||
MaxXPRate = 10
|
||||
DefaultXPRate = 1
|
||||
@@ -11,6 +11,9 @@ Coded by Talamortis - For Azerothcore
|
||||
Thanks to Rochet for the assistance
|
||||
*/
|
||||
|
||||
uint32 MaxRate;
|
||||
uint32 DefaultRate;
|
||||
|
||||
class PlayerXpRate : public DataMap::Base
|
||||
{
|
||||
public:
|
||||
@@ -19,8 +22,6 @@ public:
|
||||
uint32 XPRate = 1;
|
||||
};
|
||||
|
||||
uint32 MaxRate;
|
||||
|
||||
class Individual_XP : public PlayerScript
|
||||
{
|
||||
public:
|
||||
@@ -29,12 +30,16 @@ public:
|
||||
void OnLogin(Player* p) override
|
||||
{
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT `XPRate` FROM `individualxp` WHERE `CharacterGUID` = %u", p->GetGUIDLow());
|
||||
if (result)
|
||||
if (!result)
|
||||
{
|
||||
p->CustomData.GetDefault<PlayerXpRate>("Individual_XP")->XPRate = DefaultRate;
|
||||
}
|
||||
else
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
p->CustomData.Set("Individual_XP", new PlayerXpRate(fields[0].GetUInt32()));
|
||||
}
|
||||
ChatHandler(p->GetSession()).SendSysMessage("This server is running the |cff4CFF00Individual XP |rmodule. Use .SetXP <amount> to change.");
|
||||
ChatHandler(p->GetSession()).SendSysMessage("This server is running the |cff4CFF00Individual XP |rmodule. Use .XP to see all the commands.");
|
||||
}
|
||||
|
||||
void OnLogout(Player* p) override
|
||||
@@ -42,10 +47,7 @@ public:
|
||||
if (PlayerXpRate* data = p->CustomData.Get<PlayerXpRate>("Individual_XP"))
|
||||
{
|
||||
uint32 rate = data->XPRate;
|
||||
if (rate <= 1)
|
||||
CharacterDatabase.DirectPExecute("DELETE FROM `individualxp` WHERE `CharacterGUID` = %u", p->GetGUIDLow());
|
||||
else
|
||||
CharacterDatabase.DirectPExecute("REPLACE INTO `individualxp` (`CharacterGUID`, `XPRate`) VALUES (%u, %u);", p->GetGUIDLow(), rate);
|
||||
CharacterDatabase.DirectPExecute("REPLACE INTO `individualxp` (`CharacterGUID`, `XPRate`) VALUES (%u, %u);", p->GetGUIDLow(), rate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,14 +65,52 @@ public:
|
||||
|
||||
std::vector<ChatCommand> GetCommands() const override
|
||||
{
|
||||
static std::vector<ChatCommand> IndividualXPTable =
|
||||
|
||||
static std::vector<ChatCommand> IndividualXPCommandTable =
|
||||
{
|
||||
{ "SetXP", SEC_PLAYER, false, &HandleIndividualXPCommand, "" }
|
||||
// View Command
|
||||
{ "View", SEC_PLAYER, false, &HandleViewCommand, "" },
|
||||
// Set Command
|
||||
{ "Set", SEC_PLAYER, false, &HandleSetCommand, "" },
|
||||
// Default Command
|
||||
{ "Default", SEC_PLAYER, false, &HandleDefaultCommand, "" },
|
||||
// Disable Command
|
||||
{ "Disable", SEC_PLAYER, false, &HandleDisableCommand, "" },
|
||||
//Enable Command
|
||||
{ "Enable", SEC_PLAYER, false, &HandleEnableCommand, "" }
|
||||
};
|
||||
return IndividualXPTable;
|
||||
|
||||
static std::vector<ChatCommand> IndividualXPBaseTable =
|
||||
{
|
||||
{ "XP", SEC_PLAYER, false, nullptr, "", IndividualXPCommandTable }
|
||||
};
|
||||
|
||||
return IndividualXPBaseTable;
|
||||
}
|
||||
|
||||
static bool HandleIndividualXPCommand(ChatHandler* handler, char const* args)
|
||||
|
||||
// View Command
|
||||
static bool HandleViewCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (*args)
|
||||
return false;
|
||||
|
||||
Player* me = handler->GetSession()->GetPlayer();
|
||||
if (!me)
|
||||
return false;
|
||||
|
||||
if (me->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN))
|
||||
{
|
||||
me->GetSession()->SendAreaTriggerMessage("Your XP is currently disabled. Do .Xp Enable to re-enable it.");
|
||||
}
|
||||
else
|
||||
{
|
||||
me->GetSession()->SendAreaTriggerMessage("Your current XP rate is %u", me->CustomData.GetDefault<PlayerXpRate>("Individual_XP")->XPRate);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Set Command
|
||||
static bool HandleSetCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
@@ -87,6 +127,52 @@ public:
|
||||
me->GetSession()->SendAreaTriggerMessage("You have updated your XP rate to %u", rate);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Disable Command
|
||||
static bool HandleDisableCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (*args)
|
||||
return false;
|
||||
|
||||
Player* me = handler->GetSession()->GetPlayer();
|
||||
if (!me)
|
||||
return false;
|
||||
|
||||
// Turn Disabled On But Don't Change Value...
|
||||
me->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
|
||||
me->GetSession()->SendAreaTriggerMessage("You have Disabled your XP gain.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Enable Command
|
||||
static bool HandleEnableCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (*args)
|
||||
return false;
|
||||
|
||||
Player* me = handler->GetSession()->GetPlayer();
|
||||
if (!me)
|
||||
return false;
|
||||
|
||||
me->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
|
||||
me->GetSession()->SendAreaTriggerMessage("You have enabled your XP gain.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Default Command
|
||||
static bool HandleDefaultCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (*args)
|
||||
return false;
|
||||
|
||||
Player* me = handler->GetSession()->GetPlayer();
|
||||
if (!me)
|
||||
return false;
|
||||
|
||||
me->CustomData.GetDefault<PlayerXpRate>("Individual_XP")->XPRate = DefaultRate;
|
||||
me->GetSession()->SendAreaTriggerMessage("You have restored your XP rate to the default value of %u", DefaultRate);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class Individual_XP_conf : public WorldScript
|
||||
@@ -108,6 +194,7 @@ public:
|
||||
sConfigMgr->LoadMore(cfg_def_file.c_str());
|
||||
sConfigMgr->LoadMore(cfg_file.c_str());
|
||||
MaxRate = sConfigMgr->GetIntDefault("MaxXPRate", 10);
|
||||
DefaultRate = sConfigMgr->GetIntDefault("DefaultXPRate", 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user