Core/Conversations: Dropped time fields and calculate them using db2 data
Port From (https://github.com/TrinityCore/TrinityCore/commit/94b14e4f6355a7bab8004dcc2ecadadbc52833de)
This commit is contained in:
@@ -18,9 +18,11 @@
|
||||
using Framework.Constants;
|
||||
using Game.DataStorage;
|
||||
using Game.Maps;
|
||||
using Game.Spells;
|
||||
using System.Collections.Generic;
|
||||
using Game.Networking;
|
||||
using Game.Spells;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Entities
|
||||
{
|
||||
@@ -28,8 +30,6 @@ namespace Game.Entities
|
||||
{
|
||||
public Conversation() : base(false)
|
||||
{
|
||||
_duration = 0;
|
||||
|
||||
ObjectTypeMask |= TypeMask.Conversation;
|
||||
ObjectTypeId = TypeId.Conversation;
|
||||
|
||||
@@ -61,9 +61,9 @@ namespace Game.Entities
|
||||
|
||||
public override void Update(uint diff)
|
||||
{
|
||||
if (GetDuration() > diff)
|
||||
if (GetDuration() > TimeSpan.FromMilliseconds(diff))
|
||||
{
|
||||
_duration -= diff;
|
||||
_duration -= TimeSpan.FromMilliseconds(diff);
|
||||
DoWithSuppressingObjectUpdates(() =>
|
||||
{
|
||||
// Only sent in CreateObject
|
||||
@@ -121,8 +121,6 @@ namespace Game.Entities
|
||||
SetEntry(conversationEntry);
|
||||
SetObjectScale(1.0f);
|
||||
|
||||
SetUpdateFieldValue(m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.LastLineEndTime), conversationTemplate.LastLineEndTime);
|
||||
_duration = conversationTemplate.LastLineEndTime + 10 * Time.InMilliseconds;
|
||||
_textureKitId = conversationTemplate.TextureKitId;
|
||||
|
||||
if (conversationTemplate.Actors != null)
|
||||
@@ -171,16 +169,38 @@ namespace Game.Entities
|
||||
|
||||
ConversationLine lineField = new();
|
||||
lineField.ConversationLineID = line.Id;
|
||||
lineField.StartTime = line.StartTime;
|
||||
lineField.UiCameraID = line.UiCameraID;
|
||||
lineField.ActorIndex = line.ActorIdx;
|
||||
lineField.Flags = line.Flags;
|
||||
|
||||
ConversationLineRecord convoLine = CliDB.ConversationLineStorage.LookupByKey(line.Id); // never null for conversationTemplate->Lines
|
||||
|
||||
for (Locale locale = Locale.enUS; locale < Locale.Total; locale = locale + 1)
|
||||
{
|
||||
if (locale == Locale.None)
|
||||
continue;
|
||||
|
||||
_lineStartTimes[(locale, line.Id)] = _lastLineEndTimes[(int)locale];
|
||||
if (locale == Locale.enUS)
|
||||
lineField.StartTime = (uint)_lastLineEndTimes[(int)locale].TotalMilliseconds;
|
||||
|
||||
int broadcastTextDuration = Global.DB2Mgr.GetBroadcastTextDuration((int)convoLine.BroadcastTextID, locale);
|
||||
if (broadcastTextDuration != 0)
|
||||
_lastLineEndTimes[(int)locale] += TimeSpan.FromMilliseconds(broadcastTextDuration);
|
||||
|
||||
_lastLineEndTimes[(int)locale] += TimeSpan.FromMilliseconds(convoLine.AdditionalDuration);
|
||||
}
|
||||
|
||||
lines.Add(lineField);
|
||||
}
|
||||
|
||||
_duration = _lastLineEndTimes.Max();
|
||||
SetUpdateFieldValue(m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.LastLineEndTime), (uint)_duration.TotalMilliseconds);
|
||||
SetUpdateFieldValue(m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.Lines), lines);
|
||||
|
||||
// conversations are despawned 5-20s after LastLineEndTime
|
||||
_duration += TimeSpan.FromSeconds(10);
|
||||
|
||||
Global.ScriptMgr.OnConversationCreate(this, creator);
|
||||
|
||||
// All actors need to be set
|
||||
@@ -207,6 +227,16 @@ namespace Game.Entities
|
||||
SetUpdateFieldValue(ref actorField.Type, ConversationActorType.WorldObjectActor);
|
||||
}
|
||||
|
||||
public TimeSpan GetLineStartTime(Locale locale, int lineId)
|
||||
{
|
||||
return _lineStartTimes.LookupByKey((locale, lineId));
|
||||
}
|
||||
|
||||
public TimeSpan GetLastLineEndTime(Locale locale)
|
||||
{
|
||||
return _lastLineEndTimes[(int)locale];
|
||||
}
|
||||
|
||||
public uint GetScriptId()
|
||||
{
|
||||
return Global.ConversationDataStorage.GetConversationTemplate(GetEntry()).ScriptId;
|
||||
@@ -274,13 +304,13 @@ namespace Game.Entities
|
||||
base.ClearUpdateMask(remove);
|
||||
}
|
||||
|
||||
uint GetDuration() { return _duration; }
|
||||
TimeSpan GetDuration() { return _duration; }
|
||||
public uint GetTextureKitId() { return _textureKitId; }
|
||||
|
||||
public ObjectGuid GetCreatorGuid() { return _creatorGuid; }
|
||||
public override ObjectGuid GetOwnerGUID() { return GetCreatorGuid(); }
|
||||
public override uint GetFaction() { return 0; }
|
||||
|
||||
|
||||
public override float GetStationaryX() { return _stationaryPosition.GetPositionX(); }
|
||||
public override float GetStationaryY() { return _stationaryPosition.GetPositionY(); }
|
||||
public override float GetStationaryZ() { return _stationaryPosition.GetPositionZ(); }
|
||||
@@ -291,7 +321,10 @@ namespace Game.Entities
|
||||
|
||||
Position _stationaryPosition = new();
|
||||
ObjectGuid _creatorGuid;
|
||||
uint _duration;
|
||||
TimeSpan _duration;
|
||||
uint _textureKitId;
|
||||
|
||||
Dictionary<(Locale locale, uint lineId), TimeSpan> _lineStartTimes = new();
|
||||
TimeSpan[] _lastLineEndTimes = new TimeSpan[(int)Locale.Total];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5622,7 +5622,7 @@ namespace Game.Entities
|
||||
public void WriteCreate(WorldPacket data, Conversation owner, Player receiver)
|
||||
{
|
||||
data.WriteUInt32(ConversationLineID);
|
||||
data.WriteUInt32(StartTime);
|
||||
data.WriteUInt32(GetViewerStartTime(this, owner, receiver));
|
||||
data.WriteUInt32(UiCameraID);
|
||||
data.WriteUInt8(ActorIndex);
|
||||
data.WriteUInt8(Flags);
|
||||
@@ -5632,12 +5632,24 @@ namespace Game.Entities
|
||||
public void WriteUpdate(WorldPacket data, bool ignoreChangesMask, Conversation owner, Player receiver)
|
||||
{
|
||||
data.WriteUInt32(ConversationLineID);
|
||||
data.WriteUInt32(StartTime);
|
||||
data.WriteUInt32(GetViewerStartTime(this, owner, receiver));
|
||||
data.WriteUInt32(UiCameraID);
|
||||
data.WriteUInt8(ActorIndex);
|
||||
data.WriteUInt8(Flags);
|
||||
data.WriteUInt8(ChatType);
|
||||
}
|
||||
|
||||
public uint GetViewerStartTime(ConversationLine conversationLine, Conversation conversation, Player receiver)
|
||||
{
|
||||
uint startTime = conversationLine.StartTime;
|
||||
Locale locale = receiver.GetSession().GetSessionDbLocaleIndex();
|
||||
|
||||
TimeSpan localizedStartTime = conversation.GetLineStartTime(locale, (int)conversationLine.ConversationLineID);
|
||||
if (localizedStartTime != TimeSpan.Zero)
|
||||
startTime = (uint)localizedStartTime.TotalMilliseconds;
|
||||
|
||||
return startTime;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConversationActorField
|
||||
@@ -5685,7 +5697,7 @@ namespace Game.Entities
|
||||
public void WriteCreate(WorldPacket data, UpdateFieldFlag fieldVisibilityFlags, Conversation owner, Player receiver)
|
||||
{
|
||||
data.WriteInt32(((List<ConversationLine>)Lines).Count);
|
||||
data.WriteUInt32(LastLineEndTime);
|
||||
data.WriteUInt32(GetViewerLastLineEndTime(this, owner, receiver));
|
||||
data.WriteUInt32(Progress);
|
||||
for (int i = 0; i < ((List<ConversationLine>)Lines).Count; ++i)
|
||||
{
|
||||
@@ -5751,7 +5763,7 @@ namespace Game.Entities
|
||||
}
|
||||
if (_changesMask[4])
|
||||
{
|
||||
data.WriteUInt32(LastLineEndTime);
|
||||
data.WriteUInt32(GetViewerLastLineEndTime(this, owner, receiver));
|
||||
}
|
||||
if (_changesMask[5])
|
||||
{
|
||||
@@ -5770,5 +5782,11 @@ namespace Game.Entities
|
||||
ClearChangesMask(Progress);
|
||||
_changesMask.ResetAll();
|
||||
}
|
||||
|
||||
public uint GetViewerLastLineEndTime(ConversationData conversationLineData, Conversation conversation, Player receiver)
|
||||
{
|
||||
Locale locale = receiver.GetSession().GetSessionDbLocaleIndex();
|
||||
return (uint)conversation.GetLastLineEndTime(locale).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user