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

Allow zero enchant rarity #20

Merged
merged 4 commits into from
Aug 26, 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
106 changes: 66 additions & 40 deletions HalgarisRPGLoot/ArmorAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,45 +134,49 @@ public void Analyze()

var forLevel = AllEnchantments;
var takeMin = Math.Min(Settings.Rarities[i].NumEnchantments, forLevel.Length);
var enchs = new ResolvedEnchantment[takeMin];
enchs[0] = AllEnchantments[coreEnchant];
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;
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)
for (int t = takeMin; t < AllEnchantments.Length; ++t)
{
result[m] = t;
if (t == coreEnchant)
int m = r.Next(0, t + 1);
if (m < takeMin)
{
result[m] = result[0];
result[0] = t;
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]];
}
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);
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);
}
}
}
}
}

public void Generate()
{
foreach (var ench in AllUnenchantedItems)
Expand Down Expand Up @@ -212,18 +216,40 @@ private FormKey enchantItem(ResolvedListItem<IArmorGetter> item, int rarity)
itemName = MakeName(item.Resolved.EditorID);
}
Console.WriteLine("Generating Enchanted version of " + itemName);
var nitm = State.PatchMod.Armors.AddNewLocking(State.PatchMod.GetNextFormKey());
var nrec = GenerateEnchantment(rarity);
var effects = ChosenRPGEnchantEffects[rarity].GetValueOrDefault(nrec);
nitm.DeepCopyIn(item.Resolved);
nitm.EditorID = "HAL_ARMOR_" + nitm.EditorID;
nitm.ObjectEffect.SetTo(nrec);
nitm.EnchantmentAmount = (ushort)effects.Where(e => e.Amount.HasValue).Sum(e => e.Amount.Value);
nitm.Name = Settings.Rarities[rarity].Label + " " + itemName + " of " + effects.First().Enchantment.Name;


Console.WriteLine("Generated " + Settings.Rarities[rarity].Label + " " + itemName + " of " + effects.First().Enchantment.Name);
return nitm.FormKey;
if (Settings.Rarities[rarity].NumEnchantments != 0)
{
var nitm = State.PatchMod.Armors.AddNewLocking(State.PatchMod.GetNextFormKey());
var nrec = GenerateEnchantment(rarity);
var effects = ChosenRPGEnchantEffects[rarity].GetValueOrDefault(nrec);
nitm.DeepCopyIn(item.Resolved);
nitm.EditorID = "HAL_ARMOR_" + Settings.Rarities[rarity].Label.ToUpper() + "_" + nitm.EditorID + "_of_" + effects.First().Enchantment.Name;
nitm.ObjectEffect.SetTo(nrec);
nitm.EnchantmentAmount = (ushort)effects.Where(e => e.Amount.HasValue).Sum(e => e.Amount.Value);
nitm.Name = Settings.Rarities[rarity].Label + " " + itemName + " of " + effects.First().Enchantment.Name;


Console.WriteLine("Generated " + Settings.Rarities[rarity].Label + " " + itemName + " of " + effects.First().Enchantment.Name);
return nitm.FormKey;
}
else
{
var nitm = State.PatchMod.Armors.AddNewLocking(State.PatchMod.GetNextFormKey());
nitm.DeepCopyIn(item.Resolved);
nitm.EditorID = "HAL_ARMOR_" + nitm.EditorID;
if (Settings.Rarities[rarity].Label.Equals("") || Settings.Rarities[rarity].Label.Equals(null))
{
nitm.Name = itemName;
Console.WriteLine("Generated " + itemName);
}
else
{
nitm.Name = Settings.Rarities[rarity].Label + " " + itemName;
Console.WriteLine("Generated " + Settings.Rarities[rarity].Label + " " + itemName);
}
return nitm.FormKey;
}


}
private FormKey GenerateEnchantment(int rarity)
{
Expand Down
4 changes: 2 additions & 2 deletions HalgarisRPGLoot/HalgarisRPGLoot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mutagen.Bethesda" Version="0.30.6" />
<PackageReference Include="Mutagen.Bethesda.Synthesis" Version="0.19.2" />
<PackageReference Include="Mutagen.Bethesda" Version="0.31.0" />
<PackageReference Include="Mutagen.Bethesda.Synthesis" Version="0.19.3" />
<PackageReference Include="Mutagen.Bethesda.FormKeys.SkyrimSE" Version="2.1.0" />
</ItemGroup>
</Project>
105 changes: 64 additions & 41 deletions HalgarisRPGLoot/WeaponAnalyer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,45 +139,48 @@ public void Analyze()

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

int[] result = new int[takeMin];
for (int j = 0; j < takeMin; ++j)
result[j] = j;
var enchs = new ResolvedEnchantment[takeMin];
enchs[0] = AllEnchantments[coreEnchant];

for (int t = takeMin; t < AllEnchantments.Length; ++t)
{
int m = r.Next(0, t + 1);
if (m < takeMin)
int[] result = new int[takeMin];
for (int j = 0; j < takeMin; ++j)
result[j] = j;

for (int t = takeMin; t < AllEnchantments.Length; ++t)
{
result[m] = t;
if(t == coreEnchant)
int m = r.Next(0, t + 1);
if (m < takeMin)
{
result[m] = result[0];
result[0] = t;
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]];
}
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 + " 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 All @@ -192,18 +195,38 @@ private FormKey enchantItem(ResolvedListItem<IWeaponGetter> item,int rarity)
}

