mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-26 05:22:25 +00:00
[Commands] Adjust #kill and #list Commands (#4271)
* [Commands] Adjust #kill/#list Commands * Update list.cpp
This commit is contained in:
parent
c4cda66c3b
commit
943274b443
@ -2,27 +2,40 @@
|
|||||||
|
|
||||||
void command_kill(Client *c, const Seperator *sep)
|
void command_kill(Client *c, const Seperator *sep)
|
||||||
{
|
{
|
||||||
auto target = c->GetTarget();
|
if (!sep->IsNumber(1) && !c->GetTarget()) {
|
||||||
if (!target) {
|
c->Message(Chat::White, "#kill - Kills your target");
|
||||||
c->Message(Chat::White, "You must have a target to use this command.");
|
c->Message(Chat::White, "#kill [entity_id] - Kills the entity ID you provided");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
Mob* t = nullptr;
|
||||||
!target->IsClient() ||
|
uint16 entity_id = 0;
|
||||||
target->CastToClient()->Admin() <= c->Admin()
|
|
||||||
) {
|
if (sep->IsNumber(1)) {
|
||||||
if (c != target) {
|
entity_id = static_cast<uint16>(Strings::ToUnsignedInt(sep->arg[1]));
|
||||||
|
t = entity_list.GetMob(entity_id);
|
||||||
|
} else {
|
||||||
|
t = c->GetTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!t) {
|
||||||
|
c->Message(Chat::White, "You must have a target or supply an entity ID to use this command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!t->IsClient() || t->CastToClient()->Admin() <= c->Admin()) {
|
||||||
|
if (c != t) {
|
||||||
c->Message(
|
c->Message(
|
||||||
Chat::White,
|
Chat::White,
|
||||||
fmt::format(
|
fmt::format(
|
||||||
"Killing {}.",
|
"Killing {}{}.",
|
||||||
c->GetTargetDescription(target)
|
c->GetTargetDescription(t),
|
||||||
|
entity_id ? " by entity id" : ""
|
||||||
).c_str()
|
).c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
target->Kill();
|
t->Kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,13 +12,16 @@ struct UniqueEntity {
|
|||||||
|
|
||||||
void command_list(Client *c, const Seperator *sep)
|
void command_list(Client *c, const Seperator *sep)
|
||||||
{
|
{
|
||||||
const int arguments = sep->argnum;
|
const uint16 arguments = sep->argnum;
|
||||||
if (!arguments) {
|
if (!arguments) {
|
||||||
c->Message(Chat::White, "Usage: #list [corpses|doors|npcs|objects|players] [search]");
|
c->Message(Chat::White, "Usage: #list [bots|corpses|doors|npcs|objects|players] [search]");
|
||||||
c->Message(Chat::White, "Example: #list npcs (Blank for all)");
|
c->Message(Chat::White, "Example: #list npcs (Blank for all)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool can_kill = c->Admin() >= GetCommandStatus("kill");
|
||||||
|
|
||||||
|
const bool is_bots = !strcasecmp(sep->arg[1], "bots");
|
||||||
const bool is_corpses = !strcasecmp(sep->arg[1], "corpses");
|
const bool is_corpses = !strcasecmp(sep->arg[1], "corpses");
|
||||||
const bool is_doors = !strcasecmp(sep->arg[1], "doors");
|
const bool is_doors = !strcasecmp(sep->arg[1], "doors");
|
||||||
const bool is_npcs = !strcasecmp(sep->arg[1], "npcs");
|
const bool is_npcs = !strcasecmp(sep->arg[1], "npcs");
|
||||||
@ -26,13 +29,14 @@ void command_list(Client *c, const Seperator *sep)
|
|||||||
const bool is_players = !strcasecmp(sep->arg[1], "players");
|
const bool is_players = !strcasecmp(sep->arg[1], "players");
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
!is_bots &&
|
||||||
!is_corpses &&
|
!is_corpses &&
|
||||||
!is_doors &&
|
!is_doors &&
|
||||||
!is_npcs &&
|
!is_npcs &&
|
||||||
!is_objects &&
|
!is_objects &&
|
||||||
!is_players
|
!is_players
|
||||||
) {
|
) {
|
||||||
c->Message(Chat::White, "Usage: #list [npcs|players|corpses|doors|objects] [search]");
|
c->Message(Chat::White, "Usage: #list [bots|corpses|doors|npcs|objects|players] [search]");
|
||||||
c->Message(Chat::White, "Example: #list npcs (Blank for all)");
|
c->Message(Chat::White, "Example: #list npcs (Blank for all)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -40,7 +44,10 @@ void command_list(Client *c, const Seperator *sep)
|
|||||||
std::string search_type;
|
std::string search_type;
|
||||||
std::string unique_type;
|
std::string unique_type;
|
||||||
|
|
||||||
if (is_corpses) {
|
if (is_bots) {
|
||||||
|
search_type = "bot";
|
||||||
|
unique_type = "Bot ID";
|
||||||
|
} else if (is_corpses) {
|
||||||
search_type = "corpse";
|
search_type = "corpse";
|
||||||
unique_type = "Corpse ID";
|
unique_type = "Corpse ID";
|
||||||
} else if (is_doors) {
|
} else if (is_doors) {
|
||||||
@ -64,16 +71,38 @@ void command_list(Client *c, const Seperator *sep)
|
|||||||
|
|
||||||
std::vector<UniqueEntity> unique_entities;
|
std::vector<UniqueEntity> unique_entities;
|
||||||
|
|
||||||
if (is_corpses) {
|
if (is_bots) {
|
||||||
const auto &l = entity_list.GetCorpseList();
|
const auto& l = entity_list.GetBotList();
|
||||||
|
|
||||||
for (const auto &e : l) {
|
for (const auto& e: l) {
|
||||||
Corpse *entity = e.second;
|
entity_count++;
|
||||||
|
|
||||||
|
const std::string& entity_name = Strings::ToLower(e->GetName());
|
||||||
|
if (!search_string.empty() && !Strings::Contains(entity_name, search_string)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
unique_entities.emplace_back(
|
||||||
|
UniqueEntity{
|
||||||
|
.entity_id = e->GetID(),
|
||||||
|
.entity_name = e->GetName(),
|
||||||
|
.unique_id = e->GetBotID(),
|
||||||
|
.position = e->GetPosition()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
found_count++;
|
||||||
|
}
|
||||||
|
} else if (is_corpses) {
|
||||||
|
const auto& l = entity_list.GetCorpseList();
|
||||||
|
|
||||||
|
for (const auto& e: l) {
|
||||||
|
Corpse* entity = e.second;
|
||||||
|
|
||||||
entity_count++;
|
entity_count++;
|
||||||
|
|
||||||
const std::string &entity_name = Strings::ToLower(entity->GetName());
|
const std::string& entity_name = Strings::ToLower(entity->GetName());
|
||||||
if (!search_string.empty() && entity_name.find(search_string) == std::string::npos) {
|
if (!search_string.empty() && !Strings::Contains(entity_name, search_string)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,15 +118,15 @@ void command_list(Client *c, const Seperator *sep)
|
|||||||
found_count++;
|
found_count++;
|
||||||
}
|
}
|
||||||
} else if (is_doors) {
|
} else if (is_doors) {
|
||||||
const auto &l = entity_list.GetDoorsList();
|
const auto& l = entity_list.GetDoorsList();
|
||||||
|
|
||||||
for (const auto &e : l) {
|
for (const auto& e: l) {
|
||||||
Doors *entity = e.second;
|
Doors* entity = e.second;
|
||||||
|
|
||||||
entity_count++;
|
entity_count++;
|
||||||
|
|
||||||
const std::string &entity_name = Strings::ToLower(entity->GetDoorName());
|
const std::string& entity_name = Strings::ToLower(entity->GetDoorName());
|
||||||
if (!search_string.empty() && entity_name.find(search_string) == std::string::npos) {
|
if (!search_string.empty() && !Strings::Contains(entity_name, search_string)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,18 +142,18 @@ void command_list(Client *c, const Seperator *sep)
|
|||||||
found_count++;
|
found_count++;
|
||||||
}
|
}
|
||||||
} else if (is_npcs) {
|
} else if (is_npcs) {
|
||||||
const auto &l = entity_list.GetMobList();
|
const auto& l = entity_list.GetMobList();
|
||||||
|
|
||||||
for (const auto &e : l) {
|
for (const auto& e: l) {
|
||||||
Mob *entity = e.second;
|
Mob* entity = e.second;
|
||||||
if (!entity->IsNPC()) {
|
if (!entity->IsNPC()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity_count++;
|
entity_count++;
|
||||||
|
|
||||||
const std::string &entity_name = Strings::ToLower(entity->GetName());
|
const std::string& entity_name = Strings::ToLower(entity->GetName());
|
||||||
if (!search_string.empty() && entity_name.find(search_string) == std::string::npos) {
|
if (!search_string.empty() && !Strings::Contains(entity_name, search_string)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,15 +169,15 @@ void command_list(Client *c, const Seperator *sep)
|
|||||||
found_count++;
|
found_count++;
|
||||||
}
|
}
|
||||||
} else if (is_objects) {
|
} else if (is_objects) {
|
||||||
const auto &l = entity_list.GetObjectList();
|
const auto& l = entity_list.GetObjectList();
|
||||||
|
|
||||||
for (const auto &e : l) {
|
for (const auto& e: l) {
|
||||||
Object *entity = e.second;
|
Object* entity = e.second;
|
||||||
|
|
||||||
entity_count++;
|
entity_count++;
|
||||||
|
|
||||||
const std::string &entity_name = Strings::ToLower(entity->GetModelName());
|
const std::string& entity_name = Strings::ToLower(entity->GetModelName());
|
||||||
if (!search_string.empty() && entity_name.find(search_string) == std::string::npos) {
|
if (!search_string.empty() && !Strings::Contains(entity_name, search_string)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,15 +193,15 @@ void command_list(Client *c, const Seperator *sep)
|
|||||||
found_count++;
|
found_count++;
|
||||||
}
|
}
|
||||||
} else if (is_players) {
|
} else if (is_players) {
|
||||||
const auto &l = entity_list.GetClientList();
|
const auto& l = entity_list.GetClientList();
|
||||||
|
|
||||||
for (const auto &e : l) {
|
for (const auto& e: l) {
|
||||||
Client *entity = e.second;
|
Client* entity = e.second;
|
||||||
|
|
||||||
entity_count++;
|
entity_count++;
|
||||||
|
|
||||||
const std::string &entity_name = Strings::ToLower(entity->GetName());
|
const std::string& entity_name = Strings::ToLower(entity->GetName());
|
||||||
if (!search_string.empty() && entity_name.find(search_string) == std::string::npos) {
|
if (!search_string.empty() && !Strings::Contains(entity_name, search_string)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,27 +226,31 @@ void command_list(Client *c, const Seperator *sep)
|
|||||||
search_type,
|
search_type,
|
||||||
(
|
(
|
||||||
!search_string.empty() ?
|
!search_string.empty() ?
|
||||||
fmt::format(
|
fmt::format(
|
||||||
" matching '{}'",
|
" matching '{}'",
|
||||||
search_string
|
search_string
|
||||||
) :
|
) :
|
||||||
""
|
""
|
||||||
)
|
)
|
||||||
).c_str()
|
).c_str()
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(unique_entities.begin(), unique_entities.end(), [](UniqueEntity a, UniqueEntity b) {
|
std::sort(
|
||||||
if (a.entity_id && b.entity_id) {
|
unique_entities.begin(),
|
||||||
return a.entity_id < b.entity_id;
|
unique_entities.end(),
|
||||||
} else {
|
[](UniqueEntity a, UniqueEntity b) {
|
||||||
return a.unique_id < b.unique_id;
|
if (a.entity_id && b.entity_id) {
|
||||||
|
return a.entity_id < b.entity_id;
|
||||||
|
} else {
|
||||||
|
return a.unique_id < b.unique_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
for (const auto& e : unique_entities) {
|
for (const auto& e : unique_entities) {
|
||||||
const std::string &saylink = Saylink::Silent(
|
const std::string& saylink = Saylink::Silent(
|
||||||
fmt::format(
|
fmt::format(
|
||||||
"#goto {:.2f} {:.2f} {:.2f}",
|
"#goto {:.2f} {:.2f} {:.2f}",
|
||||||
e.position.x,
|
e.position.x,
|
||||||
@ -230,7 +263,7 @@ void command_list(Client *c, const Seperator *sep)
|
|||||||
c->Message(
|
c->Message(
|
||||||
Chat::White,
|
Chat::White,
|
||||||
fmt::format(
|
fmt::format(
|
||||||
"| {}{}{} | {} |",
|
"| {}{}{} | {} |{}",
|
||||||
saylink,
|
saylink,
|
||||||
(
|
(
|
||||||
e.entity_id ?
|
e.entity_id ?
|
||||||
@ -249,7 +282,21 @@ void command_list(Client *c, const Seperator *sep)
|
|||||||
) :
|
) :
|
||||||
""
|
""
|
||||||
),
|
),
|
||||||
e.entity_name
|
e.entity_name,
|
||||||
|
(
|
||||||
|
(can_kill && (is_bots || is_npcs || is_players)) ?
|
||||||
|
fmt::format(
|
||||||
|
" {} |",
|
||||||
|
Saylink::Silent(
|
||||||
|
fmt::format(
|
||||||
|
"#kill {}",
|
||||||
|
e.entity_id
|
||||||
|
),
|
||||||
|
"Kill"
|
||||||
|
)
|
||||||
|
) :
|
||||||
|
""
|
||||||
|
)
|
||||||
).c_str()
|
).c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user