Skip to content

Commit

Permalink
code optimization + balance fix
Browse files Browse the repository at this point in the history
  • Loading branch information
EzioTheDeadPoet committed Jan 31, 2023
1 parent b10d830 commit 5499bce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 76 deletions.
99 changes: 29 additions & 70 deletions SlotsSlotsSlots/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static void RunPatch(IPatcherState<ISkyrimMod, ISkyrimModGetter> state)
var potionWeights = Settings.PotionSlotUse;
var scrollWeights = Settings.ScrollSlotUse;
var useBaseMult = Settings.UseRaceMult;
var noHealFromWeightless = Settings.WeightlessItemsOfferNoHealing;
var minWeaponSlots = Settings.MinimumUsedWeaponSlots;
var maxWeaponSlots = Settings.MaximumUsedWeaponSlots;
var minArmorslots = Settings.MinimumUsedArmorSlots;
Expand Down Expand Up @@ -117,7 +116,7 @@ public static void RunPatch(IPatcherState<ISkyrimMod, ISkyrimModGetter> state)
}
}

// The following could profit from optimization, way to many foreach loops.
// The following could probably profit from optimization, way to many foreach loops.

foreach (var perk in state.LoadOrder.PriorityOrder.Perk().WinningOverrides())
{
Expand All @@ -129,36 +128,31 @@ public static void RunPatch(IPatcherState<ISkyrimMod, ISkyrimModGetter> state)
{
foreach (var carryWeightSpell in carryWeightSpells)
{
if (carryWeightSpell.SpellAndEffects.TryGetValue(fl.FormKey, out var spellEffectSet))
if (!carryWeightSpell.SpellAndEffects.TryGetValue(fl.FormKey, out var spellEffectSet))
continue;
foreach (var spellEffect in spellEffectSet)
{
foreach (var spellEffect in spellEffectSet)
if (!carryWeightSpell.EffectAndMagnitudes.TryGetValue(spellEffect,
out var magnitudesList)) continue;
foreach (var magnitude in magnitudesList)
{
if (carryWeightSpell.EffectAndMagnitudes.TryGetValue(spellEffect,
out var magnitudesList))
{
foreach (var magnitude in magnitudesList)
{
if ((deepCopyPerk.Description.ToString().Contains($"carry") ||
deepCopyPerk.Description.ToString().Contains($"Carry")) &&
deepCopyPerk.Description.ToString().Contains($"{magnitude}"))
{
var slots = (int) (magnitude * effectMultiplier);
deepCopyPerk.Description = deepCopyPerk.Description
.ToString()
.Replace($" {magnitude} ", $" {slots} ")
.Replace($" {magnitude}.", $" {slots}.")
.Replace($" {magnitude},", $" {slots},")
.Replace($"Carry Weight is", "Slots are")
.Replace($"Carry Weight", $"Number of Slots")
.Replace($"carry weight is", "slots are")
.Replace($"carry weight", $"number of slots");
Console.WriteLine(
$"{perk.EditorID} was considered a CarryWeight altering Perk and the description, if needed, adjusted:\n \"{deepCopyPerk.Description}\"\n");

state.PatchMod.Perks.Set(deepCopyPerk);
}
}
}
if (!deepCopyPerk.Description.ToString()
.Contains($"carry", StringComparison.OrdinalIgnoreCase) ||
!deepCopyPerk.Description.ToString().Contains($"{magnitude}")) continue;
var slots = (int) (magnitude * effectMultiplier);
deepCopyPerk.Description = deepCopyPerk.Description
.ToString()
.Replace($" {magnitude} ", $" {slots} ")
.Replace($" {magnitude}.", $" {slots}.")
.Replace($" {magnitude},", $" {slots},")
.Replace($"Carry Weight is", "Slots are")
.Replace($"Carry Weight", $"Number of Slots")
.Replace($"carry weight is", "slots are")
.Replace($"carry weight", $"number of slots");
Console.WriteLine(
$"{perk.EditorID} was considered a CarryWeight altering Perk and the description, if needed, adjusted:\n \"{deepCopyPerk.Description}\"\n");

state.PatchMod.Perks.Set(deepCopyPerk);
}
}
}
Expand Down Expand Up @@ -187,36 +181,16 @@ public static void RunPatch(IPatcherState<ISkyrimMod, ISkyrimModGetter> state)
}
else if (!(ingestible.EditorID?.Equals("dunSleepingTreeCampSap") ?? false))
{
ingestibleCopy.Weight = (useBaseMult) ? ingestibleCopy.Weight * baseCarryWeightMult : 0.0f;
ingestibleCopy.Weight *= baseCarryWeightMult;
}

foreach (var carryWeightEffect in magicEffects.carryWeight)
{
foreach (var effect in ingestibleCopy.Effects)
{
if (carryWeightEffect.Equals(effect.BaseEffect))
{
effect.Data ??= new();
effect.Data.Magnitude *= effectMultiplier;
}
}
}

if (noHealFromWeightless)
{
foreach (var healthEffect in magicEffects.health)
{
foreach (var e in ingestibleCopy.Effects)
{
if (healthEffect.Equals(e.BaseEffect)
&&
!(ingestible.HasKeyword(Skyrim.Keyword.VendorItemPotion)
|| (ingestible.EditorID?.Equals("dunSleepingTreeCampSap") ?? false)))
{
e.Data ??= new();
e.Data.Magnitude = 0;
}
}
if (!carryWeightEffect.Equals(effect.BaseEffect)) continue;
effect.Data ??= new();
effect.Data.Magnitude *= effectMultiplier;
}
}

Expand All @@ -227,7 +201,7 @@ public static void RunPatch(IPatcherState<ISkyrimMod, ISkyrimModGetter> state)
foreach (var ingredient in state.LoadOrder.PriorityOrder.Ingredient().WinningOverrides())
{
var ingredientCopy = ingredient.DeepCopy();
ingredientCopy.Weight = (useBaseMult) ? ingredientCopy.Weight * baseCarryWeightMult : 0.0f;
ingredientCopy.Weight = ingredientCopy.Weight * baseCarryWeightMult;
foreach (var carryWeightEffect in magicEffects.carryWeight)
{
foreach (var effect in ingredientCopy.Effects)
Expand All @@ -240,21 +214,6 @@ public static void RunPatch(IPatcherState<ISkyrimMod, ISkyrimModGetter> state)
}
}

if (noHealFromWeightless)
{
foreach (var healthMagicEffect in magicEffects.health)
{
foreach (var e in ingredientCopy.Effects)
{
if (healthMagicEffect.Equals(e.BaseEffect))
{
e.Data ??= new();
e.Data.Magnitude = 0;
}
}
}
}

state.PatchMod.Ingredients.Set(ingredientCopy);
}

Expand Down
6 changes: 0 additions & 6 deletions SlotsSlotsSlots/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ public record Settings
"\nDefault is not to use this and making items weightless.")]
public bool UseRaceMult = false;

[SynthesisOrder]
[SynthesisSettingName("No healing from lesser items")]
[SynthesisDescription("This disables the healing effect from any item that isn't a potion, as they are excluded from the slot system.")]
[SynthesisTooltip("This disables the healing effect from any item that isn't a potion, as they are excluded from the slot system.")]
public bool WeightlessItemsOfferNoHealing = true;

[SynthesisOrder]
[SynthesisSettingName("Minimum Weaponslots")]
[SynthesisDescription("This is the number of slots the lightest weapons will need.")]
Expand Down

0 comments on commit 5499bce

Please sign in to comment.