From e9eb2962ef6e9fe392e164c3c1e7bd4817f4f259 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 22 Nov 2017 12:02:38 -0500 Subject: [PATCH] Implemented Conversation scripts --- Source/Game/DataStorage/ConversationDataStorage.cs | 4 +++- Source/Game/Entities/Conversation.cs | 7 +++++++ Source/Game/Globals/ObjectManager.cs | 1 + Source/Game/Scripting/CoreScripts.cs | 13 +++++++++++++ Source/Game/Scripting/ScriptManager.cs | 12 ++++++++++-- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Source/Game/DataStorage/ConversationDataStorage.cs b/Source/Game/DataStorage/ConversationDataStorage.cs index 324a09bc7..e50323ebd 100644 --- a/Source/Game/DataStorage/ConversationDataStorage.cs +++ b/Source/Game/DataStorage/ConversationDataStorage.cs @@ -158,7 +158,7 @@ namespace Game.DataStorage Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation actors. DB table `conversation_actors` is empty."); } - SQLResult templateResult = DB.World.Query("SELECT Id, FirstLineId, LastLineEndTime, VerifiedBuild FROM conversation_template"); + SQLResult templateResult = DB.World.Query("SELECT Id, FirstLineId, LastLineEndTime, ScriptName FROM conversation_template"); if (!templateResult.IsEmpty()) { uint oldMSTime = Time.GetMSTime(); @@ -169,6 +169,7 @@ namespace Game.DataStorage conversationTemplate.Id = templateResult.Read(0); conversationTemplate.FirstLineId = templateResult.Read(1); conversationTemplate.LastLineEndTime = templateResult.Read(2); + conversationTemplate.ScriptId = Global.ObjectMgr.GetScriptId(templateResult.Read(3)); conversationTemplate.Actors = actorsByConversation[conversationTemplate.Id].ToList(); conversationTemplate.ActorGuids = actorGuidsByConversation[conversationTemplate.Id].ToList(); @@ -234,6 +235,7 @@ namespace Game.DataStorage public uint Id; public uint FirstLineId; // Link to ConversationLine.db2 public uint LastLineEndTime; // Time in ms after conversation creation the last line fades out + public uint ScriptId; public List Actors = new List(); public List ActorGuids = new List(); diff --git a/Source/Game/Entities/Conversation.cs b/Source/Game/Entities/Conversation.cs index f99a4f01a..66a982510 100644 --- a/Source/Game/Entities/Conversation.cs +++ b/Source/Game/Entities/Conversation.cs @@ -145,6 +145,8 @@ namespace Game.Entities } } + Global.ScriptMgr.OnConversationCreate(this, creator); + List actorIndices = new List(); foreach (ConversationLineTemplate line in conversationTemplate.Lines) { @@ -182,6 +184,11 @@ namespace Game.Entities _participants.Add(participantGuid); } + public uint GetScriptId() + { + return Global.ConversationDataStorage.GetConversationTemplate(GetEntry()).ScriptId; + } + uint GetDuration() { return _duration; } public ObjectGuid GetCreatorGuid() { return _creatorGuid; } diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index c32c2eba2..aff9a9981 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -1031,6 +1031,7 @@ namespace Game scriptNamesStorage.Add(""); SQLResult result = DB.World.Query( "SELECT DISTINCT(ScriptName) FROM Battleground_template WHERE ScriptName <> '' " + + "UNION SELECT DISTINCT(ScriptName) FROM conversation_template WHERE ScriptName <> '' " + "UNION SELECT DISTINCT(ScriptName) FROM creature WHERE ScriptName <> '' " + "UNION SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' " + "UNION SELECT DISTINCT(ScriptName) FROM criteria_data WHERE ScriptName <> '' AND type = 11 " + diff --git a/Source/Game/Scripting/CoreScripts.cs b/Source/Game/Scripting/CoreScripts.cs index 6e34de543..f489a31a7 100644 --- a/Source/Game/Scripting/CoreScripts.cs +++ b/Source/Game/Scripting/CoreScripts.cs @@ -736,6 +736,19 @@ namespace Game.Scripting public virtual AreaTriggerAI GetAI(AreaTrigger at) { return null; } } + class ConversationScript : ScriptObject + { + public ConversationScript(string name) : base(name) + { + Global.ScriptMgr.AddScript(this); + } + + public override bool IsDatabaseBound() { return true; } + + // Called when Conversation is created but not added to Map yet. + public virtual void OnConversationCreate(Conversation conversation, Unit creator) { } + } + public class SceneScript : ScriptObject { public SceneScript(string name) : base(name) diff --git a/Source/Game/Scripting/ScriptManager.cs b/Source/Game/Scripting/ScriptManager.cs index 15654d780..66db8b928 100644 --- a/Source/Game/Scripting/ScriptManager.cs +++ b/Source/Game/Scripting/ScriptManager.cs @@ -257,7 +257,7 @@ namespace Game.Scripting if (!m_mSplineChainsMap.ContainsKey(key)) m_mSplineChainsMap[key] = new List(); - var chain = m_mSplineChainsMap[Tuple.Create(entry,chainId)]; + var chain = m_mSplineChainsMap[Tuple.Create(entry, chainId)]; if (splineId != chain.Count) { Log.outWarn(LogFilter.ServerLoading, "Creature #{0}: Chain {1} has orphaned spline {2}, skipped.", entry, chainId, splineId); @@ -281,7 +281,7 @@ namespace Game.Scripting float posX = resultWP.Read(4); float posY = resultWP.Read(5); float posZ = resultWP.Read(6); - var chain = m_mSplineChainsMap.LookupByKey(Tuple.Create(entry,chainId)); + var chain = m_mSplineChainsMap.LookupByKey(Tuple.Create(entry, chainId)); if (chain == null) { Log.outWarn(LogFilter.ServerLoading, "Creature #{0} has waypoint data for spline chain {1}. No such chain exists - entry skipped.", entry, chainId); @@ -1289,6 +1289,14 @@ namespace Game.Scripting return RunScriptRet(p => p.GetAI(areaTrigger), areaTrigger.GetScriptId(), null); } + // ConversationScript + public void OnConversationCreate(Conversation conversation, Unit creator) + { + Contract.Assert(conversation != null); + + RunScript(script => script.OnConversationCreate(conversation, creator), conversation.GetScriptId()); + } + //SceneScript public void OnSceneStart(Player player, uint sceneInstanceID, SceneTemplate sceneTemplate) {