This commit is contained in:
IgorEisberg 2023-07-09 22:38:08 +03:00
parent db8e7de58e
commit 302173daff
9 changed files with 172 additions and 192 deletions

View File

@ -20,7 +20,7 @@ namespace IcyClawz.CustomInteractions
}
}
public class ItemUiContextPatch : ModulePatch
internal class ItemUiContextPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() =>
typeof(ItemUiContext).GetMethod("GetItemContextInteractions", BindingFlags.Public | BindingFlags.Instance);
@ -42,7 +42,7 @@ namespace IcyClawz.CustomInteractions
}
}
public class InteractionButtonsContainerPatch : ModulePatch
internal class InteractionButtonsContainerPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() =>
typeof(InteractionButtonsContainer).GetMethod("method_3", BindingFlags.NonPublic | BindingFlags.Instance);

View File

@ -14,7 +14,7 @@ namespace IcyClawz.ItemAttributeFix
}
}
public class CompactCharacteristicPanelPatch : ModulePatch
internal class CompactCharacteristicPanelPatch : ModulePatch
{
private static readonly FieldInfo ItemAttributeField =
typeof(CompactCharacteristicPanel).GetField("ItemAttribute", BindingFlags.NonPublic | BindingFlags.Instance);

View File

@ -29,7 +29,7 @@ namespace IcyClawz.ItemContextMenuExt
((ILightTemplate)component.Item.Template).ModesCount;
}
public sealed class CustomInteractionsProvider : IItemCustomInteractionsProvider
internal sealed class CustomInteractionsProvider : IItemCustomInteractionsProvider
{
internal const string IconsPrefix = "Characteristics/Icons/";
internal static StaticIcons StaticIcons => EFTHardSettings.Instance.StaticIcons;

View File

@ -12,7 +12,32 @@ using CurrencyUtil = GClass2181;
namespace IcyClawz.ItemSellPrice
{
public static class ItemSellPrice
internal static class TraderClassExtensions
{
private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession();
private static readonly FieldInfo SupplyDataField =
typeof(TraderClass).GetField("supplyData_0", BindingFlags.NonPublic | BindingFlags.Instance);
public static SupplyData GetSupplyData(this TraderClass trader) =>
SupplyDataField.GetValue(trader) as SupplyData;
public static void SetSupplyData(this TraderClass trader, SupplyData supplyData) =>
SupplyDataField.SetValue(trader, supplyData);
public static async void UpdateSupplyData(this TraderClass trader)
{
Result<SupplyData> result = await Session.GetSupplyData(trader.Id);
if (result.Failed)
{
Debug.LogError("Failed to download supply data");
return;
}
trader.SetSupplyData(result.Value);
}
}
internal static class ItemExtensions
{
private static readonly Dictionary<string, string[]> DisplayNames = new Dictionary<string, string[]>()
{
@ -34,42 +59,76 @@ namespace IcyClawz.ItemSellPrice
{ "tu", new[] { "Satış fiyatı ({0})", "Tüccarlara satılamaz" } }
};
private static readonly FieldInfo SupplyDataField =
typeof(TraderClass).GetField("supplyData_0", BindingFlags.NonPublic | BindingFlags.Instance);
private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession();
public static async void UpdateSupplyData(this TraderClass trader)
{
Result<SupplyData> result = await Session.GetSupplyData(trader.Id);
if (result.Failed)
{
Debug.LogError("Failed to download supply data");
return;
}
trader.SetSupplyData(result.Value);
}
public static SupplyData GetSupplyData(this TraderClass trader) =>
SupplyDataField.GetValue(trader) as SupplyData;
public static void SetSupplyData(this TraderClass trader, SupplyData supplyData) =>
SupplyDataField.SetValue(trader, supplyData);
public static void AddTraderOfferAttribute(this Item item)
{
List<ItemAttributeClass> attributes = new List<ItemAttributeClass>
{
new ItemAttributeClass(EItemAttributeId.MoneySum)
ItemAttributeClass attribute = new ItemAttributeClass(EItemAttributeId.MoneySum)
{
Name = EItemAttributeId.MoneySum.GetName(),
DisplayNameFunc = () => GetDisplayName(item),
Base = () => GetBase(item),
StringValue = () => GetStringValue(item),
FullStringValue = () => GetFullStringValue(item),
DisplayType = () => EItemAttributeDisplayType.Compact
DisplayNameFunc = () =>
{
string language = Singleton<SharedGameSettingsClass>.Instance?.Game?.Settings?.Language?.GetValue();
if (language == null || !DisplayNames.ContainsKey(language))
{
language = "en";
}
if (GetBestTraderOffer(item) is TraderOffer offer)
{
return string.Format(DisplayNames[language][0], offer.Name);
}
else
{
return DisplayNames[language][1];
}
},
Base = () =>
{
if (GetBestTraderOffer(item) is TraderOffer offer)
{
return offer.Price;
}
else
{
return 0.01f;
}
},
StringValue = () =>
{
if (GetBestTraderOffer(item) is TraderOffer offer)
{
string value = $"{offer.Currency} {offer.Price}";
if (offer.Count > 1)
{
value += $" ({offer.Count})";
}
return value;
}
else
{
return string.Empty;
}
},
FullStringValue = () =>
{
if (GetAllTraderOffers(item) is List<TraderOffer> offers)
{
string[] lines = new string[offers.Count];
for (int i = 0; i < offers.Count; i++)
{
TraderOffer offer = offers[i];
lines[i] = $"{offer.Name}: {offer.Currency} {offer.Price}";
}
return string.Join(Environment.NewLine, lines);
}
else
{
return string.Empty;
}
},
DisplayType = () => EItemAttributeDisplayType.Compact
};
List<ItemAttributeClass> attributes = new List<ItemAttributeClass> { attribute };
attributes.AddRange(item.Attributes);
item.Attributes = attributes;
}
@ -149,69 +208,5 @@ namespace IcyClawz.ItemSellPrice
return null;
}
}
public static string GetDisplayName(Item item)
{
string language = Singleton<SharedGameSettingsClass>.Instance?.Game?.Settings?.Language?.GetValue();
if (language == null || !DisplayNames.ContainsKey(language))
{
language = "en";
}
if (GetBestTraderOffer(item) is TraderOffer offer)
{
return string.Format(DisplayNames[language][0], offer.Name);
}
else
{
return DisplayNames[language][1];
}
}
public static float GetBase(Item item)
{
if (GetBestTraderOffer(item) is TraderOffer offer)
{
return offer.Price;
}
else
{
return 0.01f;
}
}
public static string GetStringValue(Item item)
{
if (GetBestTraderOffer(item) is TraderOffer offer)
{
string value = $"{offer.Currency} {offer.Price}";
if (offer.Count > 1)
{
value += $" ({offer.Count})";
}
return value;
}
else
{
return string.Empty;
}
}
public static string GetFullStringValue(Item item)
{
if (GetAllTraderOffers(item) is List<TraderOffer> offers)
{
string[] lines = new string[offers.Count];
for (int i = 0; i < offers.Count; i++)
{
TraderOffer offer = offers[i];
lines[i] = $"{offer.Name}: {offer.Currency} {offer.Price}";
}
return string.Join(Environment.NewLine, lines);
}
else
{
return string.Empty;
}
}
}
}

