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

105 lines
2.1 KiB
C++
Executable File

#include "../client.h"
void command_dbspawn2(Client *c, const Seperator *sep)
{
auto arguments = sep->argnum;
if (
!arguments ||
!sep->IsNumber(1) ||
!sep->IsNumber(2) ||
!sep->IsNumber(3)
) {
c->Message(Chat::White, "Usage: #dbspawn2 [Spawngroup ID] [Respawn] [Variance] [Condition ID] [Condition Minimum]");
c->Message(Chat::White, "Note: Respawn and Variance are in Seconds.");
return;
}
auto position = c->GetPosition();
auto spawngroup_id = Strings::ToUnsignedInt(sep->arg[1]);
auto respawn = Strings::ToUnsignedInt(sep->arg[2]);
auto variance = Strings::ToUnsignedInt(sep->arg[3]);
auto condition_id = sep->IsNumber(4) ? static_cast<uint16>(Strings::ToUnsignedInt(sep->arg[4])) : static_cast<uint16>(0);
auto condition_minimum = sep->IsNumber(5) ? static_cast<int16>(Strings::ToUnsignedInt(sep->arg[5])) : static_cast<int16>(0);
if (!database.CreateSpawn2(
c,
spawngroup_id,
zone->GetShortName(),
position,
respawn,
variance,
condition_id,
condition_minimum
)) {
c->Message(
Chat::White,
fmt::format(
"Failed to add Spawngroup ID {} to {} at {:.2f}, {:.2f}, {:.2f}, {:.2f}.",
spawngroup_id,
zone->GetZoneDescription(),
position.x,
position.y,
position.z,
position.w
).c_str()
);
return;
}
c->Message(
Chat::White,
fmt::format(
"Spawngroup Added | ID: {}",
spawngroup_id
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"Spawngroup Added | Zone: {}",
zone->GetZoneDescription()
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"Spawngroup Added | Position: {:.2f}, {:.2f}, {:.2f}, {:.2f}",
position.x,
position.y,
position.z,
position.w
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"Spawngroup Added | Respawn: {} ({})",
Strings::SecondsToTime(respawn),
respawn
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"Spawngroup Added | Variance: {} ({})",
Strings::SecondsToTime(variance),
variance
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"Spawngroup Added | Condition ID: {} Condition Minimum: {}",
condition_id,
condition_minimum
).c_str()
);
}