From 586dddec4d52f21ba9abbfafa481c4d2313ab308 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 11 Oct 2021 20:01:48 -0400 Subject: [PATCH] Core/PacketIO: Implemented CMSG_CONVERSATION_LINE_STARTED Port From (https://github.com/TrinityCore/TrinityCore/commit/6d9ce8e8baa100ecc7650d0ae56037c131bab2e0) --- Source/Game/BattleGrounds/BattleGround.cs | 4 +- Source/Game/Entities/Conversation.cs | 4 +- Source/Game/Entities/Player/SceneMgr.cs | 1 - Source/Game/Globals/ObjectAccessor.cs | 2 +- Source/Game/Handlers/MiscHandler.cs | 9 +++- Source/Game/Networking/Packets/MiscPackets.cs | 20 ++++++-- Source/Game/Scripting/CoreScripts.cs | 5 +- Source/Game/Scripting/ScriptManager.cs | 8 +++ Source/Scripts/World/Conversation.cs | 49 +++++++++++++++++++ .../world/master/2021_10_12_00_world.sql | 18 +++++++ 10 files changed, 109 insertions(+), 11 deletions(-) create mode 100644 Source/Scripts/World/Conversation.cs create mode 100644 sql/updates/world/master/2021_10_12_00_world.sql diff --git a/Source/Game/BattleGrounds/BattleGround.cs b/Source/Game/BattleGrounds/BattleGround.cs index f0f140802..a4583f1da 100644 --- a/Source/Game/BattleGrounds/BattleGround.cs +++ b/Source/Game/BattleGrounds/BattleGround.cs @@ -351,7 +351,7 @@ namespace Game.BattleGrounds StartTimer timer = new(); timer.Type = TimerType.Pvp; - timer.TimeRemaining = countdownMaxForBGType - (GetElapsedTime() / 1000); + timer.TimeLeft = countdownMaxForBGType - (GetElapsedTime() / 1000); timer.TotalTime = countdownMaxForBGType; foreach (var guid in GetPlayers().Keys) @@ -1059,7 +1059,7 @@ namespace Game.BattleGrounds uint countdownMaxForBGType = IsArena() ? BattlegroundConst.ArenaCountdownMax : BattlegroundConst.BattlegroundCountdownMax; StartTimer timer = new(); timer.Type = TimerType.Pvp; - timer.TimeRemaining = countdownMaxForBGType - (GetElapsedTime() / 1000); + timer.TimeLeft = countdownMaxForBGType - (GetElapsedTime() / 1000); timer.TotalTime = countdownMaxForBGType; player.SendPacket(timer); diff --git a/Source/Game/Entities/Conversation.cs b/Source/Game/Entities/Conversation.cs index 092a2efc2..25a2aaec4 100644 --- a/Source/Game/Entities/Conversation.cs +++ b/Source/Game/Entities/Conversation.cs @@ -122,7 +122,7 @@ namespace Game.Entities SetObjectScale(1.0f); SetUpdateFieldValue(m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.LastLineEndTime), conversationTemplate.LastLineEndTime); - _duration = conversationTemplate.LastLineEndTime; + _duration = conversationTemplate.LastLineEndTime + 10 * Time.InMilliseconds; _textureKitId = conversationTemplate.TextureKitId; if (conversationTemplate.Actors != null) @@ -197,7 +197,7 @@ namespace Game.Entities return true; } - void AddActor(ObjectGuid actorGuid, ushort actorIdx) + public void AddActor(ObjectGuid actorGuid, ushort actorIdx) { ConversationActorField actorField = m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.Actors, actorIdx); SetUpdateFieldValue(ref actorField.ActorGUID, actorGuid); diff --git a/Source/Game/Entities/Player/SceneMgr.cs b/Source/Game/Entities/Player/SceneMgr.cs index b2767ca60..af1e79e5e 100644 --- a/Source/Game/Entities/Player/SceneMgr.cs +++ b/Source/Game/Entities/Player/SceneMgr.cs @@ -19,7 +19,6 @@ using Framework.Constants; using Game.DataStorage; using Game.Networking; using Game.Networking.Packets; -using System; using System.Collections.Generic; namespace Game.Entities diff --git a/Source/Game/Globals/ObjectAccessor.cs b/Source/Game/Globals/ObjectAccessor.cs index 1ae30618e..fe609ca51 100644 --- a/Source/Game/Globals/ObjectAccessor.cs +++ b/Source/Game/Globals/ObjectAccessor.cs @@ -144,7 +144,7 @@ public class ObjectAccessor : Singleton return u.GetMap().GetSceneObject(guid); } - static Conversation GetConversation(WorldObject u, ObjectGuid guid) + public static Conversation GetConversation(WorldObject u, ObjectGuid guid) { return u.GetMap().GetConversation(guid); } diff --git a/Source/Game/Handlers/MiscHandler.cs b/Source/Game/Handlers/MiscHandler.cs index c307ab25a..bd7b9eae4 100644 --- a/Source/Game/Handlers/MiscHandler.cs +++ b/Source/Game/Handlers/MiscHandler.cs @@ -23,7 +23,6 @@ using Game.Entities; using Game.Groups; using Game.Guilds; using Game.Maps; -using Game.Misc; using Game.Networking; using Game.Networking.Packets; using Game.PvP; @@ -454,6 +453,14 @@ namespace Game _player.PlayerTalkClass.GetInteractionData().Reset(); } + [WorldPacketHandler(ClientOpcodes.ConversationLineStarted)] + void HandleConversationLineStarted(ConversationLineStarted conversationLineStarted) + { + Conversation convo = ObjectAccessor.GetConversation(_player, conversationLineStarted.ConversationGUID); + if (convo != null) + Global.ScriptMgr.OnConversationLineStarted(convo, conversationLineStarted.LineID, _player); + } + [WorldPacketHandler(ClientOpcodes.ChatUnregisterAllAddonPrefixes)] void HandleUnregisterAllAddonPrefixes(ChatUnregisterAllAddonPrefixes packet) { diff --git a/Source/Game/Networking/Packets/MiscPackets.cs b/Source/Game/Networking/Packets/MiscPackets.cs index 02aa97716..5bd7d4042 100644 --- a/Source/Game/Networking/Packets/MiscPackets.cs +++ b/Source/Game/Networking/Packets/MiscPackets.cs @@ -1239,15 +1239,29 @@ namespace Game.Networking.Packets public override void Write() { _worldPacket.WriteUInt32((uint)Type); - _worldPacket.WriteUInt32(TimeRemaining); + _worldPacket.WriteUInt32(TimeLeft); _worldPacket.WriteUInt32(TotalTime); } - public uint TimeRemaining; - public uint TotalTime; public TimerType Type; + public uint TimeLeft; + public uint TotalTime; } + class ConversationLineStarted : ClientPacket + { + public ObjectGuid ConversationGUID; + public uint LineID; + + public ConversationLineStarted(WorldPacket packet) : base(packet) { } + + public override void Read() + { + ConversationGUID = _worldPacket.ReadPackedGuid(); + LineID = _worldPacket.ReadUInt32(); + } + } + class DisplayGameError : ServerPacket { public DisplayGameError(GameError error) : base(ServerOpcodes.DisplayGameError) diff --git a/Source/Game/Scripting/CoreScripts.cs b/Source/Game/Scripting/CoreScripts.cs index 0702aee40..fad0cde3d 100644 --- a/Source/Game/Scripting/CoreScripts.cs +++ b/Source/Game/Scripting/CoreScripts.cs @@ -760,7 +760,7 @@ namespace Game.Scripting public virtual AreaTriggerAI GetAI(AreaTrigger at) { return null; } } - class ConversationScript : ScriptObject + public class ConversationScript : ScriptObject { public ConversationScript(string name) : base(name) { @@ -771,6 +771,9 @@ namespace Game.Scripting // Called when Conversation is created but not added to Map yet. public virtual void OnConversationCreate(Conversation conversation, Unit creator) { } + + // Called when player sends CMSG_CONVERSATION_LINE_STARTED with valid conversation guid + public virtual void OnConversationLineStarted(Conversation conversation, uint lineId, Player sender) { } } public class SceneScript : ScriptObject diff --git a/Source/Game/Scripting/ScriptManager.cs b/Source/Game/Scripting/ScriptManager.cs index 55abbbee2..df605e78e 100644 --- a/Source/Game/Scripting/ScriptManager.cs +++ b/Source/Game/Scripting/ScriptManager.cs @@ -1117,6 +1117,14 @@ namespace Game.Scripting RunScript(script => script.OnConversationCreate(conversation, creator), conversation.GetScriptId()); } + public void OnConversationLineStarted(Conversation conversation, uint lineId, Player sender) + { + Cypher.Assert(conversation != null); + Cypher.Assert(sender != null); + + RunScript(script => script.OnConversationLineStarted(conversation, lineId, sender), conversation.GetScriptId()); + } + //SceneScript public void OnSceneStart(Player player, uint sceneInstanceID, SceneTemplate sceneTemplate) { diff --git a/Source/Scripts/World/Conversation.cs b/Source/Scripts/World/Conversation.cs new file mode 100644 index 000000000..11134a0ed --- /dev/null +++ b/Source/Scripts/World/Conversation.cs @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2012-2020 CypherCore + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using Framework.Constants; +using Game.Entities; +using Game.Scripting; + +namespace Scripts.World +{ + [Script] + class conversation_allied_race_dk_defender_of_azeroth : ConversationScript + { + const uint NpcTalkToYourCommanderCredit = 161709; + const uint NpcListenToYourCommanderCredit = 163027; + const uint ConversationLinePlayer = 32926; + + public conversation_allied_race_dk_defender_of_azeroth() : base("conversation_allied_race_dk_defender_of_azeroth") { } + + public override void OnConversationCreate(Conversation conversation, Unit creator) + { + conversation.AddActor(ObjectGuid.Create(HighGuid.Player, 0xFFFFFFFFFFFFFFFF), 1); + Player player = creator.ToPlayer(); + if (player != null) + player.KilledMonsterCredit(NpcTalkToYourCommanderCredit); + } + + public override void OnConversationLineStarted(Conversation conversation, uint lineId, Player sender) + { + if (lineId != ConversationLinePlayer) + return; + + sender.KilledMonsterCredit(NpcListenToYourCommanderCredit); + } + } +} diff --git a/sql/updates/world/master/2021_10_12_00_world.sql b/sql/updates/world/master/2021_10_12_00_world.sql new file mode 100644 index 000000000..160a65769 --- /dev/null +++ b/sql/updates/world/master/2021_10_12_00_world.sql @@ -0,0 +1,18 @@ +-- +DELETE FROM `conversation_line_template` WHERE `Id` IN (32915, 32916, 32917, 32918, 32919, 32926); +INSERT INTO `conversation_line_template` (`Id`, `StartTime`, `UiCameraID`, `ActorIdx`, `Flags`, `VerifiedBuild`) VALUES +(32915, 0, 0, 0, 0, 40120), +(32916, 9878, 0, 0, 0, 40120), +(32917, 22389, 0, 0, 0, 40120), +(32918, 33855, 0, 0, 0, 40120), +(32919, 43842, 0, 0, 0, 40120), +(32926, 55409, 0, 1, 1, 40120); + +DELETE FROM `conversation_template` WHERE `Id`=13254; +INSERT INTO `conversation_template` (`Id`, `FirstLineID`, `LastLineEndTime`, `TextureKitId`, `ScriptName`, `VerifiedBuild`) VALUES +(13254, 32915, 55409, 0, 'conversation_allied_race_dk_defender_of_azeroth', 40120); + +DELETE FROM `conversation_actors` WHERE (`ConversationId`=13254 AND `Idx`=0); +INSERT INTO `conversation_actors` (`ConversationId`, `ConversationActorId`, `ConversationActorGuid`, `Idx`, `VerifiedBuild`) VALUES +-- (13254, 0, 0, 1, 40120), -- Full: 0x0800040000000000FFFFFFFFFFFFFFFF Player/0 R1/S16777215 Map: 0 (Eastern Kingdoms) Low: 1099511627775 +(13254, 74042, 1050053, 0, 40120); -- Full: 0x203AF51F209DEB400009E0000059DA73 Creature/0 R3773/S2528 Map: 2297 (Icecrown Citadel (8.3)) Entry: 161709 (Highlord Darion Mograine) Low: 5888627