diff --git a/src/game/AI/CreatureEventAIMgr.cpp b/src/game/AI/CreatureEventAIMgr.cpp index d55329f5c..99096967a 100644 --- a/src/game/AI/CreatureEventAIMgr.cpp +++ b/src/game/AI/CreatureEventAIMgr.cpp @@ -39,7 +39,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts(bool check_entry_use) m_CreatureEventAI_TextMap.clear(); // Load EventAI Text - sObjectMgr.LoadMangosStrings(WorldDatabase, "creature_ai_texts", MIN_CREATURE_AI_TEXT_STRING_ID, MAX_CREATURE_AI_TEXT_STRING_ID); + sObjectMgr.LoadMangosStrings(WorldDatabase, "creature_ai_texts", MIN_CREATURE_AI_TEXT_STRING_ID, MAX_CREATURE_AI_TEXT_STRING_ID, false); // Gather Additional data from EventAI Texts QueryResult *result = WorldDatabase.Query("SELECT entry, sound, type, language, emote FROM creature_ai_texts"); diff --git a/src/game/AI/ScriptedInstance.cpp b/src/game/AI/ScriptedInstance.cpp index 932653489..235446f82 100644 --- a/src/game/AI/ScriptedInstance.cpp +++ b/src/game/AI/ScriptedInstance.cpp @@ -123,6 +123,22 @@ void ScriptedInstance::LoadSaveData(const char* pStr, uint32* encounters, uint32 } } + +/// Get the first found Player* (with requested properties) in the map. Can return nullptr. +Player* ScriptedInstance::GetPlayerInMap(bool bOnlyAlive /*=false*/, bool bCanBeGamemaster /*=true*/) +{ + Map::PlayerList const& lPlayers = instance->GetPlayers(); + + for (Map::PlayerList::const_iterator itr = lPlayers.begin(); itr != lPlayers.end(); ++itr) + { + Player* pPlayer = itr->getSource(); + if (pPlayer && (!bOnlyAlive || pPlayer->isAlive()) && (bCanBeGamemaster || !pPlayer->isGameMaster())) + return pPlayer; + } + + return nullptr; +} + /// Returns a pointer to a loaded GameObject that was stored in m_mGoEntryGuidStore. Can return NULL GameObject* ScriptedInstance::GetSingleGameObjectFromStorage(uint32 uiEntry) { @@ -183,12 +199,11 @@ void ScriptedInstance_PTR::Update(uint32 diff) ScriptedInstance::Update(diff); } - /** -Constructor for DialogueHelper -@param pDialogueArray The static const array of DialogueEntry holding the information about the dialogue. This array MUST be terminated by {0,0,0} + Constructor for DialogueHelper + @param pDialogueArray The static const array of DialogueEntry holding the information about the dialogue. This array MUST be terminated by {0,0,0} */ -DialogueHelper::DialogueHelper(DialogueEntry const* pDialogueArray) : +DialogueHelper::DialogueHelper(SIDialogueEntry const* pDialogueArray) : m_pInstance(nullptr), m_pDialogueArray(pDialogueArray), m_pCurrentEntry(nullptr), @@ -200,10 +215,10 @@ DialogueHelper::DialogueHelper(DialogueEntry const* pDialogueArray) : {} /** -Constructor for DialogueHelper (Two Sides) -@param pDialogueTwoSideArray The static const array of DialogueEntryTwoSide holding the information about the dialogue. This array MUST be terminated by {0,0,0,0,0} + Constructor for DialogueHelper (Two Sides) + @param pDialogueTwoSideArray The static const array of DialogueEntryTwoSide holding the information about the dialogue. This array MUST be terminated by {0,0,0,0,0} */ -DialogueHelper::DialogueHelper(DialogueEntryTwoSide const* pDialogueTwoSideArray) : +DialogueHelper::DialogueHelper(SIDialogueEntryTwoSide const* pDialogueTwoSideArray) : m_pInstance(nullptr), m_pDialogueArray(nullptr), m_pCurrentEntry(nullptr), @@ -215,8 +230,8 @@ DialogueHelper::DialogueHelper(DialogueEntryTwoSide const* pDialogueTwoSideArray {} /** -Function to start a (part of a) dialogue -@param iTextEntry The TextEntry of the dialogue that will be started (must be always the entry of first side) + Function to start a (part of a) dialogue + @param iTextEntry The TextEntry of the dialogue that will be started (must be always the entry of first side) */ void DialogueHelper::StartNextDialogueText(int32 iTextEntry) { @@ -225,7 +240,7 @@ void DialogueHelper::StartNextDialogueText(int32 iTextEntry) if (m_pDialogueArray) // One Side { - for (DialogueEntry const* pEntry = m_pDialogueArray; pEntry->iTextEntry; ++pEntry) + for (SIDialogueEntry const* pEntry = m_pDialogueArray; pEntry->iTextEntry; ++pEntry) { if (pEntry->iTextEntry == iTextEntry) { @@ -237,7 +252,7 @@ void DialogueHelper::StartNextDialogueText(int32 iTextEntry) } else // Two Sides { - for (DialogueEntryTwoSide const* pEntry = m_pDialogueTwoSideArray; pEntry->iTextEntry; ++pEntry) + for (SIDialogueEntryTwoSide const* pEntry = m_pDialogueTwoSideArray; pEntry->iTextEntry; ++pEntry) { if (pEntry->iTextEntry == iTextEntry) { @@ -246,11 +261,11 @@ void DialogueHelper::StartNextDialogueText(int32 iTextEntry) break; } } - } + } if (!bFound) { - script_error_log("Script call DialogueHelper::StartNextDialogueText, but textEntry %i is not in provided dialogue (on map id %u)", iTextEntry, m_pInstance ? m_pInstance->instance->GetId() : 0); + sLog.outError("Script call DialogueHelper::StartNextDialogueText, but textEntry %i is not in provided dialogue (on map id %u)", iTextEntry, m_pInstance ? m_pInstance->instance->GetId() : 0); return; } @@ -304,7 +319,7 @@ void DialogueHelper::DoNextDialogueStep() DoScriptText(iTextEntry, pSpeaker); } - JustDidDialogueStep(m_pDialogueArray ? m_pCurrentEntry->iTextEntry : m_pCurrentEntryTwoSide->iTextEntry); + JustDidDialogueStep(m_pDialogueArray ? m_pCurrentEntry->iTextEntry : m_pCurrentEntryTwoSide->iTextEntry); // Increment position if (m_pDialogueArray) @@ -323,4 +338,4 @@ void DialogueHelper::DialogueUpdate(uint32 uiDiff) else m_uiTimer -= uiDiff; } -} \ No newline at end of file +} diff --git a/src/game/AI/ScriptedInstance.h b/src/game/AI/ScriptedInstance.h index 9c6b06893..09aa51c52 100644 --- a/src/game/AI/ScriptedInstance.h +++ b/src/game/AI/ScriptedInstance.h @@ -49,13 +49,15 @@ class MANGOS_DLL_DECL ScriptedInstance : public InstanceData std::string GenSaveData(uint32* encounters, uint32 maxIndex); void LoadSaveData(const char* pStr, uint32* encounters, uint32 maxIndex); - /// Wrapper for simulating map-wide text in this instance. It is expected that the Creature is stored in m_mNpcEntryGuidStore if loaded. - void DoOrSimulateScriptTextForThisInstance(int32 iTextEntry, uint32 uiCreatureEntry) - { - // Prevent debug output in GetSingleCreatureFromStorage - DoOrSimulateScriptTextForMap(iTextEntry, uiCreatureEntry, instance, GetSingleCreatureFromStorage(uiCreatureEntry, true)); - } + // Get a Player from map + Player* GetPlayerInMap(bool bOnlyAlive = false, bool bCanBeGamemaster = true); + /// Wrapper for simulating map-wide text in this instance. It is expected that the Creature is stored in m_mNpcEntryGuidStore if loaded. + void DoOrSimulateScriptTextForThisInstance(int32 iTextEntry, uint32 uiCreatureEntry) + { + // Prevent debug output in GetSingleCreatureFromStorage + DoOrSimulateScriptTextForMap(iTextEntry, uiCreatureEntry, instance, GetSingleCreatureFromStorage(uiCreatureEntry, true)); + } protected: // Storage for GO-Guids and NPC-Guids typedef std::map EntryGuidMap; @@ -73,19 +75,9 @@ protected: std::map boss_expirations; // For PTR testes }; -class MANGOS_DLL_DECL ScriptedInstance_PTR : public ScriptedInstance -{ -public: - explicit ScriptedInstance_PTR(Map* pMap) : ScriptedInstance(pMap) {} - void OnCreatureEnterCombat(Creature* creature) override; - void Update(uint32 diff) override; -protected: - std::map boss_expirations; // For PTR testes -}; - /// A static const array of this structure must be handled to DialogueHelper -struct DialogueEntry +struct SIDialogueEntry { int32 iTextEntry; ///< To be said text entry uint32 uiSayerEntry; ///< Entry of the mob who should say @@ -93,7 +85,7 @@ struct DialogueEntry }; /// A static const array of this structure must be handled to DialogueHelper -struct DialogueEntryTwoSide +struct SIDialogueEntryTwoSide { int32 iTextEntry; ///< To be said text entry (first side) uint32 uiSayerEntry; ///< Entry of the mob who should say (first side) @@ -107,9 +99,9 @@ class DialogueHelper { public: // The array MUST be terminated by {0,0,0} - DialogueHelper(DialogueEntry const* pDialogueArray); + DialogueHelper(SIDialogueEntry const* pDialogueArray); // The array MUST be terminated by {0,0,0,0,0} - DialogueHelper(DialogueEntryTwoSide const* aDialogueTwoSide); + DialogueHelper(SIDialogueEntryTwoSide const* aDialogueTwoSide); /// Function to initialize the dialogue helper for instances. If not used with instances, GetSpeakerByEntry MUST be overwritten to obtain the speakers void InitializeDialogueHelper(ScriptedInstance* pInstance, bool bCanSimulateText = false) { m_pInstance = pInstance; m_bCanSimulate = bCanSimulateText; } @@ -131,10 +123,10 @@ private: ScriptedInstance* m_pInstance; - DialogueEntry const* m_pDialogueArray; - DialogueEntry const* m_pCurrentEntry; - DialogueEntryTwoSide const* m_pDialogueTwoSideArray; - DialogueEntryTwoSide const* m_pCurrentEntryTwoSide; + SIDialogueEntry const* m_pDialogueArray; + SIDialogueEntry const* m_pCurrentEntry; + SIDialogueEntryTwoSide const* m_pDialogueTwoSideArray; + SIDialogueEntryTwoSide const* m_pCurrentEntryTwoSide; uint32 m_uiTimer; bool m_bIsFirstSide; diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 627ed1521..806b19c17 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -6877,7 +6877,7 @@ void ObjectMgr::LoadGameObjectForQuests() sLog.outString(">> Loaded %u GameObjects for quests", count); } -bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value) +bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value, bool extra_content) { int32 start_value = min_value; int32 end_value = max_value; @@ -6913,7 +6913,7 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min ++itr; } - QueryResult *result = db.PQuery("SELECT entry,content_default,content_loc1,content_loc2,content_loc3,content_loc4,content_loc5,content_loc6,content_loc7,content_loc8 FROM %s", table); + QueryResult *result = db.PQuery("SELECT entry,content_default,content_loc1,content_loc2,content_loc3,content_loc4,content_loc5,content_loc6,content_loc7,content_loc8 %s FROM %s", extra_content ? ",sound,type,language,emote" : "", table); if (!result) { @@ -6981,6 +6981,40 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min } } } + + + // Load additional string content if necessary + if (extra_content) + { + data.SoundId = fields[10].GetUInt32(); + data.Type = fields[11].GetUInt32(); + data.LanguageId = Language(fields[12].GetUInt32()); + data.Emote = fields[13].GetUInt32(); + + if (data.SoundId && !sSoundEntriesStore.LookupEntry(data.SoundId)) + { + sLog.outErrorDb("Entry %i in table `%s` has soundId %u but sound does not exist.", entry, table, data.SoundId); + data.SoundId = 0; + } + + if (!GetLanguageDescByID(data.LanguageId)) + { + sLog.outErrorDb("Entry %i in table `%s` using Language %u but Language does not exist.", entry, table, uint32(data.LanguageId)); + data.LanguageId = LANG_UNIVERSAL; + } + + if (data.Type > CHAT_TYPE_ZONE_YELL) + { + sLog.outErrorDb("Entry %i in table `%s` has Type %u but this Chat Type does not exist.", entry, table, data.Type); + data.Type = CHAT_TYPE_SAY; + } + + if (data.Emote && !sEmotesStore.LookupEntry(data.Emote)) + { + sLog.outErrorDb("Entry %i in table `%s` has Emote %u but emote does not exist.", entry, table, data.Emote); + data.Emote = EMOTE_ONESHOT_NONE; + } + } } while (result->NextRow()); @@ -8006,7 +8040,7 @@ void ObjectMgr::RemoveGroup(Group* group) } // Functions for scripting access -bool LoadMangosStrings(DatabaseType& db, char const* table, int32 start_value, int32 end_value) +bool LoadMangosStrings(DatabaseType& db, char const* table, int32 start_value, int32 end_value, bool extra_content) { // MAX_DB_SCRIPT_STRING_ID is max allowed negative value for scripts (scrpts can use only more deep negative values // start/end reversed for negative values @@ -8016,7 +8050,7 @@ bool LoadMangosStrings(DatabaseType& db, char const* table, int32 start_value, i return false; } - return sObjectMgr.LoadMangosStrings(db, table, start_value, end_value); + return sObjectMgr.LoadMangosStrings(db, table, start_value, end_value, extra_content); } CreatureInfo const* GetCreatureTemplateStore(uint32 entry) diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 8ca539cf7..126555387 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -1,8 +1,6 @@ /* * Copyright (C) 2005-2011 MaNGOS * Copyright (C) 2009-2011 MaNGOSZero - * Copyright (C) 2011-2016 Nostalrius - * Copyright (C) 2016-2017 Elysium Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -110,7 +108,13 @@ typedef UNORDERED_MAP MapObjectGuids; struct MangosStringLocale { + MangosStringLocale() : SoundId(0), Type(0), LanguageId(LANG_UNIVERSAL), Emote(0) { } + std::vector Content; // 0 -> default, i -> i-1 locale index + uint32 SoundId; + uint8 Type; + Language LanguageId; + uint32 Emote; }; typedef UNORDERED_MAP CreatureDataMap; @@ -485,8 +489,8 @@ enum PermVariables DEF_STOP_DELAY = 5, // default times event check will not stop the event NPC_YSONDRE = 14887, - NPC_LETHON = 14888, - NPC_EMERISS = 14889, + NPC_LETHON = 14888, + NPC_EMERISS = 14889, NPC_TAERAR = 14890, GUID_YSONDRE = 52350, @@ -739,8 +743,8 @@ class ObjectMgr void LoadCreatureQuestRelations(); void LoadCreatureInvolvedRelations(); - bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value); - bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); } + bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value, bool extra_content); + bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID, false); } bool LoadNostalriusStrings(); void LoadPetCreateSpells(); void LoadCreatureLocales(); @@ -1337,7 +1341,7 @@ class ObjectMgr #define sObjectMgr MaNGOS::Singleton::Instance() // scripting access functions -MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = MAX_CREATURE_AI_TEXT_STRING_ID, int32 end_value = std::numeric_limits::min()); +MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = MAX_CREATURE_AI_TEXT_STRING_ID, int32 end_value = std::numeric_limits::min(), bool extra_content = false); MANGOS_DLL_SPEC CreatureInfo const* GetCreatureTemplateStore(uint32 entry); MANGOS_DLL_SPEC Quest const* GetQuestTemplateStore(uint32 entry); diff --git a/src/game/ScriptMgr.cpp b/src/game/ScriptMgr.cpp index 71ea1e856..f7d495e82 100644 --- a/src/game/ScriptMgr.cpp +++ b/src/game/ScriptMgr.cpp @@ -1,8 +1,6 @@ /* * Copyright (C) 2005-2011 MaNGOS * Copyright (C) 2009-2011 MaNGOSZero - * Copyright (C) 2011-2016 Nostalrius - * Copyright (C) 2016-2017 Elysium Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -682,7 +680,7 @@ void ScriptMgr::LoadCreatureMovementScripts() void ScriptMgr::LoadDbScriptStrings() { - sObjectMgr.LoadMangosStrings(WorldDatabase, "db_script_string", MIN_DB_SCRIPT_STRING_ID, MAX_DB_SCRIPT_STRING_ID); + sObjectMgr.LoadMangosStrings(WorldDatabase, "db_script_string", MIN_DB_SCRIPT_STRING_ID, MAX_DB_SCRIPT_STRING_ID, false); std::set ids; @@ -790,7 +788,7 @@ void ScriptMgr::LoadEventIdScripts() BarGoLink bar(result->GetRowCount()); std::set eventIds; // Store possible event ids - + CollectPossibleEventIds(eventIds); do @@ -1241,7 +1239,7 @@ void ScriptMgr::LoadDatabase() void ScriptMgr::LoadScriptTexts() { sLog.outString("Loading Script Texts..."); - LoadMangosStrings(WorldDatabase, "script_texts", TEXT_SOURCE_TEXT_START, TEXT_SOURCE_TEXT_END); + LoadMangosStrings(WorldDatabase, "script_texts", TEXT_SOURCE_TEXT_START, TEXT_SOURCE_TEXT_END, true); QueryResult* result = WorldDatabase.PQuery("SELECT entry, sound, type, language, emote FROM script_texts WHERE entry BETWEEN %i AND %i", TEXT_SOURCE_GOSSIP_END, TEXT_SOURCE_TEXT_START); @@ -1303,7 +1301,7 @@ void ScriptMgr::LoadScriptTexts() void ScriptMgr::LoadScriptTextsCustom() { sLog.outString("Loading Custom Texts..."); - LoadMangosStrings(WorldDatabase, "custom_texts", TEXT_SOURCE_CUSTOM_START, TEXT_SOURCE_CUSTOM_END); + LoadMangosStrings(WorldDatabase, "custom_texts", TEXT_SOURCE_CUSTOM_START, TEXT_SOURCE_CUSTOM_END, true); QueryResult* result = WorldDatabase.PQuery("SELECT entry, sound, type, language, emote FROM custom_texts WHERE entry BETWEEN %i AND %i", TEXT_SOURCE_CUSTOM_END, TEXT_SOURCE_CUSTOM_START); @@ -1624,6 +1622,62 @@ void DoScriptText(int32 iTextEntry, WorldObject* pSource, Unit* pTarget) } } + +/** + * Function that either simulates or does script text for a map + * + * @param iTextEntry Entry of the text, stored in SD2-database, only type CHAT_TYPE_ZONE_YELL supported + * @param uiCreatureEntry Id of the creature of whom saying will be simulated + * @param pMap Given Map on which the map-wide text is displayed + * @param pCreatureSource Can be nullptr. If pointer to Creature is given, then the creature does the map-wide text + * @param pTarget Can be nullptr. Possible target for the text + */ +void DoOrSimulateScriptTextForMap(int32 iTextEntry, uint32 uiCreatureEntry, Map* pMap, Creature* pCreatureSource /*=nullptr*/, Unit* pTarget /*=nullptr*/) +{ + if (!pMap) + { + sLog.outError("DoOrSimulateScriptTextForMap entry %i, invalid Map pointer.", iTextEntry); + return; + } + + if (iTextEntry >= 0) + { + sLog.outError("DoOrSimulateScriptTextForMap with source entry %u for map %u attempts to process text entry %i, but text entry must be negative.", uiCreatureEntry, pMap->GetId(), iTextEntry); + return; + } + + CreatureInfo const* pInfo = GetCreatureTemplateStore(uiCreatureEntry); + if (!pInfo) + { + sLog.outError("DoOrSimulateScriptTextForMap has invalid source entry %u for map %u.", uiCreatureEntry, pMap->GetId()); + return; + } + + MangosStringLocale const* pData = sObjectMgr.GetMangosStringLocale(iTextEntry); + if (!pData) + { + sLog.outError("DoOrSimulateScriptTextForMap with source entry %u for map %u could not find text entry %i.", uiCreatureEntry, pMap->GetId(), iTextEntry); + return; + } + + sLog.outDebug("SD2: DoOrSimulateScriptTextForMap: text entry=%i, Sound=%u, Type=%u, Language=%u, Emote=%u", + iTextEntry, pData->SoundId, pData->Type, pData->LanguageId, pData->Emote); + + if (pData->Type != CHAT_TYPE_ZONE_YELL) + { + sLog.outError("DoSimulateScriptTextForMap entry %i has not supported chat type %u.", iTextEntry, pData->Type); + return; + } + + if (pData->SoundId) + pMap->PlayDirectSoundToMap(pData->SoundId); + + if (pCreatureSource) // If provided pointer for sayer, use direct version + pMap->MonsterYellToMap(pCreatureSource->GetObjectGuid(), iTextEntry, pData->LanguageId, pTarget); + else // Simulate yell + pMap->MonsterYellToMap(pInfo, iTextEntry, pData->LanguageId, pTarget); +} + void Script::RegisterSelf(bool bReportError) { if (uint32 id = sScriptMgr.GetScriptId(Name.c_str())) @@ -1724,4 +1778,3 @@ void ScriptMgr::FillSpellSummary() } } } - diff --git a/src/game/ScriptMgr.h b/src/game/ScriptMgr.h index 8f560a960..590d818ea 100644 --- a/src/game/ScriptMgr.h +++ b/src/game/ScriptMgr.h @@ -1,8 +1,6 @@ /* * Copyright (C) 2005-2011 MaNGOS * Copyright (C) 2009-2011 MaNGOSZero - * Copyright (C) 2011-2016 Nostalrius - * Copyright (C) 2016-2017 Elysium Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -640,6 +638,7 @@ class ScriptMgr //Generic scripting text function void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target = nullptr); +void DoOrSimulateScriptTextForMap(int32 iTextEntry, uint32 uiCreatureEntry, Map* pMap, Creature* pCreatureSource = nullptr, Unit* pTarget = nullptr); #define sScriptMgr MaNGOS::Singleton::Instance()