2023-07-08 23:42:42 +03:00
|
|
|
|
using Aki.Reflection.Utils;
|
|
|
|
|
using Comfort.Common;
|
|
|
|
|
using EFT;
|
|
|
|
|
using EFT.InventoryLogic;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2023-07-31 19:57:13 +03:00
|
|
|
|
using InGameStatus = GClass1819;
|
2023-07-08 23:42:42 +03:00
|
|
|
|
|
|
|
|
|
namespace IcyClawz.MagazineInspector
|
|
|
|
|
{
|
2023-07-09 22:38:08 +03:00
|
|
|
|
internal static class MagazineClassExtensions
|
2023-07-08 23:42:42 +03:00
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
2023-07-09 22:38:08 +03:00
|
|
|
|
private static Profile ActiveProfile => InGameStatus.InRaid ? GamePlayerOwner.MyPlayer.Profile : Session.Profile;
|
2023-07-08 23:42:42 +03:00
|
|
|
|
|
|
|
|
|
public static void AddAmmoCountAttribute(this MagazineClass magazine)
|
|
|
|
|
{
|
|
|
|
|
ItemAttributeClass attribute = magazine.Attributes.Find(attr => attr.Id is EItemAttributeId.MaxCount);
|
|
|
|
|
if (attribute == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-07-09 22:38:08 +03:00
|
|
|
|
attribute.DisplayNameFunc = () =>
|
|
|
|
|
{
|
|
|
|
|
string language = Singleton<SharedGameSettingsClass>.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<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;
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-07-08 23:42:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|