Alex King 2a6cf8c8e7
[Strings] Add more number formatters (#2873)
* [Strings] Add more number formatters

# Notes
- Adds `Strings::ToUnsignedInt` for `uint32` support.
- Adds `Strings::ToBigInt` for `int64` support.
- Adds `Strings::ToUnsignedBigInt` for `uint64` support.
- Adds `Strings::ToFloat` for `float` support.
- Replaces all `std::stoi` references with `Strings::ToInt`.
- Replaces all `atoi` references with `Strings::ToInt`.
- Replaces all `std::stoul` references with `Strings::ToUnsignedInt`.
- Replaces all `atoul` references with `Strings::ToUnsignedInt`.
- Replaces all `std::stoll` references with `Strings::ToBigInt`.
- Replaces all `atoll` references with `Strings::ToBigInt`.
- Replaces all `std::stoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `atoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `std::stof` references with `Strings::ToFloat`.

* [Strings] Add more number formatters

- Adds `Strings::ToUnsignedInt` for `uint32` support.
- Adds `Strings::ToBigInt` for `int64` support.
- Adds `Strings::ToUnsignedBigInt` for `uint64` support.
- Adds `Strings::ToFloat` for `float` support.
- Replaces all `std::stoi` references with `Strings::ToInt`.
- Replaces all `atoi` references with `Strings::ToInt`.
- Replaces all `std::stoul` references with `Strings::ToUnsignedInt`.
- Replaces all `atoul` references with `Strings::ToUnsignedInt`.
- Replaces all `std::stoll` references with `Strings::ToBigInt`.
- Replaces all `atoll` references with `Strings::ToBigInt`.
- Replaces all `std::stoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `atoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `std::stof` references with `Strings::ToFloat`.

* Rebase cleanup

* Changes/benchmarks/tests

---------

Co-authored-by: Akkadius <akkadius1@gmail.com>
2023-03-04 17:01:19 -06:00

106 lines
2.0 KiB
C++
Executable File

#include "../client.h"
void command_npcspawn(Client *c, const Seperator *sep)
{
if (!c->GetTarget() || !c->GetTarget()->IsNPC()) {
c->Message(Chat::White, "You must target an NPC to use this command.");
return;
}
int arguments = sep->argnum;
if (!arguments) {
c->Message(Chat::White, "Command Syntax: #npcspawn [Add|Create|Delete|Remove|Update]");
return;
}
auto target = c->GetTarget()->CastToNPC();
uint32 extra = 0;
bool is_add = !strcasecmp(sep->arg[1], "add");
bool is_create = !strcasecmp(sep->arg[1], "create");
bool is_delete = !strcasecmp(sep->arg[1], "delete");
bool is_remove = !strcasecmp(sep->arg[1], "remove");
bool is_update = !strcasecmp(sep->arg[1], "update");
if (
!is_add &&
!is_create &&
!is_delete &&
!is_remove &&
!is_update
) {
c->Message(Chat::White, "Command Syntax: #npcspawn [Add|Create|Delete|Remove|Update]");
return;
}
if (is_add || is_create) {
extra = (
sep->IsNumber(2) ?
(
is_add ?
Strings::ToInt(sep->arg[2]) :
1
) : (
is_add ?
1200 :
0
)
); // Default to 1200 for Add, 0 for Create if not set
content_db.NPCSpawnDB(
is_add ? NPCSpawnTypes::AddNewSpawngroup : NPCSpawnTypes::CreateNewSpawn,
zone->GetShortName(),
zone->GetInstanceVersion(),
c,
target,
extra
);
c->Message(
Chat::White,
fmt::format(
"Spawn {} | Name: {}",
is_add ? "Added" : "Created",
c->GetTargetDescription(target)
).c_str()
);
}
else if (is_delete || is_remove || is_update) {
uint8 spawn_update_type = (
is_delete ?
NPCSpawnTypes::DeleteSpawn :
(
is_remove ?
NPCSpawnTypes::RemoveSpawn :
NPCSpawnTypes::UpdateAppearance
)
);
std::string spawn_message = (
is_delete ?
"Deleted" :
(
is_remove ?
"Removed" :
"Updated"
)
);
content_db.NPCSpawnDB(
spawn_update_type,
zone->GetShortName(),
zone->GetInstanceVersion(),
c,
target
);
c->Message(
Chat::White,
fmt::format(
"Spawn {} | Name: {}",
spawn_message,
c->GetTargetDescription(target)
).c_str()
);
}
}