Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using BattleTech;
using MechEngineer.Features.OrderedStatusEffects;
Expand All @@ -9,6 +10,11 @@ namespace MechEngineer.Features.OverrideStatTooltips.Helper;

internal static class MechDefStatisticModifier
{
private static readonly Dictionary<string, Func<MechDef, MechComponentDef, EffectData, bool>> filters = new Dictionary<string, Func<MechDef, MechComponentDef, EffectData, bool>>();
internal static void RegisterFilter(string name, Func<MechDef, MechComponentDef, EffectData, bool> filter)
{
filters[name] = filter;
}
internal static T ModifyStatistic<T>(StatisticAdapter<T> stat, MechDef mechDef, bool acceptAllDamageLevels = false) where T : notnull
{
var effects = new List<EffectData>();
Expand All @@ -34,6 +40,13 @@ internal static T ModifyStatistic<T>(StatisticAdapter<T> stat, MechDef mechDef,
{
continue;
}
bool can_be_applied = true;
foreach(var filter in filters)
{
if (filter.Value == null) { continue; }
if (filter.Value(mechDef, null, effectData) == false) { can_be_applied = false; break; }
}
if (can_be_applied == false) { continue; }
effects.Add(effectData);
}
}
Expand All @@ -46,11 +59,6 @@ internal static T ModifyStatistic<T>(StatisticAdapter<T> stat, MechDef mechDef,
}

internal static T ModifyWeaponStatistic<T>(StatisticAdapter<T> stat, MechDef mechDef, WeaponDef weaponDef) where T : notnull
{
return ModifyWeaponStatistic<T>(stat, mechDef, weaponDef.WeaponSubType, weaponDef.Type, weaponDef.WeaponCategoryValue);
}

private static T ModifyWeaponStatistic<T>(StatisticAdapter<T> stat, MechDef mechDef, WeaponSubType subType, WeaponType type, WeaponCategoryValue categoryValue) where T : notnull
{
var effects = new List<EffectData>();
foreach (var componentDef in mechDef.Inventory.Where(x => x.IsFunctionalORInstalling()).Select(x => x.Def))
Expand All @@ -75,10 +83,17 @@ private static T ModifyWeaponStatistic<T>(StatisticAdapter<T> stat, MechDef mech
{
continue;
}
if (!IsStatusEffectAffectingWeapon(effectData.statisticData, subType, type, categoryValue))
if (!IsStatusEffectAffectingWeapon(effectData.statisticData, weaponDef.WeaponSubType, weaponDef.Type, weaponDef.WeaponCategoryValue))
{
continue;
}
bool can_be_applied = true;
foreach (var filter in filters)
{
if (filter.Value == null) { continue; }
if (filter.Value(mechDef, weaponDef, effectData) == false) { can_be_applied = false; break; }
}
if (can_be_applied == false) { continue; }
effects.Add(effectData);
}
}
Expand Down