Added DB-support for conversation actorGuids
This commit is contained in:
@@ -394,6 +394,7 @@ public enum LogFilter
|
|||||||
Cheat,
|
Cheat,
|
||||||
Commands,
|
Commands,
|
||||||
Condition,
|
Condition,
|
||||||
|
Conversation,
|
||||||
Garrison,
|
Garrison,
|
||||||
Gameevent,
|
Gameevent,
|
||||||
Guild,
|
Guild,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ using Framework.Database;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Game.Entities;
|
||||||
|
|
||||||
namespace Game.DataStorage
|
namespace Game.DataStorage
|
||||||
{
|
{
|
||||||
@@ -33,6 +34,7 @@ namespace Game.DataStorage
|
|||||||
_conversationTemplateStorage.Clear();
|
_conversationTemplateStorage.Clear();
|
||||||
|
|
||||||
Dictionary<uint, ConversationActorTemplate[]> actorsByConversation = new Dictionary<uint, ConversationActorTemplate[]>();
|
Dictionary<uint, ConversationActorTemplate[]> actorsByConversation = new Dictionary<uint, ConversationActorTemplate[]>();
|
||||||
|
Dictionary<uint, ulong[]> actorGuidsByConversation = new Dictionary<uint, ulong[]>();
|
||||||
|
|
||||||
SQLResult actorTemplates = DB.World.Query("SELECT Id, CreatureId, CreatureModelId FROM conversation_actor_template");
|
SQLResult actorTemplates = DB.World.Query("SELECT Id, CreatureId, CreatureModelId FROM conversation_actor_template");
|
||||||
if (!actorTemplates.IsEmpty())
|
if (!actorTemplates.IsEmpty())
|
||||||
@@ -91,7 +93,7 @@ namespace Game.DataStorage
|
|||||||
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation line templates. DB table `conversation_line_template` is empty.");
|
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation line templates. DB table `conversation_line_template` is empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLResult actorResult = DB.World.Query("SELECT ConversationId, ConversationActorId, Idx FROM conversation_actors");
|
SQLResult actorResult = DB.World.Query("SELECT ConversationId, ConversationActorId, ConversationActorGuid, Idx FROM conversation_actors");
|
||||||
if (!actorResult.IsEmpty())
|
if (!actorResult.IsEmpty())
|
||||||
{
|
{
|
||||||
uint oldMSTime = Time.GetMSTime();
|
uint oldMSTime = Time.GetMSTime();
|
||||||
@@ -101,23 +103,51 @@ namespace Game.DataStorage
|
|||||||
{
|
{
|
||||||
uint conversationId = actorResult.Read<uint>(0);
|
uint conversationId = actorResult.Read<uint>(0);
|
||||||
uint actorId = actorResult.Read<uint>(1);
|
uint actorId = actorResult.Read<uint>(1);
|
||||||
ushort idx = actorResult.Read<ushort>(2);
|
ulong actorGuid = actorResult.Read<ulong>(2);
|
||||||
|
ushort idx = actorResult.Read<ushort>(3);
|
||||||
|
|
||||||
ConversationActorTemplate conversationActorTemplate = _conversationActorTemplateStorage.LookupByKey(actorId);
|
if (actorId != 0 && actorGuid != 0)
|
||||||
if (conversationActorTemplate != null)
|
|
||||||
{
|
{
|
||||||
if (!actorsByConversation.ContainsKey(conversationId))
|
Log.outError(LogFilter.Sql, $"Table `conversation_actors` references both actor (ID: {actorId}) and actorGuid (GUID: {actorGuid}) for Conversation {conversationId}, skipped.");
|
||||||
actorsByConversation[conversationId] = new ConversationActorTemplate[idx + 1];
|
continue;
|
||||||
|
|
||||||
ConversationActorTemplate[] actors = actorsByConversation[conversationId];
|
|
||||||
if (actors.Length <= idx)
|
|
||||||
Array.Resize(ref actors, idx + 1);
|
|
||||||
|
|
||||||
actors[idx] = conversationActorTemplate;
|
|
||||||
++count;
|
|
||||||
}
|
}
|
||||||
else
|
if (actorId != 0)
|
||||||
Log.outError(LogFilter.Sql, "Table `conversation_actors` references an invalid actor (ID: {0}) for Conversation {1}, skipped", actorId, conversationId);
|
{
|
||||||
|
ConversationActorTemplate conversationActorTemplate = _conversationActorTemplateStorage.LookupByKey(actorId);
|
||||||
|
if (conversationActorTemplate != null)
|
||||||
|
{
|
||||||
|
if (!actorsByConversation.ContainsKey(conversationId))
|
||||||
|
actorsByConversation[conversationId] = new ConversationActorTemplate[idx + 1];
|
||||||
|
|
||||||
|
ConversationActorTemplate[] actors = actorsByConversation[conversationId];
|
||||||
|
if (actors.Length <= idx)
|
||||||
|
Array.Resize(ref actors, idx + 1);
|
||||||
|
|
||||||
|
actors[idx] = conversationActorTemplate;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Log.outError(LogFilter.Sql, "Table `conversation_actors` references an invalid actor (ID: {0}) for Conversation {1}, skipped", actorId, conversationId);
|
||||||
|
}
|
||||||
|
else if (actorGuid != 0)
|
||||||
|
{
|
||||||
|
CreatureData creData = Global.ObjectMgr.GetCreatureData(actorGuid);
|
||||||
|
if (creData != null)
|
||||||
|
{
|
||||||
|
if (!actorGuidsByConversation.ContainsKey(conversationId))
|
||||||
|
actorGuidsByConversation[conversationId] = new ulong[idx + 1];
|
||||||
|
|
||||||
|
var guids = actorGuidsByConversation[conversationId];
|
||||||
|
if (guids.Length <= idx)
|
||||||
|
Array.Resize(ref guids, idx + 1);
|
||||||
|
|
||||||
|
guids[idx] = actorGuid;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Log.outError(LogFilter.Sql, $"Table `conversation_actors` references an invalid creature guid (GUID: {actorGuid}) for Conversation {conversationId}, skipped");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
while (actorResult.NextRow());
|
while (actorResult.NextRow());
|
||||||
|
|
||||||
@@ -141,6 +171,7 @@ namespace Game.DataStorage
|
|||||||
conversationTemplate.LastLineEndTime = templateResult.Read<uint>(2);
|
conversationTemplate.LastLineEndTime = templateResult.Read<uint>(2);
|
||||||
|
|
||||||
conversationTemplate.Actors = actorsByConversation[conversationTemplate.Id].ToList();
|
conversationTemplate.Actors = actorsByConversation[conversationTemplate.Id].ToList();
|
||||||
|
conversationTemplate.ActorGuids = actorGuidsByConversation[conversationTemplate.Id].ToList();
|
||||||
|
|
||||||
ConversationLineRecord currentConversationLine = CliDB.ConversationLineStorage.LookupByKey(conversationTemplate.FirstLineId);
|
ConversationLineRecord currentConversationLine = CliDB.ConversationLineStorage.LookupByKey(conversationTemplate.FirstLineId);
|
||||||
if (currentConversationLine == null)
|
if (currentConversationLine == null)
|
||||||
@@ -205,6 +236,7 @@ namespace Game.DataStorage
|
|||||||
public uint LastLineEndTime; // Time in ms after conversation creation the last line fades out
|
public uint LastLineEndTime; // Time in ms after conversation creation the last line fades out
|
||||||
|
|
||||||
public List<ConversationActorTemplate> Actors = new List<ConversationActorTemplate>();
|
public List<ConversationActorTemplate> Actors = new List<ConversationActorTemplate>();
|
||||||
|
public List<ulong> ActorGuids = new List<ulong>();
|
||||||
public List<ConversationLineTemplate> Lines = new List<ConversationLineTemplate>();
|
public List<ConversationLineTemplate> Lines = new List<ConversationLineTemplate>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,23 +120,48 @@ namespace Game.Entities
|
|||||||
SetUInt32Value(ConversationFields.LastLineEndTime, conversationTemplate.LastLineEndTime);
|
SetUInt32Value(ConversationFields.LastLineEndTime, conversationTemplate.LastLineEndTime);
|
||||||
_duration = conversationTemplate.LastLineEndTime;
|
_duration = conversationTemplate.LastLineEndTime;
|
||||||
|
|
||||||
ushort actorsIndex = 0;
|
for (ushort actorIndex = 0; actorIndex < conversationTemplate.Actors.Count; ++actorIndex)
|
||||||
foreach (ConversationActorTemplate actor in conversationTemplate.Actors)
|
|
||||||
{
|
{
|
||||||
|
ConversationActorTemplate actor = conversationTemplate.Actors[actorIndex];
|
||||||
if (actor != null)
|
if (actor != null)
|
||||||
{
|
{
|
||||||
ConversationDynamicFieldActor actorField = new ConversationDynamicFieldActor();
|
ConversationDynamicFieldActor actorField = new ConversationDynamicFieldActor();
|
||||||
actorField.ActorTemplate = actor;
|
actorField.ActorTemplate = actor;
|
||||||
actorField.Type = ConversationDynamicFieldActor.ActorType.CreatureActor;
|
actorField.Type = ConversationDynamicFieldActor.ActorType.CreatureActor;
|
||||||
SetDynamicStructuredValue(ConversationDynamicFields.Actors, actorsIndex++, actorField);
|
SetDynamicStructuredValue(ConversationDynamicFields.Actors, actorIndex, actorField);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
++actorsIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ushort linesIndex = 0;
|
for (ushort actorIndex = 0; actorIndex < conversationTemplate.ActorGuids.Count; ++actorIndex)
|
||||||
|
{
|
||||||
|
ulong actorGuid = conversationTemplate.ActorGuids[actorIndex];
|
||||||
|
if (actorGuid == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var creature in map.GetCreatureBySpawnIdStore().LookupByKey(actorGuid))
|
||||||
|
{
|
||||||
|
// we just need the last one, overriding is legit
|
||||||
|
AddActor(creature.GetGUID(), actorIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ushort> actorIndices = new List<ushort>();
|
||||||
foreach (ConversationLineTemplate line in conversationTemplate.Lines)
|
foreach (ConversationLineTemplate line in conversationTemplate.Lines)
|
||||||
SetDynamicStructuredValue(ConversationDynamicFields.Lines, linesIndex++, line);
|
{
|
||||||
|
actorIndices.Add(line.ActorIdx);
|
||||||
|
AddDynamicStructuredValue(ConversationDynamicFields.Lines, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
// All actors need to be set
|
||||||
|
foreach (ushort actorIndex in actorIndices)
|
||||||
|
{
|
||||||
|
ConversationDynamicFieldActor actor = GetDynamicStructuredValue<ConversationDynamicFieldActor>(ConversationDynamicFields.Actors, actorIndex);
|
||||||
|
if (actor == null || actor.IsEmpty())
|
||||||
|
{
|
||||||
|
Log.outError(LogFilter.Conversation, $"Failed to create conversation (Id: {conversationEntry}) due to missing actor (Idx: {actorIndex}).");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!GetMap().AddToMap(this))
|
if (!GetMap().AddToMap(this))
|
||||||
return false;
|
return false;
|
||||||
@@ -181,6 +206,11 @@ namespace Game.Entities
|
|||||||
CreatureActor = 1
|
CreatureActor = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsEmpty()
|
||||||
|
{
|
||||||
|
return ActorGuid.IsEmpty(); // this one is good enough
|
||||||
|
}
|
||||||
|
|
||||||
public ObjectGuid ActorGuid;
|
public ObjectGuid ActorGuid;
|
||||||
public ConversationActorTemplate ActorTemplate;
|
public ConversationActorTemplate ActorTemplate;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user