Console.WriteLine("Generating Enchanted version of " + itemName);
var nitm = State.PatchMod.Weapons.AddNewLocking(State.PatchMod.GetNextFormKey());
var nrec = GenerateEnchantment(rarity);
var effects = ChosenRPGEnchantEffects[rarity].GetValueOrDefault(nrec);
nitm.DeepCopyIn(item.Resolved);
nitm.EditorID = "HAL_WEAPON_" + Settings.Rarities[rarity].Label.ToUpper() + "_" + nitm.EditorID + "_of_" + effects.First().Enchantment.Name;
nitm.ObjectEffect.SetTo(nrec);
nitm.EnchantmentAmount = (ushort)effects.Where(e => e.Amount.HasValue).Sum(e => e.Amount.Value);
nitm.Name = Settings.Rarities[rarity].Label + " " + itemName + " of " + effects.First().Enchantment.Name;


Console.WriteLine("Generated " + Settings.Rarities[rarity].Label + " " + itemName + " of " + effects.First().Enchantment.Name);
return nitm.FormKey;
if (Settings.Rarities[rarity].NumEnchantments != 0)
{
var nitm = State.PatchMod.Weapons.AddNewLocking(State.PatchMod.GetNextFormKey());
var nrec = GenerateEnchantment(rarity);
var effects = ChosenRPGEnchantEffects[rarity].GetValueOrDefault(nrec);
nitm.DeepCopyIn(item.Resolved);
nitm.EditorID = "HAL_WEAPON_" + Settings.Rarities[rarity].Label.ToUpper() + "_" + nitm.EditorID + "_of_" + effects.First().Enchantment.Name;
nitm.ObjectEffect.SetTo(nrec);
nitm.EnchantmentAmount = (ushort)effects.Where(e => e.Amount.HasValue).Sum(e => e.Amount.Value);
nitm.Name = Settings.Rarities[rarity].Label + " " + itemName + " of " + effects.First().Enchantment.Name;


Console.WriteLine("Generated " + Settings.Rarities[rarity].Label + " " + itemName + " of " + effects.First().Enchantment.Name);
return nitm.FormKey;
}
else
{
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))
{
nitm.Name = itemName;
Console.WriteLine("Generated " + itemName);
}
else
{
nitm.Name = Settings.Rarities[rarity].Label + " " + itemName;
Console.WriteLine("Generated " + Settings.Rarities[rarity].Label + " " + itemName);
}
return nitm.FormKey;
}
}

private FormKey GenerateEnchantment(int rarity)
Expand Down