mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Scripts/Commands: New command ".go instance". Goes to an instance.
(cherry picked from commit 6a0870a999)
This commit is contained in:
@@ -1437,6 +1437,7 @@ INSERT INTO `rbac_linked_permissions` VALUES
|
||||
(198,852),
|
||||
(198,855),
|
||||
(198,868),
|
||||
(198,874),
|
||||
(199,207),
|
||||
(199,209),
|
||||
(199,210),
|
||||
@@ -2166,6 +2167,7 @@ INSERT INTO `rbac_permissions` VALUES
|
||||
(871,'Command: debug instancespawn'),
|
||||
(872,'Command: server debug'),
|
||||
(873,'Command: reload creature_movement_override'),
|
||||
(874,'Command: go instance'),
|
||||
(881,'Command: reload vehicle_template'),
|
||||
(882,'Command: reload spell_script_names');
|
||||
/*!40000 ALTER TABLE `rbac_permissions` ENABLE KEYS */;
|
||||
@@ -2393,6 +2395,7 @@ INSERT INTO `updates` VALUES
|
||||
('2018_06_22_00_auth.sql','9DA24F70B8A365AFDEF58A9B578255CDEDFCA47C','ARCHIVED','2018-06-22 17:45:45',0),
|
||||
('2018_06_23_00_auth.sql','BE35312C386A127D047E5A7CE0D14DB41D905F8E','ARCHIVED','2018-05-23 10:14:39',0),
|
||||
('2018_06_29_00_auth.sql','03AAEA7E52848FA5522C3F0C6D9C38B988407480','ARCHIVED','2018-06-29 22:34:04',0),
|
||||
('2018_08_30_00_auth.sql','22F69864361D3E72F800379338310172C0576D1C','RELEASED','2018-08-30 10:14:39',0),
|
||||
('2018_12_09_00_auth_2017_01_06_00_auth.sql','6CCFE6A9774EC733C9863D36A0F15F3534189BBD','ARCHIVED','2018-11-22 22:21:26',0),
|
||||
('2018_12_09_01_auth.sql','576C2A11BE671D8420FA3EB705E594E381ECCC56','ARCHIVED','2018-12-09 14:49:17',0),
|
||||
('2019_06_08_00_auth.sql','EA5A78F5A26C17BC790481EA9B3772D3A6912459','ARCHIVED','2019-05-20 17:21:20',0),
|
||||
|
||||
9
sql/updates/auth/master/2018_08_30_00_auth.sql
Normal file
9
sql/updates/auth/master/2018_08_30_00_auth.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
--
|
||||
DELETE FROM `rbac_permissions` WHERE `id`=874;
|
||||
INSERT INTO `rbac_permissions` (`id`,`name`) VALUES
|
||||
(874, "Command: go instance");
|
||||
|
||||
SET @parent := (SELECT `id` FROM `rbac_linked_permissions` WHERE `linkedId`=852);
|
||||
DELETE FROM `rbac_linked_permissions` WHERE `linkedId`=874;
|
||||
INSERT INTO `rbac_linked_permissions` (`id`,`linkedId`) VALUES
|
||||
(@parent, 874);
|
||||
@@ -0,0 +1,6 @@
|
||||
--
|
||||
DELETE FROM `command` WHERE `name`="go instance";
|
||||
INSERT INTO `command` (`name`,`permission`,`help`) VALUES
|
||||
('go instance', 874, 'Syntax: .go instance [mapid | name]
|
||||
|
||||
Teleports you to entrance of instance with script name matching input (or given mapid)');
|
||||
@@ -779,7 +779,7 @@ enum RBACPermissions
|
||||
RBAC_PERM_COMMAND_DEBUG_INSTANCESPAWN = 871,
|
||||
RBAC_PERM_COMMAND_SERVER_DEBUG = 872,
|
||||
RBAC_PERM_COMMAND_RELOAD_CREATURE_MOVEMENT_OVERRIDE = 873,
|
||||
// 874 previously used, do not reuse
|
||||
RBAC_PERM_COMMAND_GO_INSTANCE = 874,
|
||||
RBAC_PERM_COMMAND_LOOKUP_MAP_ID = 875,
|
||||
RBAC_PERM_COMMAND_LOOKUP_ITEM_ID = 876,
|
||||
RBAC_PERM_COMMAND_LOOKUP_QUEST_ID = 877,
|
||||
|
||||
@@ -1085,6 +1085,7 @@ class TC_GAME_API ObjectMgr
|
||||
ItemTemplate const* GetItemTemplate(uint32 entry) const;
|
||||
ItemTemplateContainer const& GetItemTemplateStore() const { return _itemTemplateStore; }
|
||||
|
||||
InstanceTemplateContainer const& GetInstanceTemplates() const { return _instanceTemplateStore; }
|
||||
InstanceTemplate const* GetInstanceTemplate(uint32 mapId) const;
|
||||
|
||||
PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint8 level) const;
|
||||
|
||||
@@ -59,6 +59,7 @@ public:
|
||||
{ "complaintticket", rbac::RBAC_PERM_COMMAND_GO_COMPLAINT_TICKET, false, &HandleGoTicketCommand<ComplaintTicket>, "" },
|
||||
{ "suggestionticket", rbac::RBAC_PERM_COMMAND_GO_SUGGESTION_TICKET, false, &HandleGoTicketCommand<SuggestionTicket>, "" },
|
||||
{ "offset", rbac::RBAC_PERM_COMMAND_GO_OFFSET, false, &HandleGoOffsetCommand, "" },
|
||||
{ "instance", rbac::RBAC_PERM_COMMAND_GO_INSTANCE, false, &HandleGoInstanceCommand, "" }
|
||||
};
|
||||
|
||||
static std::vector<ChatCommand> commandTable =
|
||||
@@ -628,6 +629,122 @@ public:
|
||||
player->TeleportTo(player->GetMapId(), x, y, z, o);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGoInstanceCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
std::vector<std::string> labels;
|
||||
|
||||
// tokenize and convert to lowercase
|
||||
char* pos = const_cast<char*>(args);
|
||||
char* last = nullptr;
|
||||
do
|
||||
{
|
||||
if (*pos == ' ')
|
||||
{
|
||||
if (last)
|
||||
{
|
||||
*pos = '\0';
|
||||
labels.emplace_back(last);
|
||||
last = nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!last)
|
||||
last = pos;
|
||||
*pos = tolower(*pos);
|
||||
}
|
||||
} while (*++pos);
|
||||
if (last)
|
||||
labels.emplace_back(last);
|
||||
// tokenizing done
|
||||
|
||||
uint32 mapid = 0;
|
||||
if (labels.size() == 1)
|
||||
{
|
||||
try { mapid = std::stoi(labels[0]); }
|
||||
catch (...) {}
|
||||
}
|
||||
|
||||
if (!mapid)
|
||||
{
|
||||
std::multimap<uint32, std::pair<uint16, std::string>> matches;
|
||||
for (auto const& pair : sObjectMgr->GetInstanceTemplates())
|
||||
{
|
||||
uint32 count = 0;
|
||||
std::string const& scriptName = sObjectMgr->GetScriptName(pair.second.ScriptId);
|
||||
for (std::string const& label : labels)
|
||||
if (scriptName.find(label) != std::string::npos)
|
||||
++count;
|
||||
|
||||
if (count)
|
||||
matches.emplace(count, decltype(matches)::mapped_type({ pair.first, scriptName }));
|
||||
}
|
||||
if (matches.empty())
|
||||
{
|
||||
handler->SendSysMessage("No matches found for your input");
|
||||
return false;
|
||||
}
|
||||
auto it = matches.rbegin();
|
||||
uint32 maxCount = it->first;
|
||||
mapid = it->second.first;
|
||||
if (++it != matches.rend() && it->first == maxCount)
|
||||
{
|
||||
handler->SendSysMessage("Multiple matches found for your input - please specify:");
|
||||
--it;
|
||||
do
|
||||
handler->PSendSysMessage("* Map %03u: '%s'", it->second.first, it->second.second);
|
||||
while (++it != matches.rend() && it->first == maxCount);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(mapid);
|
||||
|
||||
InstanceTemplate const* temp = sObjectMgr->GetInstanceTemplate(mapid);
|
||||
if (!temp)
|
||||
{
|
||||
handler->PSendSysMessage("Map %u is not instanced", mapid);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
std::string const& scriptname = sObjectMgr->GetScriptName(temp->ScriptId);
|
||||
|
||||
AreaTriggerStruct const* entrance = sObjectMgr->GetMapEntranceTrigger(mapid);
|
||||
if (!entrance)
|
||||
{
|
||||
handler->PSendSysMessage("Could not find entrance for instance %u (%s)", mapid, scriptname);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
if (player->IsInFlight())
|
||||
player->FinishTaxiFlight();
|
||||
else
|
||||
player->SaveRecallPosition();
|
||||
|
||||
if (player->TeleportTo(entrance->target_mapId, entrance->target_X, entrance->target_Y, entrance->target_Z, entrance->target_Orientation))
|
||||
handler->PSendSysMessage("Teleported you to entrance of mapid %u (%s)", mapid, scriptname);
|
||||
else
|
||||
{
|
||||
AreaTriggerStruct const* exit = sObjectMgr->GetGoBackTrigger(mapid);
|
||||
if (player->TeleportTo(exit->target_mapId, exit->target_X, exit->target_Y, exit->target_Z, exit->target_Orientation + M_PI))
|
||||
handler->PSendSysMessage("Teleported you in front of entrance to mapid %u (%s)", mapid, scriptname);
|
||||
else
|
||||
{
|
||||
handler->PSendSysMessage("Failed to teleport you to entrance of mapid %u (%s) - missing attunement/expansion for parent map?", mapid, scriptname);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_go_commandscript()
|
||||
|
||||
Reference in New Issue
Block a user