-
Contributor
19.7.1.0 breaking change: IItemStat
Removing IItemStat.Value totally is quite drastic change and breaks some plugins and causes lots of difficulties to THUD users as THUD will not start anymore if you got one of those plugins that can not compile anymore.
Especially for those users that are using Jack's Extensions will suffer and maybe can not fix it by themselves like programmers can.
I suggest that give us Value back and maybe make it return a string like the new StringValue.
At least for some grace period to get all plugins compile or something.
And I don't understand why IItemStat.IntegerValue is nullable but IItemStat.DoubleValue and IItemStat.StringValue are not!?
I agree that IItemStat.Value is quite "hard" to use and changes to make it more user friendly are welcome.
-
I had no idea anybody is using IItemStat
Do not send me private messages unless it is absolutely necessary or the content is sensitive or when I ask you to do that...
-
uploaded 19.7.2.0, added back .Value
Do not send me private messages unless it is absolutely necessary or the content is sensitive or when I ask you to do that...
-
Originally Posted by
JarJarD3
And I don't understand why IItemStat.IntegerValue is nullable but IItemStat.DoubleValue and IItemStat.StringValue are not!?
strings are reference types, so "nullable" by default
Do not send me private messages unless it is absolutely necessary or the content is sensitive or when I ask you to do that...
-
Post Thanks / Like - 1 Thanks
xblade2k7 (1 members gave Thanks to KillerJohn for this useful post)
-
Contributor
With comments in IItemStat in version 19.7.2.0 everything is now A-OK and makes sense to me.
Code:
double DoubleValue { get; } // always has a value, even if the attribute value type is _int
int? IntegerValue { get; } // contains the value as an integer - only if the attribute value type is _int
string StringValue { get; } // there is only one stat (Id = "name") which has a StringValue
Jack has a lot of code similar to this (which needs to be refactored soon):
Code:
public static int intValue(this IEnumerable<IItemStat> stats, string id)
{
return stats.Where(s => s.Id == id).Select(s => int.Parse(s.Value.ToString())).FirstOrDefault();
}
public static float floatValue(this IEnumerable<IItemStat> stats, string id)
{
return stats.Where(s => s.Id == id).Select(s => float.Parse(s.Value.ToString())).FirstOrDefault();
}
I use it to check if an item has been "enchanted":
Code:
private static ISnoItemMod GetEnhancedItemMod(IItem item)
{
if (item.StatList != null && item.Affixes != null)
{
var stat = item.StatList.FirstOrDefault(x => x.Id == "EnchantedAffixNew#1048575");
if (stat != null)
{
var integerValue = stat.IntegerValue;
if (integerValue.HasValue)
{
var enchantedAffix = (uint)integerValue.Value;
if (enchantedAffix > 0)
{
var affix = item.Affixes.FirstOrDefault(x => x.Id == enchantedAffix);
if (affix != null && affix.Mods.Length > 0)
{
return affix.Mods[0];
}
}
}
}
}
return null;
}
if IntegerValue is not costly operation, I could even make it easier to read (querying it twice):
Code:
private static ISnoItemMod GetEnhancedItemMod(IItem item)
{
if (item.StatList != null && item.Affixes != null)
{
var stat = item.StatList.FirstOrDefault(x => x.Id == "EnchantedAffixNew#1048575");
if (stat != null && stat.IntegerValue.HasValue)
{
var enchantedAffix = (uint)stat.IntegerValue.Value;
if (enchantedAffix > 0)
{
var affix = item.Affixes.FirstOrDefault(x => x.Id == enchantedAffix);
if (affix != null && affix.Mods.Length > 0)
{
return affix.Mods[0];
}
}
}
}
return null;
}
-
Post Thanks / Like - 1 Thanks
SeaDragon (1 members gave Thanks to JarJarD3 for this useful post)
-
why don't you use item.EnchantedAffixNew instead of finding it in the stat list ?
var affix = item.EnchantedAffixNew != 0
? item.Affixes.FirstOrDefault(x => x.Id == item.EnchantedAffixNew)
: null;
Do not send me private messages unless it is absolutely necessary or the content is sensitive or when I ask you to do that...