[Commands] Cleanup #npctypespawn Command. (#2110)

- Cleanup messages and logic.
This commit is contained in:
Kinglykrab
2022-05-06 20:50:02 -04:00
committed by GitHub
parent ee86001132
commit 26b26af8d7
2 changed files with 52 additions and 16 deletions
+51 -15
View File
@@ -2,13 +2,22 @@
void command_npctypespawn(Client *c, const Seperator *sep)
{
if (sep->IsNumber(1)) {
const NPCType *tmp = 0;
if ((tmp = content_db.LoadNPCTypesData(atoi(sep->arg[1])))) {
//tmp->fixedZ = 1;
auto npc = new NPC(tmp, 0, c->GetPosition(), GravityBehavior::Water);
if (npc && sep->IsNumber(2)) {
npc->SetNPCFactionID(atoi(sep->arg[2]));
int arguments = sep->argnum;
if (!arguments || !sep->IsNumber(1)) {
c->Message(Chat::White, "Usage: #npctypespawn [NPC ID] [Faction ID]");
return;
}
auto npc_id = std::stoul(sep->arg[1]);
int faction_id = 0;
auto npc_type = content_db.LoadNPCTypesData(npc_id);
if (npc_type) {
auto npc = new NPC(npc_type, 0, c->GetPosition(), GravityBehavior::Water);
if (npc) {
if (sep->IsNumber(2)) {
faction_id = std::stoi(sep->arg[2]);
npc->SetNPCFactionID(faction_id);
}
npc->AddLootTable();
@@ -16,14 +25,41 @@ void command_npctypespawn(Client *c, const Seperator *sep)
npc->CheckGlobalLootTables();
}
entity_list.AddNPC(npc);
}
else {
c->Message(Chat::White, "NPC Type %i not found", atoi(sep->arg[1]));
}
}
else {
c->Message(Chat::White, "Usage: #npctypespawn npctypeid factionid");
}
c->Message(
Chat::White,
fmt::format(
"Spawned {} ({}){}.",
npc->GetCleanName(),
npc_id,
(
faction_id ?
fmt::format(
" on the {} Faction ({})",
content_db.GetFactionName(faction_id),
faction_id
) :
""
)
).c_str()
);
} else {
c->Message(
Chat::White,
fmt::format(
"Failed to spawn NPC ID {}.",
npc_id
).c_str()
);
}
} else {
c->Message(
Chat::White,
fmt::format(
"NPC ID {} was not found.",
npc_id
).c_str()
);
}
}