Implemented Conversation scripts

This commit is contained in:
hondacrx
2017-11-22 12:02:38 -05:00
parent 1a26ce6002
commit e9eb2962ef
5 changed files with 34 additions and 3 deletions
@@ -158,7 +158,7 @@ namespace Game.DataStorage
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation actors. DB table `conversation_actors` is empty."); 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()) if (!templateResult.IsEmpty())
{ {
uint oldMSTime = Time.GetMSTime(); uint oldMSTime = Time.GetMSTime();
@@ -169,6 +169,7 @@ namespace Game.DataStorage
conversationTemplate.Id = templateResult.Read<uint>(0); conversationTemplate.Id = templateResult.Read<uint>(0);
conversationTemplate.FirstLineId = templateResult.Read<uint>(1); conversationTemplate.FirstLineId = templateResult.Read<uint>(1);
conversationTemplate.LastLineEndTime = templateResult.Read<uint>(2); conversationTemplate.LastLineEndTime = templateResult.Read<uint>(2);
conversationTemplate.ScriptId = Global.ObjectMgr.GetScriptId(templateResult.Read<string>(3));
conversationTemplate.Actors = actorsByConversation[conversationTemplate.Id].ToList(); conversationTemplate.Actors = actorsByConversation[conversationTemplate.Id].ToList();
conversationTemplate.ActorGuids = actorGuidsByConversation[conversationTemplate.Id].ToList(); conversationTemplate.ActorGuids = actorGuidsByConversation[conversationTemplate.Id].ToList();
@@ -234,6 +235,7 @@ namespace Game.DataStorage
public uint Id; public uint Id;
public uint FirstLineId; // Link to ConversationLine.db2 public uint FirstLineId; // Link to ConversationLine.db2
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 uint ScriptId;
public List<ConversationActorTemplate> Actors = new List<ConversationActorTemplate>(); public List<ConversationActorTemplate> Actors = new List<ConversationActorTemplate>();
public List<ulong> ActorGuids = new List<ulong>(); public List<ulong> ActorGuids = new List<ulong>();
+7
View File
@@ -145,6 +145,8 @@ namespace Game.Entities
} }
} }
Global.ScriptMgr.OnConversationCreate(this, creator);
List<ushort> actorIndices = new List<ushort>(); List<ushort> actorIndices = new List<ushort>();
foreach (ConversationLineTemplate line in conversationTemplate.Lines) foreach (ConversationLineTemplate line in conversationTemplate.Lines)
{ {
@@ -182,6 +184,11 @@ namespace Game.Entities
_participants.Add(participantGuid); _participants.Add(participantGuid);
} }
public uint GetScriptId()
{
return Global.ConversationDataStorage.GetConversationTemplate(GetEntry()).ScriptId;
}
uint GetDuration() { return _duration; } uint GetDuration() { return _duration; }
public ObjectGuid GetCreatorGuid() { return _creatorGuid; } public ObjectGuid GetCreatorGuid() { return _creatorGuid; }
+1
View File
@@ -1031,6 +1031,7 @@ namespace Game
scriptNamesStorage.Add(""); scriptNamesStorage.Add("");
SQLResult result = DB.World.Query( SQLResult result = DB.World.Query(
"SELECT DISTINCT(ScriptName) FROM Battleground_template WHERE ScriptName <> '' " + "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 WHERE ScriptName <> '' " +
"UNION SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' " + "UNION SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' " +
"UNION SELECT DISTINCT(ScriptName) FROM criteria_data WHERE ScriptName <> '' AND type = 11 " + "UNION SELECT DISTINCT(ScriptName) FROM criteria_data WHERE ScriptName <> '' AND type = 11 " +
+13
View File
@@ -736,6 +736,19 @@ namespace Game.Scripting
public virtual AreaTriggerAI GetAI(AreaTrigger at) { return null; } 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 class SceneScript : ScriptObject
{ {
public SceneScript(string name) : base(name) public SceneScript(string name) : base(name)
+8
View File
@@ -1289,6 +1289,14 @@ namespace Game.Scripting
return RunScriptRet<AreaTriggerEntityScript, AreaTriggerAI>(p => p.GetAI(areaTrigger), areaTrigger.GetScriptId(), null); return RunScriptRet<AreaTriggerEntityScript, AreaTriggerAI>(p => p.GetAI(areaTrigger), areaTrigger.GetScriptId(), null);
} }
// ConversationScript
public void OnConversationCreate(Conversation conversation, Unit creator)
{
Contract.Assert(conversation != null);
RunScript<ConversationScript>(script => script.OnConversationCreate(conversation, creator), conversation.GetScriptId());
}
//SceneScript //SceneScript
public void OnSceneStart(Player player, uint sceneInstanceID, SceneTemplate sceneTemplate) public void OnSceneStart(Player player, uint sceneInstanceID, SceneTemplate sceneTemplate)
{ {