Skip to content

Commit

Permalink
DBC: Fixed crash and load of SpellMisc data
Browse files Browse the repository at this point in the history
  • Loading branch information
BertiRean committed Mar 20, 2024
1 parent 20a78f2 commit 086bf4d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
63 changes: 42 additions & 21 deletions SpellWork/DBC/DBC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,19 @@ public static async void Load()

await Task.WhenAll(Task.Run(() =>
{
foreach (var effect in SpellInfoStore.Where(effect => SpellMisc.ContainsKey(effect.Value.Spell.ID)))
foreach (var spellMisc in SpellMisc.Values.Where(misc => SpellInfoStore.ContainsKey(misc.SpellID)))
{
effect.Value.Misc = SpellMisc[effect.Value.Spell.ID];
if (spellMisc.DifficultyID != 0)
continue;

var spell = SpellInfoStore[spellMisc.SpellID];
spell.Misc = spellMisc;

if (SpellDuration.ContainsKey(effect.Value.Misc.DurationIndex))
effect.Value.DurationEntry = SpellDuration[effect.Value.Misc.DurationIndex];
if (SpellDuration.ContainsKey(spellMisc.DurationIndex))
spell.DurationEntry = SpellDuration[spellMisc.DurationIndex];

if (SpellRange.ContainsKey(effect.Value.Misc.RangeIndex))
effect.Value.Range = SpellRange[effect.Value.Misc.RangeIndex];
if (SpellRange.ContainsKey(spellMisc.RangeIndex))
spell.Range = SpellRange[spellMisc.RangeIndex];
}
}), Task.Run(() =>
{
Expand All @@ -139,32 +143,35 @@ await Task.WhenAll(Task.Run(() =>
}
}), Task.Run(() =>
{
foreach (var effect in SpellTargetRestrictions.Values)
foreach (var spellTargetRestrictions in SpellTargetRestrictions.Values)
{
if (!SpellInfoStore.ContainsKey(effect.SpellID))
if (spellTargetRestrictions.DifficultyID != 0)
continue;

if (!SpellInfoStore.ContainsKey(spellTargetRestrictions.SpellID))
{
Console.WriteLine(
$"SpellTargetRestrictions: Unknown spell {effect.SpellID} referenced, ignoring!");
$"SpellTargetRestrictions: Unknown spell {spellTargetRestrictions.SpellID} referenced, ignoring!");
continue;
}

SpellInfoStore[effect.SpellID].TargetRestrictions.Add(effect);
SpellInfoStore[spellTargetRestrictions.SpellID].TargetRestrictions.Add(spellTargetRestrictions);
}
}), Task.Run(() =>
{
foreach (var spellXSpellVisual in SpellXSpellVisual.Where(effect =>
effect.Value.DifficultyID == 0 && effect.Value.CasterPlayerConditionID == 0))
foreach (var spellXSpellVisual in SpellXSpellVisual.Values.Where(effect => effect.CasterPlayerConditionID == 0))
{
if (spellXSpellVisual.Value.DifficultyID != 0) { continue; }
if (spellXSpellVisual.DifficultyID != 0)
continue;

if (!SpellInfoStore.ContainsKey(spellXSpellVisual.Value.SpellID))
if (!SpellInfoStore.ContainsKey(spellXSpellVisual.SpellID))
{
Console.WriteLine(
$"SpellXSpellVisual: Unknown spell {spellXSpellVisual.Value.SpellID} referenced, ignoring!");
$"SpellXSpellVisual: Unknown spell {spellXSpellVisual.SpellID} referenced, ignoring!");
continue;
}

SpellInfoStore[spellXSpellVisual.Value.SpellID].SpellXSpellVisual = spellXSpellVisual.Value;
SpellInfoStore[spellXSpellVisual.SpellID].SpellXSpellVisual = spellXSpellVisual;
}
}), Task.Run(() =>
{
Expand All @@ -176,13 +183,15 @@ await Task.WhenAll(Task.Run(() =>
$"SpellScaling: Unknown spell {spellScaling.SpellID} referenced, ignoring!");
continue;
}

SpellInfoStore[spellScaling.SpellID].Scaling = spellScaling;
}
}), Task.Run(() =>
{
foreach (var spellAuraOptions in SpellAuraOptions.Values)
{
if (spellAuraOptions.DifficultyID != 0)
continue;

if (!SpellInfoStore.ContainsKey(spellAuraOptions.SpellID))
{
Console.WriteLine(
Expand All @@ -198,6 +207,9 @@ await Task.WhenAll(Task.Run(() =>
{
foreach (var spellAuraRestriction in SpellAuraRestrictions.Values)
{
if (spellAuraRestrictions.DifficultyID != 0)
continue;

if (!SpellInfoStore.ContainsKey(spellAuraRestriction.SpellID))
{
Console.WriteLine(
Expand All @@ -211,6 +223,9 @@ await Task.WhenAll(Task.Run(() =>
{
foreach (var spellCategory in SpellCategories.Values)
{
if (spellCategory.DifficultyID != 0)
continue;

if (!SpellInfoStore.ContainsKey(spellCategory.SpellID))
{
Console.WriteLine(
Expand Down Expand Up @@ -250,6 +265,9 @@ await Task.WhenAll(Task.Run(() =>
{
foreach (var spellCooldown in SpellCooldowns.Values)
{
if (spellCooldown.DifficultyID != 0)
continue;

if (!SpellInfoStore.ContainsKey(spellCooldown.SpellID))
{
Console.WriteLine(
Expand Down Expand Up @@ -289,6 +307,9 @@ await Task.WhenAll(Task.Run(() =>
{
foreach (var spellLevel in SpellLevels.Values)
{
if (spellLevel.DifficultyID != 0)
continue;

if (!SpellInfoStore.ContainsKey(spellLevel.SpellID))
{
Console.WriteLine($"SpellLevels: Unknown spell {spellLevel.SpellID} referenced, ignoring!");
Expand All @@ -299,16 +320,16 @@ await Task.WhenAll(Task.Run(() =>
}
}), Task.Run(() =>
{
foreach (var effect in SpellReagents)
foreach (var spellReagents in SpellReagents)
{
if (!SpellInfoStore.ContainsKey(effect.Value.SpellID))
if (!SpellInfoStore.ContainsKey(spellReagents.Value.SpellID))
{
Console.WriteLine(
$"SpellReagents: Unknown spell {effect.Value.SpellID} referenced, ignoring!");
$"SpellReagents: Unknown spell {spellReagents.Value.SpellID} referenced, ignoring!");
continue;
}

SpellInfoStore[effect.Value.SpellID].Reagents = effect.Value;
SpellInfoStore[spellReagents.Value.SpellID].Reagents = spellReagents.Value;
}
}), Task.Run(() =>
{
Expand Down
4 changes: 2 additions & 2 deletions SpellWork/Spell/SpellInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SpellInfo
{
public SpellEntry Spell { get; set; }
public SpellAuraOptionsEntry AuraOptions { get; set; }
public SpellAuraRestrictionsEntry AuraRestrictions { get; set; }
public List<SpellAuraRestrictionsEntry> AuraRestrictions { get; set; }
public SpellCastingRequirementsEntry CastingRequirements { get; set; }
public SpellCategoriesEntry Categories { get; set; }
public SpellClassOptionsEntry ClassOptions { get; set; }
Expand Down Expand Up @@ -769,7 +769,7 @@ from skill in temp.DefaultIfEmpty(new SkillLineAbilityEntry())
if ((Mechanics)effect.EffectMechanic != Mechanics.MECHANIC_NONE)
rtb.AppendFormatLine("Effect Mechanic = {0} ({1})", effect.EffectMechanic, (Mechanics)effect.EffectMechanic);

rtb.AppendFormatLineIfNotNull("Attributes {0:X8} ({0})", effect.EffectAttributes);
rtb.AppendFormatLineIfNotNull("Attributes {0:X8} ({0})", (uint)effect.EffectAttributes);
rtb.AppendLine();
}

Expand Down

0 comments on commit 086bf4d

Please sign in to comment.