From 324bfd448e7b70d4b65bc3f1da9174b78ebf0579 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Thu, 25 May 2023 19:49:09 -0400 Subject: [PATCH] [Commands] Add entity variable command (#3345) * [Commands] Add entity variable commands # Commands - Add `#clearentityvariables` to clear all entity variables from yourself or your target. - Add `#deleteentityvariable [Variable Name]` to delete an entity variable from yourself or your target. - Add `#setentityvariable [Variable Name] [Variable Value]` to set an entity variable for yourself or your target. - Add `#viewentityvariables [Search Criteria]` to view your or your target's entity variables. # Notes - `#setentityvariable` can use multi-word names/values by using double quotes like `#setentityvariable "Test Variable" "Test Value"`. - `#viewentityvariable` does not require a search criteria, not using one shows all entity variables on yourself or your target. * Update viewentityvariables.cpp * Unnecessary parameter. * Consolidate commands. * Update entityvariable.cpp * Update command.cpp * Proper arguments. --- zone/command.cpp | 2 + zone/command.h | 1 + zone/gm_commands/appearanceeffects.cpp | 4 +- zone/gm_commands/entityvariable.cpp | 190 +++++++++++++++++++++++++ zone/gm_commands/exptoggle.cpp | 2 +- zone/gm_commands/xtargets.cpp | 2 +- 6 files changed, 197 insertions(+), 4 deletions(-) create mode 100644 zone/gm_commands/entityvariable.cpp diff --git a/zone/command.cpp b/zone/command.cpp index 81bfb3ec4..62d1d03ac 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -131,6 +131,7 @@ int command_init(void) command_add("emptyinventory", "Clears your or your target's entire inventory (Equipment, General, Bank, and Shared Bank)", AccountStatus::GMImpossible, command_emptyinventory) || command_add("enablerecipe", "[Recipe ID] - Enables a Recipe", AccountStatus::QuestTroupe, command_enablerecipe) || command_add("endurance", "Restores your or your target's endurance.", AccountStatus::Guide, command_endurance) || + command_add("entityvariable", "[clear|delete|set|view] - Modify entity variables for yourself or your target", AccountStatus::GMAdmin, command_entityvariable) || command_add("exptoggle", "[Toggle] - Toggle your or your target's experience gain.", AccountStatus::QuestTroupe, command_exptoggle) || command_add("faction", "[Find (criteria | all ) | Review (criteria | all) | Reset (id)] - Resets Player's Faction", AccountStatus::QuestTroupe, command_faction) || command_add("factionassociation", "[factionid] [amount] - triggers a faction hits via association", AccountStatus::GMLeadAdmin, command_faction_association) || @@ -977,6 +978,7 @@ void command_bot(Client *c, const Seperator *sep) #include "gm_commands/emptyinventory.cpp" #include "gm_commands/enablerecipe.cpp" #include "gm_commands/endurance.cpp" +#include "gm_commands/entityvariable.cpp" #include "gm_commands/exptoggle.cpp" #include "gm_commands/faction.cpp" #include "gm_commands/feature.cpp" diff --git a/zone/command.h b/zone/command.h index 13e3da464..c2d90740c 100644 --- a/zone/command.h +++ b/zone/command.h @@ -82,6 +82,7 @@ void command_emoteview(Client *c, const Seperator *sep); void command_emptyinventory(Client *c, const Seperator *sep); void command_enablerecipe(Client *c, const Seperator *sep); void command_endurance(Client *c, const Seperator *sep); +void command_entityvariable(Client *c, const Seperator *sep); void command_exptoggle(Client *c, const Seperator *sep); void command_faction(Client *c, const Seperator *sep); void command_faction_association(Client *c, const Seperator *sep); diff --git a/zone/gm_commands/appearanceeffects.cpp b/zone/gm_commands/appearanceeffects.cpp index d978c527e..c019462af 100644 --- a/zone/gm_commands/appearanceeffects.cpp +++ b/zone/gm_commands/appearanceeffects.cpp @@ -62,7 +62,7 @@ void command_appearanceeffects(Client *c, const Seperator *sep) "Appearance Effect ID {} in slot ID {} has been set for {}.", effect_id, slot_id, - c->GetTargetDescription(t, TargetDescriptionType::LCSelf) + c->GetTargetDescription(t) ).c_str() ); } else if (is_remove) { @@ -90,7 +90,7 @@ void command_appearanceeffects(Client *c, const Seperator *sep) Chat::White, fmt::format( "Appearance Effects have been removed for {}.", - c->GetTargetDescription(t, TargetDescriptionType::LCSelf) + c->GetTargetDescription(t) ).c_str() ); } else if (is_view) { diff --git a/zone/gm_commands/entityvariable.cpp b/zone/gm_commands/entityvariable.cpp new file mode 100644 index 000000000..d6e10d204 --- /dev/null +++ b/zone/gm_commands/entityvariable.cpp @@ -0,0 +1,190 @@ +#include "../client.h" + +void command_entityvariable(Client *c, const Seperator *sep) +{ + const auto arguments = sep->argnum; + + if (!arguments) { + c->Message(Chat::White, "Usage: #entityvariable clear - Clear all entity variables on yourself or your target"); + c->Message(Chat::White, "Usage: #entityvariable delete [Variable Name] - Delete an entity variable from yourself or your target"); + c->Message(Chat::White, "Usage: #entityvariable set [Variable Name] [Variable Value] - Set an entity variable for yourself or your target"); + c->Message(Chat::White, "Usage: #entityvariable view [Variable Name] - View an entity variable on yourself or your target"); + c->Message(Chat::White, "Note: You can have spaces in variable names and values by wrapping in double quotes like this"); + c->Message(Chat::White, "Example: #entityvariable set \"Test Variable\" \"Test Value\""); + c->Message(Chat::White, "Note: Variable Value is optional and can be set to empty by not providing a value"); + return; + } + + const bool is_clear = !strcasecmp(sep->arg[1], "clear"); + const bool is_delete = !strcasecmp(sep->arg[1], "delete"); + const bool is_set = !strcasecmp(sep->arg[1], "set"); + const bool is_view = !strcasecmp(sep->arg[1], "view"); + + if ( + !is_clear && + !is_delete && + !is_set && + !is_view + ) { + c->Message(Chat::White, "Usage: #entityvariable clear - Clear all entity variables on yourself or your target"); + c->Message(Chat::White, "Usage: #entityvariable delete [Variable Name] - Delete an entity variable from yourself or your target"); + c->Message(Chat::White, "Usage: #entityvariable set [Variable Name] [Variable Value] - Set an entity variable for yourself or your target"); + c->Message(Chat::White, "Usage: #entityvariable view [Variable Name] - View an entity variable on yourself or your target"); + c->Message(Chat::White, "Note: You can have spaces in variable names and values by wrapping in double quotes like this"); + c->Message(Chat::White, "Example: #entityvariable set \"Test Variable\" \"Test Value\""); + c->Message(Chat::White, "Note: Variable Value is optional and can be set to empty by not providing a value"); + return; + } + + Mob* t = c; + if (c->GetTarget()) { + t = c->GetTarget(); + } + + if (is_clear) { + const auto cleared = t->ClearEntityVariables(); + + if (!cleared) { + c->Message( + Chat::White, + fmt::format( + "{} {} not have any entity variables to clear.", + c->GetTargetDescription(t, TargetDescriptionType::UCYou), + c == t ? "do" : "does" + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Cleared all entity variables for {}.", + c->GetTargetDescription(t) + ).c_str() + ); + } else if (is_delete) { + const std::string variable_name = sep->argplus[2]; + + if (!t->EntityVariableExists(variable_name)) { + c->Message( + Chat::White, + fmt::format( + "{} {} not have an entity variable named '{}'.", + c->GetTargetDescription(t, TargetDescriptionType::UCYou), + c == t ? "do" : "does", + variable_name + ).c_str() + ); + + return; + } + + t->DeleteEntityVariable(variable_name); + + c->Message( + Chat::White, + fmt::format( + "Deleted an entity variable named '{}' from {}.", + variable_name, + c->GetTargetDescription(t) + ).c_str() + ); + + return; + } else if (is_set) { + const std::string variable_name = sep->arg[2]; + const std::string variable_value = sep->arg[3]; + + t->SetEntityVariable(variable_name, variable_value); + + c->Message( + Chat::White, + fmt::format( + "Set an entity variable named '{}' to a value of '{}' for {}.", + variable_name, + variable_value, + c->GetTargetDescription(t) + ).c_str() + ); + } else if (is_view) { + const auto &l = t->GetEntityVariables(); + + uint32 variable_count = 0; + uint32 variable_number = 1; + const std::string search_criteria = arguments ? sep->argplus[2] : ""; + + for (const auto &e: l) { + if ( + search_criteria.empty() || + Strings::Contains(Strings::ToLower(e), Strings::ToLower(search_criteria)) + ) { + c->Message( + Chat::White, + fmt::format( + "Variable {} | Name: {} Value: {} | {}", + variable_number, + e, + t->GetEntityVariable(e), + Saylink::Silent( + fmt::format( + "#entityvariable delete {}", + e + ), + "Delete" + ) + ).c_str() + ); + + variable_count++; + variable_number++; + } + } + + if (!variable_count) { + c->Message( + Chat::White, + fmt::format( + "{} {} no entity variables{}.", + c->GetTargetDescription(t, TargetDescriptionType::UCYou), + c == t ? "have" : "has", + ( + !search_criteria.empty() ? + fmt::format( + " matching '{}'", + search_criteria + ) : + "" + ) + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} {} {} entity variable{}{}, would you like to {} all of {} entity variables?", + c->GetTargetDescription(t, TargetDescriptionType::UCYou), + c == t ? "have" : "has", + variable_count, + variable_count != 1 ? "s" : "", + ( + !search_criteria.empty() ? + fmt::format( + " matching '{}'", + search_criteria + ) : + "" + ), + Saylink::Silent( + "#entityvariable clear", + "clear" + ), + c == t ? "your" : "their" + ).c_str() + ); + } +} diff --git a/zone/gm_commands/exptoggle.cpp b/zone/gm_commands/exptoggle.cpp index b267b4f7e..abc1d2b92 100644 --- a/zone/gm_commands/exptoggle.cpp +++ b/zone/gm_commands/exptoggle.cpp @@ -21,7 +21,7 @@ void command_exptoggle(Client *c, const Seperator *sep) Chat::White, fmt::format( "Experience gain for {} is now {}abled.", - c->GetTargetDescription(t, TargetDescriptionType::LCSelf), + c->GetTargetDescription(t), is_exp_enabled ? "en" : "dis" ).c_str() ); diff --git a/zone/gm_commands/xtargets.cpp b/zone/gm_commands/xtargets.cpp index e153c477c..3ae8a6236 100755 --- a/zone/gm_commands/xtargets.cpp +++ b/zone/gm_commands/xtargets.cpp @@ -34,7 +34,7 @@ void command_xtargets(Client *c, const Seperator *sep) fmt::format( "Max number of XTargets set to {} for {}.", new_max, - c->GetTargetDescription(t, TargetDescriptionType::LCSelf) + c->GetTargetDescription(t) ).c_str() ); }