From e87b8e268226685eaef61cc4154b94afe966f8e5 Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Fri, 26 Nov 2021 10:01:35 -0500 Subject: [PATCH] [Commands] Cleanup #gender Command. (#1832) - Cleanup message and logic. - Cleanup other spots using similar logic so they're all uniform. --- zone/command.cpp | 65 ++++++++++--------- zone/gm_commands/castspell.cpp | 41 +++++------- zone/gm_commands/gender.cpp | 47 +++++++++++--- .../getplayerburiedcorpsecount.cpp | 7 +- zone/gm_commands/ginfo.cpp | 23 +++++-- zone/gm_commands/givemoney.cpp | 10 ++- zone/gm_commands/loc.cpp | 14 ++-- zone/gm_commands/nukeitem.cpp | 20 +++++- zone/gm_commands/permagender.cpp | 15 ++++- zone/gm_commands/permarace.cpp | 10 ++- zone/gm_commands/scribespells.cpp | 26 ++++---- zone/gm_commands/setaapts.cpp | 18 +++-- zone/gm_commands/setaaxp.cpp | 20 ++++-- zone/gm_commands/setcrystals.cpp | 25 ++++--- zone/gm_commands/setpvppoints.cpp | 10 ++- zone/gm_commands/stun.cpp | 30 ++++----- zone/gm_commands/traindisc.cpp | 17 +++-- 17 files changed, 258 insertions(+), 140 deletions(-) diff --git a/zone/command.cpp b/zone/command.cpp index 619406a69..6855cd72a 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -1099,39 +1099,40 @@ void command_emptyinventory(Client *c, const Seperator *sep) } } - if (c != target) { - auto target_name = target->GetCleanName(); - if (removed_count) { - c->Message( - Chat::White, - fmt::format( - "Inventory cleared for {}, {} items deleted.", - target_name, - removed_count - ).c_str() - ); - } else { - c->Message( - Chat::White, - fmt::format( - "{} has no items to delete.", - target_name - ).c_str() - ); - } + if (removed_count) { + c->Message( + Chat::White, + fmt::format( + "Inventory cleared for {}, {} items deleted.", + ( + c == target ? + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ), + removed_count + ).c_str() + ); } else { - if (removed_count) { - c->Message( - Chat::White, - fmt::format( - "Your inventory has been cleared, {} items deleted.", - removed_count - ).c_str() - ); - } else { - c->Message(Chat::White, "You have no items to delete."); - } - } + c->Message( + Chat::White, + fmt::format( + "{} no items to delete.", + ( + c == target ? + "You have" : + fmt::format( + "{} ({}) has", + target->GetCleanName(), + target->GetID() + ) + ) + ).c_str() + ); + } } // All new code added to command.cpp should be BEFORE this comment line. Do no append code to this file below the BOTS code block. diff --git a/zone/gm_commands/castspell.cpp b/zone/gm_commands/castspell.cpp index b4410084d..68e2e1801 100755 --- a/zone/gm_commands/castspell.cpp +++ b/zone/gm_commands/castspell.cpp @@ -48,29 +48,24 @@ void command_castspell(Client *c, const Seperator *sep) c->CastSpell(spell_id, target->GetID(), EQ::spells::CastingSlot::Item, spells[spell_id].cast_time); } - if (c != target) { - c->Message( - Chat::White, - fmt::format( - "Cast {} ({}) on {}{}.", - GetSpellName(spell_id), - spell_id, - target->GetCleanName(), - instant_cast ? " instantly" : "" - ).c_str() - ); - } - else { - c->Message( - Chat::White, - fmt::format( - "Cast {} ({}) on yourself{}.", - GetSpellName(spell_id), - spell_id, - instant_cast ? " instantly" : "" - ).c_str() - ); - } + c->Message( + Chat::White, + fmt::format( + "Cast {} ({}) on {}{}.", + GetSpellName(spell_id), + spell_id, + ( + c == target ? + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ), + instant_cast ? " instantly" : "" + ).c_str() + ); } } } diff --git a/zone/gm_commands/gender.cpp b/zone/gm_commands/gender.cpp index 0051ddd43..000d65f23 100755 --- a/zone/gm_commands/gender.cpp +++ b/zone/gm_commands/gender.cpp @@ -2,16 +2,45 @@ void command_gender(Client *c, const Seperator *sep) { - Mob *t = c->CastToMob(); + int arguments = sep->argnum; + if (!arguments || !sep->IsNumber(1)) { + c->Message(Chat::White, "Usage: #gender [Gender ID]"); + c->Message(Chat::White, "Genders: 0 = Male, 1 = Female, 2 = Neuter"); + return; + } - if (sep->IsNumber(1) && atoi(sep->arg[1]) >= 0 && atoi(sep->arg[1]) <= 500) { - if ((c->GetTarget()) && c->Admin() >= commandGenderOthers) { - t = c->GetTarget(); - } - t->SendIllusionPacket(t->GetRace(), atoi(sep->arg[1])); + Mob *target = c; + if (c->GetTarget() && c->Admin() >= commandGenderOthers) { + target = c->GetTarget(); } - else { - c->Message(Chat::White, "Usage: #gender [0/1/2]"); + + auto gender_id = std::stoi(sep->arg[1]); + if (gender_id < 0 || gender_id > 2) { + c->Message(Chat::White, "Usage: #gender [Gender ID]"); + c->Message(Chat::White, "Genders: 0 = Male, 1 = Female, 2 = Neuter"); + return; } + + target->SendIllusionPacket( + target->GetRace(), + gender_id + ); + + c->Message( + Chat::White, + fmt::format( + "Gender changed for {} to {} ({}).", + ( + c == target ? + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ), + GetGenderName(gender_id), + gender_id + ).c_str() + ); } - diff --git a/zone/gm_commands/getplayerburiedcorpsecount.cpp b/zone/gm_commands/getplayerburiedcorpsecount.cpp index 1a9c1332a..20e82bac4 100755 --- a/zone/gm_commands/getplayerburiedcorpsecount.cpp +++ b/zone/gm_commands/getplayerburiedcorpsecount.cpp @@ -12,17 +12,16 @@ void command_getplayerburiedcorpsecount(Client *c, const Seperator *sep) c->Message( Chat::White, fmt::format( - "{} {} {} buried corpse{}.", + "{} {} buried corpse{}.", ( c == target ? - "You" : + "You have" : fmt::format( - "{} ({})", + "{} ({}) has", target->GetCleanName(), target->GetID() ) ), - c == target ? "have" : "has", ( corpse_count ? std::to_string(corpse_count) : diff --git a/zone/gm_commands/ginfo.cpp b/zone/gm_commands/ginfo.cpp index 53af4fbf6..a64b11fff 100755 --- a/zone/gm_commands/ginfo.cpp +++ b/zone/gm_commands/ginfo.cpp @@ -13,9 +13,16 @@ void command_ginfo(Client *c, const Seperator *sep) c->Message( Chat::White, fmt::format( - "{} {} not in a group.", - c == target ? "You" : target->GetCleanName(), - c == target ? "are" : "is" + "{} not in a group.", + ( + c == target ? + "You are" : + fmt::format( + "{} ({}) is", + target->GetCleanName(), + target->GetID() + ) + ) ).c_str() ); return; @@ -25,7 +32,15 @@ void command_ginfo(Client *c, const Seperator *sep) Chat::White, fmt::format( "Group Info for {} | ID: {} Members: {}", - c == target ? "Yourself" : target->GetCleanName(), + ( + c == target ? + "Yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ), target_group->GetID(), target_group->GroupCount() ).c_str() diff --git a/zone/gm_commands/givemoney.cpp b/zone/gm_commands/givemoney.cpp index 3e3727292..705ab7461 100755 --- a/zone/gm_commands/givemoney.cpp +++ b/zone/gm_commands/givemoney.cpp @@ -36,7 +36,15 @@ void command_givemoney(Client *c, const Seperator *sep) fmt::format( "Added {} to {}.", ConvertMoneyToString(platinum, gold, silver, copper), - c == target ? "yourself" : target->GetCleanName() + ( + c == target ? + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ) ).c_str() ); } diff --git a/zone/gm_commands/loc.cpp b/zone/gm_commands/loc.cpp index 79d734711..c45513dc9 100755 --- a/zone/gm_commands/loc.cpp +++ b/zone/gm_commands/loc.cpp @@ -12,15 +12,15 @@ void command_loc(Client *c, const Seperator *sep) c->Message( Chat::White, fmt::format( - "{} Location | XYZ: {:.2f}, {:.2f}, {:.2f} Heading: {:.2f}", + "Location for {} | XYZ: {:.2f}, {:.2f}, {:.2f} Heading: {:.2f}", ( c == target ? - "Your" : - fmt::format( - "{} ({})", - target->GetCleanName(), - target->GetID() - ) + "Yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) ), target_position.x, target_position.y, diff --git a/zone/gm_commands/nukeitem.cpp b/zone/gm_commands/nukeitem.cpp index 60fccd00f..1856b9b1f 100755 --- a/zone/gm_commands/nukeitem.cpp +++ b/zone/gm_commands/nukeitem.cpp @@ -23,7 +23,15 @@ void command_nukeitem(Client *c, const Seperator *sep) deleted_count, database.CreateItemLink(item_id), item_id, - c == target ? "yourself" : target->GetCleanName() + ( + c == target ? + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ) ).c_str() ); } else { @@ -33,7 +41,15 @@ void command_nukeitem(Client *c, const Seperator *sep) "Could not find any {} ({}) to delete from {}.", database.CreateItemLink(item_id), item_id, - c == target ? "yourself" : target->GetCleanName() + ( + c == target ? + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ) ).c_str() ); } diff --git a/zone/gm_commands/permagender.cpp b/zone/gm_commands/permagender.cpp index 8520d3374..bdfd33013 100755 --- a/zone/gm_commands/permagender.cpp +++ b/zone/gm_commands/permagender.cpp @@ -15,6 +15,11 @@ void command_permagender(Client *c, const Seperator *sep) } auto gender_id = std::stoi(sep->arg[1]); + if (gender_id < 0 || gender_id > 2) { + c->Message(Chat::White, "Usage: #permagender [Gender ID]"); + c->Message(Chat::White, "Genders: 0 = Male, 1 = Female, 2 = Neuter"); + return; + } LogInfo("Gender changed by {} for {} to {} ({})", c->GetCleanName(), @@ -31,7 +36,15 @@ void command_permagender(Client *c, const Seperator *sep) Chat::White, fmt::format( "Gender changed for {} to {} ({}).", - c == target ? "yourself" : target->GetCleanName(), + ( + c == target ? + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ), GetGenderName(gender_id), gender_id ).c_str() diff --git a/zone/gm_commands/permarace.cpp b/zone/gm_commands/permarace.cpp index d6065a797..bee8e6dc2 100755 --- a/zone/gm_commands/permarace.cpp +++ b/zone/gm_commands/permarace.cpp @@ -36,7 +36,15 @@ void command_permarace(Client *c, const Seperator *sep) Chat::White, fmt::format( "Race changed for {} to {} ({}).", - c == target ? "yourself" : target->GetCleanName(), + ( + c == target ? + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ), GetRaceIDName(race_id), race_id ).c_str() diff --git a/zone/gm_commands/scribespells.cpp b/zone/gm_commands/scribespells.cpp index ef30d6384..2d084d9df 100755 --- a/zone/gm_commands/scribespells.cpp +++ b/zone/gm_commands/scribespells.cpp @@ -13,12 +13,11 @@ void command_scribespells(Client *c, const Seperator *sep) } uint8 rule_max_level = (uint8) RuleI(Character, MaxLevel); - uint8 max_level = (uint8) std::stoi(sep->arg[1]); - uint8 min_level = ( + uint8 max_level = (uint8) std::stoi(sep->arg[1]); + uint8 min_level = ( sep->IsNumber(2) ? - (uint8) - std::stoi(sep->arg[2]) : - 1 + (uint8) std::stoi(sep->arg[2]) : + 1 ); // Default to Level 1 if there isn't a 2nd argument if (!c->GetGM()) { // Default to Character:MaxLevel if we're not a GM and Level is higher than the max level @@ -42,15 +41,18 @@ void command_scribespells(Client *c, const Seperator *sep) } uint16 scribed_spells = target->ScribeSpells(min_level, max_level); - if (target != c) { + if (c != target) { std::string spell_message = ( scribed_spells > 0 ? - ( - scribed_spells == 1 ? - "A new spell" : - fmt::format("{} New spells", scribed_spells) - ) : - "No new spells" + ( + scribed_spells == 1 ? + "A new spell" : + fmt::format( + "{} New spells", + scribed_spells + ) + ) : + "No new spells" ); c->Message( Chat::White, diff --git a/zone/gm_commands/setaapts.cpp b/zone/gm_commands/setaapts.cpp index e8222a08f..cb5e9f3f0 100755 --- a/zone/gm_commands/setaapts.cpp +++ b/zone/gm_commands/setaapts.cpp @@ -18,10 +18,10 @@ void command_setaapts(Client *c, const Seperator *sep) std::string aa_type = str_tolower(sep->arg[1]); std::string group_raid_string; - uint32 aa_points = static_cast(std::min(std::stoull(sep->arg[2]), (unsigned long long) 2000000000)); - bool is_aa = aa_type.find("aa") != std::string::npos; - bool is_group = aa_type.find("group") != std::string::npos; - bool is_raid = aa_type.find("raid") != std::string::npos; + uint32 aa_points = static_cast(std::min(std::stoull(sep->arg[2]), (unsigned long long) 2000000000)); + bool is_aa = aa_type.find("aa") != std::string::npos; + bool is_group = aa_type.find("group") != std::string::npos; + bool is_raid = aa_type.find("raid") != std::string::npos; if (!is_aa && !is_group && !is_raid) { c->Message(Chat::White, "Usage: #setaapts [AA|Group|Raid] [AA Amount]"); return; @@ -48,7 +48,15 @@ void command_setaapts(Client *c, const Seperator *sep) std::string aa_message = fmt::format( "{} now {} {} {}AA Point{}.", - c == target ? "You" : target->GetCleanName(), + ( + c == target ? + "You" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ), c == target ? "have" : "has", aa_points, group_raid_string, diff --git a/zone/gm_commands/setaaxp.cpp b/zone/gm_commands/setaaxp.cpp index 32c060aed..081a7d1d6 100755 --- a/zone/gm_commands/setaaxp.cpp +++ b/zone/gm_commands/setaaxp.cpp @@ -16,15 +16,15 @@ void command_setaaxp(Client *c, const Seperator *sep) target = c->GetTarget()->CastToClient(); } - std::string aa_type = str_tolower(sep->arg[1]); + std::string aa_type = str_tolower(sep->arg[1]); std::string group_raid_string; - uint32 aa_experience = static_cast(std::min( + uint32 aa_experience = static_cast(std::min( std::stoull(sep->arg[2]), (unsigned long long) 2000000000 )); - bool is_aa = aa_type.find("aa") != std::string::npos; - bool is_group = aa_type.find("group") != std::string::npos; - bool is_raid = aa_type.find("raid") != std::string::npos; + bool is_aa = aa_type.find("aa") != std::string::npos; + bool is_group = aa_type.find("group") != std::string::npos; + bool is_raid = aa_type.find("raid") != std::string::npos; if (!is_aa && !is_group && !is_raid) { c->Message(Chat::White, "Usage: #setaaxp [AA|Group|Raid] [AA Experience]"); return; @@ -54,7 +54,15 @@ void command_setaaxp(Client *c, const Seperator *sep) std::string aa_exp_message = fmt::format( "{} now {} {} {}AA Experience.", - c == target ? "You" : target->GetCleanName(), + ( + c == target ? + "You" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ), c == target ? "have" : "has", aa_experience, group_raid_string diff --git a/zone/gm_commands/setcrystals.cpp b/zone/gm_commands/setcrystals.cpp index 32d22f449..4f7f1f14f 100755 --- a/zone/gm_commands/setcrystals.cpp +++ b/zone/gm_commands/setcrystals.cpp @@ -13,13 +13,13 @@ void command_setcrystals(Client *c, const Seperator *sep) target = c->GetTarget()->CastToClient(); } - std::string crystal_type = str_tolower(sep->arg[1]); - uint32 crystal_amount = static_cast(std::min( + std::string crystal_type = str_tolower(sep->arg[1]); + uint32 crystal_amount = static_cast(std::min( std::stoull(sep->arg[2]), (unsigned long long) 2000000000 )); - bool is_ebon = crystal_type.find("ebon") != std::string::npos; - bool is_radiant = crystal_type.find("radiant") != std::string::npos; + bool is_ebon = crystal_type.find("ebon") != std::string::npos; + bool is_radiant = crystal_type.find("radiant") != std::string::npos; if (!is_ebon && !is_radiant) { c->Message(Chat::White, "Usage: #setcrystals [Ebon|Radiant] [Crystal Amount]"); return; @@ -27,15 +27,14 @@ void command_setcrystals(Client *c, const Seperator *sep) uint32 crystal_item_id = ( is_ebon ? - RuleI(Zone, EbonCrystalItemID) : - RuleI(Zone, RadiantCrystalItemID) + RuleI(Zone, EbonCrystalItemID) : + RuleI(Zone, RadiantCrystalItemID) ); auto crystal_link = database.CreateItemLink(crystal_item_id); if (is_radiant) { target->SetRadiantCrystals(crystal_amount); - } - else { + } else { target->SetEbonCrystals(crystal_amount); } @@ -43,7 +42,15 @@ void command_setcrystals(Client *c, const Seperator *sep) Chat::White, fmt::format( "{} now {} {} {}.", - c == target ? "You" : target->GetCleanName(), + ( + c == target ? + "You" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ), c == target ? "have" : "has", crystal_amount, crystal_link diff --git a/zone/gm_commands/setpvppoints.cpp b/zone/gm_commands/setpvppoints.cpp index 27eae29cd..d124cb6eb 100755 --- a/zone/gm_commands/setpvppoints.cpp +++ b/zone/gm_commands/setpvppoints.cpp @@ -19,7 +19,15 @@ void command_setpvppoints(Client *c, const Seperator *sep) target->SendPVPStats(); std::string pvp_message = fmt::format( "{} now {} {} PVP Point{}.", - c == target ? "You" : target->GetCleanName(), + ( + c == target ? + "You" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ), c == target ? "have" : "has", pvp_points, pvp_points != 1 ? "s" : "" diff --git a/zone/gm_commands/stun.cpp b/zone/gm_commands/stun.cpp index 01acce4f0..53bfad8cc 100755 --- a/zone/gm_commands/stun.cpp +++ b/zone/gm_commands/stun.cpp @@ -19,12 +19,10 @@ void command_stun(Client *c, const Seperator *sep) target = c->GetTarget(); if (target->IsClient()) { target->CastToClient()->Stun(duration); - } - else if (target->IsNPC()) { + } else if (target->IsNPC()) { target->CastToNPC()->Stun(duration); } - } - else { + } else { c->Stun(duration); } @@ -34,12 +32,12 @@ void command_stun(Client *c, const Seperator *sep) "You stunned {} for {}.", ( c == target ? - "yourself" : - fmt::format( - "{} ({})", - target->GetCleanName(), - target->GetID() - ) + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) ), ConvertMillisecondsToTime(duration) ) : @@ -47,12 +45,12 @@ void command_stun(Client *c, const Seperator *sep) "You unstunned {}.", ( c == target ? - "yourself" : - fmt::format( - "{} ({})", - target->GetCleanName(), - target->GetID() - ) + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) ) ) ); diff --git a/zone/gm_commands/traindisc.cpp b/zone/gm_commands/traindisc.cpp index 1e3226a85..7e5fff255 100755 --- a/zone/gm_commands/traindisc.cpp +++ b/zone/gm_commands/traindisc.cpp @@ -42,15 +42,18 @@ void command_traindisc(Client *c, const Seperator *sep) } uint16 learned_disciplines = target->LearnDisciplines(min_level, max_level); - if (target != c) { + if (c != target) { std::string discipline_message = ( learned_disciplines > 0 ? - ( - learned_disciplines == 1 ? - "A new discipline" : - fmt::format("{} New disciplines", learned_disciplines) - ) : - "No new disciplines" + ( + learned_disciplines == 1 ? + "A new discipline" : + fmt::format( + "{} New disciplines", + learned_disciplines + ) + ) : + "No new disciplines" ); c->Message( Chat::White,