View File

@ -8,9 +8,6 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Aki.Common">
<HintPath>..\Shared\Aki.Common.dll</HintPath>
</Reference>
<Reference Include="Aki.Reflection">
<HintPath>..\Shared\Aki.Reflection.dll</HintPath>
</Reference>

View File

@ -18,7 +18,7 @@ namespace IcyClawz.ItemSellPrice
}
}
public class TraderPatch : ModulePatch
internal class TraderPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() =>
typeof(TraderClass).GetConstructors()[0];
@ -30,7 +30,7 @@ namespace IcyClawz.ItemSellPrice
}
}
public class ItemPatch : ModulePatch
internal class ItemPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() =>
typeof(Item).GetConstructors()[0];
@ -42,7 +42,7 @@ namespace IcyClawz.ItemSellPrice
}
}
public class AmmoPatch : ModulePatch
internal class AmmoPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() =>
typeof(BulletClass).GetConstructors()[0];
@ -54,7 +54,7 @@ namespace IcyClawz.ItemSellPrice
}
}
public class GrenadePatch : ModulePatch
internal class GrenadePatch : ModulePatch
{
protected override MethodBase GetTargetMethod() =>
typeof(GrenadeClass).GetConstructors()[0];
@ -66,7 +66,7 @@ namespace IcyClawz.ItemSellPrice
}
}
public class SecureContainerPatch : ModulePatch
internal class SecureContainerPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() =>
typeof(ItemContainerClass).GetConstructors()[0];

View File

