Kinglykrab 39c27c987d
[Commands] Cleanup #peqzone Command. (#1794)
- Cleanup messages and logic.
- Add RULE_INT(Zone, PEQZoneHPRatio, 75, "Required HP Ratio to use #peqzone")
- Modify #peqzone Timer rule to allow it to be disabled.
2021-11-21 14:19:08 -05:00

111 lines
2.2 KiB
C++
Executable File

#include "../client.h"
void command_peqzone(Client *c, const Seperator *sep)
{
int arguments = sep->argnum;
if (!arguments) {
c->Message(Chat::White, "Usage: #peqzone [Zone ID] or #peqzone [Zone Short Name]");
return;
}
auto reuse_timer = RuleI(Zone, PEQZoneReuseTime);
if (reuse_timer) {
uint32 time_left = c->GetPTimers().GetRemainingTime(pTimerPeqzoneReuse);
if (!c->GetPTimers().Expired(&database, pTimerPeqzoneReuse, false)) {
c->Message(
Chat::White,
fmt::format(
"You must wait {} before using this command again.",
ConvertSecondsToTime(time_left)
).c_str()
);
return;
}
}
auto hp_ratio = RuleI(Zone, PEQZoneHPRatio);
if (c->GetHPRatio() < hp_ratio) {
c->Message(
Chat::White,
fmt::format(
"You cannot use this command with less than {}%% health.",
hp_ratio
).c_str()
);
return;
}
if (
c->IsInvisible(c) ||
c->IsRooted() ||
c->IsStunned() ||
c->IsMezzed() ||
c->AutoAttackEnabled() ||
c->GetInvul()
) {
c->Message(Chat::White, "You cannot use this command in your current state. Settle down and wait.");
return;
}
auto zone_id = (
sep->IsNumber(1) ?
static_cast<uint16>(std::stoul(sep->arg[1])) :
static_cast<uint16>(ZoneID(sep->arg[1]))
);
auto zone_short_name = ZoneName(zone_id);
auto zone_long_name = ZoneLongName(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;
}
bool allows_peqzone = (
content_db.GetPEQZone(zone_id, 0) ?
true :
false
);
if (!allows_peqzone) {
c->Message(
Chat::White,
fmt::format(
"You cannot use this command to enter {} ({}).",
zone_long_name,
zone_short_name
).c_str()
);
return;
}
if (zone_id == zone->GetZoneID()) {
c->Message(
Chat::White,
fmt::format(
"You are already in {} ({}).",
zone->GetLongName(),
zone->GetShortName()
).c_str()
);
return;
}
if (RuleB(Zone, UsePEQZoneDebuffs)) {
c->SpellOnTarget(RuleI(Zone, PEQZoneDebuff1), c);
c->SpellOnTarget(RuleI(Zone, PEQZoneDebuff2), c);
}
if (reuse_timer) {
c->GetPTimers().Start(pTimerPeqzoneReuse, reuse_timer);
}
c->MoveZone(zone_short_name);
}