Skip to content

Commit

Permalink
1.0.49.1202
Browse files Browse the repository at this point in the history
  • Loading branch information
SphereII committed Aug 13, 2024
1 parent 878668c commit 6d1923e
Show file tree
Hide file tree
Showing 32 changed files with 642 additions and 80 deletions.
4 changes: 3 additions & 1 deletion Mods/0-SCore/0-SCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<Compile Include="Features\Fire\Scripts\NetPackage\NetPackageRemoveFirePosition.cs" />
<Compile Include="Features\Fire\Scripts\NetPackage\NetPackageRemoveParticleEffect.cs" />
<Compile Include="Features\FlickeringLights\Harmony\DisableFlickeringLights.cs" />
<Compile Include="Features\FoodSpoilage\Harmony\FoodSpoilage.cs" />
<Compile Include="Features\FoodSpoilage\Harmony\Freshness.cs" />
<Compile Include="Features\FoodSpoilage\Harmony\XUiC_ItemInfoWindow.cs" />
<Compile Include="Features\LockPicking\Harmony\BlockSecureLootPatch.cs" />
<Compile Include="Features\LockPicking\Harmony\BlockDoorSecurePatch.cs" />
<Compile Include="Features\LockPicking\Harmony\LockPickingUtils.cs" />
Expand Down Expand Up @@ -138,7 +141,6 @@
<Compile Include="Harmony\ErrorHandling\NoExceptionHijack.cs" />
<Compile Include="Harmony\Faction\FactionRelationshipCVars.cs" />
<Compile Include="Harmony\Faction\FactionTweaks.cs" />
<Compile Include="Harmony\FoodSpoilage\FoodSpoilage.cs" />
<Compile Include="Harmony\GameManager\BroadcastHook.cs" />
<Compile Include="Harmony\GamePath\TraversalProvider.cs" />
<Compile Include="Harmony\GamePath\UtilsDrawLine.cs" />
Expand Down
5 changes: 4 additions & 1 deletion Mods/0-SCore/Config/Localization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,7 @@ xuiSCoreUtilsAutoRedeemChallenges,"Auto Redeem Challenges",""
xuiSCoreUtilsAutoRedeemChallengesToolTip,"Auto Redeem Challenges as they complete.",""
ObjectiveBuffSDX_keyword,"Get",""
ItemCannotBePlaced,"This item cannot go into this slot.",""
npcNoStorage,"NPCs Cannot Be Placed In Storage.",""
npcNoStorage,"NPCs Cannot Be Placed In Storage.",""
buffFreshnessSCoreName,"Fresh Food",""
buffFreshnessSCore,"Fresh Food!",""
buffFreshnessSCoreDesc,"Warm food and drink warms the soul!",""
5 changes: 5 additions & 0 deletions Mods/0-SCore/Config/buffs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<duration value="5"/>
</buff>

<buff name="buffFreshnessSCore" name_key="buffFreshnessSCoreName" description_key="buffFreshnessSCoreDesc" icon="ui_game_symbol_add">
<stack_type value="ignore"/>
<duration value="20"/>
</buff>

