2023-07-08 23:42:42 +03:00
|
|
|
|
using Comfort.Common;
|
|
|
|
|
using EFT;
|
|
|
|
|
using EFT.InventoryLogic;
|
2024-07-10 23:03:39 +03:00
|
|
|
|
using SPT.Reflection.Utils;
|
2023-07-08 23:42:42 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2024-12-02 15:59:14 +02:00
|
|
|
|
using InGameStatus = GClass2064;
|
2023-07-08 23:42:42 +03:00
|
|
|
|
|
2024-03-05 22:48:21 +02:00
|
|
|
|
namespace IcyClawz.MagazineInspector;
|
|
|
|
|
|
|
|
|
|
internal static class MagazineClassExtensions
|
2023-07-08 23:42:42 +03:00
|
|
|
|
{
|
2024-03-05 22:48:21 +02:00
|
|
|
|
private static readonly Dictionary<string, string> DisplayNames = new()
|
2023-07-08 23:42:42 +03:00
|
|
|
|
{
|
2024-03-05 22:48:21 +02:00
|
|
|
|
["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",
|
2024-10-25 20:55:26 +03:00
|
|
|
|
["tu"] = "Yüklü mühimmat",
|
2024-03-05 22:48:21 +02:00
|
|
|
|
};
|
2023-07-08 23:42:42 +03:00
|
|
|
|
|
2024-03-05 22:48:21 +02:00
|
|
|
|
private static ISession _Session;
|
|
|
|
|
private static ISession Session => _Session ??= ClientAppUtils.GetMainApp().GetClientBackEndSession();
|
2023-07-08 23:42:42 +03:00
|
|
|
|
|
2024-03-05 22:48:21 +02:00
|
|
|
|
private static Profile ActiveProfile => InGameStatus.InRaid ? GamePlayerOwner.MyPlayer.Profile : Session.Profile;
|
2023-07-08 23:42:42 +03:00
|
|
|
|
|
2024-12-02 15:59:14 +02:00
|
|
|
|
public static void AddAmmoCountAttribute(this MagazineItemClass magazine)
|
2024-03-05 22:48:21 +02:00
|
|
|
|
{
|
|
|
|
|
ItemAttributeClass attribute = magazine.Attributes.Find(attr => attr.Id is EItemAttributeId.MaxCount);
|
|
|
|
|
if (attribute is null)
|
|
|
|
|
return;
|
|
|
|
|
attribute.DisplayNameFunc = () =>
|
2023-07-08 23:42:42 +03:00
|
|
|
|
{
|
2024-03-05 22:48:21 +02:00
|
|
|
|
string language = Singleton<SharedGameSettingsClass>.Instance?.Game?.Settings?.Language?.GetValue();
|
|
|
|
|
if (language is null || !DisplayNames.ContainsKey(language))
|
|
|
|
|
language = "en";
|
|
|
|
|
return DisplayNames[language];
|
|
|
|
|
};
|
|
|
|
|
attribute.Base = () =>
|
|
|
|
|
{
|
|
|
|
|
int? ammoCount = GetAmmoCount(magazine, ActiveProfile, out _);
|
|
|
|
|
return ammoCount ?? 0f;
|
|
|
|
|
};
|
|
|
|
|
attribute.StringValue = () =>
|
|
|
|
|
{
|
|
|
|
|
int? ammoCount = GetAmmoCount(magazine, ActiveProfile, out _);
|
|
|
|
|
return $"{ammoCount?.ToString() ?? "?"}/{magazine.MaxCount}";
|
|
|
|
|
};
|
|
|
|
|
attribute.FullStringValue = () =>
|
|
|
|
|
{
|
|
|
|
|
int? ammoCount = GetAmmoCount(magazine, ActiveProfile, out bool magChecked);
|
|
|
|
|
return magChecked
|
|
|
|
|
? string.Join(Environment.NewLine, magazine.Cartridges.Items.Reverse().Select(cartridge =>
|
2023-07-09 22:38:08 +03:00
|
|
|
|
{
|
2024-03-05 22:48:21 +02:00
|
|
|
|
string count = ammoCount is not null ? cartridge.StackObjectsCount.ToString() : "?";
|
|
|
|
|
string name = ActiveProfile.Examined(cartridge) ? cartridge.LocalizedName() : "Unknown item".Localized();
|
|
|
|
|
return $"{count} × {name}";
|
|
|
|
|
}))
|
|
|
|
|
: "";
|
|
|
|
|
};
|
|
|
|
|
}
|
2023-07-08 23:42:42 +03:00
|
|
|
|
|
2024-12-02 15:59:14 +02:00
|
|
|
|
private static int? GetAmmoCount(MagazineItemClass magazine, Profile profile, out bool magChecked)
|
2024-03-05 22:48:21 +02:00
|
|
|
|
{
|
|
|
|
|
if (!InGameStatus.InRaid || magazine.Count == 0)
|
2023-07-08 23:42:42 +03:00
|
|
|
|
{
|
2024-03-05 22:48:21 +02:00
|
|
|
|
magChecked = true;
|
|
|
|
|
return magazine.Count;
|
2023-07-08 23:42:42 +03:00
|
|
|
|
}
|
2024-03-05 22:48:21 +02:00
|
|
|
|
magChecked = profile.CheckedMagazines.ContainsKey(magazine.Id);
|
|
|
|
|
if (!magChecked)
|
|
|
|
|
return null;
|
|
|
|
|
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);
|
|
|
|
|
return skill > 1 || (skill == 1 && magazine.MaxCount <= 10) ? magazine.Count : null;
|
2023-07-08 23:42:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|