private static FloatRange CalculateStatRange(StatDef stat) { var statRange = FloatRange.Zero; var apparelFilter = new ThingFilter(); apparelFilter.SetAllow(ThingCategoryDefOf.Apparel, true); var apparels = ThingCategoryNodeDatabase.RootNode.catDef.DescendantThingDefs .Where(t => apparelFilter.Allows(t) && !apparelFilter.IsAlwaysDisallowedDueToSpecialFilters(t)).ToList() .Where(a => a.statBases != null && a.StatBaseDefined(stat) || a.equippedStatOffsets != null && a.equippedStatOffsets.Any(o => o.stat == stat)).ToList(); if (apparels.Any()) { foreach (var apparel in apparels) { var statBase = apparel.statBases?.Find(sm => sm.stat == stat); var baseStatValue = statBase?.value ?? stat.defaultBaseValue; float statOffsetValue = 0; var statOffset = apparel.equippedStatOffsets?.Find(sm => sm.stat == stat); if (statOffset != null) { statOffsetValue = statOffset.value; } var totalStatValue = baseStatValue + statOffsetValue - stat.defaultBaseValue; if (Math.Abs(statRange.min) < 0.0001 && Math.Abs(statRange.max) < 0.0001) { statRange.min = totalStatValue; statRange.max = totalStatValue; } else { if (statRange.min > totalStatValue) { statRange.min = totalStatValue; } if (statRange.max < totalStatValue) { statRange.max = totalStatValue; } } } } else { statRange.min = stat.defaultBaseValue; statRange.max = stat.defaultBaseValue; } StatRanges.Add(stat, statRange); return(statRange); }
private bool Visible(ThingDef td) { if (td.menuHidden) { return(false); } if (forceHiddenDefs != null && forceHiddenDefs.Contains(td)) { return(false); } if (parentFilter != null) { if (!parentFilter.Allows(td)) { return(false); } if (parentFilter.IsAlwaysDisallowedDueToSpecialFilters(td)) { return(false); } } return(true); }