fix(Script/Command): Allow guid for npc move and delete (#21008)

This commit is contained in:
Kitzunu
2024-12-22 09:42:21 +01:00
committed by GitHub
parent 2110f7cc84
commit 1462d1ae39
+25 -13
View File
@@ -373,20 +373,24 @@ public:
return true; return true;
} }
static bool HandleNpcDeleteCommand(ChatHandler* handler) static bool HandleNpcDeleteCommand(ChatHandler* handler, Optional<ObjectGuid::LowType> lowGuid)
{ {
Creature* unit = handler->getSelectedCreature(); Creature* creature;
if (lowGuid.has_value())
creature = handler->GetCreatureFromPlayerMapByDbGuid(*lowGuid);
else
creature = handler->getSelectedCreature();
if (!unit || unit->IsPet() || unit->IsTotem()) if (!creature || creature->IsPet() || creature->IsTotem())
{ {
handler->SendErrorMessage(LANG_SELECT_CREATURE); handler->SendErrorMessage(LANG_SELECT_CREATURE);
return false; return false;
} }
// Delete the creature // Delete the creature
unit->CombatStop(); creature->CombatStop();
unit->DeleteFromDB(); creature->DeleteFromDB();
unit->AddObjectToRemoveList(); creature->AddObjectToRemoveList();
handler->SendSysMessage(LANG_COMMAND_DELCREATMESSAGE); handler->SendSysMessage(LANG_COMMAND_DELCREATMESSAGE);
@@ -711,25 +715,33 @@ public:
} }
//move selected creature //move selected creature
static bool HandleNpcMoveCommand(ChatHandler* handler) static bool HandleNpcMoveCommand(ChatHandler* handler, Optional<ObjectGuid::LowType> guid)
{ {
Creature* creature = handler->getSelectedCreature(); Creature* creature;
if (guid.has_value())
creature = handler->GetCreatureFromPlayerMapByDbGuid(*guid);
else
creature = handler->getSelectedCreature();
if (!creature) if (!creature)
return false; return false;
ObjectGuid::LowType lowguid = creature->GetSpawnId(); ObjectGuid::LowType lowGuid;
if (guid.has_value())
lowGuid = *guid;
else
lowGuid = creature->GetSpawnId();
CreatureData const* data = sObjectMgr->GetCreatureData(lowguid); CreatureData const* data = sObjectMgr->GetCreatureData(lowGuid);
if (!data) if (!data)
{ {
handler->SendErrorMessage(LANG_COMMAND_CREATGUIDNOTFOUND, lowguid); handler->SendErrorMessage(LANG_COMMAND_CREATGUIDNOTFOUND, lowGuid);
return false; return false;
} }
if (handler->GetSession()->GetPlayer()->GetMapId() != data->mapid) if (handler->GetSession()->GetPlayer()->GetMapId() != data->mapid)
{ {
handler->SendErrorMessage(LANG_COMMAND_CREATUREATSAMEMAP, lowguid); handler->SendErrorMessage(LANG_COMMAND_CREATUREATSAMEMAP, lowGuid);
return false; return false;
} }
@@ -763,7 +775,7 @@ public:
stmt->SetData(1, y); stmt->SetData(1, y);
stmt->SetData(2, z); stmt->SetData(2, z);
stmt->SetData(3, o); stmt->SetData(3, o);
stmt->SetData(4, lowguid); stmt->SetData(4, lowGuid);
WorldDatabase.Execute(stmt); WorldDatabase.Execute(stmt);