Skip to content

Commit 189c52e

Browse files
authored
Merge pull request #629 from Vapok/pr/EpicLoot-0.9.23
Epic Loot 0.9.23 - Crafting with Enchanted Components
2 parents a66716c + df010a5 commit 189c52e

6 files changed

Lines changed: 122 additions & 6 deletions

File tree

EpicLoot/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
## Version 0.9.23 - Crafting with Enchanted Components
2+
* Recipes built with items that are Enchanted will now carry over their magical properties to the new item.
3+
* The highest magical rarity will carry over if more than one magical item is consumed.
4+
* Server-Synced Configuration is available toggle the enablement of this functionality.
5+
* Default will leave this functionality Disabled.
6+
17
## Version 0.9.22 - Bounty System Improvements Part 2
28
* Would help if I included the translations in the Module Zip
3-
* Also, when Auga is NOT installed, have to forcably localize the strings.
9+
* Also, when Auga is NOT installed, have to forcably localize the strings.
410
* Added the new trophies to the Enchantcosts
511

612
## Version 0.9.21 - Bounty System Improvements
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System.Collections.Generic;
2+
using HarmonyLib;
3+
using JetBrains.Annotations;
4+
using UnityEngine;
5+
6+
namespace EpicLoot.Crafting;
7+
8+
public static class TransferMagicalEffects
9+
{
10+
11+
private static bool IsDoCraft;
12+
private static ItemDrop.ItemData CraftedItem = null;
13+
private static List<ItemDrop.ItemData> ConsumedMagicItems = new ();
14+
15+
private static void TransferMagicToCraftedItem(Player player)
16+
{
17+
if (!IsDoCraft || !EpicLoot.TransferMagicItemToCrafts.Value || CraftedItem == null || ConsumedMagicItems.Count == 0) return;
18+
19+
MagicItem highestTierMagicItem = null;
20+
21+
foreach (var itemData in ConsumedMagicItems)
22+
{
23+
var magicItem = itemData.GetMagicItem();
24+
if (magicItem == null)
25+
continue;
26+
if (highestTierMagicItem == null)
27+
highestTierMagicItem = magicItem;
28+
else
29+
{
30+
if (magicItem.Rarity > highestTierMagicItem.Rarity)
31+
highestTierMagicItem = magicItem;
32+
else if (magicItem.Rarity == highestTierMagicItem.Rarity)
33+
if (magicItem.Effects.Count > highestTierMagicItem.Effects.Count)
34+
highestTierMagicItem = magicItem;
35+
}
36+
}
37+
38+
if (highestTierMagicItem == null)
39+
return;
40+
41+
IsDoCraft = false;
42+
CraftedItem.SaveMagicItem(highestTierMagicItem);
43+
}
44+
45+
[HarmonyPatch(typeof(InventoryGui), nameof(InventoryGui.DoCrafting))]
46+
static class InventoryGuiDoCraftingPatch
47+
{
48+
[UsedImplicitly]
49+
static void Prefix(InventoryGui __instance)
50+
{
51+
IsDoCraft = true;
52+
}
53+
54+
[UsedImplicitly]
55+
static void Postfix(InventoryGui __instance, Player player)
56+
{
57+
TransferMagicToCraftedItem(player);
58+
IsDoCraft = false;
59+
CraftedItem = null;
60+
ConsumedMagicItems = new List<ItemDrop.ItemData>();
61+
}
62+
}
63+
64+
[HarmonyPatch(typeof(Inventory), nameof(Inventory.AddItem), new []{typeof(string), typeof(int), typeof(int), typeof(int), typeof(long),typeof(string),typeof(bool)})]
65+
static class InventoryAddItemPatch
66+
{
67+
[UsedImplicitly]
68+
static void Postfix(Inventory __instance, ref ItemDrop.ItemData __result)
69+
{
70+
if (!IsDoCraft) return;
71+
72+
CraftedItem = __result;
73+
}
74+
}
75+
76+
[HarmonyPatch(typeof(Inventory), nameof(Inventory.RemoveItem), new[] { typeof(string), typeof(int), typeof(int), typeof(bool) })]
77+
static class InventoryRemoveItemPatch
78+
{
79+
private static void CheckConsumedResource(ItemDrop.ItemData itemData)
80+
{
81+
if (!IsDoCraft) return;
82+
83+
if (itemData.IsMagic())
84+
ConsumedMagicItems.Add(itemData);
85+
}
86+
87+
[UsedImplicitly]
88+
public static void Prefix(Inventory __instance, string name, int amount, int itemQuality, bool worldLevelBased)
89+
{
90+
if (!IsDoCraft || __instance == null) return;
91+
92+
foreach (var itemData in __instance.m_inventory)
93+
{
94+
if (itemData.m_shared.m_name == name
95+
&& (itemQuality < 0 || itemData.m_quality == itemQuality)
96+
&& (!worldLevelBased || itemData.m_worldLevel >= Game.m_worldLevel))
97+
{
98+
var num = Mathf.Min(itemData.m_stack, amount);
99+
amount -= num;
100+
if (amount > 0) continue;
101+
CheckConsumedResource(itemData);
102+
break;
103+
}
104+
}
105+
}
106+
}
107+
}

