148 lines
5.3 KiB
C#
148 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 = GClass1716;
|
||
|
||
namespace IcyClawz.MagazineInspector
|
||
{
|
||
internal static class MagazineClassExtensions
|
||
{
|
||
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 ? GamePlayerOwner.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 = () =>
|
||
{
|
||
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;
|
||
}
|
||
};
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
} |