-
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
32 changed files
with
642 additions
and
80 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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using HarmonyLib; | ||
using UnityEngine; | ||
|
||
namespace SCore.Features.FoodSpoilage.Harmony { | ||
public class Freshness { | ||
private const string AdvFeatureClass = "FoodSpoilage"; | ||
private const string Feature = "FoodSpoilage"; | ||
private static readonly bool FoodSpoilage = Configuration.CheckFeatureStatus(AdvFeatureClass, Feature); | ||
|
||
[HarmonyPatch(typeof(MinEventActionModifyCVar))] | ||
[HarmonyPatch("Execute")] | ||
public class MinEventActionModifyCVarExecute { | ||
private static void Postfix(MinEventActionModifyCVar __instance, MinEventParams _params) { | ||
if (!FoodSpoilage) return; | ||
// No item action? | ||
if (_params.ItemActionData is not ItemActionEat.MyInventoryData actionData) return; | ||
// Not an add? | ||
if (__instance.operation != MinEventActionModifyCVar.OperationTypes.add) return; | ||
|
||
// Check to see if we need to re-run for freshness | ||
if (_params.ItemValue.IsEmpty()) return; | ||
if (!_params.ItemValue.HasMetadata("Freshness")) return; | ||
var freshNess = (float)_params.ItemValue.GetMetadata("Freshness"); | ||
if (freshNess < 0.1f) return; | ||
var multiplier = freshNess + 1f; | ||
|
||
if (_params.ItemValue.ItemClass.Properties.Contains("FreshnessCVar")) | ||
{ | ||
var approvedCVar = _params.ItemValue.ItemClass.Properties.GetString("FreshnessCVar"); | ||
if (approvedCVar.Contains("none")) return; | ||
if (approvedCVar != "all") | ||
{ | ||
if (!approvedCVar.Contains(__instance.cvarName)) | ||
return; | ||
} | ||
} | ||
foreach (var t in __instance.targets) | ||
{ | ||
var currentValue = t.Buffs.GetCustomVar(__instance.cvarName, 0f); | ||
switch (__instance.operation) | ||
{ | ||
case MinEventActionModifyCVar.OperationTypes.add: | ||
currentValue += __instance.value * multiplier; | ||
break; | ||
} | ||
|
||
var freshnessBuff = "buffFreshnessSCore"; | ||
t.Buffs.AddBuff(freshnessBuff); | ||
t.Buffs.SetCustomVar(__instance.cvarName, currentValue, | ||
(t.isEntityRemote && !_params.Self.isEntityRemote) || _params.IsLocal); | ||
} | ||
} | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
Mods/0-SCore/Features/FoodSpoilage/Harmony/XUiC_ItemInfoWindow.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,47 @@ | ||
using HarmonyLib; | ||
using UnityEngine; | ||
|
||
public class XUiC_ItemInfoWindowPatch { | ||
|
||
private const string AdvFeatureClass = "FoodSpoilage"; | ||
private const string Feature = "FoodSpoilage"; | ||
private static readonly bool FoodSpoilage = Configuration.CheckFeatureStatus(AdvFeatureClass, Feature); | ||
public class SCoreGetBindingValueHelper { | ||
|
||
public static string GetItemTypeIcon(ItemStack itemStack, string bindingName) { | ||
|
||
if (bindingName != "itemtypeicon") return string.Empty; | ||
if (itemStack.IsEmpty() || itemStack.itemValue.ItemClass == null) return string.Empty; | ||
if (itemStack.itemValue.ItemClass.IsBlock()) return string.Empty; | ||
if (!itemStack.itemValue.HasMetadata("Freshness")) return string.Empty; | ||
var freshNess = (float)itemStack.itemValue.GetMetadata("Freshness"); | ||
if (freshNess < 0.1f) return string.Empty; | ||
return itemStack.itemValue.ItemClass.AltItemTypeIcon ?? string.Empty; | ||
} | ||
|
||
} | ||
[HarmonyPatch(typeof(XUiC_ItemInfoWindow))] | ||
[HarmonyPatch("GetBindingValue")] | ||
public class ItemInfoWindowGetBindingValue { | ||
private static bool Prefix(ref bool __result, XUiC_ItemInfoWindow __instance, ref string value, string bindingName) { | ||
if (!FoodSpoilage) return true; | ||
var result = SCoreGetBindingValueHelper.GetItemTypeIcon(__instance.itemStack, bindingName); | ||
if (string.IsNullOrEmpty(result)) return true; | ||
value = result; | ||
__result = true; | ||
return false; | ||
} | ||
} | ||
[HarmonyPatch(typeof(XUiC_ItemStack))] | ||
[HarmonyPatch("GetBindingValue")] | ||
public class XUiC_ItemStackGetBindingValue { | ||
private static bool Prefix(ref bool __result, XUiC_ItemStack __instance, ref string _value, string _bindingName) { | ||
if (!FoodSpoilage) return true; | ||
var result = SCoreGetBindingValueHelper.GetItemTypeIcon(__instance.itemStack, _bindingName); | ||
if (string.IsNullOrEmpty(result)) return true; | ||
_value = result; | ||
__result = true; | ||
return false; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.