157 lines
5.3 KiB
C#
157 lines
5.3 KiB
C#
|
using Aki.Reflection.Utils;
|
|||
|
using Comfort.Common;
|
|||
|
using EFT;
|
|||
|
using EFT.InventoryLogic;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
using InGameStatus = GClass1756;
|
|||
|
|
|||
|
namespace IcyClawz.MagazineInspector
|
|||
|
{
|
|||
|
public static class MagazineInspector
|
|||
|
{
|
|||
|
private static readonly Dictionary<string, string> DisplayNames = new Dictionary<string, string>()
|
|||
|
{
|
|||
|
{ "ch", "上膛弹药" },
|
|||
|
{ "cz", "Nabité střelivo" },
|
|||
|
{ "en", "Loaded ammo" },
|
|||
|
{ "es", "Munición cargada" },
|
|||
|
{ "es-mx", "Munición cargada" },
|
|||
|
{ "fr", "Munitions chargées" },
|
|||
|
{ "ge", "Geladene Munition" },
|
|||
|
{ "hu", "Töltött lőszer" },
|
|||
|
{ "it", "Munizioni caricate" },
|
|||
|
{ "jp", "装填弾薬" },
|
|||
|
{ "kr", "장전 탄약" },
|
|||
|
{ "pl", "Załadowana amunicja" },
|
|||
|
{ "po", "Munição carregada" },
|
|||
|
{ "ru", "Заряженные боеприпасы" },
|
|||
|
{ "sk", "Nabitá munícia" },
|
|||
|
{ "tu", "Yüklü mühimmat" }
|
|||
|
};
|
|||
|
|
|||
|
private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession();
|
|||
|
|
|||
|
private static Profile ActiveProfile => InGameStatus.InRaid ? ClientPlayerOwner.MyPlayer.Profile : Session.Profile;
|
|||
|
|
|||
|
public static void AddAmmoCountAttribute(this MagazineClass magazine)
|
|||
|
{
|
|||
|
ItemAttributeClass attribute = magazine.Attributes.Find(attr => attr.Id is EItemAttributeId.MaxCount);
|
|||
|
if (attribute == null)
|
|||
|
{
|
|||
|
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()
|
|||
|
{
|
|||
|
string language = Singleton<SharedGameSettingsClass>.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<Item> cartridges = new List<Item>(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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|