Compare commits

..

No commits in common. "master" and "v1.2" have entirely different histories.
master ... v1.2

5 changed files with 36 additions and 62 deletions

View File

@ -27,7 +27,7 @@ public class GearsetterIpcTestPlugin : IDalamudPlugin
{
int currentGearsetIndex = RaptureGearsetModule.Instance()->CurrentGearsetIndex;
var recommendations = _pluginInterface
.GetIpcSubscriber<byte, List<(uint ItemId, InventoryType? SourceInventory, byte? SourceInventorySlot, RaptureGearsetModule.GearsetItemIndex TargetSlot)>>(
.GetIpcSubscriber<byte, List<(uint ItemId, InventoryType? SourceInventory, byte? SourceInventorySlot)>>(
"Gearsetter.GetRecommendationsForGearset").InvokeFunc((byte)currentGearsetIndex);
if (recommendations.Count == 0)
_chatGui.Print($"No recommendations for gearset #{currentGearsetIndex}.");
@ -35,7 +35,7 @@ public class GearsetterIpcTestPlugin : IDalamudPlugin
{
foreach (var recommendation in recommendations)
_chatGui.Print(
$"Recommendation: Equip item {recommendation.ItemId} from {recommendation.SourceInventory} (slot {recommendation.SourceInventorySlot}) as {recommendation.TargetSlot}");
$"Recommendation: Equip item {recommendation.ItemId} from {recommendation.SourceInventory} (slot {recommendation.SourceInventorySlot})");
}
}

View File

@ -17,8 +17,7 @@ internal sealed class GearsetterIpc : IDisposable
private readonly IPluginLog _pluginLog;
private readonly ICallGateProvider<byte,
List<(uint ItemId, InventoryType? SourceInventory, int? SourceInventorySlot,
RaptureGearsetModule.GearsetItemIndex TargetSlot)>>
List<(uint ItemId, InventoryType? SourceInventory, int? SourceInventorySlot)>>
_getRecommendationsForGearset;
public GearsetterIpc(GearsetterPlugin plugin, IDalamudPluginInterface pluginInterface, IPluginLog pluginLog)
@ -26,15 +25,11 @@ internal sealed class GearsetterIpc : IDisposable
_plugin = plugin;
_pluginLog = pluginLog;
_getRecommendationsForGearset =
pluginInterface
.GetIpcProvider<byte,
List<(uint, InventoryType?, int?, RaptureGearsetModule.GearsetItemIndex TargetSlot)>>(
IpcGetRecommendationsForGearset);
pluginInterface.GetIpcProvider<byte, List<(uint, InventoryType?, int?)>>(IpcGetRecommendationsForGearset);
_getRecommendationsForGearset.RegisterFunc(GetRecommendationsForGearset);
}
private unsafe List<(uint ItemId, InventoryType? SourceInventory, int? SourceInventorySlot,
RaptureGearsetModule.GearsetItemIndex TargetSlot)>
private unsafe List<(uint ItemId, InventoryType? SourceInventory, int? SourceInventorySlot)>
GetRecommendationsForGearset(byte gearsetId)
{
if (gearsetId > 100)
@ -53,7 +48,7 @@ internal sealed class GearsetterIpc : IDisposable
_pluginLog.Verbose($"Checking for gearset upgrades for gearset {gearset->Id}.");
return _plugin.GetRecommendedUpgrades(gearset)
.Select(x => (x.ItemId, x.SourceInventory, x.SourceInventorySlot, x.TargetSlot))
.Select(x => (x.ItemId, x.SourceInventory, x.SourceInventorySlot))
.ToList();
}

View File

@ -1,6 +1,6 @@
<Project Sdk="Dalamud.NET.Sdk/9.0.2">
<PropertyGroup>
<Version>1.3</Version>
<Version>1.2</Version>
<OutputPath>dist</OutputPath>
</PropertyGroup>

View File

