Skip to content

Commit

Permalink
Fixed some bugs, added small crafting experience on repair, fixed dur…
Browse files Browse the repository at this point in the history
…ability of crafted items, added temporary in-ui debug info
  • Loading branch information
AnnanFay committed Oct 11, 2021
1 parent 533219a commit 7c1ed6f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
47 changes: 46 additions & 1 deletion CraftingSkill/CraftingSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static float GetCraftExperience(Recipe recipe, int craftLevel)
}

[HarmonyPatch(typeof(InventoryGui), "DoCrafting")]
public static class InventoryGuiPatcher
public static class InventoryGuiPatcherDoCrafting
{
static int m_crafts;
static int craftLevel;
Expand Down Expand Up @@ -305,5 +305,50 @@ Recipe ___m_craftRecipe
}
}
}

[HarmonyPatch(typeof(InventoryGui), "RepairOneItem")]
public static class InventoryGuiPatcherRepairOneItem
{
static int REPAIR_EXPERIENCE = 1;

// private void RepairOneItem()
static void Prefix(InventoryGui __instance,
// private fields
ItemDrop.ItemData ___m_craftUpgradeItem,
int ___m_craftVariant,
List<ItemDrop.ItemData> m_tempWornItems
)
{
if (Player.m_localPlayer == null)
{
return;
}
CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation();
if ((currentCraftingStation == null && !Player.m_localPlayer.NoCostCheat())
|| ((bool)currentCraftingStation && !currentCraftingStation.CheckUsable(Player.m_localPlayer, showMessage: false)))
{
return;
}
m_tempWornItems.Clear();
Player.m_localPlayer.GetInventory().GetWornItems(m_tempWornItems);
var CanRepair = __instance.GetType().GetMethod("CanRepair", BindingFlags.NonPublic | BindingFlags.Instance);
foreach (ItemDrop.ItemData tempWornItem in m_tempWornItems)
{
if ((bool)CanRepair.Invoke(__instance, new object[] { tempWornItem }))
{
// tempWornItem.m_durability = tempWornItem.GetMaxDurability();
Player.m_localPlayer.RaiseSkill((Skills.SkillType)CRAFTING_SKILL_ID, REPAIR_EXPERIENCE);
return;
}
}
}

// static void Postfix(InventoryGui __instance, Player player,
// // private fields
// Recipe ___m_craftRecipe
// )
// {
// }
}
}
}
16 changes: 10 additions & 6 deletions CraftingSkill/Quality.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ public string GetTooltip(CraftingConfig config)
QualityTier tier = GetQualityTier(factor);
factor = tier.GetFactor();
return String.Format(
"{0} ({1})",
GetQualityTier(this.Skill).GetTooltip(),
(factor * 100f).ToString("0")
"{0} ({1}) #debug: {2} {3} {4}",
GetQualityTier(factor).GetTooltip(),
(factor * 100f).ToString("0"),
(Skill * 100f).ToString("0"), Variance, StationLevel
);
}

return String.Format(
"{0} / 100",
(factor * 100f).ToString("0")
"{0} / 100 #debug: {1} {2} {3}",
(factor * 100f).ToString("0"),
(Skill * 100f).ToString("0"), Variance, StationLevel
);
}

Expand All @@ -53,7 +55,7 @@ public float ScalingFactor(CraftingConfig config)
// map 0,1 to -1,+1
var variance = 2.0f * (this.Variance - 0.5f);
// scale by config, add to factor
factor += config.StochasticVariance * variance;
factor += (config.StochasticVariance/100.0f) * variance;
// clamp invalid values (level 0 and 100)
factor = Mathf.Clamp(factor, 0.0f, 1.0f);
}
Expand All @@ -67,8 +69,10 @@ public float ScalingFactor(CraftingConfig config)
}
public static QualityTier GetQualityTier(float factor)
{
//Debug.Log("GetQualityTier: ", factor);
foreach (QualityTier tier in (QualityTier[])Enum.GetValues(typeof(QualityTier)))
{
//Debug.Log("GetQualityTier -> ", tier.GetFactor(), " >= ", factor, tier.GetFactor() >= factor);
if (tier.GetFactor() >= factor)
{
return tier;
Expand Down
7 changes: 7 additions & 0 deletions CraftingSkill/QualityComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public string GetTooltip(CraftingConfig config)

public static void OnNewExtendedItemData(ExtendedItemData itemdata)
{
// This gets triggered on generated items and crafted items
// Also on items moved between containers, etc.

// ZLog.LogError("OnNewExtendedItemData!");
Recipe recipe = ObjectDB.instance.GetRecipe(itemdata);
if (recipe == null)
Expand Down Expand Up @@ -101,6 +104,7 @@ public static void OnNewExtendedItemData(ExtendedItemData itemdata)
return;
}

// If we get to this point, the current player has just crafted a new item
var skill = player.GetSkillFactor((Skills.SkillType)CraftingSkillsPlugin.CRAFTING_SKILL_ID);
var quantity = itemdata.m_stack;

Expand All @@ -110,6 +114,9 @@ public static void OnNewExtendedItemData(ExtendedItemData itemdata)
var quality = new StackableQuality(skill, quantity, stationLevel);

itemdata.AddComponent<QualityComponent>().SetQuality(quality);

// Quality may have changed durability on our new item, so fix it
itemdata.m_durability = itemdata.GetMaxDurability();
}

public static void OnLoadExtendedItemData(ExtendedItemData itemdata)
Expand Down

0 comments on commit 7c1ed6f

Please sign in to comment.