EpicLoot/EpicLoot.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ public class EpicLoot : BaseUnityPlugin
8989
{
9090
public const string PluginId = "randyknapp.mods.epicloot";
9191
public const string DisplayName = "Epic Loot";
92-
public const string Version = "0.9.22";
92+
public const string Version = "0.9.23";
9393

94-
private readonly ConfigSync _configSync = new ConfigSync(PluginId) { DisplayName = DisplayName, CurrentVersion = Version, MinimumRequiredVersion = "0.9.22" };
94+
private readonly ConfigSync _configSync = new ConfigSync(PluginId) { DisplayName = DisplayName, CurrentVersion = Version, MinimumRequiredVersion = "0.9.23" };
9595

9696
private static ConfigEntry<string> _setItemColor;
9797
private static ConfigEntry<string> _magicRarityColor;
@@ -107,6 +107,7 @@ public class EpicLoot : BaseUnityPlugin
107107
// TODO: Mythic Hookup
108108
//private static ConfigEntry<int> _mythicMaterialIconColor;
109109
public static ConfigEntry<bool> UseScrollingCraftDescription;
110+
public static ConfigEntry<bool> TransferMagicItemToCrafts;
110111
public static ConfigEntry<CraftingTabStyle> CraftingTabStyle;
111112
private static ConfigEntry<bool> _loggingEnabled;
112113
private static ConfigEntry<LogLevel> _logLevel;
@@ -220,6 +221,7 @@ private void Awake()
220221
SetItemDropChance = SyncedConfig("Balance", "Set Item Drop Chance", 0.15f, "The percent chance that a legendary item will be a set item. Min = 0, Max = 1");
221222
GlobalDropRateModifier = SyncedConfig("Balance", "Global Drop Rate Modifier", 1.0f, "A global percentage that modifies how likely items are to drop. 1 = Exactly what is in the loot tables will drop. 0 = Nothing will drop. 2 = The number of items in the drop table are twice as likely to drop (note, this doesn't double the number of items dropped, just doubles the relative chance for them to drop). Min = 0, Max = 4");
222223
ItemsToMaterialsDropRatio = SyncedConfig("Balance", "Items To Materials Drop Ratio", 0.0f, "Sets the chance that item drops are instead dropped as magic crafting materials. 0 = all items, no materials. 1 = all materials, no items. Values between 0 and 1 change the ratio of items to materials that drop. At 0.5, half of everything that drops would be items and the other half would be materials. Min = 0, Max = 1");
224+
TransferMagicItemToCrafts = SyncedConfig("Balance", "Transfer Enchants to Crafted Items", false, "When enchanted items are used as ingredients in recipes, transfer the highest enchant to the newly crafted item. Default: False.");
223225

224226
AlwaysShowWelcomeMessage = Config.Bind("Debug", "AlwaysShowWelcomeMessage", false, "Just a debug flag for testing the welcome message, do not use.");
225227
OutputPatchedConfigFiles = Config.Bind("Debug", "OutputPatchedConfigFiles", false, "Just a debug flag for testing the patching system, do not use.");

EpicLoot/EpicLoot.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
<Compile Include="Crafting\AugmentHelper.cs" />
133133
<Compile Include="Crafting\CraftSuccessDialog.cs" />
134134
<Compile Include="Crafting\EnchantHelper.cs" />
135+
<Compile Include="Crafting\TransferMagicalEffects.cs" />
135136
<Compile Include="Data\ConfigValue.cs" />
136137
<Compile Include="Data\EIDFLegacy.cs" />
137138
<Compile Include="Data\CustomDataManager.cs" />

EpicLoot/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("0.9.22")]
35-
[assembly: AssemblyFileVersion("0.9.22")]
34+
[assembly: AssemblyVersion("0.9.23")]
35+
[assembly: AssemblyFileVersion("0.9.23")]

EpicLoot/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "EpicLoot",
3-
"version_number": "0.9.22",
3+
"version_number": "0.9.23",
44
"website_url": "https://github.com/RandyKnapp/ValheimMods/wiki/What-is-Epic-Loot%3F",
55
"description": "Adds loot drops, magic items, and enchanting to Valheim.",
66
"dependencies": [

0 commit comments

Comments
 (0)