diff --git a/Source/Game/DataStorage/ConversationDataStorage.cs b/Source/Game/DataStorage/ConversationDataStorage.cs index 442ad2826..13da98827 100644 --- a/Source/Game/DataStorage/ConversationDataStorage.cs +++ b/Source/Game/DataStorage/ConversationDataStorage.cs @@ -113,6 +113,21 @@ namespace Game.DataStorage Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation actors. DB table `conversation_actors` is empty."); } + // Validate FirstLineId + Dictionary prevConversationLineIds = new(); + foreach (var conversationLine in CliDB.ConversationLineStorage.Values) + if (conversationLine.NextConversationLineID != 0) + prevConversationLineIds[conversationLine.NextConversationLineID] = conversationLine.Id; + + uint getFirstLineIdFromAnyLineId(uint lineId) + { + uint prevLineId; + while ((prevLineId = prevConversationLineIds.LookupByKey(lineId)) != 0) + lineId = prevLineId; + + return lineId; + } + SQLResult templateResult = DB.World.Query("SELECT Id, FirstLineId, TextureKitId, ScriptName FROM conversation_template"); if (!templateResult.IsEmpty()) { @@ -128,6 +143,13 @@ namespace Game.DataStorage conversationTemplate.Actors = actorsByConversation.TryGetValue(conversationTemplate.Id, out var actors) ? actors.ToList() : null; + uint correctedFirstLineId = getFirstLineIdFromAnyLineId(conversationTemplate.FirstLineId); + if (conversationTemplate.FirstLineId != correctedFirstLineId) + { + Log.outError(LogFilter.Sql, $"Table `conversation_template` has incorrect FirstLineId {conversationTemplate.FirstLineId}, it should be {correctedFirstLineId} for Conversation {conversationTemplate.Id}, corrected"); + conversationTemplate.FirstLineId = correctedFirstLineId; + } + ConversationLineRecord currentConversationLine = CliDB.ConversationLineStorage.LookupByKey(conversationTemplate.FirstLineId); if (currentConversationLine == null) Log.outError(LogFilter.Sql, "Table `conversation_template` references an invalid line (ID: {0}) for Conversation {1}, skipped", conversationTemplate.FirstLineId, conversationTemplate.Id);