Fix potential issue with max values
This commit is contained in:
parent
ccad3d23d0
commit
7183b28e8b
@ -68,15 +68,15 @@ internal static class IconCache
|
|||||||
|
|
||||||
internal static class AmmoTemplateExtensions
|
internal static class AmmoTemplateExtensions
|
||||||
{
|
{
|
||||||
private static readonly float MaxMalfMisfireChance = (float)
|
|
||||||
typeof(AmmoTemplate).GetField("MaxMalfMisfireChance", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
|
|
||||||
|
|
||||||
private static readonly float MaxMalfFeedChance = (float)
|
|
||||||
typeof(AmmoTemplate).GetField("MaxMalfFeedChance", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
|
|
||||||
|
|
||||||
private static readonly string[] MalfChancesKeys = (string[])
|
private static readonly string[] MalfChancesKeys = (string[])
|
||||||
typeof(AmmoTemplate).GetField("MalfChancesKeys", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
|
typeof(AmmoTemplate).GetField("MalfChancesKeys", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
|
||||||
|
|
||||||
|
private static readonly FieldInfo MaxMalfMisfireChance =
|
||||||
|
typeof(AmmoTemplate).GetField("MaxMalfMisfireChance", BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
|
|
||||||
|
private static readonly FieldInfo MaxMalfFeedChance =
|
||||||
|
typeof(AmmoTemplate).GetField("MaxMalfFeedChance", BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
|
|
||||||
private static readonly FieldInfo CachedQualitiesField =
|
private static readonly FieldInfo CachedQualitiesField =
|
||||||
typeof(AmmoTemplate).GetField("_cachedQualities", BindingFlags.NonPublic | BindingFlags.Instance);
|
typeof(AmmoTemplate).GetField("_cachedQualities", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
|
||||||
@ -138,20 +138,14 @@ internal static class AmmoTemplateExtensions
|
|||||||
Base = () => instance.MalfMisfireChance,
|
Base = () => instance.MalfMisfireChance,
|
||||||
StringValue = () =>
|
StringValue = () =>
|
||||||
{
|
{
|
||||||
string value;
|
float maxMalfMisfireChance = (float)MaxMalfMisfireChance.GetValue(null);
|
||||||
if (instance.MalfMisfireChance <= 0f)
|
int index = instance.MalfMisfireChance <= 0f ? 0
|
||||||
value = MalfChancesKeys[0];
|
: instance.MalfMisfireChance < 3f * maxMalfMisfireChance / 7f ? 1
|
||||||
else if (instance.MalfMisfireChance < 3f * MaxMalfMisfireChance / 7f)
|
: instance.MalfMisfireChance < 4f * maxMalfMisfireChance / 7f ? 2
|
||||||
value = MalfChancesKeys[1];
|
: instance.MalfMisfireChance < 5f * maxMalfMisfireChance / 7f ? 3
|
||||||
else if (instance.MalfMisfireChance < 4f * MaxMalfMisfireChance / 7f)
|
: instance.MalfMisfireChance < 6f * maxMalfMisfireChance / 7f ? 4
|
||||||
value = MalfChancesKeys[2];
|
: 5;
|
||||||
else if (instance.MalfMisfireChance < 5f * MaxMalfMisfireChance / 7f)
|
return MalfChancesKeys[index].Localized();
|
||||||
value = MalfChancesKeys[3];
|
|
||||||
else if (instance.MalfMisfireChance < 6f * MaxMalfMisfireChance / 7f)
|
|
||||||
value = MalfChancesKeys[4];
|
|
||||||
else
|
|
||||||
value = MalfChancesKeys[5];
|
|
||||||
return value.Localized();
|
|
||||||
},
|
},
|
||||||
DisplayType = () => EItemAttributeDisplayType.Compact,
|
DisplayType = () => EItemAttributeDisplayType.Compact,
|
||||||
});
|
});
|
||||||
@ -162,20 +156,14 @@ internal static class AmmoTemplateExtensions
|
|||||||
Base = () => instance.MalfFeedChance,
|
Base = () => instance.MalfFeedChance,
|
||||||
StringValue = () =>
|
StringValue = () =>
|
||||||
{
|
{
|
||||||
string value;
|
float maxMalfFeedChance = (float)MaxMalfFeedChance.GetValue(null);
|
||||||
if (instance.MalfFeedChance <= 0f)
|
int index = instance.MalfFeedChance <= 0f ? 0
|
||||||
value = MalfChancesKeys[0];
|
: instance.MalfFeedChance < 1f * maxMalfFeedChance / 7f ? 1
|
||||||
else if (instance.MalfFeedChance < 1f * MaxMalfFeedChance / 7f)
|
: instance.MalfFeedChance < 3f * maxMalfFeedChance / 7f ? 2
|
||||||
value = MalfChancesKeys[1];
|
: instance.MalfFeedChance < 5f * maxMalfFeedChance / 7f ? 3
|
||||||
else if (instance.MalfFeedChance < 3f * MaxMalfFeedChance / 7f)
|
: instance.MalfFeedChance < 6f * maxMalfFeedChance / 7f ? 4
|
||||||
value = MalfChancesKeys[2];
|
: 5;
|
||||||
else if (instance.MalfFeedChance < 5f * MaxMalfFeedChance / 7f)
|
return MalfChancesKeys[index].Localized();
|
||||||
value = MalfChancesKeys[3];
|
|
||||||
else if (instance.MalfFeedChance < 6f * MaxMalfFeedChance / 7f)
|
|
||||||
value = MalfChancesKeys[4];
|
|
||||||
else
|
|
||||||
value = MalfChancesKeys[5];
|
|
||||||
return value.Localized();
|
|
||||||
},
|
},
|
||||||
DisplayType = () => EItemAttributeDisplayType.Compact,
|
DisplayType = () => EItemAttributeDisplayType.Compact,
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net472</TargetFramework>
|
<TargetFramework>net472</TargetFramework>
|
||||||
<AssemblyName>IcyClawz.MunitionsExpert</AssemblyName>
|
<AssemblyName>IcyClawz.MunitionsExpert</AssemblyName>
|
||||||
<Version>1.4.1</Version>
|
<Version>1.4.2</Version>
|
||||||
<RootNamespace>IcyClawz.MunitionsExpert</RootNamespace>
|
<RootNamespace>IcyClawz.MunitionsExpert</RootNamespace>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -13,7 +13,7 @@ using UnityEngine.UI;
|
|||||||
|
|
||||||
namespace IcyClawz.MunitionsExpert;
|
namespace IcyClawz.MunitionsExpert;
|
||||||
|
|
||||||
[BepInPlugin("com.IcyClawz.MunitionsExpert", "IcyClawz.MunitionsExpert", "1.4.1")]
|
[BepInPlugin("com.IcyClawz.MunitionsExpert", "IcyClawz.MunitionsExpert", "1.4.2")]
|
||||||
public class Plugin : BaseUnityPlugin
|
public class Plugin : BaseUnityPlugin
|
||||||
{
|
{
|
||||||
private static ConfigEntry<bool> ColorizeSwitch { get; set; }
|
private static ConfigEntry<bool> ColorizeSwitch { get; set; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user