So, I recently went from looking up items from their CGItem pointer to using the WoW cache to get ItemRec and ItemRecSparse. This lead me to a bit of a trouble when reading stats from items (such as itemlinks) with RandomProperty or RandomSuffix set. I don't fully understand how this works as I haven't found a function that reads random stats from the WoWDB2. I have been using https://github.com/mangos/mangos/blo.../game/Item.cpp as a reference. What I've made so far is this:
Code:
public Dictionary<ItemStatType, int> RandomStats
{
get
{
if (RandomProperty == 0 && RandomSuffix == 0)
return null;
var sieEntries = new List<SpellItemEnchantmentRec>();
var sieStorage = WoWDB.GetTable(ClientDB.SpellItemEnchantment);
if (RandomProperty > 0)
{ // ItemRandomProperty
var irp = WoWDB.GetTable(ClientDB.ItemRandomProperties).GetRow(RandomProperty);
for (uint i = 2; i < 6; i++)
{
var sieRef = irp.GetField<int>(i);
if (sieRef == 0) continue;
sieEntries.Add(sieStorage.GetRow(sieRef).GetStruct<SpellItemEnchantmentRec>());
}
}
else
{ // ItemRandomSuffix
var irs = WoWDB.GetTable(ClientDB.ItemRandomSuffix).GetRow(RandomSuffix);
for (uint i = 3; i < 7; i++)
{
var sieRef = irs.GetField<int>(i);
if (sieRef == 0) continue;
sieEntries.Add(sieStorage.GetRow(sieRef).GetStruct<SpellItemEnchantmentRec>());
}
}
var stats = new Dictionary<ItemStatType, int>();
foreach (var sie in sieEntries)
{
for (var i = 0; i < 3; i++)
{
if (sie.EffectID[i] == 0
|| (sie.EffectValueMin[i] == 0 && sie.EffectValueMax[i] == 0))
continue;
var stat = (ItemStatType)sie.EffectID[i];
var value = (sie.EffectValueMin[i] + sie.EffectValueMax[i]) / 2; // get average
if (stats.ContainsKey(stat))
stats[stat] += value;
else
stats.Add(stat, value);
}
}
return stats;
}
}
I think the problem is that the ItemRandomSuffix is a bit different than ItemRandomProperty, but I'm treating them the same. The current method goes like this:
Get RandomProperty/Suffix -> Look up entry in DBC -> Get the 5 SpellItemEffect rows -> Look up each in the DBCs -> Find average stat value -> Sum everything up and return
Has anyone done any research on this? Any advice?