[Commands] npc_edit faction and #setfaction duplicate and incorrect. (#3577)

* [Commands] npc_edit faction and #setfaction duplicate and incorrect.

* Fix assignment
This commit is contained in:
Paul Coene
2023-09-02 21:21:48 -04:00
committed by GitHub
parent ca933fce45
commit a64425ebe6
3 changed files with 26 additions and 73 deletions
-54
View File
@@ -1,54 +0,0 @@
#include "../../client.h"
void SetFaction(Client *c, const Seperator *sep)
{
const auto arguments = sep->argnum;
if (arguments < 2 || !sep->IsNumber(2)) {
c->Message(Chat::White, "Usage: #set faction [Faction ID]");
return;
}
if (
!c->GetTarget() ||
(
c->GetTarget() &&
c->GetTarget()->IsClient()
)
) {
c->Message(Chat::White, "You must target an NPC to use this command.");
return;
}
NPC* t = c->GetTarget()->CastToNPC();
const uint32 npc_id = t->GetNPCTypeID();
const int faction_id = Strings::ToInt(sep->arg[2]);
const std::string& faction_name = content_db.GetFactionName(faction_id);
if (faction_name.empty()) {
c->Message(
Chat::White,
"Invalid Faction ID, please specify a valid Faction ID."
);
return;
}
c->Message(
Chat::White,
fmt::format(
"Faction Changed | Name: {} ({}) Faction: {} ({}).",
t->GetCleanName(),
npc_id,
content_db.GetFactionName(faction_id),
faction_id
).c_str()
);
const std::string &query = fmt::format(
"UPDATE npc_types SET npc_faction_id = {} WHERE id = {}",
faction_id,
npc_id
);
content_db.QueryDatabase(query);
}