From 706567186c3fc651cc42e126dbd80d1a2b13c9c3 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sun, 10 Oct 2021 17:02:33 -0400 Subject: [PATCH] Core/Spells: Implemented SpellReagentsCurrency.db2 Port From (https://github.com/TrinityCore/TrinityCore/commit/8492c273dd50227ca01ead785eda6c4de9361e74) --- .../Database/Databases/HotfixDatabase.cs | 5 +++ Source/Game/DataStorage/CliDB.cs | 2 ++ Source/Game/DataStorage/Structs/S_Records.cs | 8 +++++ Source/Game/Spells/Spell.cs | 32 +++++++++++++++++-- Source/Game/Spells/SpellInfo.cs | 3 ++ Source/Game/Spells/SpellManager.cs | 7 ++++ .../master/2021_10_10_00_hotfixes.sql | 23 +++++++++++++ 7 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 sql/updates/hotfixes/master/2021_10_10_00_hotfixes.sql diff --git a/Source/Framework/Database/Databases/HotfixDatabase.cs b/Source/Framework/Database/Databases/HotfixDatabase.cs index eb65053f2..23274d503 100644 --- a/Source/Framework/Database/Databases/HotfixDatabase.cs +++ b/Source/Framework/Database/Databases/HotfixDatabase.cs @@ -1048,6 +1048,9 @@ namespace Framework.Database PrepareStatement(HotfixStatements.SEL_SPELL_REAGENTS, "SELECT ID, SpellID, Reagent1, Reagent2, Reagent3, Reagent4, Reagent5, Reagent6, Reagent7, Reagent8, " + "ReagentCount1, ReagentCount2, ReagentCount3, ReagentCount4, ReagentCount5, ReagentCount6, ReagentCount7, ReagentCount8 FROM spell_reagents"); + // SpellReagentsCurrency.db2 + PrepareStatement(HotfixStatements.SEL_SPELL_REAGENTS_CURRENCY, "SELECT ID, SpellID, CurrencyTypesID, CurrencyCount FROM spell_reagents_currency"); + // SpellScaling.db2 PrepareStatement(HotfixStatements.SEL_SPELL_SCALING, "SELECT ID, SpellID, MinScalingLevel, MaxScalingLevel, ScalesFromItemLevel FROM spell_scaling"); @@ -1749,6 +1752,8 @@ namespace Framework.Database SEL_SPELL_REAGENTS, + SEL_SPELL_REAGENTS_CURRENCY, + SEL_SPELL_SCALING, SEL_SPELL_SHAPESHIFT, diff --git a/Source/Game/DataStorage/CliDB.cs b/Source/Game/DataStorage/CliDB.cs index 86a0d107c..dfdc5b5bd 100644 --- a/Source/Game/DataStorage/CliDB.cs +++ b/Source/Game/DataStorage/CliDB.cs @@ -293,6 +293,7 @@ namespace Game.DataStorage SpellRadiusStorage = ReadDB2("SpellRadius.db2", HotfixStatements.SEL_SPELL_RADIUS); SpellRangeStorage = ReadDB2("SpellRange.db2", HotfixStatements.SEL_SPELL_RANGE, HotfixStatements.SEL_SPELL_RANGE_LOCALE); SpellReagentsStorage = ReadDB2("SpellReagents.db2", HotfixStatements.SEL_SPELL_REAGENTS); + SpellReagentsCurrencyStorage = ReadDB2("SpellReagentsCurrency.db2", HotfixStatements.SEL_SPELL_REAGENTS_CURRENCY); SpellScalingStorage = ReadDB2("SpellScaling.db2", HotfixStatements.SEL_SPELL_SCALING); SpellShapeshiftStorage = ReadDB2("SpellShapeshift.db2", HotfixStatements.SEL_SPELL_SHAPESHIFT); SpellShapeshiftFormStorage = ReadDB2("SpellShapeshiftForm.db2", HotfixStatements.SEL_SPELL_SHAPESHIFT_FORM, HotfixStatements.SEL_SPELL_SHAPESHIFT_FORM_LOCALE); @@ -665,6 +666,7 @@ namespace Game.DataStorage public static DB6Storage SpellRadiusStorage; public static DB6Storage SpellRangeStorage; public static DB6Storage SpellReagentsStorage; + public static DB6Storage SpellReagentsCurrencyStorage; public static DB6Storage SpellScalingStorage; public static DB6Storage SpellShapeshiftStorage; public static DB6Storage SpellShapeshiftFormStorage; diff --git a/Source/Game/DataStorage/Structs/S_Records.cs b/Source/Game/DataStorage/Structs/S_Records.cs index d369edd68..cd47a8287 100644 --- a/Source/Game/DataStorage/Structs/S_Records.cs +++ b/Source/Game/DataStorage/Structs/S_Records.cs @@ -482,6 +482,14 @@ namespace Game.DataStorage public ushort[] ReagentCount = new ushort[SpellConst.MaxReagents]; } + public sealed class SpellReagentsCurrencyRecord + { + public uint Id; + public int SpellID; + public ushort CurrencyTypesID; + public ushort CurrencyCount; + } + public sealed class SpellScalingRecord { public uint Id; diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 86e36cad3..2a48ba6ee 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -3367,7 +3367,6 @@ namespace Game.Spells packet.FailedArg1 = (int)param1; else { - uint missingItem = 0; for (uint i = 0; i < SpellConst.MaxReagents; i++) { if (spellInfo.Reagent[i] <= 0) @@ -3378,12 +3377,25 @@ namespace Game.Spells if (!caster.HasItemCount(itemid, itemcount)) { - missingItem = itemid; + packet.FailedArg1 = (int)itemid; // first missing item break; } } + } - packet.FailedArg1 = (int)missingItem; // first missing item + if (param2.HasValue) + packet.FailedArg2 = (int)param2; + else if (!param1.HasValue) + { + foreach (var reagentsCurrency in spellInfo.ReagentsCurrency) + { + if (!caster.HasCurrency(reagentsCurrency.CurrencyTypesID, reagentsCurrency.CurrencyCount)) + { + packet.FailedArg1 = -1; + packet.FailedArg2 = reagentsCurrency.CurrencyTypesID; + break; + } + } } break; } @@ -4240,6 +4252,9 @@ namespace Game.Spells p_caster.DestroyItemCount(itemid, itemcount, true); } + + foreach (var reagentsCurrency in m_spellInfo.ReagentsCurrency) + p_caster.ModifyCurrency((CurrencyTypes)reagentsCurrency.CurrencyTypesID, -reagentsCurrency.CurrencyCount, false, true); } void HandleThreatSpells() @@ -6002,6 +6017,17 @@ namespace Game.Spells return SpellCastResult.Reagents; } } + + foreach (var reagentsCurrency in m_spellInfo.ReagentsCurrency) + { + if (!player.HasCurrency(reagentsCurrency.CurrencyTypesID, reagentsCurrency.CurrencyCount)) + { + param1 = -1; + param2 = reagentsCurrency.CurrencyTypesID; + + return SpellCastResult.Reagents; + } + } } // check totem-item requirements (items presence in inventory) diff --git a/Source/Game/Spells/SpellInfo.cs b/Source/Game/Spells/SpellInfo.cs index ec5b76bfc..0846eff4b 100644 --- a/Source/Game/Spells/SpellInfo.cs +++ b/Source/Game/Spells/SpellInfo.cs @@ -208,6 +208,8 @@ namespace Game.Spells } } + ReagentsCurrency = data.ReagentsCurrency; + // SpellShapeshiftEntry SpellShapeshiftRecord _shapeshift = data.Shapeshift; if (_shapeshift != null) @@ -3883,6 +3885,7 @@ namespace Game.Spells public uint[] TotemCategory = new uint[SpellConst.MaxTotems]; public int[] Reagent = new int[SpellConst.MaxReagents]; public uint[] ReagentCount = new uint[SpellConst.MaxReagents]; + public List ReagentsCurrency = new(); public ItemClass EquippedItemClass { get; set; } public int EquippedItemSubClassMask { get; set; } public int EquippedItemInventoryTypeMask { get; set; } diff --git a/Source/Game/Spells/SpellManager.cs b/Source/Game/Spells/SpellManager.cs index 8812fa231..048cb97d6 100644 --- a/Source/Game/Spells/SpellManager.cs +++ b/Source/Game/Spells/SpellManager.cs @@ -2255,6 +2255,9 @@ namespace Game.Entities foreach (SpellReagentsRecord reagents in CliDB.SpellReagentsStorage.Values) GetLoadHelper(reagents.SpellID, 0).Reagents = reagents; + foreach (SpellReagentsCurrencyRecord reagentsCurrency in CliDB.SpellReagentsCurrencyStorage.Values) + GetLoadHelper((uint)reagentsCurrency.SpellID, 0).ReagentsCurrency.Add(reagentsCurrency); + foreach (SpellScalingRecord scaling in CliDB.SpellScalingStorage.Values) GetLoadHelper(scaling.SpellID, 0).Scaling = scaling; @@ -2336,6 +2339,9 @@ namespace Game.Entities if (data.Value.Reagents == null) data.Value.Reagents = fallbackData.Reagents; + if (data.Value.ReagentsCurrency.Empty()) + data.Value.ReagentsCurrency = fallbackData.ReagentsCurrency; + if (data.Value.Scaling == null) data.Value.Scaling = fallbackData.Scaling; @@ -4672,6 +4678,7 @@ namespace Game.Entities public SpellMiscRecord Misc; public SpellPowerRecord[] Powers = new SpellPowerRecord[SpellConst.MaxPowersPerSpell]; public SpellReagentsRecord Reagents; + public List ReagentsCurrency = new(); public SpellScalingRecord Scaling; public SpellShapeshiftRecord Shapeshift; public SpellTargetRestrictionsRecord TargetRestrictions; diff --git a/sql/updates/hotfixes/master/2021_10_10_00_hotfixes.sql b/sql/updates/hotfixes/master/2021_10_10_00_hotfixes.sql new file mode 100644 index 000000000..8ec989f1b --- /dev/null +++ b/sql/updates/hotfixes/master/2021_10_10_00_hotfixes.sql @@ -0,0 +1,23 @@ +-- +-- Table structure for table `spell_reagents_currency` +-- +DROP TABLE IF EXISTS `spell_reagents_currency`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `spell_reagents_currency` ( + `ID` int(10) unsigned NOT NULL DEFAULT '0', + `SpellID` int(11) NOT NULL DEFAULT '0', + `CurrencyTypesID` smallint(5) unsigned NOT NULL DEFAULT '0', + `CurrencyCount` smallint(5) unsigned NOT NULL DEFAULT '0', + `VerifiedBuild` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`ID`,`VerifiedBuild`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table data for table `spell_reagents_currency` +-- +INSERT INTO `spell_reagents_currency` +SELECT hb.`RecordId`, CONV(HEX(SUBSTRING(hb.`Blob`, 1, 4)), 16, 10), CONV(HEX(SUBSTRING(hb.`Blob`, 5, 2)), 16, 10), CONV(HEX(SUBSTRING(hb.`Blob`, 7, 2)), 16, 10), hb.`VerifiedBuild` FROM `hotfix_blob` hb WHERE hb.`TableHash`=0x2049B60C AND hb.`locale`='enUS'; + +DELETE FROM `hotfix_blob` WHERE `TableHash`=0x2049B60C;