[Commands] Cleanup #zone and #zoneinstance Commands. (#2202)

* [Commands] Cleanup #zone and #zoneinstance Commands.
- Cleanup messages and logic.
- Broke these commands out in to their own files.

* Update database.cpp

* Update database.cpp

* Update database.cpp
This commit is contained in:
Kinglykrab
2022-05-27 15:26:30 -04:00
committed by GitHub
parent 7072b5721b
commit 275995a374
5 changed files with 146 additions and 113 deletions
+56
View File
@@ -0,0 +1,56 @@
#include "../client.h"
void command_zone(Client *c, const Seperator *sep)
{
int arguments = sep->argnum;
if (!arguments) {
c->Message(Chat::White, "Usage: #zone [Zone ID|Zone Short Name] [X] [Y] [Z]");
return;
}
auto zone_id = (
sep->IsNumber(1) ?
std::stoul(sep->arg[1]) :
ZoneID(sep->arg[1])
);
auto zone_short_name = ZoneName(zone_id);
if (
!zone_id ||
!zone_short_name
) {
c->Message(
Chat::White,
fmt::format(
"No zones were found matching '{}'.",
sep->arg[1]
).c_str()
);
return;
}
auto min_status = database.GetMinStatus(zone_id, 0);
if (c->Admin() < min_status) {
c->Message(Chat::White, "Your status is not high enough to go to this zone.");
return;
}
#ifdef BOTS
// This block is necessary to clean up any bot objects owned by a Client
if (zone_id != c->GetZoneID()) {
Bot::ProcessClientZoneChange(c);
}
#endif
auto x = sep->IsNumber(2) ? std::stof(sep->arg[2]) : 0.0f;
auto y = sep->IsNumber(3) ? std::stof(sep->arg[3]) : 0.0f;
auto z = sep->IsNumber(4) ? std::stof(sep->arg[4]) : 0.0f;
c->MovePC(
zone_id,
x,
y,
z,
0.0f,
sep->IsNumber(2) ? 0 : ZoneToSafeCoords
);
}
+70
View File
@@ -0,0 +1,70 @@
#include "../client.h"
void command_zone_instance(Client *c, const Seperator *sep)
{
int arguments = sep->argnum;
if (!arguments || !sep->IsNumber(1)) {
c->Message(Chat::White, "Usage: #zoneinstance [Instance ID] [X] [Y] [Z]");
return;
}
auto instance_id = std::stoul(sep->arg[1]);
if (!instance_id) {
c->Message(Chat::White, "You must enter a valid instance id.");
return;
}
if (!database.CheckInstanceExists(instance_id)) {
c->Message(
Chat::White,
fmt::format(
"Instance ID {} does not exist.",
instance_id
).c_str()
);
return;
}
auto zone_id = database.ZoneIDFromInstanceID(instance_id);
if (!zone_id) {
c->Message(
Chat::White,
fmt::format(
"Instance ID {} not found or zone is set to null.",
instance_id
).c_str()
);
return;
}
if (database.CharacterInInstanceGroup(instance_id, c->CharacterID())) {
c->Message(Chat::White, "You are already a part of this instance, sending you there.");
c->MoveZoneInstance(instance_id);
return;
}
if (!database.VerifyInstanceAlive(instance_id, c->CharacterID())) {
c->Message(
Chat::White,
fmt::format(
"Instance ID {} expired or you are not apart of this instance.",
instance_id
).c_str()
);
return;
}
auto x = sep->IsNumber(2) ? std::stof(sep->arg[2]) : 0.0f;
auto y = sep->IsNumber(3) ? std::stof(sep->arg[3]) : 0.0f;
auto z = sep->IsNumber(4) ? std::stof(sep->arg[4]) : 0.0f;
c->MovePC(
zone_id,
instance_id,
x,
y,
z,
0.0f,
sep->IsNumber(2) ? 0 : ZoneToSafeCoords
);
}