From a6a9d05e981d6a6b766de5a00e279b30b31bd0e0 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sat, 13 Aug 2022 17:54:36 -0400 Subject: [PATCH] Core/Gossips: Added support for FriendshipFactionID Port From (https://github.com/TrinityCore/TrinityCore/commit/1bbc8592d95978a4c681fa6177c7c457189ef485) --- Source/Game/Entities/Creature/Gossip.cs | 12 ++++- Source/Game/Globals/ObjectManager.cs | 48 ++++++++++++++++++- Source/Game/Networking/Packets/NPCPackets.cs | 4 +- Source/Game/World/WorldManager.cs | 3 ++ .../world/master/2022_08_13_00_world.sql | 19 ++++++++ 5 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 sql/updates/world/master/2022_08_13_00_world.sql diff --git a/Source/Game/Entities/Creature/Gossip.cs b/Source/Game/Entities/Creature/Gossip.cs index 82f31e9c4..b21769505 100644 --- a/Source/Game/Entities/Creature/Gossip.cs +++ b/Source/Game/Entities/Creature/Gossip.cs @@ -249,7 +249,12 @@ namespace Game.Misc GossipMessagePkt packet = new(); packet.GossipGUID = objectGUID; - packet.GossipID = (int)_gossipMenu.GetMenuId(); + packet.GossipID = _gossipMenu.GetMenuId(); + + GossipMenuAddon addon = Global.ObjectMgr.GetGossipMenuAddon(packet.GossipID); + if (addon != null) + packet.FriendshipFactionID = addon.FriendshipFactionID; + NpcText text = Global.ObjectMgr.GetNpcText(titleTextId); if (text != null) packet.TextID = (int)text.Data.SelectRandomElementByWeight(data => data.Probability).BroadcastTextID; @@ -747,6 +752,11 @@ namespace Game.Misc public List Conditions = new(); } + public class GossipMenuAddon + { + public int FriendshipFactionID; + } + public class PointOfInterest { public uint Id; diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index c4b6dd786..fb13c7e34 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -652,6 +652,47 @@ namespace Game Log.outInfo(LogFilter.ServerLoading, $"Loaded {gossipMenuItemsStorage.Count} gossip_menu_option entries in {Time.GetMSTimeDiffToNow(oldMSTime)} ms"); } + public void LoadGossipMenuFriendshipFactions() + { + uint oldMSTime = Time.GetMSTime(); + + _gossipMenuAddonStorage.Clear(); + + // 0 1 + SQLResult result = DB.World.Query("SELECT MenuID, FriendshipFactionID FROM gossip_menu_addon"); + if (result.IsEmpty()) + { + Log.outInfo(LogFilter.ServerLoading, "Loaded 0 gossip_menu_addon IDs. DB table `gossip_menu_addon` is empty!"); + return; + } + + do + { + uint menuID = result.Read(0); + GossipMenuAddon addon = new(); + addon.FriendshipFactionID = result.Read(1); + + var faction = CliDB.FactionStorage.LookupByKey(addon.FriendshipFactionID); + if (faction != null) + { + if (!CliDB.FriendshipReputationStorage.ContainsKey(faction.FriendshipRepID)) + { + Log.outError(LogFilter.Sql, $"Table gossip_menu_addon: ID {menuID} is using FriendshipFactionID {addon.FriendshipFactionID} referencing non-existing FriendshipRepID {faction.FriendshipRepID}"); + addon.FriendshipFactionID = 0; + } + } + else + { + Log.outError(LogFilter.Sql, $"Table gossip_menu_addon: ID {menuID} is using non-existing FriendshipFactionID {addon.FriendshipFactionID}"); + addon.FriendshipFactionID = 0; + } + + _gossipMenuAddonStorage[menuID] = addon; + } while (result.NextRow()); + + Log.outInfo(LogFilter.ServerLoading, $"Loaded {_gossipMenuAddonStorage.Count} gossip_menu_addon IDs in {Time.GetMSTimeDiffToNow(oldMSTime)} ms"); + } + public void LoadPointsOfInterest() { uint oldMSTime = Time.GetMSTime(); @@ -702,6 +743,10 @@ namespace Game { return gossipMenuItemsStorage.LookupByKey(uiMenuId); } + public GossipMenuAddon GetGossipMenuAddon(uint menuId) + { + return _gossipMenuAddonStorage.LookupByKey(menuId); + } public PointOfInterest GetPointOfInterest(uint id) { return pointsOfInterestStorage.LookupByKey(id); @@ -10778,8 +10823,9 @@ namespace Game Dictionary _skillTiers = new(); //Gossip - MultiMap gossipMenuItemsStorage = new(); MultiMap gossipMenusStorage = new(); + MultiMap gossipMenuItemsStorage = new(); + Dictionary _gossipMenuAddonStorage = new(); Dictionary pointsOfInterestStorage = new(); //Creature diff --git a/Source/Game/Networking/Packets/NPCPackets.cs b/Source/Game/Networking/Packets/NPCPackets.cs index a4bd6fe27..b5bc6bfbc 100644 --- a/Source/Game/Networking/Packets/NPCPackets.cs +++ b/Source/Game/Networking/Packets/NPCPackets.cs @@ -50,7 +50,7 @@ namespace Game.Networking.Packets public override void Write() { _worldPacket.WritePackedGuid(GossipGUID); - _worldPacket.WriteInt32(GossipID); + _worldPacket.WriteUInt32(GossipID); _worldPacket.WriteInt32(FriendshipFactionID); _worldPacket.WriteInt32(TextID); @@ -89,7 +89,7 @@ namespace Game.Networking.Packets public ObjectGuid GossipGUID; public List GossipText = new(); public int TextID; - public int GossipID; + public uint GossipID; } public class GossipSelectOption : ClientPacket diff --git a/Source/Game/World/WorldManager.cs b/Source/Game/World/WorldManager.cs index a0fec302f..ea1545b1c 100644 --- a/Source/Game/World/WorldManager.cs +++ b/Source/Game/World/WorldManager.cs @@ -885,6 +885,9 @@ namespace Game Log.outInfo(LogFilter.ServerLoading, "Loading Gossip menu options..."); Global.ObjectMgr.LoadGossipMenuItems(); + Log.outInfo(LogFilter.ServerLoading, "Loading Gossip menu friendship factions..."); + Global.ObjectMgr.LoadGossipMenuFriendshipFactions(); + Log.outInfo(LogFilter.ServerLoading, "Loading Creature trainers..."); Global.ObjectMgr.LoadCreatureTrainers(); // must be after LoadGossipMenuItems diff --git a/sql/updates/world/master/2022_08_13_00_world.sql b/sql/updates/world/master/2022_08_13_00_world.sql new file mode 100644 index 000000000..40db49904 --- /dev/null +++ b/sql/updates/world/master/2022_08_13_00_world.sql @@ -0,0 +1,19 @@ +DROP TABLE IF EXISTS `gossip_menu_addon`; +CREATE TABLE `gossip_menu_addon` ( + `MenuID` INT UNSIGNED NOT NULL DEFAULT 0, + `FriendshipFactionID` INT NOT NULL DEFAULT 0, + `VerifiedBuild` INT NOT NULL DEFAULT 0, + PRIMARY KEY (`MenuID`) +) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DELETE FROM `gossip_menu_addon` WHERE `MenuID` IN (13332, 13338, 13470, 13475, 13486, 13574, 13593, 13594, 13595); +INSERT INTO `gossip_menu_addon` (`MenuID`, `FriendshipFactionID`, `VerifiedBuild`) VALUES +(13332, 1283, 44908), -- 57298 (Farmer Fung) +(13338, 1279, 44908), -- 57402 (Haohan Mudclaw) +(13470, 1281, 44908), -- 58706 (Gina Mudclaw) +(13475, 1281, 44908), -- 58706 (Gina Mudclaw) +(13486, 1275, 44908), -- 58647 (Ella) +(13574, 1282, 44908), -- 58705 (Fish Fellreed) +(13593, 1280, 44908), -- 58761 (Tina Mudclaw) +(13594, 1277, 44908), -- 58709 (Chee Chee) +(13595, 1276, 44908); -- 58707 (Old Hillpaw)