Core/AI: Implemented conversation ai

Port From (https://github.com/TrinityCore/TrinityCore/commit/309ba22a15e5e0b4321b99f7157ccb18e0adc8dd)
This commit is contained in:
Hondacrx
2025-05-19 17:23:36 -04:00
parent 4f63e81373
commit e44861a629
10 changed files with 160 additions and 126 deletions
+14 -12
View File
@@ -247,13 +247,24 @@ namespace Game.Scripting
public virtual BattlegroundScript GetBattlegroundScript(BattlegroundMap map) { return null; }
}
public class GenericConversationScript<Script> : ConversationScript where Script : ConversationAI
{
public GenericConversationScript(string name) : base(name) { }
public override ConversationAI GetAI(Conversation conversation)
{
return (Script)Activator.CreateInstance(typeof(Script), [conversation]);
}
}
class GenericBattlegroundMapScript<Script> : BattlegroundMapScript where Script : BattlegroundScript
{
public GenericBattlegroundMapScript(string name, uint mapId) : base(name, mapId) { }
public override BattlegroundScript GetBattlegroundScript(BattlegroundMap map)
{
return (Script)Activator.CreateInstance(typeof(Script), new object[] { map });
return (Script)Activator.CreateInstance(typeof(Script), [map]);
}
}
@@ -806,17 +817,8 @@ namespace Game.Scripting
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) { }
// Called when Conversation is started
public virtual void OnConversationStart(Conversation conversation) { }
// Called when player sends CMSG_CONVERSATION_LINE_STARTED with valid conversation guid
public virtual void OnConversationLineStarted(Conversation conversation, uint lineId, Player sender) { }
// Called for each update tick
public virtual void OnConversationUpdate(Conversation conversation, uint diff) { }
// Called when a ConversationAI object is needed for the conversation.
public virtual ConversationAI GetAI(Conversation conversation) { return null; }
}
public class SceneScript : ScriptObject
+12 -30
View File
@@ -601,6 +601,18 @@ namespace Game.Scripting
return RunScriptRet<AreaTriggerScript>(p => entered ? p.OnTrigger(player, trigger) : p.OnExit(player, trigger), Global.ObjectMgr.GetAreaTriggerScriptId(trigger.Id));
}
public bool CanCreateConversationAI(uint scriptId)
{
return GetScriptRegistry<ConversationScript>().GetScriptById(scriptId) == null;
}
public ConversationAI GetConversationAI(Conversation conversation)
{
Cypher.Assert(conversation != null);
return RunScriptRet<ConversationScript, ConversationAI>(p => p.GetAI(conversation), conversation.GetScriptId());
}
//BattlefieldScript
public BattleField CreateBattlefield(uint scriptId, Map map)
{
@@ -1044,36 +1056,6 @@ namespace Game.Scripting
return RunScriptRet<AreaTriggerEntityScript, AreaTriggerAI>(p => p.GetAI(areaTrigger), areaTrigger.GetScriptId(), null);
}
// ConversationScript
public void OnConversationCreate(Conversation conversation, Unit creator)
{
Cypher.Assert(conversation != null);
RunScript<ConversationScript>(script => script.OnConversationCreate(conversation, creator), conversation.GetScriptId());
}
public void OnConversationStart(Conversation conversation)
{
Cypher.Assert(conversation != null);
RunScript<ConversationScript>(script => script.OnConversationStart(conversation), conversation.GetScriptId());
}
public void OnConversationLineStarted(Conversation conversation, uint lineId, Player sender)
{
Cypher.Assert(conversation != null);
Cypher.Assert(sender != null);
RunScript<ConversationScript>(script => script.OnConversationLineStarted(conversation, lineId, sender), conversation.GetScriptId());
}
public void OnConversationUpdate(Conversation conversation, uint diff)
{
Cypher.Assert(conversation != null);
RunScript<ConversationScript>(script => script.OnConversationUpdate(conversation, diff), conversation.GetScriptId());
}
//SceneScript
public void OnSceneStart(Player player, uint sceneInstanceID, SceneTemplate sceneTemplate)
{