[Commands] Cleanup #level Command. (#2203)

- Cleanup messages and logic.
- Breakout #level into its own command file.
This commit is contained in:
Kinglykrab 2022-05-27 14:45:26 -04:00 committed by GitHub
parent 0de90dc135
commit 129a738072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 35 deletions

View File

@ -223,7 +223,7 @@ int command_init(void)
command_add("kill", "- Kill your target", AccountStatus::GMAdmin, command_kill) ||
command_add("killallnpcs", " [npc_name] Kills all npcs by search name, leave blank for all attackable NPC's", AccountStatus::GMMgmt, command_killallnpcs) ||
command_add("lastname", "[Last Name] - Set you or your player target's lastname", AccountStatus::Guide, command_lastname) ||
command_add("level", "[level] - Set your or your target's level", AccountStatus::Steward, command_level) ||
command_add("level", "[Level] - Set your target's level", AccountStatus::Steward, command_level) ||
command_add("list", "[npcs|players|corpses|doors|objects] [search] - Search entities", AccountStatus::ApprenticeGuide, command_list) ||
command_add("listpetition", "- List petitions", AccountStatus::Guide, command_listpetition) ||
command_add("load_shared_memory", "[shared_memory_name] - Reloads shared memory and uses the input as output", AccountStatus::GMImpossible, command_load_shared_memory) ||
@ -746,40 +746,6 @@ void command_zone_instance(Client *c, const Seperator *sep)
}
}
void command_level(Client *c, const Seperator *sep)
{
uint16 level = atoi(sep->arg[1]);
if ((level <= 0) || ((level > RuleI(Character, MaxLevel)) && (c->Admin() < commandLevelAboveCap))) {
c->Message(Chat::White, "Error: #Level: Invalid Level");
}
else if (c->Admin() < RuleI(GM, MinStatusToLevelTarget)) {
c->SetLevel(level, true);
#ifdef BOTS
if(RuleB(Bots, BotLevelsWithOwner))
Bot::LevelBotWithClient(c, level, true);
#endif
}
else if (!c->GetTarget()) {
c->Message(Chat::White, "Error: #Level: No target");
}
else {
if (!c->GetTarget()->IsNPC() && ((c->Admin() < commandLevelNPCAboveCap) && (level > RuleI(Character, MaxLevel)))) {
c->Message(Chat::White, "Error: #Level: Invalid Level");
}
else {
c->GetTarget()->SetLevel(level, true);
if(c->GetTarget()->IsClient()) {
c->GetTarget()->CastToClient()->SendLevelAppearance();
#ifdef BOTS
if(RuleB(Bots, BotLevelsWithOwner))
Bot::LevelBotWithClient(c->GetTarget()->CastToClient(), level, true);
#endif
}
}
}
}
void command_spawneditmass(Client *c, const Seperator *sep)
{
std::string query = fmt::format(
@ -1235,6 +1201,7 @@ void command_bot(Client *c, const Seperator *sep)
#include "gm_commands/kill.cpp"
#include "gm_commands/killallnpcs.cpp"
#include "gm_commands/lastname.cpp"
#include "gm_commands/level.cpp"
#include "gm_commands/list.cpp"
#include "gm_commands/listpetition.cpp"
#include "gm_commands/loc.cpp"

View File

@ -0,0 +1,51 @@
#include "../client.h"
void command_level(Client *c, const Seperator *sep)
{
int arguments = sep->argnum;
if (!arguments || !sep->IsNumber(1)) {
c->Message(Chat::White, "Usage: #level [Level]");
return;
}
auto target = c->GetTarget();
if (!target) {
c->Message(Chat::White, "You must have a target to use this command.");
return;
}
auto level = static_cast<uint8>(std::stoul(sep->arg[1]));
auto max_level = static_cast<uint8>(RuleI(Character, MaxLevel));
if (c->Admin() < RuleI(GM, MinStatusToLevelTarget)) {
c->Message(Chat::White, "Your status is not high enough to change another person's level.");
return;
}
if (
level > max_level &&
c->Admin() < commandLevelAboveCap
) {
c->Message(
Chat::White,
fmt::format(
"Level {} is above the Maximum Level of {} and your status is not high enough to go beyond the cap.",
level,
max_level
).c_str()
);
return;
}
target->SetLevel(level, true);
if (target->IsClient()) {
target->CastToClient()->SendLevelAppearance();
#ifdef BOTS
if (RuleB(Bots, BotLevelsWithOwner)) {
Bot::LevelBotWithClient(target->CastToClient(), level, true);
}
#endif
}
}