2023-09-29 00:59:42 +00:00
|
|
|
|
using Lumina.Excel.GeneratedSheets;
|
2020-08-23 14:55:52 +00:00
|
|
|
|
using System;
|
2020-08-04 23:30:29 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-08-22 03:27:12 +00:00
|
|
|
|
using System.Globalization;
|
2020-08-23 14:55:52 +00:00
|
|
|
|
using System.Linq;
|
2023-09-29 00:59:42 +00:00
|
|
|
|
using Dalamud.Plugin.Services;
|
2021-05-16 00:31:22 +00:00
|
|
|
|
using NoSoliciting.Ml;
|
2020-08-04 23:30:29 +00:00
|
|
|
|
|
|
|
|
|
namespace NoSoliciting {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
public static class FilterUtil {
|
2020-12-20 01:19:03 +00:00
|
|
|
|
private static int MaxItemLevel { get; set; }
|
2020-08-23 14:55:52 +00:00
|
|
|
|
|
2020-12-20 01:19:03 +00:00
|
|
|
|
private enum Slot {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
MainHand,
|
|
|
|
|
OffHand,
|
|
|
|
|
Head,
|
|
|
|
|
Chest,
|
|
|
|
|
Hands,
|
|
|
|
|
Waist,
|
|
|
|
|
Legs,
|
|
|
|
|
Feet,
|
|
|
|
|
Earrings,
|
|
|
|
|
Neck,
|
|
|
|
|
Wrist,
|
|
|
|
|
RingL,
|
|
|
|
|
RingR,
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 01:19:03 +00:00
|
|
|
|
private static Slot? SlotFromItem(Item item) {
|
|
|
|
|
var cat = item.EquipSlotCategory.Value;
|
2020-08-23 14:55:52 +00:00
|
|
|
|
if (cat == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.MainHand != 0) {
|
|
|
|
|
return Slot.MainHand;
|
2020-11-23 18:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.Head != 0) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
return Slot.Head;
|
2020-11-23 18:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.Body != 0) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
return Slot.Chest;
|
2020-11-23 18:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.Gloves != 0) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
return Slot.Hands;
|
2020-11-23 18:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.Waist != 0) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
return Slot.Waist;
|
2020-11-23 18:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.Legs != 0) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
return Slot.Legs;
|
2020-11-23 18:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.Feet != 0) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
return Slot.Feet;
|
2020-11-23 18:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.OffHand != 0) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
return Slot.OffHand;
|
2020-11-23 18:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.Ears != 0) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
return Slot.Earrings;
|
2020-11-23 18:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.Neck != 0) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
return Slot.Neck;
|
2020-11-23 18:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.Wrists != 0) {
|
|
|
|
|
return Slot.Wrist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.FingerL != 0) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
return Slot.RingL;
|
2020-11-23 18:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.FingerR != 0) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
return Slot.RingR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-29 00:59:42 +00:00
|
|
|
|
public static int MaxItemLevelAttainable(IDataManager data) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
if (MaxItemLevel > 0) {
|
|
|
|
|
return MaxItemLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data == null) {
|
|
|
|
|
throw new ArgumentNullException(nameof(data), "DataManager cannot be null");
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 01:19:03 +00:00
|
|
|
|
var ilvls = new Dictionary<Slot, int>();
|
2020-08-23 14:55:52 +00:00
|
|
|
|
|
2021-08-22 22:07:28 +00:00
|
|
|
|
foreach (var item in data.GetExcelSheet<Item>()!) {
|
2020-12-20 01:19:03 +00:00
|
|
|
|
var slot = SlotFromItem(item);
|
2020-08-23 14:55:52 +00:00
|
|
|
|
if (slot == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 01:19:03 +00:00
|
|
|
|
var itemLevel = 0;
|
|
|
|
|
var ilvl = item.LevelItem.Value;
|
2020-08-23 14:55:52 +00:00
|
|
|
|
if (ilvl != null) {
|
2020-12-20 01:19:03 +00:00
|
|
|
|
itemLevel = (int) ilvl.RowId;
|
2020-08-23 14:55:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 01:19:03 +00:00
|
|
|
|
if (ilvls.TryGetValue((Slot) slot, out var currentMax) && currentMax > itemLevel) {
|
2020-08-23 14:55:52 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 01:19:03 +00:00
|
|
|
|
ilvls[(Slot) slot] = itemLevel;
|
2020-08-23 14:55:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 01:19:03 +00:00
|
|
|
|
MaxItemLevel = (int) ilvls.Values.Average();
|
2020-08-23 14:55:52 +00:00
|
|
|
|
|
|
|
|
|
return MaxItemLevel;
|
|
|
|
|
}
|
2020-08-04 23:30:29 +00:00
|
|
|
|
}
|
2020-08-22 03:27:12 +00:00
|
|
|
|
|
2021-05-16 00:31:22 +00:00
|
|
|
|
public static class Extensions {
|
2020-08-22 03:27:12 +00:00
|
|
|
|
public static bool ContainsIgnoreCase(this string haystack, string needle) {
|
|
|
|
|
return CultureInfo.InvariantCulture.CompareInfo.IndexOf(haystack, needle, CompareOptions.IgnoreCase) >= 0;
|
|
|
|
|
}
|
2021-05-16 00:31:22 +00:00
|
|
|
|
|
|
|
|
|
public static bool WasEnabled(this IEnumerable<MessageCategory> enabled, MessageCategory category) {
|
2021-05-16 00:40:06 +00:00
|
|
|
|
return category == MessageCategory.Normal || enabled.Contains(category);
|
2021-05-16 00:31:22 +00:00
|
|
|
|
}
|
2020-08-22 03:27:12 +00:00
|
|
|
|
}
|
2020-08-04 23:30:29 +00:00
|
|
|
|
}
|