@ -189,8 +189,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
private List<RecommendedItemChange> GetRecommendedUpgrades(GearsetData gearset,
Dictionary<(uint ItemId, bool Hql), List<MateriaStats>> inventoryItems, byte? level)
{
List<RecommendedItemChange> Handle(string label,
(EquipmentItem?, RaptureGearsetModule.GearsetItemIndex)[] gearsetItems,
List<RecommendedItemChange> Handle(string label, EquipmentItem?[] gearsetItems,
EEquipSlotCategory category)
{
return HandleGearsetItem(label, gearset, gearsetItems, inventoryItems, category, level);
@ -198,25 +197,20 @@ public sealed class GearsetterPlugin : IDalamudPlugin
List<List<RecommendedItemChange>> upgrades = new()
{
Handle("Main Hand", [(gearset.MainHand, RaptureGearsetModule.GearsetItemIndex.MainHand)],
EEquipSlotCategory.None),
Handle("Main Hand", [gearset.MainHand], EEquipSlotCategory.None),
HandleOffHand(gearset, inventoryItems, level),
Handle("Head", [(gearset.Head, RaptureGearsetModule.GearsetItemIndex.Head)], EEquipSlotCategory.Head),
Handle("Body", [(gearset.Body, RaptureGearsetModule.GearsetItemIndex.Body)], EEquipSlotCategory.Body),
Handle("Hands", [(gearset.Hands, RaptureGearsetModule.GearsetItemIndex.Hands)], EEquipSlotCategory.Hands),
Handle("Legs", [(gearset.Legs, RaptureGearsetModule.GearsetItemIndex.Legs)], EEquipSlotCategory.Legs),
Handle("Feet", [(gearset.Feet, RaptureGearsetModule.GearsetItemIndex.Feet)], EEquipSlotCategory.Feet),
Handle("Head", [gearset.Head], EEquipSlotCategory.Head),
Handle("Body", [gearset.Body], EEquipSlotCategory.Body),
Handle("Hands", [gearset.Hands], EEquipSlotCategory.Hands),
Handle("Legs", [gearset.Legs], EEquipSlotCategory.Legs),
Handle("Feet", [gearset.Feet], EEquipSlotCategory.Feet),
Handle("Ears", [(gearset.Ears, RaptureGearsetModule.GearsetItemIndex.Ears)], EEquipSlotCategory.Ears),
Handle("Neck", [(gearset.Neck, RaptureGearsetModule.GearsetItemIndex.Neck)], EEquipSlotCategory.Neck),
Handle("Wrists", [(gearset.Wrists, RaptureGearsetModule.GearsetItemIndex.Wrists)],
EEquipSlotCategory.Wrists),
Handle("Ears", [gearset.Ears], EEquipSlotCategory.Ears),
Handle("Neck", [gearset.Neck], EEquipSlotCategory.Neck),
Handle("Wrists", [gearset.Wrists], EEquipSlotCategory.Wrists),
Handle("Rings",
[
(gearset.RingLeft, RaptureGearsetModule.GearsetItemIndex.RingLeft),
(gearset.RingRight, RaptureGearsetModule.GearsetItemIndex.RingRight)
],
[gearset.RingLeft, gearset.RingRight],
EEquipSlotCategory.Rings),
};
@ -257,18 +251,17 @@ public sealed class GearsetterPlugin : IDalamudPlugin
=> gearset->NameString.Split((char)0)[0];
private List<RecommendedItemChange> HandleGearsetItem(string label, GearsetData gearset,
(EquipmentItem? Item, RaptureGearsetModule.GearsetItemIndex Slot)[] gearsetItems,
EquipmentItem?[] gearsetItems,
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems,
EEquipSlotCategory equipSlotCategory, byte? level)
{
EClassJob classJob = gearset.ClassJob;
List<RaptureGearsetModule.GearsetItemIndex> availableGearsetSlots = gearsetItems.Select(x => x.Slot).ToList();
var itemLists = _gameDataHolder.GetItemLists(classJob);
if (equipSlotCategory == EEquipSlotCategory.None && gearsetItems.Any(x => x.Item != null))
if (equipSlotCategory == EEquipSlotCategory.None && gearsetItems.Any(x => x != null))
{
var firstEquippedItem = gearsetItems.First(x => x.Item != null);
equipSlotCategory = firstEquippedItem.Item!.EquipSlotCategory;
var firstEquippedItem = gearsetItems.First(x => x != null);
equipSlotCategory = firstEquippedItem!.EquipSlotCategory;
}
if (equipSlotCategory == EEquipSlotCategory.None)
@ -277,16 +270,15 @@ public sealed class GearsetterPlugin : IDalamudPlugin
return [];
}
(BaseItem? Item, RaptureGearsetModule.GearsetItemIndex Slot)[] currentItems = gearsetItems
BaseItem?[] currentItems = gearsetItems
.Select(x =>
{
if (x.Item == null)
return (null, x.Slot);
if (x == null)
return null;
var baseItem = itemLists
.SelectMany(y => y.Items.Where(z => x.Item.ItemId == z.ItemId && x.Item.Hq == z.Hq))
return itemLists
.SelectMany(y => y.Items.Where(z => x.ItemId == z.ItemId && x.Hq == z.Hq))
.FirstOrDefault();
return (baseItem, x.Slot);
})
.ToArray();
@ -307,28 +299,19 @@ public sealed class GearsetterPlugin : IDalamudPlugin
.Take(gearsetItems.Length)
.ToList();
//_pluginLog.Debug(
// $"{equipSlotCategory}: {string.Join(" ", currentItems.Select(x => $"{x.Item}, {x.Slot}"))}");
// $"{equipSlotCategory}: {string.Join(" ", currentItems.Select(x => $"{x?.ItemId}|{x?.Hq}"))}");
foreach (var currentItem in currentItems)
{
var foundIndex = bestItems.FindIndex(x =>
currentItem.Item != null && currentItem.Item.ItemId == x.ItemId && currentItem.Item.Hq == x.Hq);
currentItem != null && currentItem.ItemId == x.ItemId && currentItem.Hq == x.Hq);
if (foundIndex >= 0)
{
bestItems.RemoveAt(foundIndex);
availableGearsetSlots.Remove(currentItem.Slot);
}
}
return bestItems
.Select(x =>
{
var slot = availableGearsetSlots[0];
availableGearsetSlots.RemoveAt(0);
return ToItemRecommendation(x, slot,
new SeString(new TextPayload($"{label}: "))
.Append(SeString.CreateItemLink(x.ItemId, x.Hq)));
})
.Select(x => ToItemRecommendation(x,
new SeString(new TextPayload($"{label}: "))
.Append(SeString.CreateItemLink(x.ItemId, x.Hq))))
.ToList();
}
finally
@ -349,8 +332,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
if (equipSlotCategory != EEquipSlotCategory.OneHandedMainHand)
return [];
return HandleGearsetItem("Off Hand", gearset,
[(gearset.OffHand, RaptureGearsetModule.GearsetItemIndex.OffHand)],
return HandleGearsetItem("Off Hand", gearset, [gearset.OffHand],
inventoryItems,
EEquipSlotCategory.Shield, level);
}
@ -359,8 +341,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
=> RaptureGearsetModule.Instance()->EquipGearset((byte)commandId);
private unsafe RecommendedItemChange ToItemRecommendation(BaseItem baseItem,
RaptureGearsetModule.GearsetItemIndex targetSlot, SeString text)
private unsafe RecommendedItemChange ToItemRecommendation(BaseItem baseItem, SeString text)
{
InventoryManager* inventoryManager = InventoryManager.Instance();
foreach (var inventoryType in _gameDataHolder.DefaultInventoryTypes)
@ -376,12 +357,12 @@ public sealed class GearsetterPlugin : IDalamudPlugin
MateriaStats actualMateriaStats = FetchMateriaStats(item);
if (expectedMateriaStats == actualMateriaStats)
return new RecommendedItemChange(item->ItemId, inventoryType, i, targetSlot, text);
return new RecommendedItemChange(item->ItemId, inventoryType, i, text);
}
}
}
return new RecommendedItemChange(baseItem.ItemId, null, null, targetSlot, text);
return new RecommendedItemChange(baseItem.ItemId, null, null, text);
}
internal unsafe Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> GetAllInventoryItems()

View File

@ -1,6 +1,5 @@
using Dalamud.Game.Text.SeStringHandling;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
namespace Gearsetter.Model;
@ -8,5 +7,4 @@ internal sealed record RecommendedItemChange(
uint ItemId,
InventoryType? SourceInventory,
int? SourceInventorySlot,
RaptureGearsetModule.GearsetItemIndex TargetSlot,
SeString Text);