Kinglykrab 04f3d6286c
[Commands] Cleanup #attack Command. (#2103)
- Cleanup messages and logic.
2022-05-03 23:05:16 -04:00

39 lines
821 B
C++
Executable File

#include "../client.h"
void command_attack(Client *c, const Seperator *sep)
{
if (!c->GetTarget() || !c->GetTarget()->IsNPC()) {
c->Message(Chat::White, "You must target an NPC to use this command.");
return;
}
std::string entity_name = sep->argplus[1];
if (entity_name.empty()) {
c->Message(Chat::White, "Usage: #attack [Entity Name]");
return;
}
auto entity = entity_list.GetMob(entity_name.c_str());
if (entity) {
c->GetTarget()->AddToHateList(entity, 1);
c->Message(
Chat::EchoChat1,
fmt::format(
"{} whispers, 'Attacking {} ({}).'",
c->GetTarget()->GetCleanName(),
entity->GetCleanName(),
entity->GetID()
).c_str()
);
} else {
c->Message(
Chat::White,
fmt::format(
"No entity by the name of '{}' could be found.",
entity_name
).c_str()
);
}
}