Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

excluded unused settings and fixed some warnings #24

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
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
86 changes: 40 additions & 46 deletions HalgarisRPGLoot/ArmorAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void Analyze()

AllListItems = AllLeveledLists.SelectMany(lst => lst.Entries?.Select(entry =>
{
if (entry?.Data?.Reference.FormKey == default) return default;
if (entry.Data?.Reference.FormKey == default) return default;

if (!State.LinkCache.TryResolve<IArmorGetter>(entry.Data.Reference.FormKey,

Expand Down Expand Up @@ -101,12 +101,13 @@ public void Analyze()
.Distinct()
.Select(e =>
{
if (!AllObjectEffects.TryGetValue(e.FormKey, out var ench))
var (level, enchantmentAmount, formKey) = e;
if (!AllObjectEffects.TryGetValue(formKey, out var ench))
return default;
return new ResolvedEnchantment
{
Level = e.Level,
Amount = e.Item2,
Level = level,
Amount = enchantmentAmount,
Enchantment = ench
};
})
Expand All @@ -115,7 +116,7 @@ public void Analyze()

AllLevels = AllEnchantments.Select(e => e.Level).Distinct().ToHashSet();

short maxLvl = AllListItems.Select(i => i.Entry.Data.Level).Distinct().ToHashSet().Max();
var maxLvl = AllListItems.Select(i => i.Entry.Data.Level).Distinct().ToHashSet().Max();

ByLevel = AllEnchantments.GroupBy(e => e.Level)
.OrderBy(e => e.Key)
Expand All @@ -134,44 +135,37 @@ public void Analyze()

var forLevel = AllEnchantments;
var takeMin = Math.Min(Settings.Rarities[i].NumEnchantments, forLevel.Length);
if (takeMin > 0)
{
var enchs = new ResolvedEnchantment[takeMin];
enchs[0] = AllEnchantments[coreEnchant];

int[] result = new int[takeMin];
for (int j = 0; j < takeMin; ++j)
result[j] = j;

for (int t = takeMin; t < AllEnchantments.Length; ++t)
{
int m = r.Next(0, t + 1);
if (m < takeMin)
{
result[m] = t;
if (t == coreEnchant)
{
result[m] = result[0];
result[0] = t;
}
}
}
if (result[0] != coreEnchant)
{
result[0] = coreEnchant;
}
for (int len = 0; len < takeMin; len++)
{
enchs[len] = AllEnchantments[result[len]];
}

var oldench = enchs.First().Enchantment;
SortedList<String, ResolvedEnchantment[]> enchants = AllRPGEnchants[i];
Console.WriteLine("Generated raw " + Settings.Rarities[i].Label + " armor enchantment of " + oldench.Name);
if (!enchants.ContainsKey(Settings.Rarities[i].Label + " " + oldench.Name))
{
enchants.Add(Settings.Rarities[i].Label + " " + oldench.Name, enchs);
}
if (takeMin <= 0) continue;
var enchs = new ResolvedEnchantment[takeMin];
enchs[0] = AllEnchantments[coreEnchant];

int[] result = new int[takeMin];
for (int j = 0; j < takeMin; ++j)
result[j] = j;

for (int t = takeMin; t < AllEnchantments.Length; ++t)
{
var m = r.Next(0, t + 1);
if (m >= takeMin) continue;
result[m] = t;
if (t != coreEnchant) continue;
result[m] = result[0];
result[0] = t;
}

result[0] = coreEnchant;

for (int len = 0; len < takeMin; len++)
{
enchs[len] = AllEnchantments[result[len]];
}

var oldench = enchs.First().Enchantment;
SortedList<String, ResolvedEnchantment[]> enchants = AllRPGEnchants[i];
Console.WriteLine("Generated raw " + Settings.Rarities[i].Label + " armor enchantment of " + oldench.Name);
if (!enchants.ContainsKey(Settings.Rarities[i].Label + " " + oldench.Name))
{
enchants.Add(Settings.Rarities[i].Label + " " + oldench.Name, enchs);
}
}
}
Expand Down Expand Up @@ -284,9 +278,9 @@ public int RandomRarity()
{
int rar = 0;
int total = 0;
for (int i = 0; i < Settings.Rarities.Count; i++)
foreach (var t in Settings.Rarities)
{
total += Settings.Rarities[i].LLEntries;
total += t.LLEntries;
}
int roll = r.Next(0, total);
while (roll >= Settings.Rarities[rar].LLEntries && rar < Settings.Rarities.Count)
Expand All @@ -299,7 +293,7 @@ public int RandomRarity()
private static char[] Numbers = "123456890".ToCharArray();
private static Regex Splitter = new Regex("(?<=[A-Z])(?=[A-Z][a-z])|(?<=[^A-Z])(?=[A-Z])|(?<=[A-Za-z])(?=[^A-Za-z])");
private Dictionary<string, string> KnownMapping = new Dictionary<string, string>();
private string MakeName(string? resolvedEditorId)
private string MakeName(string resolvedEditorId)
{
string returning;
if (resolvedEditorId == null)
Expand Down
2 changes: 1 addition & 1 deletion HalgarisRPGLoot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Program
static Lazy<Settings> _LazySettings = null!;
public static Settings Settings => _LazySettings.Value;

static async Task<int> Main(string[] args)
private static async Task<int> Main(string[] args)
{
return await SynthesisPipeline.Instance
.AddPatch<ISkyrimMod, ISkyrimModGetter>(RunPatch)
Expand Down
8 changes: 7 additions & 1 deletion HalgarisRPGLoot/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ public class ArmorSettings
new Rarity() { Label= "Epic", NumEnchantments=3, LLEntries=5 },
new Rarity() { Label= "Legendary", NumEnchantments=4, LLEntries=2 },
};
/*
[SynthesisSettingName("Use RNGRarity")]
[SynthesisTooltip("With this set to true the number of variations\n" +
"per item will be randomised.")]
public bool UseRNGRarities = true;
*/
}

public class WeaponSettings
Expand All @@ -46,10 +48,12 @@ public class WeaponSettings
new Rarity() { Label= "Epic", NumEnchantments=3, LLEntries=5 },
new Rarity() { Label= "Legendary", NumEnchantments=4, LLEntries=2 },
};
/*
[SynthesisSettingName("Use RNGRarity")]
[SynthesisTooltip("With this set to true the number of variations\n" +
"per item will be randomised.")]
public bool UseRNGRarities = true;
*/
}

public class Rarity
Expand All @@ -58,11 +62,12 @@ public class Rarity
public string Label;
[SynthesisSettingName("Number of Enchantments")]
public int NumEnchantments;
[SynthesisSettingName("Number of LevedList Entries")]
[SynthesisSettingName("Number of LeveledList Entries")]
[SynthesisTooltip("The higher the number the more common it is.")]
public int LLEntries;
}

/*
public enum SearchMode
{
ClosestLevel,
Expand All @@ -76,5 +81,6 @@ public enum PreferredLevel
Higher,
Lower
}
*/

}
76 changes: 35 additions & 41 deletions HalgarisRPGLoot/WeaponAnalyer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public WeaponAnalyzer(IPatcherState<ISkyrimMod, ISkyrimModGetter> state)
{
ChosenRPGEnchants[i] = new Dictionary<String, FormKey>();
}
ChosenRPGEnchantEffects = new Dictionary<FormKey, ResolvedEnchantment[]>[Settings.Rarities.Count()];
ChosenRPGEnchantEffects = new Dictionary<FormKey, ResolvedEnchantment[]>[Settings.Rarities.Count];
for (int i = 0; i < ChosenRPGEnchantEffects.Length; i++)
{
ChosenRPGEnchantEffects[i] = new Dictionary<FormKey, ResolvedEnchantment[]>();
Expand All @@ -83,10 +83,10 @@ public void Analyze()
Resolved = resolved
};
}).Where(r => r != default)
?? new ResolvedListItem<IWeaponGetter>[0])
?? Array.Empty<ResolvedListItem<IWeaponGetter>>())
.Where(e =>
{
var kws = (e.Resolved.Keywords ?? new IFormLink<IKeywordGetter>[0]);
var kws = (e.Resolved.Keywords ?? Array.Empty<IFormLink<IKeywordGetter>>());
return (!kws.Contains(Skyrim.Keyword.WeapTypeStaff))
&& (!kws.Contains(Skyrim.Keyword.MagicDisallowEnchanting));
})
Expand Down Expand Up @@ -139,45 +139,39 @@ public void Analyze()

