From 302173daff7f0bbe0b4b7f74d3e2060061a3729c Mon Sep 17 00:00:00 2001 From: IgorEisberg Date: Sun, 9 Jul 2023 22:38:08 +0300 Subject: [PATCH] style --- CustomInteractions/Plugin.cs | 4 +- ItemAttributeFix/Plugin.cs | 2 +- ItemContextMenuExt/ItemContextMenuExt.cs | 2 +- ItemSellPrice/ItemSellPrice.cs | 183 ++++++++++----------- ItemSellPrice/ItemSellPrice.csproj | 3 - ItemSellPrice/Plugin.cs | 10 +- MagazineInspector/MagazineInspector.cs | 155 ++++++++--------- MagazineInspector/MagazineInspector.csproj | 3 - MagazineInspector/Plugin.cs | 2 +- 9 files changed, 172 insertions(+), 192 deletions(-) diff --git a/CustomInteractions/Plugin.cs b/CustomInteractions/Plugin.cs index fc2a80b..5aa17b4 100644 --- a/CustomInteractions/Plugin.cs +++ b/CustomInteractions/Plugin.cs @@ -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); diff --git a/ItemAttributeFix/Plugin.cs b/ItemAttributeFix/Plugin.cs index c8a8fd6..2acae2c 100644 --- a/ItemAttributeFix/Plugin.cs +++ b/ItemAttributeFix/Plugin.cs @@ -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); diff --git a/ItemContextMenuExt/ItemContextMenuExt.cs b/ItemContextMenuExt/ItemContextMenuExt.cs index 1793806..58eaf27 100644 --- a/ItemContextMenuExt/ItemContextMenuExt.cs +++ b/ItemContextMenuExt/ItemContextMenuExt.cs @@ -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; diff --git a/ItemSellPrice/ItemSellPrice.cs b/ItemSellPrice/ItemSellPrice.cs index 8b9b838..05fcf1d 100644 --- a/ItemSellPrice/ItemSellPrice.cs +++ b/ItemSellPrice/ItemSellPrice.cs @@ -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 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 DisplayNames = new Dictionary() { @@ -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 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 attributes = new List + ItemAttributeClass attribute = new ItemAttributeClass(EItemAttributeId.MoneySum) { - new ItemAttributeClass(EItemAttributeId.MoneySum) + Name = EItemAttributeId.MoneySum.GetName(), + DisplayNameFunc = () => { - Name = EItemAttributeId.MoneySum.GetName(), - DisplayNameFunc = () => GetDisplayName(item), - Base = () => GetBase(item), - StringValue = () => GetStringValue(item), - FullStringValue = () => GetFullStringValue(item), - DisplayType = () => EItemAttributeDisplayType.Compact - } + string language = Singleton.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 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 attributes = new List { 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.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 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; - } - } } } \ No newline at end of file diff --git a/ItemSellPrice/ItemSellPrice.csproj b/ItemSellPrice/ItemSellPrice.csproj index e415dd4..7347bd9 100644 --- a/ItemSellPrice/ItemSellPrice.csproj +++ b/ItemSellPrice/ItemSellPrice.csproj @@ -8,9 +8,6 @@ - - ..\Shared\Aki.Common.dll - ..\Shared\Aki.Reflection.dll diff --git a/ItemSellPrice/Plugin.cs b/ItemSellPrice/Plugin.cs index fa6f79f..f2785d0 100644 --- a/ItemSellPrice/Plugin.cs +++ b/ItemSellPrice/Plugin.cs @@ -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]; diff --git a/MagazineInspector/MagazineInspector.cs b/MagazineInspector/MagazineInspector.cs index e454431..172f637 100644 --- a/MagazineInspector/MagazineInspector.cs +++ b/MagazineInspector/MagazineInspector.cs @@ -11,7 +11,7 @@ using InGameStatus = GClass1756; namespace IcyClawz.MagazineInspector { - public static class MagazineInspector + internal static class MagazineClassExtensions { private static readonly Dictionary DisplayNames = new Dictionary() { @@ -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,10 +44,77 @@ namespace IcyClawz.MagazineInspector { return; } - attribute.DisplayNameFunc = GetDisplayName; - attribute.Base = () => GetBase(magazine); - attribute.StringValue = () => GetStringValue(magazine); - attribute.FullStringValue = () => GetFullStringValue(magazine); + attribute.DisplayNameFunc = () => + { + string language = Singleton.Instance?.Game?.Settings?.Language?.GetValue(); + if (language == null || !DisplayNames.ContainsKey(language)) + { + language = "en"; + } + return DisplayNames[language]; + }; + attribute.Base = () => + { + if (GetAmmoCount(magazine, ActiveProfile, out _) is int ammoCount) + { + return ammoCount; + } + else + { + return 0f; + } + }; + attribute.StringValue = () => + { + string value; + if (GetAmmoCount(magazine, ActiveProfile, out _) is int ammoCount) + { + value = ammoCount.ToString(); + } + else + { + value = "?"; + } + return $"{value}/{magazine.MaxCount}"; + }; + attribute.FullStringValue = () => + { + Profile profile = ActiveProfile; + int? ammoCount = GetAmmoCount(magazine, profile, out bool magChecked); + if (magChecked) + { + List cartridges = new List(magazine.Cartridges.Items); + string[] lines = new string[cartridges.Count]; + int i = cartridges.Count - 1; + foreach (Item cartridge in cartridges) + { + string count; + if (ammoCount != null) + { + count = cartridge.StackObjectsCount.ToString(); + } + else + { + count = "?"; + } + string name; + if (profile.Examined(cartridge)) + { + name = cartridge.LocalizedName(); + } + else + { + name = "Unknown item".Localized(); + } + lines[i--] = $"{count} × {name}"; + } + return string.Join(Environment.NewLine, lines); + } + else + { + return string.Empty; + } + }; } private static int? GetAmmoCount(MagazineClass magazine, Profile profile, out bool magChecked) @@ -77,81 +144,5 @@ namespace IcyClawz.MagazineInspector } return null; } - - public static string GetDisplayName() - { - string language = Singleton.Instance?.Game?.Settings?.Language?.GetValue(); - if (language == null || !DisplayNames.ContainsKey(language)) - { - language = "en"; - } - return DisplayNames[language]; - } - - public static float GetBase(MagazineClass magazine) - { - if (GetAmmoCount(magazine, ActiveProfile, out _) is int ammoCount) - { - return ammoCount; - } - else - { - return 0f; - } - } - - public static string GetStringValue(MagazineClass magazine) - { - string value; - if (GetAmmoCount(magazine, ActiveProfile, out _) is int ammoCount) - { - value = ammoCount.ToString(); - } - else - { - value = "?"; - } - return $"{value}/{magazine.MaxCount}"; - } - - - public static string GetFullStringValue(MagazineClass magazine) - { - Profile profile = ActiveProfile; - int? ammoCount = GetAmmoCount(magazine, profile, out bool magChecked); - if (magChecked) - { - List cartridges = new List(magazine.Cartridges.Items); - string[] lines = new string[cartridges.Count]; - int i = cartridges.Count - 1; - foreach (Item cartridge in cartridges) - { - string count; - if (ammoCount != null) - { - count = cartridge.StackObjectsCount.ToString(); - } - else - { - count = "?"; - } - string name; - if (profile.Examined(cartridge)) - { - name = cartridge.LocalizedName(); - } - else - { - name = "Unknown item".Localized(); - } - lines[i--] = $"{count} × {name}"; - } - return string.Join(Environment.NewLine, lines); - } - else - { - return string.Empty; - } - } } } \ No newline at end of file diff --git a/MagazineInspector/MagazineInspector.csproj b/MagazineInspector/MagazineInspector.csproj index 3efa759..b3343ef 100644 --- a/MagazineInspector/MagazineInspector.csproj +++ b/MagazineInspector/MagazineInspector.csproj @@ -8,9 +8,6 @@ - - ..\Shared\Aki.Common.dll - ..\Shared\Aki.Reflection.dll diff --git a/MagazineInspector/Plugin.cs b/MagazineInspector/Plugin.cs index 60c775a..0033fa0 100644 --- a/MagazineInspector/Plugin.cs +++ b/MagazineInspector/Plugin.cs @@ -13,7 +13,7 @@ namespace IcyClawz.MagazineInspector } } - public class MagazinePatch : ModulePatch + internal class MagazinePatch : ModulePatch { protected override MethodBase GetTargetMethod() => typeof(MagazineClass).GetConstructors()[0];