97 lines
5.5 KiB
C#
97 lines
5.5 KiB
C#
namespace Harmony.ItemValuePatches
|
|
{
|
|
[HarmonyPatch(typeof(ItemValue))]
|
|
[HarmonyPatch("ModifyValue")]
|
|
public class ModifyValuePatch
|
|
{
|
|
public static bool Prefix(ItemValue __instance, EntityAlive _entity, ItemValue _originalItemValue, PassiveEffects _passiveEffect, ref float _originalValue, ref float _perc_value, FastTags<TagGroup.Global> _tags, bool _useMods, bool _useDurability)
|
|
{
|
|
if (_originalItemValue != null && _originalItemValue.Equals(__instance))
|
|
return false;
|
|
int seed = MinEventParams.CachedEventParam.Seed;
|
|
if ((UnityEngine.Object)_entity != (UnityEngine.Object)null)
|
|
seed = _entity.MinEventContext.Seed;
|
|
ItemClass itemClass1 = __instance.ItemClass;
|
|
if (itemClass1 != null)
|
|
{
|
|
if (itemClass1.Actions != null && itemClass1.Actions.Length != 0 && itemClass1.Actions[0] is ItemActionRanged)
|
|
{
|
|
string[] magazineItemNames = (itemClass1.Actions[0] as ItemActionRanged).MagazineItemNames;
|
|
if (magazineItemNames != null)
|
|
{
|
|
ItemClass itemClass2 = ItemClass.GetItemClass(magazineItemNames[(int)__instance.SelectedAmmoTypeIndex]);
|
|
if (itemClass2 != null && itemClass2.Effects != null)
|
|
itemClass2.Effects.ModifyValue(_entity, _passiveEffect, ref _originalValue, ref _perc_value, _tags: _tags);
|
|
}
|
|
}
|
|
if (itemClass1.Effects != null)
|
|
{
|
|
ItemValue itemValue1 = MinEventParams.CachedEventParam.ItemValue;
|
|
ItemValue itemValue2 = (UnityEngine.Object)_entity != (UnityEngine.Object)null ? _entity.MinEventContext.ItemValue : (ItemValue)null;
|
|
MinEventParams.CachedEventParam.Seed = (int)__instance.Seed + (__instance.Seed != (ushort)0 ? (int)_passiveEffect : 0);
|
|
MinEventParams.CachedEventParam.ItemValue = __instance;
|
|
if ((UnityEngine.Object)_entity != (UnityEngine.Object)null)
|
|
{
|
|
_entity.MinEventContext.Seed = MinEventParams.CachedEventParam.Seed;
|
|
_entity.MinEventContext.ItemValue = __instance;
|
|
}
|
|
float num1 = _originalValue;
|
|
itemClass1.Effects.ModifyValue(_entity, _passiveEffect, ref _originalValue, ref _perc_value, (float)__instance.Quality, _tags);
|
|
if (_useDurability)
|
|
{
|
|
switch (_passiveEffect)
|
|
{
|
|
case PassiveEffects.PhysicalDamageResist:
|
|
if ((double)__instance.PercentUsesLeft < 0.5)
|
|
{
|
|
float num2 = _originalValue - num1;
|
|
_originalValue = num1 + (float)((double)num2 * (double)__instance.PercentUsesLeft * 2.0);
|
|
break;
|
|
}
|
|
break;
|
|
case PassiveEffects.ElementalDamageResist:
|
|
if ((double)__instance.PercentUsesLeft < 0.5)
|
|
{
|
|
float num3 = _originalValue - num1;
|
|
_originalValue = num1 + (float)((double)num3 * (double)__instance.PercentUsesLeft * 2.0);
|
|
break;
|
|
}
|
|
break;
|
|
case PassiveEffects.BuffResistance:
|
|
if ((double)__instance.PercentUsesLeft < 0.5)
|
|
{
|
|
float num4 = _originalValue - num1;
|
|
_originalValue = num1 + (float)((double)num4 * (double)__instance.PercentUsesLeft * 2.0);
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
MinEventParams.CachedEventParam.ItemValue = itemValue1;
|
|
if ((UnityEngine.Object)_entity != (UnityEngine.Object)null)
|
|
_entity.MinEventContext.ItemValue = itemValue2;
|
|
}
|
|
}
|
|
if (_useMods)
|
|
{
|
|
for (int index = 0; index < __instance.CosmeticMods.Length; ++index)
|
|
{
|
|
if (__instance.CosmeticMods[index] != null && __instance.CosmeticMods[index].ItemClass is ItemClassModifier)
|
|
__instance.CosmeticMods[index].ModifyValue(_entity, _originalItemValue, _passiveEffect, ref _originalValue, ref _perc_value, _tags);
|
|
}
|
|
for (int index = 0; index < __instance.Modifications.Length; ++index)
|
|
{
|
|
if (__instance.Modifications[index] != null && __instance.Modifications[index].ItemClass is ItemClassModifier)
|
|
__instance.Modifications[index].ModifyValue(_entity, _originalItemValue, _passiveEffect, ref _originalValue, ref _perc_value, _tags);
|
|
}
|
|
}
|
|
MinEventParams.CachedEventParam.Seed = seed;
|
|
if (!((UnityEngine.Object)_entity != (UnityEngine.Object)null))
|
|
return false;
|
|
_entity.MinEventContext.Seed = seed;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|