-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
165 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System.IO; | ||
using System.IO; | ||
using UnityEngine; | ||
using System; | ||
using System.Collections.Generic; | ||
|
77 changes: 77 additions & 0 deletions
77
Mods/0-SCore/Harmony/ItemActions/ItemActionRepairLimiter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using HarmonyLib; | ||
using UnityEngine; | ||
|
||
namespace Harmony.ItemActions { | ||
public class ItemActionRepairLimiter { | ||
private static int _limitRepairProperty = -1; | ||
|
||
private static int GetRepairLimit(ItemValue itemValue) { | ||
if (!itemValue.ItemClass.Properties.Contains("RepairLimit")) return -1; | ||
|
||
// Check if RepairLimit is an array or not, and if so, expect a value for each quality level. | ||
var repairLimitValue = itemValue.ItemClass.Properties.GetStringValue("RepairLimit"); | ||
if ( repairLimitValue.Contains(',')) | ||
{ | ||
var quality = itemValue.Quality; | ||
var index = 0; | ||
if (quality > 0) | ||
index = quality - 1; | ||
if (repairLimitValue.Length >= index) | ||
{ | ||
return int.Parse(repairLimitValue.Split(',')[index]); | ||
} | ||
Log.Out($"Item {itemValue.ItemClass.GetItemName()}: Invalid repair limit: {repairLimitValue} for Quality Level {quality}"); | ||
return -1; | ||
} | ||
|
||
if (StringParsers.TryParseSInt32(repairLimitValue, out var result)) | ||
return result; | ||
return -1; | ||
} | ||
private static int GetCurrentMetaData(ItemValue itemValue, string key) { | ||
var valueObj = itemValue.GetMetadata(key); | ||
if (valueObj is int obj) return obj; | ||
return 0; | ||
} | ||
private static int GetCurrentRepairLimit(XUiC_ItemStack stack) { | ||
if (stack.ItemStack == null || stack.ItemStack.IsEmpty()) return -1; | ||
var itemValue = stack.ItemStack.itemValue; | ||
if ( itemValue == null ) return -1; | ||
|
||
// Look for the property on the item. | ||
if (!itemValue.ItemClass.Properties.Contains("RepairLimit")) return -1; | ||
return GetCurrentMetaData(itemValue, "CurrentRepairLimit"); | ||
} | ||
|
||
[HarmonyPatch(typeof(ItemActionEntryRepair))] | ||
[HarmonyPatch("OnActivated")] | ||
public class ItemActionRepairLimiterItemActionEntryRepair { | ||
public static bool Prefix(ItemActionEntryRepair __instance) { | ||
// Don't bother checking empty stacks | ||
var xui = __instance.ItemController.xui; | ||
var stack = (XUiC_ItemStack)__instance.ItemController; | ||
// If it's -1, then it doesn't have a repair limit. | ||
var currentRepair = GetCurrentRepairLimit(stack); | ||
if (currentRepair == -1) return true; | ||
|
||
// Look for the property on the item, checking for quality. | ||
var itemValue = stack.ItemStack.itemValue; | ||
var repairLimit = GetRepairLimit(itemValue); | ||
|
||
if ( repairLimit == -1) return true; | ||
QuestEventManager.Current.RepairItem += RepairItem; | ||
if (currentRepair < repairLimit) return true; | ||
GameManager.ShowTooltip(xui.playerUI.entityPlayer, Localization.Get("repair_limit_reached")); | ||
return false; | ||
|
||
} | ||
|
||
private static void RepairItem(ItemValue itemValue) { | ||
var currentRepair = GetCurrentMetaData(itemValue, "CurrentRepairLimit"); | ||
currentRepair++; | ||
itemValue.SetMetadata("CurrentRepairLimit", currentRepair, TypedMetadataValue.TypeTag.Integer); | ||
QuestEventManager.Current.RepairItem -= RepairItem; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.