Skip to content

Commit 898b48b

Browse files
authored
Update spell_target_position sql generation for TARGET_DEST_NEARBY_DB (#917)
1 parent 32d61c2 commit 898b48b

File tree

5 files changed

+86
-8
lines changed

5 files changed

+86
-8
lines changed

WowPacketParser/Enums/SpellEnums.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ public enum Targets
472472
TARGET_UNIT_PASSENGER_7 = 103,
473473
TARGET_UNIT_CONE_ENEMY_104 = 104,
474474
TARGET_UNIT_UNK_105 = 105, // 1 spell
475-
TARGET_DEST_CHANNEL_CASTER = 106,
475+
TARGET_DEST_NEARBY_DB = 106,
476476
TARGET_UNK_DEST_AREA_UNK_107 = 107, // not enough info - only generic spells avalible
477477
TARGET_GAMEOBJECT_CONE = 108,
478478
TARGET_109 = 109,
@@ -1526,7 +1526,7 @@ public enum UnitMods
15261526
UNIT_MOD_POWER_START = UNIT_MOD_MANA,
15271527
UNIT_MOD_POWER_END = UNIT_MOD_ALTERNATIVE + 1,
15281528
};
1529-
1529+
15301530
public enum AuraTypeLegion
15311531
{
15321532
SPELL_AURA_NONE = 0,

WowPacketParser/SQL/Builders/Spells.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
using WowPacketParser.Enums;
1+
using System.Linq;
2+
using System.Collections.Generic;
3+
using WowPacketParser.Enums;
24
using WowPacketParser.Misc;
35
using WowPacketParser.Store;
6+
using WowPacketParser.Store.Objects;
47

58
namespace WowPacketParser.SQL.Builders
69
{
@@ -18,5 +21,56 @@ public static string SpellTargetPosition()
1821

1922
return SQLUtil.Compare(Storage.SpellTargetPositions, SQLDatabase.Get(Storage.SpellTargetPositions), t => t.EffectHelper);
2023
}
24+
25+
[BuilderMethod]
26+
public static string SpellTargetMultiplePositions()
27+
{
28+
if (Storage.SpellTargetPositions.IsEmpty())
29+
return string.Empty;
30+
31+
if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.spell_target_position))
32+
return string.Empty;
33+
34+
var rows = new RowList<SpellTargetPosition>();
35+
Dictionary<uint, uint> idCount = new Dictionary<uint, uint>();
36+
37+
foreach (var spellTargetPosition in Storage.SpellTargetMultiplePositions.OrderBy(t => t.Key))
38+
{
39+
foreach (var spellTargetPositionValue in spellTargetPosition.Value)
40+
{
41+
idCount.TryGetValue(spellTargetPosition.Key, out uint count);
42+
var duplicatedRow = rows.Where(spellTargetPosition2 =>
43+
spellTargetPosition2.Data.ID == spellTargetPosition.Key &&
44+
spellTargetPosition2.Data.PositionX == spellTargetPositionValue.Item1.PositionX &&
45+
spellTargetPosition2.Data.PositionY == spellTargetPositionValue.Item1.PositionY &&
46+
spellTargetPosition2.Data.PositionZ == spellTargetPositionValue.Item1.PositionZ &&
47+
spellTargetPosition2.Data.MapID == spellTargetPositionValue.Item1.MapID
48+
).Any();
49+
50+
if (duplicatedRow)
51+
continue;
52+
53+
var row = new Row<SpellTargetPosition>
54+
{
55+
Data = new SpellTargetPosition
56+
{
57+
ID = spellTargetPosition.Key,
58+
EffectIndex = spellTargetPositionValue.Item1.EffectIndex,
59+
OrderIndex = "ORD_INDEX+" + count,
60+
PositionX = spellTargetPositionValue.Item1.PositionX,
61+
PositionY = spellTargetPositionValue.Item1.PositionY,
62+
PositionZ = spellTargetPositionValue.Item1.PositionZ,
63+
MapID = spellTargetPositionValue.Item1.MapID
64+
},
65+
66+
Comment = spellTargetPositionValue.Item1.EffectHelper
67+
};
68+
69+
idCount[spellTargetPosition.Key] = count + 1;
70+
rows.Add(row);
71+
}
72+
}
73+
return new SQLInsert<SpellTargetPosition>(rows, false).Build();
74+
}
2175
}
2276
}

