From efcac00443d957347ce5b6cd36237eafdb41b893 Mon Sep 17 00:00:00 2001 From: Elmsroth Date: Sun, 1 Nov 2020 00:28:02 +0100 Subject: [PATCH] Fix .go creature command (#115) Allow you to teleport to a moving npc which has waypoinst defined. It will require two teleports if your are teleporting from a different map compared to the npc WARNING : THIS CORE UPDATE NEEDS DB UPDATE 21_22_20_Fix_go_creature_command --- .../TeleportationAndPositionCommands.cpp | 26 ++++++++++++++++++- src/game/Tools/Language.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/game/ChatCommands/TeleportationAndPositionCommands.cpp b/src/game/ChatCommands/TeleportationAndPositionCommands.cpp index 22b52c41..e3a9d614 100644 --- a/src/game/ChatCommands/TeleportationAndPositionCommands.cpp +++ b/src/game/ChatCommands/TeleportationAndPositionCommands.cpp @@ -1047,6 +1047,7 @@ bool ChatHandler::HandleGoCreatureCommand(char* args) } Player* _player = m_session->GetPlayer(); + ObjectGuid targetMobGuid; // "id" or number or [name] Shift-click form |color|Hcreature:creature_id|h[name]|h|r int crType; @@ -1106,6 +1107,7 @@ bool ChatHandler::HandleGoCreatureCommand(char* args) } data = &dataPair->second; + targetMobGuid = data->GetObjectGuid(dataPair->first); break; } case CREATURE_LINK_GUID: @@ -1117,12 +1119,15 @@ bool ChatHandler::HandleGoCreatureCommand(char* args) } data = sObjectMgr.GetCreatureData(lowguid); + if (!data) { SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND); SetSentErrorMessage(true); return false; } + + targetMobGuid = data->GetObjectGuid(lowguid); break; } case CREATURE_LINK_RAW: @@ -1131,12 +1136,15 @@ bool ChatHandler::HandleGoCreatureCommand(char* args) if (ExtractUInt32(&pParam1, lowguid)) { data = sObjectMgr.GetCreatureData(lowguid); + if (!data) { SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND); SetSentErrorMessage(true); return false; } + + targetMobGuid = data->GetObjectGuid(lowguid); } // Number is invalid - maybe the user specified the mob's name else @@ -1179,12 +1187,28 @@ bool ChatHandler::HandleGoCreatureCommand(char* args) } data = &dataPair->second; + targetMobGuid = data->GetObjectGuid(dataPair->first); } break; } } - return HandleGoHelper(_player, data->mapid, data->posX, data->posY, data->posZ); + // If we are on the same map then we can teleport to the creature + Creature* targetMob = _player->GetMap()->GetAnyTypeCreature(targetMobGuid); + if (targetMob) + { + HandleGoHelper(_player, targetMob->GetMapId(), targetMob->GetPositionX(), targetMob->GetPositionY(), targetMob->GetPositionZ(), _player->GetOrientation()); + } + else + { + // Go to creature initial pos to be on teh right Map + HandleGoHelper(_player, data->mapid, data->posX, data->posY, data->posZ); + + // Inform player that he will need to make the command another time to go directly to the NPC + PSendSysMessage(LANG_COMMAND_EXECUTE_GOCRE_ANOTHER_TIME, targetMobGuid.GetCounter()); + } + + return true; } // teleport to gameobject diff --git a/src/game/Tools/Language.h b/src/game/Tools/Language.h index 736e0fb3..39016003 100644 --- a/src/game/Tools/Language.h +++ b/src/game/Tools/Language.h @@ -868,6 +868,7 @@ Faction Template: %u. */ LANG_COMMAND_AURAGROUP_CANNOT_UNAURA_DEAD_PLAYER = 1703, /* Cannot remove aura(s) from %s because the player is dead. */ LANG_COMMAND_AURAGROUP_ALL_AURA_REMOVED = 1704, /* All auras have been removed from %s. */ LANG_COMMAND_AURAGROUP_AURA_REMOVED_FOR_SPELL = 1705, /* Aura from spell %u has been removedfrom %s */ + LANG_COMMAND_EXECUTE_GOCRE_ANOTHER_TIME = 1706, /* You will have to execute your command another time to get to the real moving npc position (.go creature %u) */ // FREE IDS 1701-9999 // Use for not-in-official-sources patches