Skip to content

Commit

Permalink
Avoid fetching custom components on each hit calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
CptMoore committed Jan 27, 2025
1 parent c13999c commit d745a0d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
17 changes: 12 additions & 5 deletions source/Features/CriticalEffects/ComponentCriticals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ internal int ComponentHittableCount()

internal int ComponentHitMax()
{
var inventorySize = component.componentDef.Is<CriticalChanceCustom>(out var chance) ? chance.Size : component.componentDef.InventorySize;
// TODO fix size correctly for location:
// introduce fake items for overflow location that is crit linked and overwrite component hit max for original + crit linked
var additionalSize = component.componentDef.Is<DynamicSlots.DynamicSlots>(out var slot) && slot.InnerAdjacentOnly ? slot.ReservedSlots : 0;
return inventorySize + additionalSize;
var stat = component.StatCollection.MECriticalSlotsHitMax();
if (stat.CreateIfMissing()) { // move to Mech.init and remove "CreateIfMissing" from StatAdapter
var componentDef = component.componentDef;
var size = componentDef.InventorySize;
// TODO fix size correctly for location:
// introduce fake items for overflow location that is crit linked and overwrite component hit max for original + crit linked
var additionalSize =
componentDef.Is<DynamicSlots.DynamicSlots>(out var slot)
&& slot.InnerAdjacentOnly ? slot.ReservedSlots : 0;
stat.SetDefault(size + additionalSize);
}
return stat.Get();
}

internal int ComponentHitCount(int? setHits = null)
Expand Down
14 changes: 0 additions & 14 deletions source/Features/CriticalEffects/CriticalChanceCustom.cs

This file was deleted.

5 changes: 5 additions & 0 deletions source/Features/CriticalEffects/StatCollectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace MechEngineer.Features.CriticalEffects;

internal static class StatCollectionExtension
{
internal static StatisticAdapter<int> MECriticalSlotsHitMax(this StatCollection statCollection)
{
return new("MECriticalSlotsHitMax", statCollection, 0);
}

internal static StatisticAdapter<int> MECriticalSlotsHit(this StatCollection statCollection)
{
return new("MECriticalSlotsHit", statCollection, 0);
Expand Down
4 changes: 3 additions & 1 deletion source/Helper/StatisticAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ internal void SetDefault(T value, bool reset = true)
}
}

internal void CreateIfMissing()
internal bool CreateIfMissing()
{
if (!StatCollection.ContainsStatistic(Key))
{
Create();
return true;
}
return false;
}

internal void Modify(EffectData effectData)
Expand Down

0 comments on commit d745a0d

Please sign in to comment.