var forLevel = AllEnchantments;
var takeMin = Math.Min(Settings.Rarities[i].NumEnchantments, forLevel.Length);
if (takeMin > 0)
{

var enchs = new ResolvedEnchantment[takeMin];
enchs[0] = AllEnchantments[coreEnchant];
if (takeMin <= 0) continue;
var enchs = new ResolvedEnchantment[takeMin];
enchs[0] = AllEnchantments[coreEnchant];

int[] result = new int[takeMin];
for (int j = 0; j < takeMin; ++j)
result[j] = j;
int[] result = new int[takeMin];
for (int j = 0; j < takeMin; ++j)
result[j] = j;

for (int t = takeMin; t < AllEnchantments.Length; ++t)
{
int m = r.Next(0, t + 1);
if (m < takeMin)
{
result[m] = t;
if(t == coreEnchant)
{
result[m] = result[0];
result[0] = t;
}
}
}
if(result[0] != coreEnchant)
{
result[0] = coreEnchant;
}
for(int len = 0; len < takeMin; len++)
for (int t = takeMin; t < AllEnchantments.Length; ++t)
{
int m = r.Next(0, t + 1);
if (m >= takeMin) continue;
result[m] = t;
if(t == coreEnchant)
{
enchs[len] = AllEnchantments[result[len]];
result[m] = result[0];
result[0] = t;
}
}

result[0] = coreEnchant;

for(int len = 0; len < takeMin; len++)
{
enchs[len] = AllEnchantments[result[len]];
}

var oldench = enchs.First().Enchantment;
SortedList<String, ResolvedEnchantment[]> enchants = AllRPGEnchants[i];
Console.WriteLine("Generated raw " + Settings.Rarities[i].Label + " weapon enchantment of " + oldench.Name);
if (!enchants.ContainsKey(Settings.Rarities[i].Label + " " + oldench.Name))
{
enchants.Add(Settings.Rarities[i].Label + " " + oldench.Name, enchs);
}
var oldench = enchs.First().Enchantment;
SortedList<String, ResolvedEnchantment[]> enchants = AllRPGEnchants[i];
Console.WriteLine("Generated raw " + Settings.Rarities[i].Label + " weapon enchantment of " + oldench.Name);
if (!enchants.ContainsKey(Settings.Rarities[i].Label + " " + oldench.Name))
{
enchants.Add(Settings.Rarities[i].Label + " " + oldench.Name, enchs);
}
}
}
Expand Down Expand Up @@ -215,7 +209,7 @@ private FormKey enchantItem(ResolvedListItem<IWeaponGetter> item,int rarity)
var nitm = State.PatchMod.Weapons.AddNewLocking(State.PatchMod.GetNextFormKey());
nitm.DeepCopyIn(item.Resolved);
nitm.EditorID = "HAL_WEAPON_" + nitm.EditorID;
if (Settings.Rarities[rarity].Label.Equals("") || Settings.Rarities[rarity].Label.Equals(null))
if (Settings.Rarities[rarity].Label.Equals(""))
{
nitm.Name = itemName;
Console.WriteLine("Generated " + itemName);
Expand Down Expand Up @@ -291,9 +285,9 @@ public int RandomRarity()
{
int rar = 0;
int total = 0;
for(int i = 0; i < Settings.Rarities.Count; i++)
foreach (var t in Settings.Rarities)
{
total += Settings.Rarities[i].LLEntries;
total += t.LLEntries;
}
int roll = r.Next(0, total);
while(roll >= Settings.Rarities[rar].LLEntries && rar < Settings.Rarities.Count)
Expand All @@ -307,7 +301,7 @@ public int RandomRarity()
private static char[] Numbers = "123456890".ToCharArray();
private static Regex Splitter = new Regex("(?<=[A-Z])(?=[A-Z][a-z])|(?<=[^A-Z])(?=[A-Z])|(?<=[A-Za-z])(?=[^A-Za-z])");
private Dictionary<string, string> KnownMapping = new Dictionary<string, string>();
private string MakeName(string? resolvedEditorId)
private string MakeName(string resolvedEditorId)
{
string returning;
if (resolvedEditorId == null)
Expand Down