<buff name="buffAttackCoolDown" hidden="true">
<stack_type value="ignore"/>
<duration value="30"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,33 @@ public class SphereII_FoodSpoilage {
private const string AdvFeatureClass = "FoodSpoilage";
private const string Feature = "FoodSpoilage";
private static readonly bool FoodSpoilage = Configuration.CheckFeatureStatus(AdvFeatureClass, Feature);
private static readonly bool UseAlternateItemValue = Configuration.CheckFeatureStatus(AdvFeatureClass, "UseAlternateItemValue");

private static readonly bool UseAlternateItemValue =
Configuration.CheckFeatureStatus(AdvFeatureClass, "UseAlternateItemValue");

[HarmonyPatch(typeof(ItemValue))]
[HarmonyPatch("Clone")]
public class ItemValueClone {
private static void Postfix(ref ItemValue __result, ItemValue __instance) {
if (!FoodSpoilage)
return ;
return;
if (!UseAlternateItemValue)
return ;
return;

if (__instance.ItemClass == null || !__instance.ItemClass.Properties.Contains(PropSpoilable) ||
!__instance.ItemClass.Properties.GetBool(PropSpoilable))
return ;
return;

if (__instance.Metadata == null) return ;
if (__instance.Metadata == null) return;
__result.Metadata = new Dictionary<string, TypedMetadataValue>();
foreach (var text in __instance.Metadata.Keys)
{
__result.SetMetadata(text, __instance.Metadata[text].Clone());
//__result.Metadata.Add(text, __instance.Metadata[text] ?? __instance.Metadata[text].Clone());
}


}

}

// hook into the ItemStack, which should cover all types of containers. This will run in the update task.
// It is used to calculate the amount of spoilage necessary, and display the amount of freshness is left in the item.
[HarmonyPatch(typeof(XUiC_ItemStack))]
Expand All @@ -100,6 +100,7 @@ private static float GetCurrentSpoilage(ItemValue itemValue) {
private static void SetSpoilageMax(ItemValue itemValue, float degradationMax) {
itemValue.SetMetadata(KeySpoilageAmount, degradationMax, TypedMetadataValue.TypeTag.Float);
}

private static float UpdateCurrentSpoilage(ItemValue itemValue, float spoiled) {
var currentSpoilageAmount = GetCurrentSpoilage(itemValue);
currentSpoilageAmount += spoiled;
Expand Down Expand Up @@ -133,20 +134,20 @@ private static bool IsSkippable(XUiC_ItemStack __instance) {
{
return true;
}

return false;
}

public static bool Prefix(XUiC_ItemStack __instance) {
if (IsSkippable(__instance)) return true;

// var itemStack = __instance.ItemStack;
// var itemValue = itemStack.itemValue;
var itemClass = __instance.ItemStack.itemValue.ItemClass;

var itemClass = __instance.ItemStack.itemValue.ItemClass;

// Make sure our starting information is correct.
var currentSpoilage = GetCurrentSpoilage(__instance.ItemStack.itemValue);

var strDisplay = $"XUiC_ItemStack: {itemClass.GetItemName()} :: {__instance.ItemStack.count} Slot: {__instance.SlotNumber} ";
var strDisplay =
$"XUiC_ItemStack: {itemClass.GetItemName()} :: {__instance.ItemStack.count} Slot: {__instance.SlotNumber} ";
var degradationMax = 0f;
var degradationPerUse = 0f;

Expand Down Expand Up @@ -276,6 +277,17 @@ public static bool Prefix(XUiC_ItemStack __instance) {
strDisplay += " Next Spoilage Tick: " + nextSpoilageTick;
strDisplay += " Recorded Spoilage: " + currentSpoilage;
AdvLogging.DisplayLog(AdvFeatureClass, strDisplay);

var freshness = false;
if (itemClass.Properties.Contains("FreshnessOnly"))
freshness = itemClass.Properties.GetBool("FreshnessOnly");
if (freshness)
{
var perCent = 1f - Mathf.Clamp01(currentSpoilage / degradationMax);
__instance.ItemStack.itemValue.SetMetadata("Freshness", perCent, TypedMetadataValue.TypeTag.Float);
__instance.ForceRefreshItemStack();
return true;
}


// If the spoil time is is greater than the degradation, loop around the stack, removing each layer of items.
Expand All @@ -297,7 +309,7 @@ public static bool Prefix(XUiC_ItemStack __instance) {
var fullStackSpoil = false;
if (itemClass.Properties.Contains("FullStackSpoil"))
fullStackSpoil = itemClass.Properties.GetBool("FullStackSpoil");

if (Configuration.CheckFeatureStatus(AdvFeatureClass, "FullStackSpoil") || fullStackSpoil)
{
AdvLogging.DisplayLog(AdvFeatureClass, itemClass.GetItemName() + ":Full Stack Spoil");
Expand All @@ -318,6 +330,7 @@ public static bool Prefix(XUiC_ItemStack __instance) {
}
}
}

if (__instance.ItemStack.count >= 2)
{
AdvLogging.DisplayLog(AdvFeatureClass, itemClass.GetItemName() + ": Reducing Stack by 1");
Expand All @@ -331,14 +344,21 @@ public static bool Prefix(XUiC_ItemStack __instance) {
break; // Nothing more to spoil
}
}

// Set the current spoilage value.

var perCentFresh = 1f - Mathf.Clamp01(currentSpoilage / degradationMax);
__instance.ItemStack.itemValue.SetMetadata("Freshness", perCentFresh, TypedMetadataValue.TypeTag.Float);
__instance.ForceRefreshItemStack();

return true;
}

public static bool IsFresh(ItemValue itemValue) {
if (!itemValue.HasMetadata("Freshness")) return true;
var freshNess = (float)itemValue.GetMetadata("Freshness");
return !(freshNess < 0.1f);
}

public static void Postfix(XUiC_ItemStack __instance) {
if (IsSkippable(__instance)) return;
var itemStack = __instance.ItemStack;
Expand All @@ -348,6 +368,7 @@ public static void Postfix(XUiC_ItemStack __instance) {
if (itemClass.Properties.Contains("SpoilageMax"))
degradationMax = itemClass.Properties.GetFloat("SpoilageMax");


var currentSpoilage = GetCurrentSpoilage(__instance.ItemStack.itemValue);
var perCent = 1f - Mathf.Clamp01(currentSpoilage / degradationMax);
var tierColor = 7 + (int)Math.Round(8 * perCent);
Expand All @@ -364,15 +385,15 @@ public static void Postfix(XUiC_ItemStack __instance) {
var controller = __instance.GetChildById("durability");
if (controller?.ViewComponent is XUiV_Sprite durability)
{
durability.IsVisible = true;
durability.IsVisible = IsFresh(__instance.ItemStack.itemValue);
durability.Color = QualityInfo.GetQualityColor(tierColor);
durability.Fill = perCent;
}

controller = __instance.GetChildById("durabilityBackground");
if (controller?.ViewComponent is XUiV_Sprite durabilityBackground)
{
durabilityBackground.IsVisible = true;
durabilityBackground.IsVisible = IsFresh(__instance.ItemStack.itemValue);
}
}

Expand All @@ -399,6 +420,7 @@ private static int GetNextSpoilageTick(ItemValue itemValue) {
{
return nextSpoilageTick;
}

return -1;
}

Expand All @@ -408,7 +430,7 @@ private static int GetNextSpoilageTick(ItemValue itemValue) {
/// <param name="__instance"></param>
/// <param name="nextTick"></param>
private static void SetNextSpoilageTick(ItemValue itemValue, int nextTick) {
itemValue.SetMetadata(KeyNextSpoilageTick, nextTick, TypedMetadataValue.TypeTag.Integer);
itemValue.SetMetadata(KeyNextSpoilageTick, nextTick, TypedMetadataValue.TypeTag.Integer);
}

/// <summary>
Expand Down
55 changes: 55 additions & 0 deletions Mods/0-SCore/Features/FoodSpoilage/Harmony/Freshness.cs
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 Mods/0-SCore/Features/FoodSpoilage/Harmony/XUiC_ItemInfoWindow.cs
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,6 @@ public static bool IsEnemyNearby(EntityAlive self, float distance = 20f)
if (x == null) continue;
if (x == self) continue;
if (x.IsDead()) continue;
if (!EntityTargetingUtilities.CanDamage(x, self)) continue;
// Check to see if they are our enemy first, before deciding if we should see them.
if (EntityTargetingUtilities.IsFriend(x, self)) continue;
if (player && player.Party != null)
{
// Are they in the same party?
Expand All @@ -501,6 +498,10 @@ public static bool IsEnemyNearby(EntityAlive self, float distance = 20f)
}

}
if (!EntityTargetingUtilities.CanDamage(x, self)) continue;
// Check to see if they are our enemy first, before deciding if we should see them.
if (EntityTargetingUtilities.IsFriend(x, self)) continue;

// Otherwise they are an enemy.
return true;
}
Expand Down
25 changes: 2 additions & 23 deletions Mods/0-SCore/Harmony/Faction/FactionTweaks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,6 @@ public static bool Prefix(FactionManager __instance, ref float ___saveTime, Thre
}
return false;
}

//// Loops around the instructions and removes the return condition.
//private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
//{
// // Grab all the instructions
// var codes = new List<CodeInstruction>(instructions);

// var counter = 0;
// foreach (var t in codes)
// {
// if (t.opcode != OpCodes.Brfalse) continue;
// if (counter == 4)
// {
// t.opcode = OpCodes.Brtrue;
// break;
// }

// counter++;
// }

// return codes.AsEnumerable();
//}
}

// Fixing casting bug
Expand All @@ -64,7 +42,8 @@ public class SetRelationship
{
public static bool Prefix(global::Faction __instance, byte _factionId, float _value)
{
__instance.Relationships[_factionId] = Mathf.Clamp(_value, 0f, 1000f);
//if ( __instance.Relationships.Contains(_factionId))
__instance.Relationships[_factionId] = Mathf.Clamp(_value, 0f, 1000f);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Mods/0-SCore/ModInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<Description value="SCore Mod" />
<DisplayName value="0-SCore" />
<Website value="" />
<Version value="1.0.46.1010" />
<Version value="1.0.49.1202" />
</xml>
Loading

0 comments on commit 6d1923e

Please sign in to comment.