WowPacketParser/Store/Objects/SpellTargetPosition.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using WowPacketParser.Misc;
1+
using WowPacketParser.Enums;
2+
using WowPacketParser.Misc;
23
using WowPacketParser.SQL;
34

45
namespace WowPacketParser.Store.Objects
@@ -12,6 +13,9 @@ public sealed record SpellTargetPosition : IDataModel
1213
[DBFieldName("EffectIndex", true)]
1314
public byte? EffectIndex;
1415

16+
[DBFieldName("OrderIndex", TargetedDatabaseFlag.SinceTheWarWithin, true, true)]
17+
public string OrderIndex;
18+
1519
[DBFieldName("MapID")]
1620
public ushort? MapID;
1721

WowPacketParser/Store/Storage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public static class Storage
132132

133133
// Spell Target Position
134134
public static readonly DataBag<SpellTargetPosition> SpellTargetPositions = new DataBag<SpellTargetPosition>(new List<SQLOutput> { SQLOutput.spell_target_position });
135+
public static readonly StoreMulti<uint, SpellTargetPosition> SpellTargetMultiplePositions = new StoreMulti<uint, SpellTargetPosition>(new List<SQLOutput> { SQLOutput.spell_target_position });
135136

136137
// Hotfixes
137138
public static readonly DataBag<HotfixData> HotfixDatas = new DataBag<HotfixData>(new List<SQLOutput> { SQLOutput.hotfix_data });
@@ -2122,6 +2123,7 @@ public static void ClearContainers()
21222123
SpellClicks.Clear();
21232124

21242125
SpellTargetPositions.Clear();
2126+
SpellTargetMultiplePositions.Clear();
21252127

21262128
LocalesCreatures.Clear();
21272129
LocalesQuests.Clear();

WowPacketParserModule.V8_0_1_27101/Parsers/SpellHandler.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,19 @@ public static void ReadSpellTargetData(Packet packet, PacketSpellData packetSpel
6363
if (DBC.SpellEffectStores.ContainsKey(tuple))
6464
{
6565
var effect = DBC.SpellEffectStores[tuple];
66-
if ((Targets)effect.ImplicitTarget[0] == Targets.TARGET_DEST_DB || (Targets)effect.ImplicitTarget[1] == Targets.TARGET_DEST_DB)
66+
var isValidDBTarget = (short[] implicitTargets, Targets type) =>
6767
{
68-
string effectHelper = $"Spell: { StoreGetters.GetName(StoreNameType.Spell, (int)spellID) } Efffect: { effect.Effect } ({ (SpellEffects)effect.Effect })";
68+
foreach (var implicitTarget in implicitTargets)
69+
if ((Targets)implicitTarget == type)
70+
return true;
71+
72+
return false;
73+
};
74+
var isSingleDBTarget = isValidDBTarget(effect.ImplicitTarget, Targets.TARGET_DEST_DB);
75+
var isMultipleDBTarget = isValidDBTarget(effect.ImplicitTarget, Targets.TARGET_DEST_NEARBY_DB);
76+
if (isSingleDBTarget || isMultipleDBTarget)
77+
{
78+
string effectHelper = $"Spell: { StoreGetters.GetName(StoreNameType.Spell, (int)spellID) } Effect {effect.EffectIndex}: { effect.Effect } ({ (SpellEffects)effect.Effect })";
6979

7080
var spellTargetPosition = new SpellTargetPosition
7181
{
@@ -78,8 +88,16 @@ public static void ReadSpellTargetData(Packet packet, PacketSpellData packetSpel
7888
EffectHelper = effectHelper
7989
};
8090

81-
if (!Storage.SpellTargetPositions.ContainsKey(spellTargetPosition))
82-
Storage.SpellTargetPositions.Add(spellTargetPosition);
91+
if (isSingleDBTarget)
92+
{
93+
if (!Storage.SpellTargetPositions.ContainsKey(spellTargetPosition))
94+
{
95+
spellTargetPosition.OrderIndex = "0";
96+
Storage.SpellTargetPositions.Add(spellTargetPosition);
97+
}
98+
}
99+
else
100+
Storage.SpellTargetMultiplePositions.Add(spellID, spellTargetPosition, packet.TimeSpan);
83101
}
84102
}
85103
}

0 commit comments

Comments
 (0)