Fix incosistent sorting for preorder earrings
This commit is contained in:
parent
58040f4b16
commit
e75e4b1248
@ -11,10 +11,10 @@ internal sealed class ItemList
|
|||||||
{
|
{
|
||||||
private static readonly ReadOnlyDictionary<uint, byte> PreferredItems = new Dictionary<uint, byte>()
|
private static readonly ReadOnlyDictionary<uint, byte> PreferredItems = new Dictionary<uint, byte>()
|
||||||
{
|
{
|
||||||
{ 41081, 90 },
|
{ 16039, 50 },
|
||||||
{ 33648, 80 },
|
|
||||||
{ 24589, 70 },
|
{ 24589, 70 },
|
||||||
{ 16039, 50 }
|
{ 33648, 80 },
|
||||||
|
{ 41081, 90 },
|
||||||
}.AsReadOnly();
|
}.AsReadOnly();
|
||||||
|
|
||||||
public required EClassJob ClassJob { get; init; }
|
public required EClassJob ClassJob { get; init; }
|
||||||
@ -26,28 +26,10 @@ internal sealed class ItemList
|
|||||||
|
|
||||||
public void Sort()
|
public void Sort()
|
||||||
{
|
{
|
||||||
var preferredItems = Items
|
Items = Items
|
||||||
.Where(x => PreferredItems.ContainsKey(x.ItemId))
|
|
||||||
// don't show azeyma's earring for lv90 blue mage
|
|
||||||
.Where(x => x.ItemId != 41081 || ClassJob != EClassJob.BlueMage)
|
|
||||||
.ToList();
|
|
||||||
var defaultItems = Items
|
|
||||||
.Except(preferredItems)
|
|
||||||
.OrderDescending(new ItemComparer(SubstatPriorities))
|
.OrderDescending(new ItemComparer(SubstatPriorities))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// insert the preferred items
|
|
||||||
foreach (BaseItem preferredItem in preferredItems)
|
|
||||||
{
|
|
||||||
int level = PreferredItems[preferredItem.ItemId];
|
|
||||||
int index = defaultItems.FindIndex(x => x.Level < level);
|
|
||||||
if (index >= 0)
|
|
||||||
defaultItems.Insert(index, preferredItem);
|
|
||||||
else
|
|
||||||
defaultItems.Add(preferredItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
Items = defaultItems;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateStats(Dictionary<EClassJob, EBaseParam> primaryStats, Configuration configuration)
|
public void UpdateStats(Dictionary<EClassJob, EBaseParam> primaryStats, Configuration configuration)
|
||||||
@ -123,6 +105,11 @@ internal sealed class ItemList
|
|||||||
if (damageA != damageB)
|
if (damageA != damageB)
|
||||||
return damageA.CompareTo(damageB);
|
return damageA.CompareTo(damageB);
|
||||||
|
|
||||||
|
bool hasPriorityA = TryGetPreferredItemPriority(a, b, out byte priorityA);
|
||||||
|
bool hasPriorityB = TryGetPreferredItemPriority(b, a, out byte priorityB);
|
||||||
|
if ((hasPriorityA || hasPriorityB) && priorityA != priorityB)
|
||||||
|
return priorityA.CompareTo(priorityB);
|
||||||
|
|
||||||
// gear: primary stat wins
|
// gear: primary stat wins
|
||||||
//
|
//
|
||||||
// we pretend every gear item has at least 1 primary stat to ensure weathered items are sorted last(ish),
|
// we pretend every gear item has at least 1 primary stat to ensure weathered items are sorted last(ish),
|
||||||
@ -185,5 +172,33 @@ internal sealed class ItemList
|
|||||||
// fallback
|
// fallback
|
||||||
return string.CompareOrdinal(a.Name, b.Name);
|
return string.CompareOrdinal(a.Name, b.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool TryGetPreferredItemPriority(BaseItem self, BaseItem other, out byte priority)
|
||||||
|
{
|
||||||
|
if (PreferredItems.TryGetValue(self.ItemId, out byte levelSelf))
|
||||||
|
{
|
||||||
|
// both items are preferred, sort by level only
|
||||||
|
if (PreferredItems.TryGetValue(other.ItemId, out byte _))
|
||||||
|
{
|
||||||
|
priority = levelSelf;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if they're the same level, place the preferrd item last
|
||||||
|
if (levelSelf == other.Level)
|
||||||
|
{
|
||||||
|
priority = (byte)(levelSelf - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
priority = levelSelf;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
priority = self.Level;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user