mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 01:11:29 +00:00
[Commands] Cleanup #stun Command. (#1749)
* [Commands] Cleanup #stun Command. - Cleanup message. - Add ConvertSecondsToTime() to string_util.h and convert Quest API Methods to use helper. * Add days to ConvertSecondsToTime() and cleanup logic. * Cleanup. * Typo. * Cleanup. * Cleanup.
This commit is contained in:
parent
90bcc5f03c
commit
ddcb184183
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "string_util.h"
|
||||
#include <fmt/format.h>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
@ -1019,3 +1020,146 @@ std::vector<std::string> GetBadWords()
|
||||
"zoophilia"
|
||||
};
|
||||
}
|
||||
|
||||
std::string ConvertSecondsToTime(int duration)
|
||||
{
|
||||
int timer_length = duration;
|
||||
int days = int(timer_length / 86400000);
|
||||
timer_length %= 86400000;
|
||||
int hours = int(timer_length / 3600);
|
||||
timer_length %= 3600;
|
||||
int minutes = int(timer_length / 60);
|
||||
timer_length %= 60;
|
||||
int seconds = timer_length;
|
||||
std::string time_string = "Unknown";
|
||||
std::string day_string = (days == 1 ? "Day" : "Days");
|
||||
std::string hour_string = (hours == 1 ? "Hour" : "Hours");
|
||||
std::string minute_string = (minutes == 1 ? "Minute" : "Minutes");
|
||||
std::string second_string = (seconds == 1 ? "Second" : "Seconds");
|
||||
if (days && hours && minutes && seconds) { // DHMS
|
||||
time_string = fmt::format(
|
||||
"{} {}, {} {}, {} {}, and {} {}",
|
||||
days,
|
||||
day_string,
|
||||
hours,
|
||||
hour_string,
|
||||
minutes,
|
||||
minute_string,
|
||||
seconds,
|
||||
second_string
|
||||
);
|
||||
} else if (days && hours && minutes && !seconds) { // DHM
|
||||
time_string = fmt::format(
|
||||
"{} {}, {} {}, and {} {}",
|
||||
days,
|
||||
day_string,
|
||||
hours,
|
||||
hour_string,
|
||||
minutes,
|
||||
minute_string
|
||||
);
|
||||
} else if (days && hours && !minutes && seconds) { // DHS
|
||||
time_string = fmt::format(
|
||||
"{} {}, {} {}, and {} {}",
|
||||
days,
|
||||
day_string,
|
||||
hours,
|
||||
hour_string,
|
||||
seconds,
|
||||
second_string
|
||||
);
|
||||
} else if (days && hours && !minutes && !seconds) { // DH
|
||||
time_string = fmt::format(
|
||||
"{} {} and {} {}",
|
||||
days,
|
||||
day_string,
|
||||
hours,
|
||||
hour_string
|
||||
);
|
||||
} else if (days && !hours && minutes && seconds) { // DMS
|
||||
time_string = fmt::format(
|
||||
"{} {}, {} {}, and {} {}",
|
||||
days,
|
||||
day_string,
|
||||
minutes,
|
||||
minute_string,
|
||||
seconds,
|
||||
second_string
|
||||
);
|
||||
} else if (days && !hours && minutes && !seconds) { // DM
|
||||
time_string = fmt::format(
|
||||
"{} {} and {} {}",
|
||||
days,
|
||||
day_string,
|
||||
minutes,
|
||||
minute_string
|
||||
);
|
||||
} else if (days && !hours && !minutes && seconds) { // DS
|
||||
time_string = fmt::format(
|
||||
"{} {} and {} {}",
|
||||
days,
|
||||
day_string,
|
||||
seconds,
|
||||
second_string
|
||||
);
|
||||
} else if (days && !hours && !minutes && !seconds) { // D
|
||||
time_string = fmt::format(
|
||||
"{} {}",
|
||||
days,
|
||||
day_string
|
||||
);
|
||||
} else if (!days && hours && minutes && seconds) { // HMS
|
||||
time_string = fmt::format(
|
||||
"{} {}, {} {}, and {} {}",
|
||||
hours,
|
||||
hour_string,
|
||||
minutes,
|
||||
minute_string,
|
||||
seconds,
|
||||
second_string
|
||||
);
|
||||
} else if (!days && hours && minutes && !seconds) { // HM
|
||||
time_string = fmt::format(
|
||||
"{} {} and {} {}",
|
||||
hours,
|
||||
hour_string,
|
||||
minutes,
|
||||
minute_string
|
||||
);
|
||||
} else if (!days && hours && !minutes && seconds) { // HS
|
||||
time_string = fmt::format(
|
||||
"{} {} and {} {}",
|
||||
hours,
|
||||
hour_string,
|
||||
seconds,
|
||||
second_string
|
||||
);
|
||||
} else if (!days && hours && !minutes && !seconds) { // H
|
||||
time_string = fmt::format(
|
||||
"{} {}",
|
||||
hours,
|
||||
hour_string
|
||||
);
|
||||
} else if (!days && !hours && minutes && seconds) { // MS
|
||||
time_string = fmt::format(
|
||||
"{} {} and {} {}",
|
||||
minutes,
|
||||
minute_string,
|
||||
seconds,
|
||||
second_string
|
||||
);
|
||||
} else if (!days && !hours && minutes && !seconds) { // M
|
||||
time_string = fmt::format(
|
||||
"{} {}",
|
||||
minutes,
|
||||
minute_string
|
||||
);
|
||||
} else if (!days && !hours && !minutes && seconds) { // S
|
||||
time_string = fmt::format(
|
||||
"{} {}",
|
||||
seconds,
|
||||
second_string
|
||||
);
|
||||
}
|
||||
return time_string;
|
||||
}
|
||||
|
||||
@ -45,6 +45,7 @@ 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);
|
||||
|
||||
// For converstion of numerics into English
|
||||
// Used for grid nodes, as NPC names remove numerals.
|
||||
|
||||
@ -9291,21 +9291,62 @@ void command_setcrystals(Client *c, const Seperator *sep)
|
||||
|
||||
void command_stun(Client *c, const Seperator *sep)
|
||||
{
|
||||
Mob *t=c->CastToMob();
|
||||
uint32 duration;
|
||||
|
||||
if(sep->arg[1][0])
|
||||
{
|
||||
duration = atoi(sep->arg[1]);
|
||||
if(c->GetTarget())
|
||||
t=c->GetTarget();
|
||||
if(t->IsClient())
|
||||
t->CastToClient()->Stun(duration);
|
||||
else
|
||||
t->CastToNPC()->Stun(duration);
|
||||
int arguments = sep->argnum;
|
||||
if (!arguments || !sep->IsNumber(1)) {
|
||||
c->Message(Chat::White, "Usage: #stun [Duration]");
|
||||
return;
|
||||
}
|
||||
else
|
||||
c->Message(Chat::White, "Usage: #stun [duration]");
|
||||
|
||||
Mob* target = c;
|
||||
int duration = static_cast<int>(std::min(std::stoll(sep->arg[1]), (long long) 2000000000));
|
||||
|
||||
if (duration < 0) {
|
||||
duration = 0;
|
||||
}
|
||||
|
||||
if (c->GetTarget()) {
|
||||
target = c->GetTarget();
|
||||
if (target->IsClient()) {
|
||||
target->CastToClient()->Stun(duration);
|
||||
} else if (target->IsNPC()) {
|
||||
target->CastToNPC()->Stun(duration);
|
||||
}
|
||||
} else {
|
||||
c->Stun(duration);
|
||||
}
|
||||
|
||||
std::string stun_message = (
|
||||
duration ?
|
||||
fmt::format(
|
||||
"You stunned {} for {}.",
|
||||
(
|
||||
c == target ?
|
||||
"yourself" :
|
||||
fmt::format(
|
||||
"{} ({})",
|
||||
target->GetCleanName(),
|
||||
target->GetID()
|
||||
)
|
||||
),
|
||||
ConvertSecondsToTime(duration)
|
||||
) :
|
||||
fmt::format(
|
||||
"You unstunned {}.",
|
||||
(
|
||||
c == target ?
|
||||
"yourself" :
|
||||
fmt::format(
|
||||
"{} ({})",
|
||||
target->GetCleanName(),
|
||||
target->GetID()
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
c->Message(
|
||||
Chat::White,
|
||||
stun_message.c_str()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3353,32 +3353,7 @@ EQ::ItemInstance *QuestManager::CreateItem(uint32 item_id, int16 charges, uint32
|
||||
}
|
||||
|
||||
std::string QuestManager::secondstotime(int duration) {
|
||||
int timer_length = duration;
|
||||
int hours = int(timer_length / 3600);
|
||||
timer_length %= 3600;
|
||||
int minutes = int(timer_length / 60);
|
||||
timer_length %= 60;
|
||||
int seconds = timer_length;
|
||||
std::string time_string = "Unknown";
|
||||
std::string hour_string = (hours == 1 ? "Hour" : "Hours");
|
||||
std::string minute_string = (minutes == 1 ? "Minute" : "Minutes");
|
||||
std::string second_string = (seconds == 1 ? "Second" : "Seconds");
|
||||
if (hours > 0 && minutes > 0 && seconds > 0) {
|
||||
time_string = fmt::format("{} {}, {} {}, and {} {}", hours, hour_string, minutes, minute_string, seconds, second_string);
|
||||
} else if (hours > 0 && minutes > 0 && seconds == 0) {
|
||||
time_string = fmt::format("{} {} and {} {}", hours, hour_string, minutes, minute_string);
|
||||
} else if (hours > 0 && minutes == 0 && seconds > 0) {
|
||||
time_string = fmt::format("{} {} and {} {}", hours, hour_string, seconds, second_string);
|
||||
} else if (hours > 0 && minutes == 0 && seconds == 0) {
|
||||
time_string = fmt::format("{} {}", hours, hour_string);
|
||||
} else if (hours == 0 && minutes > 0 && seconds > 0) {
|
||||
time_string = fmt::format("{} {} and {} {}", minutes, minute_string, seconds, second_string);
|
||||
} else if (hours == 0 && minutes > 0 && seconds == 0) {
|
||||
time_string = fmt::format("{} {}", minutes, minute_string);
|
||||
} else if (hours == 0 && minutes == 0 && seconds > 0) {
|
||||
time_string = fmt::format("{} {}", seconds, second_string);
|
||||
}
|
||||
return time_string;
|
||||
return ConvertSecondsToTime(duration);
|
||||
}
|
||||
|
||||
std::string QuestManager::gethexcolorcode(std::string color_name) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user