@ -11,7 +11,7 @@ using InGameStatus = GClass1756;
namespace IcyClawz.MagazineInspector
{
public static class MagazineInspector
internal static class MagazineClassExtensions
{
private static readonly Dictionary<string, string> DisplayNames = new Dictionary<string, string>()
{
@ -35,7 +35,7 @@ namespace IcyClawz.MagazineInspector
private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession();
private static Profile ActiveProfile => InGameStatus.InRaid ? ClientPlayerOwner.MyPlayer.Profile : Session.Profile;
private static Profile ActiveProfile => InGameStatus.InRaid ? GamePlayerOwner.MyPlayer.Profile : Session.Profile;
public static void AddAmmoCountAttribute(this MagazineClass magazine)
{
@ -44,41 +44,7 @@ namespace IcyClawz.MagazineInspector
{
return;
}
attribute.DisplayNameFunc = GetDisplayName;
attribute.Base = () => GetBase(magazine);
attribute.StringValue = () => GetStringValue(magazine);
attribute.FullStringValue = () => GetFullStringValue(magazine);
}
private static int? GetAmmoCount(MagazineClass magazine, Profile profile, out bool magChecked)
{
if (!InGameStatus.InRaid || magazine.Count == 0)
{
magChecked = true;
return magazine.Count;
}
magChecked = profile.CheckedMagazines.ContainsKey(magazine.Id);
if (magChecked)
{
bool equipped = profile.Inventory.Equipment.GetAllSlots().Any(slot => ReferenceEquals(slot.ContainedItem, magazine));
if (magazine.Count >= (equipped ? magazine.MaxCount - 1 : magazine.MaxCount))
{
return magazine.Count;
}
int skill = Mathf.Max(
profile.MagDrillsMastering,
profile.CheckedMagazineSkillLevel(magazine.Id),
magazine.CheckOverride
);
if (skill > 1 || (skill == 1 && magazine.MaxCount <= 10))
{
return magazine.Count;
}
}
return null;
}
public static string GetDisplayName()
attribute.DisplayNameFunc = () =>
{
string language = Singleton<SharedGameSettingsClass>.Instance?.Game?.Settings?.Language?.GetValue();
if (language == null || !DisplayNames.ContainsKey(language))
@ -86,9 +52,8 @@ namespace IcyClawz.MagazineInspector
language = "en";
}
return DisplayNames[language];
}
public static float GetBase(MagazineClass magazine)
};
attribute.Base = () =>
{
if (GetAmmoCount(magazine, ActiveProfile, out _) is int ammoCount)
{
@ -98,9 +63,8 @@ namespace IcyClawz.MagazineInspector
{
return 0f;
}
}
public static string GetStringValue(MagazineClass magazine)
};
attribute.StringValue = () =>
{
string value;
if (GetAmmoCount(magazine, ActiveProfile, out _) is int ammoCount)
@ -112,10 +76,8 @@ namespace IcyClawz.MagazineInspector
value = "?";
}
return $"{value}/{magazine.MaxCount}";
}
public static string GetFullStringValue(MagazineClass magazine)
};
attribute.FullStringValue = () =>
{
Profile profile = ActiveProfile;
int? ammoCount = GetAmmoCount(magazine, profile, out bool magChecked);
@ -152,6 +114,35 @@ namespace IcyClawz.MagazineInspector
{
return string.Empty;
}
};
}
private static int? GetAmmoCount(MagazineClass magazine, Profile profile, out bool magChecked)
{
if (!InGameStatus.InRaid || magazine.Count == 0)
{
magChecked = true;
return magazine.Count;
}
magChecked = profile.CheckedMagazines.ContainsKey(magazine.Id);
if (magChecked)
{
bool equipped = profile.Inventory.Equipment.GetAllSlots().Any(slot => ReferenceEquals(slot.ContainedItem, magazine));
if (magazine.Count >= (equipped ? magazine.MaxCount - 1 : magazine.MaxCount))
{
return magazine.Count;
}
int skill = Mathf.Max(
profile.MagDrillsMastering,
profile.CheckedMagazineSkillLevel(magazine.Id),
magazine.CheckOverride
);
if (skill > 1 || (skill == 1 && magazine.MaxCount <= 10))
{
return magazine.Count;
}
}
return null;
}
}
}

View File

@ -8,9 +8,6 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Aki.Common">
<HintPath>..\Shared\Aki.Common.dll</HintPath>
</Reference>
<Reference Include="Aki.Reflection">
<HintPath>..\Shared\Aki.Reflection.dll</HintPath>
</Reference>

View File

@ -13,7 +13,7 @@ namespace IcyClawz.MagazineInspector
}
}
public class MagazinePatch : ModulePatch
internal class MagazinePatch : ModulePatch
{
protected override MethodBase GetTargetMethod() =>
typeof(MagazineClass).GetConstructors()[0];