mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 10:31:29 +00:00
[Commands] Cleanup #roambox Command. (#2135)
- Cleanup messages and logic.
This commit is contained in:
parent
bf7c1252f8
commit
55629ce396
@ -307,7 +307,7 @@ int command_init(void)
|
||||
command_add("resetaa_timer", "Command to reset AA cooldown timers.", AccountStatus::GMMgmt, command_resetaa_timer) ||
|
||||
command_add("resetdisc_timer", "Command to reset all discipline cooldown timers.", AccountStatus::GMMgmt, command_resetdisc_timer) ||
|
||||
command_add("revoke", "[charname] [1/0] - Makes charname unable to talk on OOC", AccountStatus::GMMgmt, command_revoke) ||
|
||||
command_add("roambox", "Manages roambox settings for an NPC", AccountStatus::GMMgmt, command_roambox) ||
|
||||
command_add("roambox", "[Remove|Set] [Box Size] [Delay (Milliseconds)] - Remove or set an NPC's roambox size and delay", AccountStatus::GMMgmt, command_roambox) ||
|
||||
command_add("rules", "(subcommand) - Manage server rules", AccountStatus::GMImpossible, command_rules) ||
|
||||
command_add("save", "- Force your player or player corpse target to be saved to the database", AccountStatus::Guide, command_save) ||
|
||||
command_add("scale", "- Handles npc scaling", AccountStatus::GMLeadAdmin, command_scale) ||
|
||||
|
||||
@ -3,91 +3,103 @@
|
||||
|
||||
void command_roambox(Client *c, const Seperator *sep)
|
||||
{
|
||||
std::string arg1 = sep->arg[1];
|
||||
|
||||
Mob *target = c->GetTarget();
|
||||
if (!target || !target->IsNPC()) {
|
||||
c->Message(Chat::Red, "You need a valid NPC target for this command");
|
||||
if (!c->GetTarget() || !c->GetTarget()->IsNPC()) {
|
||||
c->Message(Chat::White, "You need a valid NPC target for this command");
|
||||
return;
|
||||
}
|
||||
|
||||
NPC *npc = dynamic_cast<NPC *>(target);
|
||||
int spawn_group_id = npc->GetSpawnGroupId();
|
||||
int arguments = sep->argnum;
|
||||
if (!arguments) {
|
||||
c->Message(Chat::White, "#roambox remove - Remove a roambox from an NPC");
|
||||
c->Message(Chat::White, "#roambox set [Box Size] [Delay] - Set a roambox for an NPC");
|
||||
return;
|
||||
}
|
||||
|
||||
auto target = c->GetTarget()->CastToNPC();
|
||||
int spawn_group_id = target->GetSpawnGroupId();
|
||||
if (spawn_group_id <= 0) {
|
||||
c->Message(Chat::Red, "NPC needs a valid SpawnGroup!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg1 == "set") {
|
||||
int box_size = (sep->arg[2] ? atoi(sep->arg[2]) : 0);
|
||||
int delay = (sep->arg[3] ? atoi(sep->arg[3]) : 15000);
|
||||
if (box_size > 0) {
|
||||
std::string query = fmt::format(
|
||||
SQL(
|
||||
UPDATE spawngroup SET
|
||||
dist = {},
|
||||
min_x = {},
|
||||
max_x = {},
|
||||
min_y = {},
|
||||
max_y = {},
|
||||
delay = {}
|
||||
WHERE id = {}
|
||||
),
|
||||
(box_size / 2),
|
||||
npc->GetX() - (box_size / 2),
|
||||
npc->GetX() + (box_size / 2),
|
||||
npc->GetY() - (box_size / 2),
|
||||
npc->GetY() + (box_size / 2),
|
||||
delay,
|
||||
spawn_group_id
|
||||
);
|
||||
|
||||
database.QueryDatabase(query);
|
||||
|
||||
c->Message(
|
||||
Chat::Yellow,
|
||||
"NPC (%s) Roam Box set to box size of [%i] SpawnGroupId [%i] delay [%i]",
|
||||
npc->GetCleanName(),
|
||||
box_size,
|
||||
spawn_group_id,
|
||||
delay
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
c->Message(Chat::Red, "Box size must be set!");
|
||||
bool is_remove = !strcasecmp(sep->arg[1], "remove");
|
||||
bool is_set = !strcasecmp(sep->arg[1], "set");
|
||||
if (!is_remove && !is_set) {
|
||||
c->Message(Chat::White, "#roambox remove - Remove a roambox from an NPC");
|
||||
c->Message(Chat::White, "#roambox set [Box Size] [Delay] - Set a roambox for an NPC");
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg1 == "remove") {
|
||||
std::string query = fmt::format(
|
||||
SQL(
|
||||
UPDATE spawngroup SET
|
||||
dist = 0,
|
||||
min_x = 0,
|
||||
max_x = 0,
|
||||
min_y = 0,
|
||||
max_y = 0,
|
||||
delay = 0
|
||||
WHERE id = {}
|
||||
),
|
||||
if (is_remove) {
|
||||
auto query = fmt::format(
|
||||
"UPDATE spawngroup SET dist = 0, min_x = 0, max_x = 0, min_y = 0, max_y = 0, delay = 0 WHERE id = {}",
|
||||
spawn_group_id
|
||||
);
|
||||
|
||||
database.QueryDatabase(query);
|
||||
|
||||
c->Message(
|
||||
Chat::Yellow,
|
||||
"NPC (%s) Roam Box has been removed from SpawnGroupID [%i]",
|
||||
npc->GetCleanName(),
|
||||
spawn_group_id
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Roambox has been removed from {} ({}) on spawn group ID {}.",
|
||||
target->GetCleanName(),
|
||||
target->GetID(),
|
||||
spawn_group_id
|
||||
).c_str()
|
||||
);
|
||||
} else if (is_set) {
|
||||
float box_size = 0.0f;
|
||||
int delay = 15000;
|
||||
|
||||
return;
|
||||
if (arguments >= 2) {
|
||||
box_size = std::stof(sep->arg[2]);
|
||||
|
||||
if (arguments == 3) {
|
||||
delay = std::stoi(sep->arg[3]);
|
||||
}
|
||||
}
|
||||
|
||||
if (box_size) {
|
||||
auto query = fmt::format(
|
||||
"UPDATE spawngroup SET dist = {:2f}, min_x = {:2f}, max_x = {:.2f}, min_y = {:2f}, max_y = {:2f}, delay = {} WHERE id = {}",
|
||||
(box_size / 2.0f),
|
||||
(target->GetX() - (box_size / 2.0f)),
|
||||
(target->GetX() + (box_size / 2.0f)),
|
||||
(target->GetY() - (box_size / 2.0f)),
|
||||
(target->GetY() + (box_size / 2.0f)),
|
||||
delay,
|
||||
spawn_group_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
|
||||
if (!results.RowsAffected()) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Failed to set roambox for {} ({}).",
|
||||
target->GetCleanName(),
|
||||
target->GetID()
|
||||
).c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Roambox set to box size of {} for {} ({}) on spawn group ID {} with a delay of {} ({}).",
|
||||
box_size,
|
||||
target->GetCleanName(),
|
||||
target->GetID(),
|
||||
spawn_group_id,
|
||||
ConvertMillisecondsToTime(delay),
|
||||
delay
|
||||
).c_str()
|
||||
);
|
||||
} else {
|
||||
c->Message(Chat::White, "Box size must be greater than 0.");
|
||||
}
|
||||
}
|
||||
|
||||
c->Message(Chat::Yellow, "> Command Usage");
|
||||
c->Message(Chat::Yellow, "#roambox set box_size [delay = 0]");
|
||||
c->Message(Chat::Yellow, "#roambox remove");
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user