Added DB-support for conversation actorGuids

This commit is contained in:
hondacrx
2017-11-05 16:55:27 -05:00
parent f6d034b7e5
commit f81a877ad3
3 changed files with 85 additions and 22 deletions
+1
View File
@@ -394,6 +394,7 @@ public enum LogFilter
Cheat,
Commands,
Condition,
Conversation,
Garrison,
Gameevent,
Guild,
@@ -19,6 +19,7 @@ using Framework.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using Game.Entities;
namespace Game.DataStorage
{
@@ -33,6 +34,7 @@ namespace Game.DataStorage
_conversationTemplateStorage.Clear();
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");
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.");
}
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())
{
uint oldMSTime = Time.GetMSTime();
@@ -101,8 +103,16 @@ namespace Game.DataStorage
{
uint conversationId = actorResult.Read<uint>(0);
uint actorId = actorResult.Read<uint>(1);
ushort idx = actorResult.Read<ushort>(2);
ulong actorGuid = actorResult.Read<ulong>(2);
ushort idx = actorResult.Read<ushort>(3);
if (actorId != 0 && actorGuid != 0)
{
Log.outError(LogFilter.Sql, $"Table `conversation_actors` references both actor (ID: {actorId}) and actorGuid (GUID: {actorGuid}) for Conversation {conversationId}, skipped.");
continue;
}
if (actorId != 0)
{
ConversationActorTemplate conversationActorTemplate = _conversationActorTemplateStorage.LookupByKey(actorId);
if (conversationActorTemplate != null)
{
@@ -119,6 +129,26 @@ namespace Game.DataStorage
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());
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} Conversation actors in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
@@ -141,6 +171,7 @@ namespace Game.DataStorage
conversationTemplate.LastLineEndTime = templateResult.Read<uint>(2);
conversationTemplate.Actors = actorsByConversation[conversationTemplate.Id].ToList();
conversationTemplate.ActorGuids = actorGuidsByConversation[conversationTemplate.Id].ToList();
ConversationLineRecord currentConversationLine = CliDB.ConversationLineStorage.LookupByKey(conversationTemplate.FirstLineId);
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 List<ConversationActorTemplate> Actors = new List<ConversationActorTemplate>();
public List<ulong> ActorGuids = new List<ulong>();
public List<ConversationLineTemplate> Lines = new List<ConversationLineTemplate>();
}
+37 -7
View File
@@ -120,23 +120,48 @@ namespace Game.Entities
SetUInt32Value(ConversationFields.LastLineEndTime, conversationTemplate.LastLineEndTime);
_duration = conversationTemplate.LastLineEndTime;
ushort actorsIndex = 0;
foreach (ConversationActorTemplate actor in conversationTemplate.Actors)
for (ushort actorIndex = 0; actorIndex < conversationTemplate.Actors.Count; ++actorIndex)
{
ConversationActorTemplate actor = conversationTemplate.Actors[actorIndex];
if (actor != null)
{
ConversationDynamicFieldActor actorField = new ConversationDynamicFieldActor();
actorField.ActorTemplate = actor;
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)
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))
return false;
@@ -181,6 +206,11 @@ namespace Game.Entities
CreatureActor = 1
}
public bool IsEmpty()
{
return ActorGuid.IsEmpty(); // this one is good enough
}
public ObjectGuid ActorGuid;
public ConversationActorTemplate ActorTemplate;