From cb74ab8075e51fc7b974dbc8f0fe5f6233eb801f Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 23 Nov 2021 22:24:04 -0500 Subject: [PATCH] Core/Players: Load faction change items from db2 instead of db Port From (https://github.com/TrinityCore/TrinityCore/commit/7b11d17f4928d17637ad8182f9c632d90f873db4) --- Source/Game/DataStorage/Structs/I_Records.cs | 2 +- Source/Game/Entities/Item/ItemTemplate.cs | 1 + Source/Game/Entities/Player/Player.Quest.cs | 2 +- Source/Game/Globals/ObjectManager.cs | 29 +++++++------------ Source/Game/Handlers/CharacterHandler.cs | 11 +++---- .../world/master/2021_11_22_03_world.sql | 1 + 6 files changed, 20 insertions(+), 26 deletions(-) create mode 100644 sql/updates/world/master/2021_11_22_03_world.sql diff --git a/Source/Game/DataStorage/Structs/I_Records.cs b/Source/Game/DataStorage/Structs/I_Records.cs index 47d377a45..2a7f69c37 100644 --- a/Source/Game/DataStorage/Structs/I_Records.cs +++ b/Source/Game/DataStorage/Structs/I_Records.cs @@ -361,7 +361,7 @@ namespace Game.DataStorage public float PriceVariance; public float PriceRandomValue; public int[] Flags = new int[4]; - public int FactionRelated; + public uint FactionRelated; public int ModifiedCraftingReagentItemID; public uint ContentTuningID; public uint PlayerLevelToItemLevelCurveID; diff --git a/Source/Game/Entities/Item/ItemTemplate.cs b/Source/Game/Entities/Item/ItemTemplate.cs index d7d2f519a..9eb1072ad 100644 --- a/Source/Game/Entities/Item/ItemTemplate.cs +++ b/Source/Game/Entities/Item/ItemTemplate.cs @@ -260,6 +260,7 @@ namespace Game.Entities public ItemFlags2 GetFlags2() { return (ItemFlags2)ExtendedData.Flags[1]; } public ItemFlags3 GetFlags3() { return (ItemFlags3)ExtendedData.Flags[2]; } public ItemFlags4 GetFlags4() { return (ItemFlags4)ExtendedData.Flags[3]; } + public uint GetOtherFactionItemId() { return ExtendedData.FactionRelated; } public float GetPriceRandomValue() { return ExtendedData.PriceRandomValue; } public float GetPriceVariance() { return ExtendedData.PriceVariance; } public uint GetBuyCount() { return Math.Max(ExtendedData.VendorStackCount, 1u); } diff --git a/Source/Game/Entities/Player/Player.Quest.cs b/Source/Game/Entities/Player/Player.Quest.cs index 51fcedbaa..9c0a92655 100644 --- a/Source/Game/Entities/Player/Player.Quest.cs +++ b/Source/Game/Entities/Player/Player.Quest.cs @@ -17,6 +17,7 @@ using Framework.Constants; using Framework.Database; +using Game.AI; using Game.Conditions; using Game.DataStorage; using Game.Groups; @@ -27,7 +28,6 @@ using Game.Networking.Packets; using Game.Spells; using System; using System.Collections.Generic; -using Game.AI; namespace Game.Entities { diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index 00e185f54..3a8e466b1 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -6539,30 +6539,20 @@ namespace Game { uint oldMSTime = Time.GetMSTime(); - SQLResult result = DB.World.Query("SELECT alliance_id, horde_id FROM player_factionchange_items"); - - if (result.IsEmpty()) - { - Log.outInfo(LogFilter.ServerLoading, "Loaded 0 faction change item pairs. DB table `player_factionchange_items` is empty."); - return; - } - uint count = 0; - do + foreach (var itemPair in ItemTemplateStorage) { - uint alliance = result.Read(0); - uint horde = result.Read(1); + if (itemPair.Value.GetOtherFactionItemId() == 0) + continue; - if (GetItemTemplate(alliance) == null) - Log.outError(LogFilter.Sql, "Item {0} (alliance_id) referenced in `player_factionchange_items` does not exist, pair skipped!", alliance); - else if (GetItemTemplate(horde) == null) - Log.outError(LogFilter.Sql, "Item {0} (horde_id) referenced in `player_factionchange_items` does not exist, pair skipped!", horde); - else - FactionChangeItems[alliance] = horde; + if (itemPair.Value.GetFlags2().HasFlag(ItemFlags2.FactionHorde)) + FactionChangeItemsHordeToAlliance[itemPair.Key] = itemPair.Value.GetOtherFactionItemId(); + + if (itemPair.Value.GetFlags2().HasFlag(ItemFlags2.FactionAlliance)) + FactionChangeItemsAllianceToHorde[itemPair.Key] = itemPair.Value.GetOtherFactionItemId(); ++count; } - while (result.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} faction change item pairs in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); } @@ -10420,7 +10410,8 @@ namespace Game //Faction Change public Dictionary FactionChangeAchievements = new(); - public Dictionary FactionChangeItems = new(); + public Dictionary FactionChangeItemsAllianceToHorde = new(); + public Dictionary FactionChangeItemsHordeToAlliance = new(); public Dictionary FactionChangeQuests = new(); public Dictionary FactionChangeReputation = new(); public Dictionary FactionChangeSpells = new(); diff --git a/Source/Game/Handlers/CharacterHandler.cs b/Source/Game/Handlers/CharacterHandler.cs index 0f225e35b..529a4bbdb 100644 --- a/Source/Game/Handlers/CharacterHandler.cs +++ b/Source/Game/Handlers/CharacterHandler.cs @@ -1997,14 +1997,15 @@ namespace Game } // Item conversion - foreach (var it in Global.ObjectMgr.FactionChangeItems) + var itemConversionMap = newTeamId == TeamId.Alliance ? Global.ObjectMgr.FactionChangeItemsHordeToAlliance : Global.ObjectMgr.FactionChangeItemsAllianceToHorde; + foreach (var it in itemConversionMap) { - uint item_alliance = it.Key; - uint item_horde = it.Value; + uint oldItemId = it.Key; + uint newItemId = it.Value; stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHAR_INVENTORY_FACTION_CHANGE); - stmt.AddValue(0, (newTeamId == TeamId.Alliance ? item_alliance : item_horde)); - stmt.AddValue(1, (newTeamId == TeamId.Alliance ? item_horde : item_alliance)); + stmt.AddValue(0, newItemId); + stmt.AddValue(1, oldItemId); stmt.AddValue(2, lowGuid); trans.Append(stmt); } diff --git a/sql/updates/world/master/2021_11_22_03_world.sql b/sql/updates/world/master/2021_11_22_03_world.sql new file mode 100644 index 000000000..45d6fdf9f --- /dev/null +++ b/sql/updates/world/master/2021_11_22_03_world.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS `player_factionchange_items`;