Add IPC method 'Gearsetter.GetRecommendationsForGearset'
This commit is contained in:
parent
e75e4b1248
commit
18c62ba0b7
3
Gearsetter.IpcTest/.gitignore
vendored
Normal file
3
Gearsetter.IpcTest/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/dist
|
||||||
|
/obj
|
||||||
|
/bin
|
8
Gearsetter.IpcTest/Gearsetter.IpcTest.csproj
Normal file
8
Gearsetter.IpcTest/Gearsetter.IpcTest.csproj
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<Project Sdk="Dalamud.NET.Sdk/9.0.2">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Version>1.0</Version>
|
||||||
|
<OutputPath>dist</OutputPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<Import Project="..\LLib\LLib.targets"/>
|
||||||
|
</Project>
|
6
Gearsetter.IpcTest/Gearsetter.IpcTest.json
Normal file
6
Gearsetter.IpcTest/Gearsetter.IpcTest.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"Name": "Gearsetter (IPC Test)",
|
||||||
|
"Author": "Liza Carvelli",
|
||||||
|
"Punchline": "dev only plugin",
|
||||||
|
"Description": "dev only plugin"
|
||||||
|
}
|
47
Gearsetter.IpcTest/GearsetterIpcTestPlugin.cs
Normal file
47
Gearsetter.IpcTest/GearsetterIpcTestPlugin.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Dalamud.Game.Command;
|
||||||
|
using Dalamud.Plugin;
|
||||||
|
using Dalamud.Plugin.Services;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
|
||||||
|
|
||||||
|
namespace Gearsetter.IpcTest;
|
||||||
|
|
||||||
|
public class GearsetterIpcTestPlugin : IDalamudPlugin
|
||||||
|
{
|
||||||
|
private readonly IDalamudPluginInterface _pluginInterface;
|
||||||
|
private readonly ICommandManager _commandManager;
|
||||||
|
private readonly IChatGui _chatGui;
|
||||||
|
|
||||||
|
public GearsetterIpcTestPlugin(IDalamudPluginInterface pluginInterface, ICommandManager commandManager,
|
||||||
|
IChatGui chatGui)
|
||||||
|
{
|
||||||
|
_pluginInterface = pluginInterface;
|
||||||
|
_commandManager = commandManager;
|
||||||
|
_chatGui = chatGui;
|
||||||
|
|
||||||
|
_commandManager.AddHandler("/recommendedgear", new CommandInfo(ProcessCommand));
|
||||||
|
}
|
||||||
|
|
||||||
|
private unsafe void ProcessCommand(string command, string arguments)
|
||||||
|
{
|
||||||
|
int currentGearsetIndex = RaptureGearsetModule.Instance()->CurrentGearsetIndex;
|
||||||
|
var recommendations = _pluginInterface
|
||||||
|
.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}.");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var recommendation in recommendations)
|
||||||
|
_chatGui.Print(
|
||||||
|
$"Recommendation: Equip item {recommendation.ItemId} from {recommendation.SourceInventory} (slot {recommendation.SourceInventorySlot})");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_commandManager.RemoveHandler("/recommendedgear");
|
||||||
|
}
|
||||||
|
}
|
87
Gearsetter.IpcTest/packages.lock.json
Normal file
87
Gearsetter.IpcTest/packages.lock.json
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"dependencies": {
|
||||||
|
"net8.0-windows7.0": {
|
||||||
|
"DalamudPackager": {
|
||||||
|
"type": "Direct",
|
||||||
|
"requested": "[2.1.13, )",
|
||||||
|
"resolved": "2.1.13",
|
||||||
|
"contentHash": "rMN1omGe8536f4xLMvx9NwfvpAc9YFFfeXJ1t4P4PE6Gu8WCIoFliR1sh07hM+bfODmesk/dvMbji7vNI+B/pQ=="
|
||||||
|
},
|
||||||
|
"DotNet.ReproducibleBuilds": {
|
||||||
|
"type": "Direct",
|
||||||
|
"requested": "[1.1.1, )",
|
||||||
|
"resolved": "1.1.1",
|
||||||
|
"contentHash": "+H2t/t34h6mhEoUvHi8yGXyuZ2GjSovcGYehJrS2MDm2XgmPfZL2Sdxg+uL2lKgZ4M6tTwKHIlxOob2bgh0NRQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.SourceLink.AzureRepos.Git": "1.1.1",
|
||||||
|
"Microsoft.SourceLink.Bitbucket.Git": "1.1.1",
|
||||||
|
"Microsoft.SourceLink.GitHub": "1.1.1",
|
||||||
|
"Microsoft.SourceLink.GitLab": "1.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Microsoft.SourceLink.Gitea": {
|
||||||
|
"type": "Direct",
|
||||||
|
"requested": "[8.0.0, )",
|
||||||
|
"resolved": "8.0.0",
|
||||||
|
"contentHash": "KOBodmDnlWGIqZt2hT47Q69TIoGhIApDVLCyyj9TT5ct8ju16AbHYcB4XeknoHX562wO1pMS/1DfBIZK+V+sxg==",
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.Build.Tasks.Git": "8.0.0",
|
||||||
|
"Microsoft.SourceLink.Common": "8.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Microsoft.Build.Tasks.Git": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "8.0.0",
|
||||||
|
"contentHash": "bZKfSIKJRXLTuSzLudMFte/8CempWjVamNUR5eHJizsy+iuOuO/k2gnh7W0dHJmYY0tBf+gUErfluCv5mySAOQ=="
|
||||||
|
},
|
||||||
|
"Microsoft.SourceLink.AzureRepos.Git": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "1.1.1",
|
||||||
|
"contentHash": "qB5urvw9LO2bG3eVAkuL+2ughxz2rR7aYgm2iyrB8Rlk9cp2ndvGRCvehk3rNIhRuNtQaeKwctOl1KvWiklv5w==",
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.Build.Tasks.Git": "1.1.1",
|
||||||
|
"Microsoft.SourceLink.Common": "1.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Microsoft.SourceLink.Bitbucket.Git": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "1.1.1",
|
||||||
|
"contentHash": "cDzxXwlyWpLWaH0em4Idj0H3AmVo3L/6xRXKssYemx+7W52iNskj/SQ4FOmfCb8YQt39otTDNMveCZzYtMoucQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.Build.Tasks.Git": "1.1.1",
|
||||||
|
"Microsoft.SourceLink.Common": "1.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Microsoft.SourceLink.Common": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "8.0.0",
|
||||||
|
"contentHash": "dk9JPxTCIevS75HyEQ0E4OVAFhB2N+V9ShCXf8Q6FkUQZDkgLI12y679Nym1YqsiSysuQskT7Z+6nUf3yab6Vw=="
|
||||||
|
},
|
||||||
|
"Microsoft.SourceLink.GitHub": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "1.1.1",
|
||||||
|
"contentHash": "IaJGnOv/M7UQjRJks7B6p7pbPnOwisYGOIzqCz5ilGFTApZ3ktOR+6zJ12ZRPInulBmdAf1SrGdDG2MU8g6XTw==",
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.Build.Tasks.Git": "1.1.1",
|
||||||
|
"Microsoft.SourceLink.Common": "1.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Microsoft.SourceLink.GitLab": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "1.1.1",
|
||||||
|
"contentHash": "tvsg47DDLqqedlPeYVE2lmiTpND8F0hkrealQ5hYltSmvruy/Gr5nHAKSsjyw5L3NeM/HLMI5ORv7on/M4qyZw==",
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.Build.Tasks.Git": "1.1.1",
|
||||||
|
"Microsoft.SourceLink.Common": "1.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"llib": {
|
||||||
|
"type": "Project",
|
||||||
|
"dependencies": {
|
||||||
|
"DalamudPackager": "[2.1.13, )"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gearsetter.Test", "Gearsett
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LLib", "LLib\LLib.csproj", "{66144F9D-AC38-4F16-B269-A610F8EB7A3F}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LLib", "LLib\LLib.csproj", "{66144F9D-AC38-4F16-B269-A610F8EB7A3F}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gearsetter.IpcTest", "Gearsetter.IpcTest\Gearsetter.IpcTest.csproj", "{D5BFA879-0A33-4640-B75E-D92D8F23D6F1}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -24,5 +26,9 @@ Global
|
|||||||
{66144F9D-AC38-4F16-B269-A610F8EB7A3F}.Debug|Any CPU.Build.0 = Debug|x64
|
{66144F9D-AC38-4F16-B269-A610F8EB7A3F}.Debug|Any CPU.Build.0 = Debug|x64
|
||||||
{66144F9D-AC38-4F16-B269-A610F8EB7A3F}.Release|Any CPU.ActiveCfg = Debug|x64
|
{66144F9D-AC38-4F16-B269-A610F8EB7A3F}.Release|Any CPU.ActiveCfg = Debug|x64
|
||||||
{66144F9D-AC38-4F16-B269-A610F8EB7A3F}.Release|Any CPU.Build.0 = Debug|x64
|
{66144F9D-AC38-4F16-B269-A610F8EB7A3F}.Release|Any CPU.Build.0 = Debug|x64
|
||||||
|
{D5BFA879-0A33-4640-B75E-D92D8F23D6F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D5BFA879-0A33-4640-B75E-D92D8F23D6F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D5BFA879-0A33-4640-B75E-D92D8F23D6F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D5BFA879-0A33-4640-B75E-D92D8F23D6F1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
59
Gearsetter/External/GearsetterIpc.cs
vendored
Normal file
59
Gearsetter/External/GearsetterIpc.cs
vendored
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Dalamud.Plugin;
|
||||||
|
using Dalamud.Plugin.Ipc;
|
||||||
|
using Dalamud.Plugin.Services;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
|
||||||
|
|
||||||
|
namespace Gearsetter.External;
|
||||||
|
|
||||||
|
internal sealed class GearsetterIpc : IDisposable
|
||||||
|
{
|
||||||
|
private const string IpcGetRecommendationsForGearset = "Gearsetter.GetRecommendationsForGearset";
|
||||||
|
|
||||||
|
private readonly GearsetterPlugin _plugin;
|
||||||
|
private readonly IPluginLog _pluginLog;
|
||||||
|
|
||||||
|
private readonly ICallGateProvider<byte,
|
||||||
|
List<(uint ItemId, InventoryType? SourceInventory, int? SourceInventorySlot)>>
|
||||||
|
_getRecommendationsForGearset;
|
||||||
|
|
||||||
|
public GearsetterIpc(GearsetterPlugin plugin, IDalamudPluginInterface pluginInterface, IPluginLog pluginLog)
|
||||||
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
_pluginLog = pluginLog;
|
||||||
|
_getRecommendationsForGearset =
|
||||||
|
pluginInterface.GetIpcProvider<byte, List<(uint, InventoryType?, int?)>>(IpcGetRecommendationsForGearset);
|
||||||
|
_getRecommendationsForGearset.RegisterFunc(GetRecommendationsForGearset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private unsafe List<(uint ItemId, InventoryType? SourceInventory, int? SourceInventorySlot)>
|
||||||
|
GetRecommendationsForGearset(byte gearsetId)
|
||||||
|
{
|
||||||
|
if (gearsetId > 100)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(gearsetId));
|
||||||
|
|
||||||
|
var gearsetModule = RaptureGearsetModule.Instance();
|
||||||
|
if (gearsetModule == null)
|
||||||
|
throw new InvalidOperationException($"{nameof(RaptureGearsetModule)} is null");
|
||||||
|
|
||||||
|
var gearset = gearsetModule->GetGearset(gearsetId);
|
||||||
|
if (gearset == null)
|
||||||
|
throw new InvalidOperationException($"Gearset {gearsetId} is null");
|
||||||
|
|
||||||
|
if (!gearset->Flags.HasFlag(RaptureGearsetModule.GearsetFlag.Exists))
|
||||||
|
throw new InvalidOperationException($"Gearset {gearsetId} does not exist");
|
||||||
|
|
||||||
|
_pluginLog.Verbose($"Checking for gearset upgrades for gearset {gearset->Id}.");
|
||||||
|
return _plugin.GetRecommendedUpgrades(gearset)
|
||||||
|
.Select(x => (x.ItemId, x.SourceInventory, x.SourceInventorySlot))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_getRecommendationsForGearset.UnregisterFunc();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Dalamud.NET.Sdk/9.0.2">
|
<Project Sdk="Dalamud.NET.Sdk/9.0.2">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>1.1</Version>
|
<Version>1.2</Version>
|
||||||
<OutputPath>dist</OutputPath>
|
<OutputPath>dist</OutputPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ using Dalamud.Plugin.Services;
|
|||||||
using FFXIVClientStructs.FFXIV.Client.Game;
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||||
using FFXIVClientStructs.FFXIV.Client.Game.UI;
|
using FFXIVClientStructs.FFXIV.Client.Game.UI;
|
||||||
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
|
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
|
||||||
|
using Gearsetter.External;
|
||||||
using Gearsetter.GameData;
|
using Gearsetter.GameData;
|
||||||
using Gearsetter.Model;
|
using Gearsetter.Model;
|
||||||
using Gearsetter.Windows;
|
using Gearsetter.Windows;
|
||||||
@ -32,11 +33,11 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
private readonly IDataManager _dataManager;
|
private readonly IDataManager _dataManager;
|
||||||
private readonly IPluginLog _pluginLog;
|
private readonly IPluginLog _pluginLog;
|
||||||
private readonly IClientState _clientState;
|
private readonly IClientState _clientState;
|
||||||
|
private readonly GearsetterIpc _gearsetterIpc;
|
||||||
private readonly Configuration _configuration;
|
private readonly Configuration _configuration;
|
||||||
private readonly GameDataHolder _gameDataHolder;
|
private readonly GameDataHolder _gameDataHolder;
|
||||||
private readonly EquipmentBrowserWindow _equipmentBrowserWindow;
|
private readonly EquipmentBrowserWindow _equipmentBrowserWindow;
|
||||||
private readonly ConfigWindow _configWindow;
|
private readonly ConfigWindow _configWindow;
|
||||||
|
|
||||||
private readonly IReadOnlyDictionary<byte, DalamudLinkPayload> _linkPayloads;
|
private readonly IReadOnlyDictionary<byte, DalamudLinkPayload> _linkPayloads;
|
||||||
private readonly Dictionary<EClassJob, byte> _classJobToArrayIndex;
|
private readonly Dictionary<EClassJob, byte> _classJobToArrayIndex;
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
_dataManager = dataManager;
|
_dataManager = dataManager;
|
||||||
_pluginLog = pluginLog;
|
_pluginLog = pluginLog;
|
||||||
_clientState = clientState;
|
_clientState = clientState;
|
||||||
|
_gearsetterIpc = new GearsetterIpc(this, _pluginInterface, _pluginLog);
|
||||||
|
|
||||||
Configuration? configuration = (Configuration?)_pluginInterface.GetPluginConfig();
|
Configuration? configuration = (Configuration?)_pluginInterface.GetPluginConfig();
|
||||||
if (configuration == null)
|
if (configuration == null)
|
||||||
@ -176,16 +178,24 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
return new GearsetData(_dataManager, gearset, name);
|
return new GearsetData(_dataManager, gearset, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool HandleGearset(GearsetData gearset,
|
internal unsafe List<RecommendedItemChange> GetRecommendedUpgrades(RaptureGearsetModule.GearsetEntry* gearset,
|
||||||
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level)
|
byte? level = null)
|
||||||
{
|
{
|
||||||
List<SeString> Handle(string label, EquipmentItem?[] gearsetItems,
|
GearsetData gearsetData = new GearsetData(_dataManager, gearset, GetGearsetName(gearset));
|
||||||
|
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems = GetAllInventoryItems();
|
||||||
|
return GetRecommendedUpgrades(gearsetData, inventoryItems, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<RecommendedItemChange> GetRecommendedUpgrades(GearsetData gearset,
|
||||||
|
Dictionary<(uint ItemId, bool Hql), List<MateriaStats>> inventoryItems, byte? level)
|
||||||
|
{
|
||||||
|
List<RecommendedItemChange> Handle(string label, EquipmentItem?[] gearsetItems,
|
||||||
EEquipSlotCategory category)
|
EEquipSlotCategory category)
|
||||||
{
|
{
|
||||||
return HandleGearsetItem(label, gearset, gearsetItems, inventoryItems, category, level);
|
return HandleGearsetItem(label, gearset, gearsetItems, inventoryItems, category, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<List<SeString>> upgrades = new()
|
List<List<RecommendedItemChange>> upgrades = new()
|
||||||
{
|
{
|
||||||
Handle("Main Hand", [gearset.MainHand], EEquipSlotCategory.None),
|
Handle("Main Hand", [gearset.MainHand], EEquipSlotCategory.None),
|
||||||
HandleOffHand(gearset, inventoryItems, level),
|
HandleOffHand(gearset, inventoryItems, level),
|
||||||
@ -204,8 +214,15 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
EEquipSlotCategory.Rings),
|
EEquipSlotCategory.Rings),
|
||||||
};
|
};
|
||||||
|
|
||||||
List<SeString> flatUpgrades = upgrades.SelectMany(x => x).ToList();
|
return upgrades.SelectMany(x => x).ToList();
|
||||||
if (flatUpgrades.Count == 0)
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private bool HandleGearset(GearsetData gearset,
|
||||||
|
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level)
|
||||||
|
{
|
||||||
|
List<RecommendedItemChange> upgrades = GetRecommendedUpgrades(gearset, inventoryItems, level);
|
||||||
|
if (upgrades.Count == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_chatGui.Print(
|
_chatGui.Print(
|
||||||
@ -220,8 +237,8 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
.AddText(level != null ? $" at {level}" : "")
|
.AddText(level != null ? $" at {level}" : "")
|
||||||
.Build());
|
.Build());
|
||||||
|
|
||||||
foreach (var upgrade in flatUpgrades)
|
foreach (var upgrade in upgrades)
|
||||||
_chatGui.Print(new SeString(new TextPayload(" - ")).Append(upgrade));
|
_chatGui.Print(new SeString(new TextPayload(" - ")).Append(upgrade.Text));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -233,7 +250,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
private unsafe string GetGearsetName(RaptureGearsetModule.GearsetEntry* gearset)
|
private unsafe string GetGearsetName(RaptureGearsetModule.GearsetEntry* gearset)
|
||||||
=> gearset->NameString.Split((char)0)[0];
|
=> gearset->NameString.Split((char)0)[0];
|
||||||
|
|
||||||
private List<SeString> HandleGearsetItem(string label, GearsetData gearset,
|
private List<RecommendedItemChange> HandleGearsetItem(string label, GearsetData gearset,
|
||||||
EquipmentItem?[] gearsetItems,
|
EquipmentItem?[] gearsetItems,
|
||||||
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems,
|
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems,
|
||||||
EEquipSlotCategory equipSlotCategory, byte? level)
|
EEquipSlotCategory equipSlotCategory, byte? level)
|
||||||
@ -249,8 +266,8 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
|
|
||||||
if (equipSlotCategory == EEquipSlotCategory.None)
|
if (equipSlotCategory == EEquipSlotCategory.None)
|
||||||
{
|
{
|
||||||
_pluginLog.Warning($"Unable to find item to determine equip slot category");
|
_pluginLog.Warning("Unable to find item to determine equip slot category");
|
||||||
return new List<SeString>();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseItem?[] currentItems = gearsetItems
|
BaseItem?[] currentItems = gearsetItems
|
||||||
@ -267,7 +284,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
|
|
||||||
var availableList = _gameDataHolder.GetItemList(classJob, equipSlotCategory);
|
var availableList = _gameDataHolder.GetItemList(classJob, equipSlotCategory);
|
||||||
if (availableList == null)
|
if (availableList == null)
|
||||||
return new List<SeString>();
|
return [];
|
||||||
|
|
||||||
if (level == null)
|
if (level == null)
|
||||||
level = GetLevel(classJob);
|
level = GetLevel(classJob);
|
||||||
@ -292,8 +309,10 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
return bestItems
|
return bestItems
|
||||||
.Select(x => new SeString(new TextPayload($"{label}: "))
|
.Select(x => ToItemRecommendation(x,
|
||||||
.Append(SeString.CreateItemLink(x.ItemId, x.Hq))).ToList();
|
new SeString(new TextPayload($"{label}: "))
|
||||||
|
.Append(SeString.CreateItemLink(x.ItemId, x.Hq))))
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -301,18 +320,17 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<RecommendedItemChange> HandleOffHand(GearsetData gearset,
|
||||||
private unsafe List<SeString> HandleOffHand(GearsetData gearset,
|
|
||||||
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level)
|
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level)
|
||||||
{
|
{
|
||||||
var mainHand = gearset.MainHand;
|
var mainHand = gearset.MainHand;
|
||||||
if (mainHand == null)
|
if (mainHand == null)
|
||||||
return new List<SeString>();
|
return [];
|
||||||
|
|
||||||
// if it's a twohanded weapon, ignore it
|
// if it's a twohanded weapon, ignore it
|
||||||
EEquipSlotCategory equipSlotCategory = mainHand.EquipSlotCategory;
|
EEquipSlotCategory equipSlotCategory = mainHand.EquipSlotCategory;
|
||||||
if (equipSlotCategory != EEquipSlotCategory.OneHandedMainHand)
|
if (equipSlotCategory != EEquipSlotCategory.OneHandedMainHand)
|
||||||
return new List<SeString>();
|
return [];
|
||||||
|
|
||||||
return HandleGearsetItem("Off Hand", gearset, [gearset.OffHand],
|
return HandleGearsetItem("Off Hand", gearset, [gearset.OffHand],
|
||||||
inventoryItems,
|
inventoryItems,
|
||||||
@ -322,6 +340,31 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
private unsafe void ChangeGearset(uint commandId, SeString seString)
|
private unsafe void ChangeGearset(uint commandId, SeString seString)
|
||||||
=> RaptureGearsetModule.Instance()->EquipGearset((byte)commandId);
|
=> RaptureGearsetModule.Instance()->EquipGearset((byte)commandId);
|
||||||
|
|
||||||
|
|
||||||
|
private unsafe RecommendedItemChange ToItemRecommendation(BaseItem baseItem, SeString text)
|
||||||
|
{
|
||||||
|
InventoryManager* inventoryManager = InventoryManager.Instance();
|
||||||
|
foreach (var inventoryType in _gameDataHolder.DefaultInventoryTypes)
|
||||||
|
{
|
||||||
|
var container = inventoryManager->GetInventoryContainer(inventoryType);
|
||||||
|
for (int i = 0; i < container->Size; ++i)
|
||||||
|
{
|
||||||
|
var item = container->GetInventorySlot(i);
|
||||||
|
if (item != null && item->ItemId == baseItem.ItemId &&
|
||||||
|
item->Flags.HasFlag(InventoryItem.ItemFlags.HighQuality) == baseItem.Hq)
|
||||||
|
{
|
||||||
|
MateriaStats expectedMateriaStats = baseItem.MateriaStats ?? new([]);
|
||||||
|
MateriaStats actualMateriaStats = FetchMateriaStats(item);
|
||||||
|
|
||||||
|
if (expectedMateriaStats == actualMateriaStats)
|
||||||
|
return new RecommendedItemChange(item->ItemId, inventoryType, i, text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RecommendedItemChange(baseItem.ItemId, null, null, text);
|
||||||
|
}
|
||||||
|
|
||||||
internal unsafe Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> GetAllInventoryItems()
|
internal unsafe Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> GetAllInventoryItems()
|
||||||
{
|
{
|
||||||
Dictionary<(uint, bool), List<MateriaStats>> inventoryItems = new();
|
Dictionary<(uint, bool), List<MateriaStats>> inventoryItems = new();
|
||||||
@ -341,6 +384,16 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
inventoryItems[key] = list;
|
inventoryItems[key] = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list.Add(FetchMateriaStats(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return inventoryItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
private unsafe MateriaStats FetchMateriaStats(InventoryItem* item)
|
||||||
|
{
|
||||||
// FIXME item->GetMateriaCount is broken on API 10, so this seems to be somewhat slow
|
// FIXME item->GetMateriaCount is broken on API 10, so this seems to be somewhat slow
|
||||||
List<(MateriaStat, byte)> materias = new();
|
List<(MateriaStat, byte)> materias = new();
|
||||||
for (int slot = 0; slot < 5; ++slot)
|
for (int slot = 0; slot < 5; ++slot)
|
||||||
@ -353,12 +406,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
materias.Add((value, item->MateriaGrades[slot]));
|
materias.Add((value, item->MateriaGrades[slot]));
|
||||||
}
|
}
|
||||||
|
|
||||||
list.Add(new MateriaStats(materias));
|
return new MateriaStats(materias);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return inventoryItems;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal unsafe byte GetLevel(EClassJob classJob)
|
internal unsafe byte GetLevel(EClassJob classJob)
|
||||||
@ -379,5 +427,6 @@ public sealed class GearsetterPlugin : IDalamudPlugin
|
|||||||
_pluginInterface.RemoveChatLinkHandler();
|
_pluginInterface.RemoveChatLinkHandler();
|
||||||
_commandManager.RemoveHandler("/gbrowser");
|
_commandManager.RemoveHandler("/gbrowser");
|
||||||
_commandManager.RemoveHandler("/gup");
|
_commandManager.RemoveHandler("/gup");
|
||||||
|
_gearsetterIpc.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ internal sealed class ItemList
|
|||||||
Items = Items
|
Items = Items
|
||||||
.OrderDescending(new ItemComparer(SubstatPriorities))
|
.OrderDescending(new ItemComparer(SubstatPriorities))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateStats(Dictionary<EClassJob, EBaseParam> primaryStats, Configuration configuration)
|
public void UpdateStats(Dictionary<EClassJob, EBaseParam> primaryStats, Configuration configuration)
|
||||||
|
@ -5,7 +5,7 @@ using Gearsetter.GameData;
|
|||||||
|
|
||||||
namespace Gearsetter.Model;
|
namespace Gearsetter.Model;
|
||||||
|
|
||||||
internal sealed class MateriaStats
|
internal sealed class MateriaStats : IEquatable<MateriaStats>
|
||||||
{
|
{
|
||||||
private readonly List<(EBaseParam, short)> _list;
|
private readonly List<(EBaseParam, short)> _list;
|
||||||
|
|
||||||
@ -32,18 +32,33 @@ internal sealed class MateriaStats
|
|||||||
|
|
||||||
public override bool Equals(object? obj)
|
public override bool Equals(object? obj)
|
||||||
{
|
{
|
||||||
if (obj is not MateriaStats other)
|
return ReferenceEquals(this, obj) || obj is MateriaStats other && Equals(other);
|
||||||
return false;
|
|
||||||
|
|
||||||
return _list == other._list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
int hash = 19;
|
return _list.GetHashCode();
|
||||||
hash = hash * 31 + Count;
|
}
|
||||||
foreach (var item in _list)
|
|
||||||
hash = hash * 31 + item.GetHashCode();
|
public bool Equals(MateriaStats? other)
|
||||||
return hash;
|
{
|
||||||
|
if (ReferenceEquals(null, other)) return false;
|
||||||
|
if (ReferenceEquals(this, other)) return true;
|
||||||
|
return _list.SequenceEqual(other._list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(MateriaStats? left, MateriaStats? right)
|
||||||
|
{
|
||||||
|
return Equals(left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(MateriaStats? left, MateriaStats? right)
|
||||||
|
{
|
||||||
|
return !Equals(left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"Materias[{string.Join(", ", _list.Select(x => $"{x.Item1}:{x.Item2}"))}]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
Gearsetter/Model/RecommendedItemChange.cs
Normal file
10
Gearsetter/Model/RecommendedItemChange.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||||
|
|
||||||
|
namespace Gearsetter.Model;
|
||||||
|
|
||||||
|
internal sealed record RecommendedItemChange(
|
||||||
|
uint ItemId,
|
||||||
|
InventoryType? SourceInventory,
|
||||||
|
int? SourceInventorySlot,
|
||||||
|
SeString Text);
|
@ -137,7 +137,8 @@ internal sealed class EquipmentBrowserWindow : LWindow
|
|||||||
if (includeDamage)
|
if (includeDamage)
|
||||||
ImGui.TableSetupColumn("Damage", ImGuiTableColumnFlags.WidthFixed, 50);
|
ImGui.TableSetupColumn("Damage", ImGuiTableColumnFlags.WidthFixed, 50);
|
||||||
foreach (var substat in itemList.SubstatPriorities)
|
foreach (var substat in itemList.SubstatPriorities)
|
||||||
ImGui.TableSetupColumn(_dataHolder.StatNames.GetValueOrDefault(substat, substat.ToString()), ImGuiTableColumnFlags.WidthFixed, 50);
|
ImGui.TableSetupColumn(_dataHolder.StatNames.GetValueOrDefault(substat, substat.ToString()),
|
||||||
|
ImGuiTableColumnFlags.WidthFixed, 50);
|
||||||
|
|
||||||
ImGui.TableHeadersRow();
|
ImGui.TableHeadersRow();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user