[Commands] Cleanup #camerashake Command. (#1787)

- Cleanup message and logic.
- Fix ConvertSecondsToTime logic for milliseconds.
- Add ConvertMillisecondsToTime inline function.
This commit is contained in:
Kinglykrab 2021-11-21 10:03:20 -05:00 committed by GitHub
parent 7154d5b841
commit 40edefa6f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 21 deletions

View File

@ -1021,9 +1021,26 @@ std::vector<std::string> GetBadWords()
};
}
std::string ConvertSecondsToTime(int duration)
std::string ConvertSecondsToTime(int duration, bool is_milliseconds)
{
int timer_length = duration;
if (duration <= 0) {
return "Unknown";
}
if (is_milliseconds && duration < 1000) {
return fmt::format(
"{} Millisecond{}",
duration,
duration != 1 ? "s" : ""
);
}
int timer_length = (
is_milliseconds ?
static_cast<int>(std::ceil(static_cast<float>(duration) / 1000.0f)) :
duration
);
int days = int(timer_length / 86400000);
timer_length %= 86400000;
int hours = int(timer_length / 3600);

View File

@ -45,7 +45,10 @@ std::vector<std::string> wrap(std::vector<std::string> &src, std::string charact
std::string implode(std::string glue, std::vector<std::string> src);
std::string convert2digit(int n, std::string suffix);
std::string numberToWords(unsigned long long int n);
std::string ConvertSecondsToTime(int duration);
std::string ConvertSecondsToTime(int duration, bool is_milliseconds = false);
inline std::string ConvertMillisecondsToTime(int duration) {
return ConvertSecondsToTime(duration, true);
}
// For converstion of numerics into English
// Used for grid nodes, as NPC names remove numerals.

View File

@ -51,7 +51,7 @@ ZSList::~ZSList() {
void ZSList::ShowUpTime(WorldTCPConnection* con, const char* adminname) {
uint32 ms = Timer::GetCurrentTime();
std::string time_string = ConvertSecondsToTime(ms);
std::string time_string = ConvertMillisecondsToTime(ms);
con->SendEmoteMessage(
adminname,
0,

View File

@ -133,7 +133,7 @@ int command_init(void)
command_add("bot", "- Type \"#bot help\" or \"^help\" to the see the list of available commands for bots.", AccountStatus::Player, command_bot) ||
#endif
command_add("camerashake", "Shakes the camera on everyone's screen globally.", AccountStatus::QuestTroupe, command_camerashake) ||
command_add("camerashake", "[Duration (Milliseconds)] [Intensity (1-10)] - Shakes the camera on everyone's screen globally.", AccountStatus::QuestTroupe, command_camerashake) ||
command_add("castspell", "[Spell ID] [Instant (0 = False, 1 = True, Default is 1 if Unused)] - Cast a spell", AccountStatus::Guide, command_castspell) ||
command_add("chat", "[channel num] [message] - Send a channel message to all zones", AccountStatus::GMMgmt, command_chat) ||
command_add("checklos", "- Check for line of sight to your target", AccountStatus::Guide, command_checklos) ||

View File

@ -5,20 +5,29 @@ extern WorldServer worldserver;
void command_camerashake(Client *c, const Seperator *sep)
{
if (c) {
if (sep->arg[1][0] && sep->arg[2][0]) {
auto pack = new ServerPacket(ServerOP_CameraShake, sizeof(ServerCameraShake_Struct));
ServerCameraShake_Struct *scss = (ServerCameraShake_Struct *) pack->pBuffer;
scss->duration = atoi(sep->arg[1]);
scss->intensity = atoi(sep->arg[2]);
worldserver.SendPacket(pack);
c->Message(Chat::Red, "Successfully sent the packet to world! Shake it, world, shake it!");
safe_delete(pack);
}
else {
c->Message(Chat::Red, "Usage -- #camerashake [duration], [intensity [1-10])");
}
int arguments = sep->argnum;
if (!arguments || !sep->IsNumber(1) || !sep->IsNumber(2)) {
c->Message(Chat::Red, "Usage: #camerashake [Duration (Milliseconds)] [Intensity (1-10)]");
return;
}
return;
auto duration = std::stoi(sep->arg[1]);
auto intensity = std::stoi(sep->arg[2]);
auto pack = new ServerPacket(ServerOP_CameraShake, sizeof(ServerCameraShake_Struct));
ServerCameraShake_Struct *camera_shake = (ServerCameraShake_Struct *) pack->pBuffer;
camera_shake->duration = duration;
camera_shake->intensity = intensity;
worldserver.SendPacket(pack);
c->Message(
Chat::White,
fmt::format(
"Sending camera shake to world with a duration of {} ({}) and an intensity of {}.",
ConvertMillisecondsToTime(duration),
duration,
intensity
).c_str()
);
safe_delete(pack);
}

View File

@ -41,7 +41,7 @@ void command_stun(Client *c, const Seperator *sep)
target->GetID()
)
),
ConvertSecondsToTime(duration)
ConvertMillisecondsToTime(duration)
) :
fmt::format(
"You unstunned {}.",

View File

@ -826,7 +826,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
}
ServerUptime_Struct* sus = (ServerUptime_Struct*)pack->pBuffer;
uint32 ms = Timer::GetCurrentTime();
std::string time_string = ConvertSecondsToTime(ms);
std::string time_string = ConvertMillisecondsToTime(ms);
SendEmoteMessage(
sus->adminname,
0,