Compare commits

...

21 Commits
v0.2 ... master

Author SHA1 Message Date
Liza 49e16ab278
Include gearset slot to upgrade (relevant for rings) with IPC recommendations 2024-08-28 21:01:00 +02:00
Liza 18c62ba0b7
Add IPC method 'Gearsetter.GetRecommendationsForGearset' 2024-08-17 18:48:48 +02:00
Liza e75e4b1248
Fix incosistent sorting for preorder earrings 2024-08-17 16:17:12 +02:00
Liza 58040f4b16
Minor error handling changes 2024-08-17 15:44:22 +02:00
Liza 3a8f9b8f66
Move EClassJob to LLib 2024-08-05 06:48:36 +02:00
Liza 1845ebf701
Calculate optimal gearset choice on a separate thread 2024-07-08 23:11:37 +02:00
Liza ae706b0461
Don't show Azeyma's earrings for max level blue mage 2024-07-08 23:11:02 +02:00
Liza 52a8ea6066
API 10 (beta) 2024-07-02 22:31:08 +02:00
Liza 517dcd5ed5
Add game data for Viper/Pictomancer 2024-06-26 22:19:46 +02:00
Liza bdffc18c39
Add hover background to tables 2024-06-26 10:53:15 +02:00
Liza 92cf0f0ff3
Consider items with materia as separate items to non-melded items 2024-06-23 22:35:26 +02:00
Liza 6c172a84f4
Adjusted sorting order for preferred and weathered items 2024-06-19 15:20:55 +02:00
Liza c60c929502
Minor style adjustments 2024-06-18 01:06:37 +02:00
Liza 85349573d9
Actually use new config option 2024-06-17 22:10:26 +02:00
Liza 74a798816c
Fix problems with ACN weapons as scholar 2024-06-17 22:08:27 +02:00
Liza 894c0d2f69
Don't show base classes in /gbrowser (too niche) 2024-06-17 22:03:40 +02:00
Liza 6dd5148599
Add config to enable/disable recommendations when entering GC area 2024-06-17 21:54:44 +02:00
Liza 21e3f7c0a9
Fix wrong items being shown for crafters; remove some additional glam items from suggestions 2024-06-17 21:42:27 +02:00
Liza 7febb06f3e
Add /gup [level] that shows all gearsets for the current class as if you were that level 2024-06-17 21:41:58 +02:00
Liza 63f65e9589
Rework logic to explicitly sort items, add /gbrowser
Since we no longer rely on an arbitrary 'score' (which wasn't ideally
calculated), we now have a stable item order which also improves the
handling of some edge-cases.
2024-06-07 23:29:07 +02:00
Liza e64e280851
Oops forgot about committing code for DT earrings 2024-06-07 17:21:45 +02:00
36 changed files with 2937 additions and 444 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "LLib"]
path = LLib
url = https://git.carvel.li/liza/LLib

3
Gearsetter.IpcTest/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/dist
/obj
/bin

View 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>

View File

@ -0,0 +1,6 @@
{
"Name": "Gearsetter (IPC Test)",
"Author": "Liza Carvelli",
"Punchline": "dev only plugin",
"Description": "dev only plugin"
}

View 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, RaptureGearsetModule.GearsetItemIndex TargetSlot)>>(
"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}) as {recommendation.TargetSlot}");
}
}
public void Dispose()
{
_commandManager.RemoveHandler("/recommendedgear");
}
}

View 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, )"
}
}
}
}
}

3
Gearsetter.Test/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/dist
/obj
/bin

View File

@ -0,0 +1,26 @@
<Project Sdk="Dalamud.NET.Sdk/9.0.2">
<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<Import Project="..\LLib\LLib.targets"/>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
</ItemGroup>
<!-- Need to be explicitly added for test projects, as it otherwise won't find the DLLs -->
<ItemGroup>
<Reference Include="Dalamud"/>
<Reference Include="Lumina"/>
<Reference Include="Lumina.Excel"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Gearsetter\Gearsetter.csproj"/>
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
{
"Name": "Gearsetter.Test",
"Author": "Liza Carvelli",
"Punchline": "",
"Description": ""
}

View File

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Gearsetter.GameData;
using Gearsetter.Model;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets;
using Xunit;
namespace Gearsetter.Test;
public sealed class ItemSortingTest
{
Lumina.GameData _lumina = new("C:/Program Files (x86)/steam/steamapps/common/FINAL FANTASY XIV Online/game/sqpack");
[Fact]
public void Test1()
{
var items = _lumina.GetExcelSheet<Item>()!;
List<uint> initialItemIds =
[
11851,
11853,
14447,
15131,
16039,
16240,
17436,
25928,
32558,
];
var itemList = new ItemList
{
ClassJob = EClassJob.Marauder,
EquipSlotCategory = EEquipSlotCategory.Ears,
ItemUiCategory = 41,
Items = initialItemIds.Select(rowId => new EquipmentItem(items.GetRow(rowId)!, false))
.Cast<BaseItem>()
.ToList(),
};
var primaryStats = _lumina.GetExcelSheet<ClassJob>()!
.Where(x => x.RowId > 0 && Enum.IsDefined(typeof(EClassJob), x.RowId))
.Where(x => x.PrimaryStat > 0)
.ToDictionary(x => (EClassJob)x.RowId, x => (EBaseParam)x.PrimaryStat);
itemList.UpdateStats(primaryStats, new Configuration());
itemList.Sort();
List<uint> expectedItems =
[
32558,
25928,
11851,
17436,
16240,
14447,
11853,
16039,
15131, // weathered earrings benefit from having primary stats
];
Assert.Equal(expectedItems, itemList.Items.Select(x => x.ItemId).ToList());
}
}

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,12 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gearsetter", "Gearsetter\Gearsetter.csproj", "{3E87693D-1FEE-486D-80E9-C6D95E68160F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gearsetter.Test", "Gearsetter.Test\Gearsetter.Test.csproj", "{19044F87-4C6D-4926-B5C8-5BB7760DC44C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LLib", "LLib\LLib.csproj", "{66144F9D-AC38-4F16-B269-A610F8EB7A3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gearsetter.IpcTest", "Gearsetter.IpcTest\Gearsetter.IpcTest.csproj", "{D5BFA879-0A33-4640-B75E-D92D8F23D6F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -12,5 +18,17 @@ Global
{3E87693D-1FEE-486D-80E9-C6D95E68160F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E87693D-1FEE-486D-80E9-C6D95E68160F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E87693D-1FEE-486D-80E9-C6D95E68160F}.Release|Any CPU.Build.0 = Release|Any CPU
{19044F87-4C6D-4926-B5C8-5BB7760DC44C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19044F87-4C6D-4926-B5C8-5BB7760DC44C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19044F87-4C6D-4926-B5C8-5BB7760DC44C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19044F87-4C6D-4926-B5C8-5BB7760DC44C}.Release|Any CPU.Build.0 = Release|Any CPU
{66144F9D-AC38-4F16-B269-A610F8EB7A3F}.Debug|Any CPU.ActiveCfg = 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.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
EndGlobal

View File

@ -990,7 +990,7 @@ csharp_space_around_binary_operators = before_and_after
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion

View File

@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Gearsetter.Test")]

View File

@ -1,147 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Lumina.Excel.GeneratedSheets;
namespace Gearsetter;
internal sealed class CachedItem : IEquatable<CachedItem>
{
public required Item Item { get; init; }
public required uint ItemId { get; init; }
public required bool Hq { get; init; }
public required string Name { get; init; }
public required byte Level { get; init; }
public required uint ItemLevel { get; init; }
public required byte Rarity { get; init; }
public required uint EquipSlotCategory { get; init; }
public required IReadOnlyList<ClassJob> ClassJobs { get; set; }
public int CalculateScore(ClassJob classJob, short level)
{
var stats = new Stats(Item, Hq);
int score = 0;
if (classJob is >= ClassJob.Miner and <= ClassJob.Fisher)
{
score += stats.Get(BaseParam.Gathering) + stats.Get(BaseParam.Perception) + stats.Get(BaseParam.GP);
}
else if (classJob is >= ClassJob.Carpenter and <= ClassJob.Culinarian)
{
score += stats.Get(BaseParam.Craftsmanship) + stats.Get(BaseParam.Control) + stats.Get(BaseParam.CP);
}
else
{
if (ItemId == 33648 && level < 80)
return int.MaxValue - 1;
else if (ItemId == 24589 && level < 70)
return int.MaxValue - 2;
else if (ItemId == 16039 && level < 50)
return int.MaxValue - 3;
if (classJob is ClassJob.Conjurer or ClassJob.WhiteMage or ClassJob.Scholar or ClassJob.Astrologian
or ClassJob.Sage or ClassJob.Thaumaturge or ClassJob.BlackMage or ClassJob.Arcanist or ClassJob.Summoner
or ClassJob.RedMage or ClassJob.BlueMage)
{
score += 1_000_000 * (Item.DamageMag + stats.Get(BaseParam.DamageMag));
}
else
score += 1_000_000 * (Item.DamagePhys + stats.Get(BaseParam.DamagePhys));
score += Item.DefensePhys + stats.Get(BaseParam.DefensePhys);
score += Item.DefenseMag + stats.Get(BaseParam.DefenseMag);
score += 100 * (stats.Get(BaseParam.Strength) + stats.Get(BaseParam.Dexterity) +
stats.Get(BaseParam.Intelligence) + stats.Get(BaseParam.Mind));
score += Rarity;
}
return score;
}
public bool Equals(CachedItem? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return ItemId == other.ItemId && Hq == other.Hq;
}
public override bool Equals(object? obj)
{
return ReferenceEquals(this, obj) || obj is CachedItem other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine(ItemId, Hq);
}
public static bool operator ==(CachedItem? left, CachedItem? right)
{
return Equals(left, right);
}
public static bool operator !=(CachedItem? left, CachedItem? right)
{
return !Equals(left, right);
}
public enum BaseParam : byte
{
Strength = 1,
Dexterity = 2,
Vitality = 3,
Intelligence = 4,
Mind = 5,
Piety = 6,
GP = 10,
CP = 11,
DamagePhys = 12,
DamageMag = 13,
DefensePhys = 21,
DefenseMag = 24,
Tenacity = 19,
Crit = 27,
DirectHit = 22,
Determination = 44,
SpellSpeed = 46,
Craftsmanship = 70,
Control = 71,
Gathering = 72,
Perception = 73,
}
private sealed class Stats
{
private readonly Dictionary<BaseParam, short> _values;
public Stats(Item item, bool hq)
{
_values = item.UnkData59.Where(x => x.BaseParam > 0)
.ToDictionary(x => (BaseParam)x.BaseParam, x => x.BaseParamValue);
if (hq)
{
foreach (var hqstat in item.UnkData73.Select(x =>
((BaseParam)x.BaseParamSpecial, x.BaseParamValueSpecial)))
{
if (_values.TryGetValue(hqstat.Item1, out var stat))
_values[hqstat.Item1] = (short)(stat + hqstat.BaseParamValueSpecial);
else
_values[hqstat.Item1] = hqstat.BaseParamValueSpecial;
}
}
}
public short Get(BaseParam param)
{
_values.TryGetValue(param, out short v);
return v;
}
}
}

View File

@ -1,46 +0,0 @@
namespace Gearsetter;
internal enum ClassJob
{
Adventurer = 0,
Gladiator = 1,
Pugilist = 2,
Marauder = 3,
Lancer = 4,
Archer = 5,
Conjurer = 6,
Thaumaturge = 7,
Carpenter = 8,
Blacksmith = 9,
Armorer = 10,
Goldsmith = 11,
Leatherworker = 12,
Weaver = 13,
Alchemist = 14,
Culinarian = 15,
Miner = 16,
Botanist = 17,
Fisher = 18,
Paladin = 19,
Monk = 20,
Warrior = 21,
Dragoon = 22,
Bard = 23,
WhiteMage = 24,
BlackMage = 25,
Arcanist = 26,
Summoner = 27,
Scholar = 28,
Rogue = 29,
Ninja = 30,
Machinist = 31,
DarkKnight = 32,
Astrologian = 33,
Samurai = 34,
RedMage = 35,
BlueMage = 36,
Gunbreaker = 37,
Dancer = 38,
Reaper = 39,
Sage = 40,
}

View File

@ -0,0 +1,38 @@
using System.Collections.Generic;
using Dalamud.Configuration;
using Gearsetter.GameData;
namespace Gearsetter;
internal sealed class Configuration : IPluginConfiguration
{
public int Version { get; set; } = 1;
public bool ShowRecommendationsWhenEnteringGcArea { get; set; } = true;
public List<EBaseParam> StatPriorityTanks { get; set; } = new();
public List<EBaseParam> StatPriorityHealer { get; set; } = new();
public List<EBaseParam> StatPriorityMelee { get; set; } = new();
public List<EBaseParam> StatPriorityPhysicalRanged { get; set; } = new();
public List<EBaseParam> StatPriorityCaster { get; set; } = new();
public List<EBaseParam> StatPriorityCrafter { get; set; } = new();
public List<EBaseParam> StatPriorityGatherer { get; set; } = new();
public static Configuration Create()
{
// this isn't ideal in all cases, but it's a starting point in case we ever want to make this class-specific
return new Configuration
{
StatPriorityTanks = [EBaseParam.Crit, EBaseParam.DirectHit, EBaseParam.Determination, EBaseParam.Tenacity],
StatPriorityHealer =
[EBaseParam.Crit, EBaseParam.DirectHit, EBaseParam.Determination, EBaseParam.SpellSpeed],
StatPriorityMelee =
[EBaseParam.Crit, EBaseParam.Determination, EBaseParam.DirectHit, EBaseParam.SkillSpeed],
StatPriorityPhysicalRanged =
[EBaseParam.Crit, EBaseParam.Determination, EBaseParam.DirectHit, EBaseParam.SkillSpeed],
StatPriorityCaster =
[EBaseParam.Crit, EBaseParam.Determination, EBaseParam.DirectHit, EBaseParam.SpellSpeed],
StatPriorityCrafter = [EBaseParam.CP, EBaseParam.Craftsmanship, EBaseParam.Control],
StatPriorityGatherer = [EBaseParam.GP, EBaseParam.Gathering, EBaseParam.Perception]
};
}
}

64
Gearsetter/External/GearsetterIpc.cs vendored Normal file
View File

@ -0,0 +1,64 @@
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,
RaptureGearsetModule.GearsetItemIndex TargetSlot)>>
_getRecommendationsForGearset;
public GearsetterIpc(GearsetterPlugin plugin, IDalamudPluginInterface pluginInterface, IPluginLog pluginLog)
{
_plugin = plugin;
_pluginLog = pluginLog;
_getRecommendationsForGearset =
pluginInterface
.GetIpcProvider<byte,
List<(uint, InventoryType?, int?, RaptureGearsetModule.GearsetItemIndex TargetSlot)>>(
IpcGetRecommendationsForGearset);
_getRecommendationsForGearset.RegisterFunc(GetRecommendationsForGearset);
}
private unsafe List<(uint ItemId, InventoryType? SourceInventory, int? SourceInventorySlot,
RaptureGearsetModule.GearsetItemIndex TargetSlot)>
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, x.TargetSlot))
.ToList();
}
public void Dispose()
{
_getRecommendationsForGearset.UnregisterFunc();
}
}

View File

@ -0,0 +1,32 @@
namespace Gearsetter.GameData;
internal enum EBaseParam : byte
{
Strength = 1,
Dexterity = 2,
Vitality = 3,
Intelligence = 4,
Mind = 5,
Piety = 6,
GP = 10,
CP = 11,
DamagePhys = 12,
DamageMag = 13,
DefensePhys = 21,
DefenseMag = 24,
Tenacity = 19,
Crit = 27,
DirectHit = 22,
Determination = 44,
SpellSpeed = 46,
SkillSpeed = 45,
Craftsmanship = 70,
Control = 71,
Gathering = 72,
Perception = 73,
}

View File

@ -0,0 +1,25 @@
using System.Diagnostics.CodeAnalysis;
namespace Gearsetter.GameData;
[SuppressMessage("Performance", "CA1028", Justification = "uint in Lumina")]
[SuppressMessage("Design", "CA1027", Justification = "Not Flags")]
public enum EEquipSlotCategory : uint
{
None = 0,
OneHandedMainHand = 1,
Shield = 2,
Head = 3,
Body = 4,
Hands = 5,
Legs = 7,
Feet = 8,
Ears = 9,
Neck = 10,
Wrists = 11,
Rings = 12,
TwoHandedMainHand = 13,
// 14 isn't used
// anything beyond is very weird gear, taking up multiple inventory slots; irrelevant in anything beyond ARR
}

View File

@ -0,0 +1,214 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Dalamud;
using Dalamud.Game;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game;
using Gearsetter.Model;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.GameData;
internal sealed class GameDataHolder
{
private readonly Configuration _configuration;
private readonly Dictionary<uint, List<EClassJob>> _classJobCategories;
private readonly IReadOnlyList<ItemList> _allItemLists;
public GameDataHolder(IDataManager dataManager, Configuration configuration)
{
_configuration = configuration;
_classJobCategories = dataManager.GetExcelSheet<ClassJobCategory>()!
.ToDictionary(x => x.RowId, x =>
new Dictionary<EClassJob, bool>
{
{ EClassJob.Adventurer, x.ADV },
{ EClassJob.Gladiator, x.GLA },
{ EClassJob.Pugilist, x.PGL },
{ EClassJob.Marauder, x.MRD },
{ EClassJob.Lancer, x.LNC },
{ EClassJob.Archer, x.ARC },
{ EClassJob.Conjurer, x.CNJ },
{ EClassJob.Thaumaturge, x.THM },
{ EClassJob.Carpenter, x.CRP },
{ EClassJob.Blacksmith, x.BSM },
{ EClassJob.Armorer, x.ARM },
{ EClassJob.Goldsmith, x.GSM },
{ EClassJob.Leatherworker, x.LTW },
{ EClassJob.Weaver, x.WVR },
{ EClassJob.Alchemist, x.ALC },
{ EClassJob.Culinarian, x.CUL },
{ EClassJob.Miner, x.MIN },
{ EClassJob.Botanist, x.BTN },
{ EClassJob.Fisher, x.FSH },
{ EClassJob.Paladin, x.PLD },
{ EClassJob.Monk, x.MNK },
{ EClassJob.Warrior, x.WAR },
{ EClassJob.Dragoon, x.DRG },
{ EClassJob.Bard, x.BRD },
{ EClassJob.WhiteMage, x.WHM },
{ EClassJob.BlackMage, x.BLM },
{ EClassJob.Arcanist, x.ACN },
{ EClassJob.Summoner, x.SMN },
{ EClassJob.Scholar, x.SCH },
{ EClassJob.Rogue, x.ROG },
{ EClassJob.Ninja, x.NIN },
{ EClassJob.Machinist, x.MCH },
{ EClassJob.DarkKnight, x.DRK },
{ EClassJob.Astrologian, x.AST },
{ EClassJob.Samurai, x.SAM },
{ EClassJob.RedMage, x.RDM },
{ EClassJob.BlueMage, x.BLU },
{ EClassJob.Gunbreaker, x.GNB },
{ EClassJob.Dancer, x.DNC },
{ EClassJob.Reaper, x.RPR },
{ EClassJob.Sage, x.SGE },
{ EClassJob.Viper, x.VPR },
{ EClassJob.Pictomancer, x.PCT }
}
.Where(y => y.Value)
.Select(y => y.Key)
.ToList());
ClassJobNames = dataManager.GetExcelSheet<ClassJob>()!
.Where(x => x.RowId > 0 && Enum.IsDefined(typeof(EClassJob), x.RowId))
.OrderBy(x => x.UIPriority)
.Select(x => ((EClassJob)x.RowId,
dataManager.Language == ClientLanguage.English ? x.NameEnglish.ToString() : x.Name.ToString()))
.ToList();
PrimaryStats = dataManager.GetExcelSheet<ClassJob>()!
.Where(x => x.RowId > 0 && Enum.IsDefined(typeof(EClassJob), x.RowId))
.Where(x => x.PrimaryStat > 0)
.ToDictionary(x => (EClassJob)x.RowId, x => (EBaseParam)x.PrimaryStat);
ItemUiCategoryNames = dataManager.GetExcelSheet<ItemUICategory>()!
.Where(x => x.RowId > 0)
.OrderBy(x => x.OrderMajor)
.ThenBy(x => x.OrderMinor)
.Select(x => (x.RowId, x.Name.ToString()))
.ToList();
Materias = dataManager.GetExcelSheet<Materia>()!
.Where(x => x.RowId > 0 && Enum.IsDefined(typeof(EBaseParam), (byte)x.BaseParam.Row))
.ToDictionary(x => x.RowId, x => new MateriaStat((EBaseParam)x.BaseParam.Row, x.Value));
_allItemLists =
dataManager.GetExcelSheet<Item>()!
.Where(x => x.RowId > 1600) // exclude outdated names
.Where(x => x.EquipSlotCategory.Row > 0 &&
Enum.IsDefined(typeof(EEquipSlotCategory), x.EquipSlotCategory.Row))
.Where(x => x.LevelItem.Row > 1) // ignore ilvl 1 glamour items (also includes starter weapons)
.Where(x => x.ItemSeries.Row is <= 3 or >= 28)
.SelectMany(LoadItem)
.SelectMany(x => x.ClassJobs.Select(y => x.Item with { ClassJob = y }))
.Where(x => x.ClassJob != EClassJob.Scholar || x.ItemUiCategory != 10) // exclude ACN weapon as scholar
.Where(x =>
{
bool isGatheringItem = x.HasAnyStat(EBaseParam.Gathering, EBaseParam.Perception, EBaseParam.GP);
if (x.ClassJob.IsGatherer())
return isGatheringItem;
bool isCraftingItem = x.HasAnyStat(EBaseParam.Craftsmanship, EBaseParam.Control, EBaseParam.CP);
if (x.ClassJob.IsCrafter())
return isCraftingItem;
return !isGatheringItem && !isCraftingItem;
})
.GroupBy(item => new
{
item.ClassJob,
item.EquipSlotCategory,
item.ItemUiCategory,
})
.Select(x => new ItemList
{
ClassJob = x.Key.ClassJob,
EquipSlotCategory = x.Key.EquipSlotCategory,
ItemUiCategory = x.Key.ItemUiCategory,
Items = x.Cast<BaseItem>().ToList(),
})
.ToList()
.AsReadOnly();
UpdateAndSortLists();
}
public IReadOnlyList<(EClassJob ClassJob, string Name)> ClassJobNames { get; }
public IReadOnlyList<(uint ItemUiCategory, string Name)> ItemUiCategoryNames { get; }
public Dictionary<EClassJob, EBaseParam> PrimaryStats { get; }
public Dictionary<uint, MateriaStat> Materias { get; set; }
public Dictionary<EBaseParam, string> StatNames { get; } = new()
{
{ EBaseParam.Crit, "Crit" },
{ EBaseParam.DirectHit, "DH" },
{ EBaseParam.Determination, "Det" },
{ EBaseParam.SkillSpeed, "SkS" },
{ EBaseParam.SpellSpeed, "SpS" },
{ EBaseParam.Tenacity, "Tenacity" },
{ EBaseParam.CP, "CP" },
{ EBaseParam.Craftsmanship, "CMS" },
{ EBaseParam.Control, "Control" },
{ EBaseParam.GP, "GP" },
{ EBaseParam.Gathering, "Gathering" },
{ EBaseParam.Perception, "Perception" },
};
public InventoryType[] DefaultInventoryTypes { get; } =
[
InventoryType.Inventory1,
InventoryType.Inventory2,
InventoryType.Inventory3,
InventoryType.Inventory4,
InventoryType.ArmoryMainHand,
InventoryType.ArmoryOffHand,
InventoryType.ArmoryHead,
InventoryType.ArmoryBody,
InventoryType.ArmoryHands,
InventoryType.ArmoryLegs,
InventoryType.ArmoryFeets,
InventoryType.ArmoryEar,
InventoryType.ArmoryNeck,
InventoryType.ArmoryWrist,
InventoryType.ArmoryRings,
InventoryType.EquippedItems
];
public void UpdateAndSortLists()
{
foreach (ItemList itemList in _allItemLists)
{
itemList.UpdateStats(PrimaryStats, _configuration);
itemList.Sort();
}
}
public IEnumerable<ItemList> GetItemLists(EClassJob classJob)
=> _allItemLists.Where(x => x.ClassJob == classJob);
public ItemList? GetItemList(EClassJob classJob, EEquipSlotCategory equipSlotCategory)
=> _allItemLists.SingleOrDefault(x => x.ClassJob == classJob && x.EquipSlotCategory == equipSlotCategory);
public IList<(EEquipSlotCategory EquipSlotCategory, string UiCategoryName)> GetItemListsForJob(EClassJob classJob)
{
return ItemUiCategoryNames
.Select(x => new
{
x.Name,
List = _allItemLists.SingleOrDefault(
y => y.ClassJob == classJob && x.ItemUiCategory == y.ItemUiCategory)
})
.Where(x => x.List != null)
.Select(x => (x.List!.EquipSlotCategory, x.Name))
.ToList();
}
private IEnumerable<(EquipmentItem Item, List<EClassJob> ClassJobs)> LoadItem(Item item)
{
var classJobCategories = _classJobCategories[item.ClassJobCategory.Row];
yield return (new EquipmentItem(item, false), classJobCategories);
if (item.CanBeHq)
yield return (new EquipmentItem(item, true), classJobCategories);
}
}

View File

@ -1,60 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Dalamud.NET.Sdk/9.0.2">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Version>0.2</Version>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<Version>1.3</Version>
<OutputPath>dist</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>portable</DebugType>
<PathMap Condition="$(SolutionDir) != ''">$(SolutionDir)=X:\</PathMap>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup>
<DalamudLibPath>$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
</PropertyGroup>
<PropertyGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'">
<DalamudLibPath>$(DALAMUD_HOME)/</DalamudLibPath>
</PropertyGroup>
<Import Project="..\LLib\LLib.targets"/>
<Import Project="..\LLib\RenameZip.targets"/>
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.12"/>
<ProjectReference Include="..\LLib\LLib.csproj"/>
</ItemGroup>
<ItemGroup>
<Reference Include="Dalamud">
<HintPath>$(DalamudLibPath)Dalamud.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="ImGui.NET">
<HintPath>$(DalamudLibPath)ImGui.NET.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Lumina">
<HintPath>$(DalamudLibPath)Lumina.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Lumina.Excel">
<HintPath>$(DalamudLibPath)Lumina.Excel.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>$(DalamudLibPath)Newtonsoft.Json.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
<Target Name="RenameLatestZip" AfterTargets="PackagePlugin" Condition="'$(Configuration)' == 'Release'">
<Exec Command="rename $(OutDir)$(AssemblyName)\latest.zip $(AssemblyName)-$(Version).zip"/>
</Target>
</Project>

View File

@ -2,55 +2,46 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dalamud.Game.Command;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.Game.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
using Gearsetter.External;
using Gearsetter.GameData;
using Gearsetter.Model;
using Gearsetter.Windows;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets;
using GrandCompany = FFXIVClientStructs.FFXIV.Client.UI.Agent.GrandCompany;
using InventoryItem = FFXIVClientStructs.FFXIV.Client.Game.InventoryItem;
namespace Gearsetter;
[SuppressMessage("ReSharper", "UnusedType.Global")]
public sealed class GearsetterPlugin : IDalamudPlugin
{
private static readonly InventoryType[] DefaultInventoryTypes =
[
InventoryType.Inventory1,
InventoryType.Inventory2,
InventoryType.Inventory3,
InventoryType.Inventory4,
InventoryType.ArmoryMainHand,
InventoryType.ArmoryOffHand,
InventoryType.ArmoryHead,
InventoryType.ArmoryBody,
InventoryType.ArmoryHands,
InventoryType.ArmoryLegs,
InventoryType.ArmoryFeets,
InventoryType.ArmoryEar,
InventoryType.ArmoryNeck,
InventoryType.ArmoryWrist,
InventoryType.ArmoryRings,
InventoryType.EquippedItems
];
private readonly DalamudPluginInterface _pluginInterface;
private readonly WindowSystem _windowSystem = new(nameof(GearsetterPlugin));
private readonly IDalamudPluginInterface _pluginInterface;
private readonly ICommandManager _commandManager;
private readonly IChatGui _chatGui;
private readonly IDataManager _dataManager;
private readonly IPluginLog _pluginLog;
private readonly IClientState _clientState;
private readonly GearsetterIpc _gearsetterIpc;
private readonly Configuration _configuration;
private readonly GameDataHolder _gameDataHolder;
private readonly EquipmentBrowserWindow _equipmentBrowserWindow;
private readonly ConfigWindow _configWindow;
private readonly IReadOnlyDictionary<byte, DalamudLinkPayload> _linkPayloads;
private readonly Dictionary<uint, List<ClassJob>> _classJobCategories;
private readonly Dictionary<byte, byte> _classJobToArrayIndex;
private readonly Dictionary<uint, CachedItem> _cachedItems = new();
private readonly Dictionary<EClassJob, byte> _classJobToArrayIndex;
public GearsetterPlugin(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IChatGui chatGui,
public GearsetterPlugin(IDalamudPluginInterface pluginInterface, ICommandManager commandManager, IChatGui chatGui,
IDataManager dataManager, IPluginLog pluginLog, IClientState clientState)
{
ArgumentNullException.ThrowIfNull(dataManager);
@ -61,153 +52,199 @@ public sealed class GearsetterPlugin : IDalamudPlugin
_dataManager = dataManager;
_pluginLog = pluginLog;
_clientState = clientState;
_gearsetterIpc = new GearsetterIpc(this, _pluginInterface, _pluginLog);
_commandManager.AddHandler("/gup", new CommandInfo(ProcessCommand));
Configuration? configuration = (Configuration?)_pluginInterface.GetPluginConfig();
if (configuration == null)
{
configuration = Configuration.Create();
_pluginInterface.SavePluginConfig(configuration);
}
_configuration = configuration;
_gameDataHolder = new GameDataHolder(dataManager, _configuration);
_equipmentBrowserWindow = new EquipmentBrowserWindow(this, _gameDataHolder, _clientState, _chatGui);
_windowSystem.AddWindow(_equipmentBrowserWindow);
_configWindow = new ConfigWindow(_pluginInterface, _configuration);
_windowSystem.AddWindow(_configWindow);
_commandManager.AddHandler("/gup", new CommandInfo(ShowUpgrades)
{
HelpMessage = "Show possible gear upgrades for all gearsets"
});
_commandManager.AddHandler("/gbrowser", new CommandInfo(ToggleEquipmentBrowser)
{
HelpMessage = "Toggle the equipment browser window"
});
_linkPayloads = Enumerable.Range(0, 100)
.ToDictionary(x => (byte)x, x => _pluginInterface.AddChatLinkHandler((byte)x, ChangeGearset)).AsReadOnly();
_clientState.TerritoryChanged += TerritoryChanged;
_pluginInterface.UiBuilder.Draw += _windowSystem.Draw;
_pluginInterface.UiBuilder.OpenMainUi += _equipmentBrowserWindow.Toggle;
_pluginInterface.UiBuilder.OpenConfigUi += _configWindow.Toggle;
_classJobToArrayIndex = dataManager.GetExcelSheet<Lumina.Excel.GeneratedSheets.ClassJob>()!
.Where(x => x.RowId > 0)
.ToDictionary(x => (byte)x.RowId, x => (byte)x.ExpArrayIndex);
_classJobCategories = _dataManager.GetExcelSheet<ClassJobCategory>()!
.ToDictionary(x => x.RowId, x =>
new Dictionary<ClassJob, bool>
{
{ ClassJob.Adventurer, x.ADV },
{ ClassJob.Gladiator, x.GLA },
{ ClassJob.Pugilist, x.PGL },
{ ClassJob.Marauder, x.MRD },
{ ClassJob.Lancer, x.LNC },
{ ClassJob.Archer, x.ARC },
{ ClassJob.Conjurer, x.CNJ },
{ ClassJob.Thaumaturge, x.THM },
{ ClassJob.Carpenter, x.CRP },
{ ClassJob.Blacksmith, x.BSM },
{ ClassJob.Armorer, x.ARM },
{ ClassJob.Goldsmith, x.GSM },
{ ClassJob.Leatherworker, x.LTW },
{ ClassJob.Weaver, x.WVR },
{ ClassJob.Alchemist, x.ALC },
{ ClassJob.Culinarian, x.CUL },
{ ClassJob.Miner, x.MIN },
{ ClassJob.Botanist, x.BTN },
{ ClassJob.Fisher, x.FSH },
{ ClassJob.Paladin, x.PLD },
{ ClassJob.Monk, x.MNK },
{ ClassJob.Warrior, x.WAR },
{ ClassJob.Dragoon, x.DRG },
{ ClassJob.Bard, x.BRD },
{ ClassJob.WhiteMage, x.WHM },
{ ClassJob.BlackMage, x.BLM },
{ ClassJob.Arcanist, x.ACN },
{ ClassJob.Summoner, x.SMN },
{ ClassJob.Scholar, x.SCH },
{ ClassJob.Rogue, x.ROG },
{ ClassJob.Ninja, x.NIN },
{ ClassJob.Machinist, x.MCH },
{ ClassJob.DarkKnight, x.DRK },
{ ClassJob.Astrologian, x.AST },
{ ClassJob.Samurai, x.SAM },
{ ClassJob.RedMage, x.RDM },
{ ClassJob.BlueMage, x.BLU },
{ ClassJob.Gunbreaker, x.GNB },
{ ClassJob.Dancer, x.DNC },
{ ClassJob.Reaper, x.RPR },
{ ClassJob.Sage, x.SGE },
}
.Where(y => y.Value)
.Select(y => y.Key)
.ToList());
_classJobToArrayIndex = dataManager.GetExcelSheet<ClassJob>()!
.Where(x => x.RowId > 0 && Enum.IsDefined(typeof(EClassJob), x.RowId))
.ToDictionary(x => (EClassJob)x.RowId, x => (byte)x.ExpArrayIndex);
}
private void TerritoryChanged(ushort territory)
private unsafe void TerritoryChanged(ushort territory)
{
if (territory == 128)
ShowUpgrades();
}
if (!_configuration.ShowRecommendationsWhenEnteringGcArea)
return;
private void ProcessCommand(string command, string arguments) => ShowUpgrades();
private unsafe void ShowUpgrades()
{
var inventoryManager = InventoryManager.Instance();
List<CachedItem> inventoryItems = new();
foreach (var inventoryType in DefaultInventoryTypes)
try
{
var container = inventoryManager->GetInventoryContainer(inventoryType);
for (int i = 0; i < container->Size; ++i)
{
var item = container->GetInventorySlot(i);
if (item != null && item->ItemID != 0)
{
CachedItem? cachedItem = LookupItem(item->ItemID, item->Flags.HasFlag(InventoryItem.ItemFlags.HQ));
if (cachedItem != null)
inventoryItems.Add(cachedItem);
}
}
var playerState = PlayerState.Instance();
if (playerState == null)
return;
var grandCompany = (GrandCompany)playerState->GrandCompany;
if ((grandCompany == GrandCompany.Maelstrom && territory == 128) ||
(grandCompany == GrandCompany.TwinAdder && territory == 132) ||
(grandCompany == GrandCompany.ImmortalFlames && territory == 130))
ShowUpgrades();
}
catch (Exception e)
{
_pluginLog.Warning(e, "Could not show upgrades when entering Grand Company area.");
}
}
private void ToggleEquipmentBrowser(string command, string arguments)
=> _equipmentBrowserWindow.Toggle();
private void ShowUpgrades(string command, string arguments)
{
byte? level = null;
if (arguments.Length > 0 && byte.TryParse(arguments, out byte parsedLevel))
level = parsedLevel;
ShowUpgrades(level);
}
private unsafe void ShowUpgrades(byte? level = null)
{
DateTime start = DateTime.Now;
var inventoryItems = GetAllInventoryItems();
var gearsetModule = RaptureGearsetModule.Instance();
if (gearsetModule == null)
return;
bool anyUpgrade = false;
bool onlyCurrentJob = level != null;
if (onlyCurrentJob)
_chatGui.Print("Checking only gearsets for your current class/job...");
List<GearsetData> gearsets = new List<GearsetData>();
for (int i = 0; i < 100; ++i)
{
var gearset = gearsetModule->GetGearset(i);
if (gearset != null && gearset->Flags.HasFlag(RaptureGearsetModule.GearsetFlag.Exists))
{
anyUpgrade |= HandleGearset(gearset, inventoryItems);
if (onlyCurrentJob && gearset->ClassJob != _clientState.LocalPlayer!.ClassJob.Id)
continue;
var gearsetData = PrepareGearset(gearset);
if (gearsetData != null)
gearsets.Add(gearsetData);
}
}
if (!anyUpgrade)
_chatGui.Print("All your gearsets are OK.");
_pluginLog.Information($"Preparing gearsets took {DateTime.Now - start}");
Task.Run(() =>
{
start = DateTime.Now;
bool anyUpgrade = false;
foreach (GearsetData gearset in gearsets)
anyUpgrade |= HandleGearset(gearset, inventoryItems, level);
if (!anyUpgrade)
_chatGui.Print("All your gearsets are OK.");
_pluginLog.Information($"Evaluating gearsets took {DateTime.Now - start}");
});
}
private unsafe bool HandleGearset(RaptureGearsetModule.GearsetEntry* gearset, List<CachedItem> inventoryItems)
private unsafe GearsetData? PrepareGearset(RaptureGearsetModule.GearsetEntry* gearset)
{
string name = GetGearsetName(gearset);
if (name.Contains('_', StringComparison.Ordinal) ||
name.Contains("Eureka", StringComparison.OrdinalIgnoreCase) ||
name.Contains("Bozja", StringComparison.OrdinalIgnoreCase))
return false;
return null;
List<List<SeString>> upgrades = new()
return new GearsetData(_dataManager, gearset, name);
}
internal unsafe List<RecommendedItemChange> GetRecommendedUpgrades(RaptureGearsetModule.GearsetEntry* gearset,
byte? level = null)
{
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?, RaptureGearsetModule.GearsetItemIndex)[] gearsetItems,
EEquipSlotCategory category)
{
HandleGearsetItem("Main Hand", gearset, gearset->MainHand, inventoryItems),
HandleGearsetItem("Off Hand", gearset, gearset->OffHand, inventoryItems),
return HandleGearsetItem(label, gearset, gearsetItems, inventoryItems, category, level);
}
HandleGearsetItem("Head", gearset, gearset->Head, inventoryItems),
HandleGearsetItem("Body", gearset, gearset->Body, inventoryItems),
HandleGearsetItem("Hands", gearset, gearset->Hands, inventoryItems),
HandleGearsetItem("Legs", gearset, gearset->Legs, inventoryItems),
HandleGearsetItem("Feet", gearset, gearset->Feet, inventoryItems),
List<List<RecommendedItemChange>> upgrades = new()
{
Handle("Main Hand", [(gearset.MainHand, RaptureGearsetModule.GearsetItemIndex.MainHand)],
EEquipSlotCategory.None),
HandleOffHand(gearset, inventoryItems, level),
HandleGearsetItem("Ears", gearset, gearset->Ears, inventoryItems),
HandleGearsetItem("Neck", gearset, gearset->Neck, inventoryItems),
HandleGearsetItem("Wrists", gearset, gearset->Wrists, inventoryItems),
HandleGearsetItem("Rings", gearset, new[] { gearset->RingRight, gearset->RingLeft }, inventoryItems),
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("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("Rings",
[
(gearset.RingLeft, RaptureGearsetModule.GearsetItemIndex.RingLeft),
(gearset.RingRight, RaptureGearsetModule.GearsetItemIndex.RingRight)
],
EEquipSlotCategory.Rings),
};
List<SeString> flatUpgrades = upgrades.SelectMany(x => x).ToList();
if (flatUpgrades.Count == 0)
return upgrades.SelectMany(x => x).ToList();
}
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;
_chatGui.Print(
new SeStringBuilder()
.Append("Gearset ")
.AddUiForeground(1)
.Add(_linkPayloads[gearset->ID])
.Append($"#{gearset->ID + 1}: ")
.Append(name)
.Add(_linkPayloads[gearset.Id])
.Append($"#{gearset.Id + 1}: ")
.Append(gearset.Name)
.Add(RawPayload.LinkTerminator)
.AddUiForegroundOff()
.AddText(level != null ? $" at {level}" : "")
.Build());
foreach (var upgrade in flatUpgrades)
_chatGui.Print(new SeString(new TextPayload(" - ")).Append(upgrade));
foreach (var upgrade in upgrades)
_chatGui.Print(new SeString(new TextPayload(" - ")).Append(upgrade.Text));
return true;
}
@ -217,97 +254,198 @@ public sealed class GearsetterPlugin : IDalamudPlugin
/// the string ends after the name (and not render ANY text on the same line after the name).
/// </summary>
private unsafe string GetGearsetName(RaptureGearsetModule.GearsetEntry* gearset)
=> Encoding.UTF8.GetString(gearset->Name, 0x2F).Split((char)0)[0];
=> gearset->NameString.Split((char)0)[0];
private unsafe List<SeString> HandleGearsetItem(string label, RaptureGearsetModule.GearsetEntry* gearset,
RaptureGearsetModule.GearsetItem gearsetItem, List<CachedItem> inventoryItems)
=> HandleGearsetItem(label, gearset, new[] { gearsetItem }, inventoryItems);
private unsafe List<SeString> HandleGearsetItem(string label, RaptureGearsetModule.GearsetEntry* gearset,
RaptureGearsetModule.GearsetItem[] gearsetItem, List<CachedItem> inventoryItems)
private List<RecommendedItemChange> HandleGearsetItem(string label, GearsetData gearset,
(EquipmentItem? Item, RaptureGearsetModule.GearsetItemIndex Slot)[] gearsetItems,
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems,
EEquipSlotCategory equipSlotCategory, byte? level)
{
gearsetItem = gearsetItem.Where(x => x.ItemID != 0).ToArray();
if (gearsetItem.Length > 0)
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))
{
ClassJob classJob = (ClassJob)gearset->ClassJob;
CachedItem[] currentItems = gearsetItem.Select(x => LookupItem(x.ItemID)).Where(x => x != null)
.Select(x => x!).ToArray();
if (currentItems.Length == 0)
{
_pluginLog.Information($"Unable to find gearset items");
return new List<SeString>();
}
var level = PlayerState.Instance()->ClassJobLevelArray[
_classJobToArrayIndex[gearset->ClassJob]];
var bestItems = inventoryItems
.Where(x => x.EquipSlotCategory == currentItems[0].EquipSlotCategory)
.Where(x => x.Level <= level)
.Where(x => x.ClassJobs.Contains(classJob))
.Where(x => x.CalculateScore(classJob, level) > 0)
.OrderByDescending(x => x.CalculateScore(classJob, level))
.Take(gearsetItem.Length)
.ToList();
foreach (var currentItem in currentItems)
{
if (bestItems.Contains(currentItem))
bestItems.Remove(currentItem);
}
// don't make suggestions for equal scores
bestItems.RemoveAll(x =>
x.CalculateScore(classJob, level) ==
currentItems.Select(y => y.CalculateScore(classJob, level)).Max());
return bestItems
.Select(x => new SeString(new TextPayload($"{label}: "))
.Append(SeString.CreateItemLink(x.ItemId, x.Hq))).ToList();
var firstEquippedItem = gearsetItems.First(x => x.Item != null);
equipSlotCategory = firstEquippedItem.Item!.EquipSlotCategory;
}
return new List<SeString>();
}
if (equipSlotCategory == EEquipSlotCategory.None)
{
_pluginLog.Warning("Unable to find item to determine equip slot category");
return [];
}
private CachedItem? LookupItem(uint itemId)
{
if (_cachedItems.TryGetValue(itemId, out CachedItem? cachedItem))
return cachedItem;
(BaseItem? Item, RaptureGearsetModule.GearsetItemIndex Slot)[] currentItems = gearsetItems
.Select(x =>
{
if (x.Item == null)
return (null, x.Slot);
var baseItem = itemLists
.SelectMany(y => y.Items.Where(z => x.Item.ItemId == z.ItemId && x.Item.Hq == z.Hq))
.FirstOrDefault();
return (baseItem, x.Slot);
})
.ToArray();
var availableList = _gameDataHolder.GetItemList(classJob, equipSlotCategory);
if (availableList == null)
return [];
if (level == null)
level = GetLevel(classJob);
try
{
var item = _dataManager.GetExcelSheet<Item>()!.GetRow(itemId % 1_000_000)!;
cachedItem = new CachedItem
availableList.ApplyFromInventory(inventoryItems, true);
var bestItems = availableList.Items
.Where(x => x.Level <= level)
.Where(x => x is Model.InventoryItem)
.Take(gearsetItems.Length)
.ToList();
//_pluginLog.Debug(
// $"{equipSlotCategory}: {string.Join(" ", currentItems.Select(x => $"{x.Item}, {x.Slot}"))}");
foreach (var currentItem in currentItems)
{
Item = item,
ItemId = item.RowId,
Hq = itemId > 1_000_000,
Name = item.Name.ToString(),
Level = item.LevelEquip,
ItemLevel = item.LevelItem.Row,
Rarity = item.Rarity,
EquipSlotCategory = item.EquipSlotCategory.Row,
ClassJobs = _classJobCategories[item.ClassJobCategory.Row],
};
_cachedItems[itemId] = cachedItem;
return cachedItem;
var foundIndex = bestItems.FindIndex(x =>
currentItem.Item != null && currentItem.Item.ItemId == x.ItemId && currentItem.Item.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)));
})
.ToList();
}
catch (Exception)
finally
{
_pluginLog.Information($"Unable to lookup item {itemId}");
return null;
availableList.ClearFromInventory();
}
}
private CachedItem? LookupItem(uint itemId, bool hq)
=> LookupItem(itemId + (hq ? 1_000_000u : 0));
private List<RecommendedItemChange> HandleOffHand(GearsetData gearset,
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level)
{
var mainHand = gearset.MainHand;
if (mainHand == null)
return [];
// if it's a twohanded weapon, ignore it
EEquipSlotCategory equipSlotCategory = mainHand.EquipSlotCategory;
if (equipSlotCategory != EEquipSlotCategory.OneHandedMainHand)
return [];
return HandleGearsetItem("Off Hand", gearset,
[(gearset.OffHand, RaptureGearsetModule.GearsetItemIndex.OffHand)],
inventoryItems,
EEquipSlotCategory.Shield, level);
}
private unsafe void ChangeGearset(uint commandId, SeString seString)
=> RaptureGearsetModule.Instance()->EquipGearset((byte)commandId);
private unsafe RecommendedItemChange ToItemRecommendation(BaseItem baseItem,
RaptureGearsetModule.GearsetItemIndex targetSlot, 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, targetSlot, text);
}
}
}
return new RecommendedItemChange(baseItem.ItemId, null, null, targetSlot, text);
}
internal unsafe Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> GetAllInventoryItems()
{
Dictionary<(uint, bool), List<MateriaStats>> inventoryItems = new();
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 != 0)
{
var key = (item->ItemId, item->Flags.HasFlag(InventoryItem.ItemFlags.HighQuality));
if (!inventoryItems.TryGetValue(key, out var list))
{
list = new List<MateriaStats>();
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
List<(MateriaStat, byte)> materias = new();
for (int slot = 0; slot < 5; ++slot)
{
var materiaId = item->Materia[slot];
if (materiaId == 0)
break;
if (_gameDataHolder.Materias.TryGetValue(materiaId, out MateriaStat? value))
materias.Add((value, item->MateriaGrades[slot]));
}
return new MateriaStats(materias);
}
internal unsafe byte GetLevel(EClassJob classJob)
{
var playerState = PlayerState.Instance();
if (playerState == null)
return 0;
return (byte)playerState->ClassJobLevels[_classJobToArrayIndex[classJob]];
}
public void Dispose()
{
_pluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle;
_pluginInterface.UiBuilder.OpenMainUi -= _equipmentBrowserWindow.Toggle;
_pluginInterface.UiBuilder.Draw -= _windowSystem.Draw;
_clientState.TerritoryChanged -= TerritoryChanged;
_pluginInterface.RemoveChatLinkHandler();
_commandManager.RemoveHandler("/gbrowser");
_commandManager.RemoveHandler("/gup");
_gearsetterIpc.Dispose();
}
}

View File

@ -0,0 +1,60 @@
using Gearsetter.GameData;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model;
internal abstract record BaseItem(Item Item, bool Hq, MateriaStats? MateriaStats = null)
{
public Item Item { get; } = Item;
public uint ItemId { get; } = Item.RowId;
public bool Hq { get; } = Hq;
public bool CanBeHq { get; } = Item.CanBeHq;
public string Name { get; } = Item.Name.ToString();
public byte Level { get; } = Item.LevelEquip;
public uint ItemLevel { get; } = Item.LevelItem.Row;
public byte Rarity { get; } = Item.Rarity;
public EEquipSlotCategory EquipSlotCategory { get; } = (EEquipSlotCategory)Item.EquipSlotCategory.Row;
public uint ItemUiCategory { get; } = Item.ItemUICategory.Row;
public abstract EClassJob ClassJob { get; init; }
public EquipmentStats Stats { get; } = new(Item, Hq, MateriaStats);
public int PrimaryStat { get; init; } = -1;
public int Damage
{
get
{
if (ClassJob.DealsMagicDamage())
return Item.DamageMag + Stats.Get(EBaseParam.DamageMag);
else if (ClassJob.DealsPhysicalDamage())
return Item.DamagePhys + Stats.Get(EBaseParam.DamagePhys);
else
return 0;
}
}
public bool HasAnyStat(params EBaseParam[] substats)
{
foreach (EBaseParam substat in substats)
{
if (Stats.Get(substat) > 0)
return true;
}
return false;
}
public bool IsCombatRelicWithoutSubstats()
{
return Rarity == 4
&& EquipSlotCategory is EEquipSlotCategory.OneHandedMainHand
or EEquipSlotCategory.TwoHandedMainHand
or EEquipSlotCategory.Shield
&& !ClassJob.IsCrafter()
&& !ClassJob.IsGatherer()
&& !HasAnyStat(EBaseParam.Crit,
EBaseParam.DirectHit, EBaseParam.Determination, EBaseParam.SkillSpeed,
EBaseParam.SpellSpeed, EBaseParam.Tenacity);
}
}

View File

@ -0,0 +1,10 @@
using Gearsetter.GameData;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model;
internal sealed record EquipmentItem(Item Item, bool Hq) : BaseItem(Item, Hq)
{
public override EClassJob ClassJob { get; init; } = EClassJob.Adventurer;
}

View File

@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Linq;
using Gearsetter.GameData;
using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model;
internal sealed class EquipmentStats
{
private readonly Dictionary<EBaseParam, short> _equipmentValues;
private readonly Dictionary<EBaseParam, short> _materiaValues;
public EquipmentStats(Item item, bool hq, MateriaStats? materiaStats)
{
_equipmentValues = item.UnkData59.Where(x => x.BaseParam > 0)
.ToDictionary(x => (EBaseParam)x.BaseParam, x => x.BaseParamValue);
if (hq)
{
foreach (var hqstat in item.UnkData73.Select(x =>
((EBaseParam)x.BaseParamSpecial, x.BaseParamValueSpecial)))
{
if (_equipmentValues.TryGetValue(hqstat.Item1, out var stat))
_equipmentValues[hqstat.Item1] = (short)(stat + hqstat.BaseParamValueSpecial);
else
_equipmentValues[hqstat.Item1] = hqstat.BaseParamValueSpecial;
}
}
_materiaValues = new();
if (materiaStats != null)
{
foreach (var materiaStat in materiaStats.Values)
{
if (_materiaValues.TryGetValue(materiaStat.Key, out var stat))
_materiaValues[materiaStat.Key] = (short)(stat + materiaStat.Value);
else
_materiaValues[materiaStat.Key] = materiaStat.Value;
}
}
}
public short Get(EBaseParam param)
{
return (short)(GetEquipment(param) + GetMateria(param));
}
public short GetEquipment(EBaseParam param)
{
_equipmentValues.TryGetValue(param, out short v);
return v;
}
public short GetMateria(EBaseParam param)
{
_materiaValues.TryGetValue(param, out short v);
return v;
}
}

View File

@ -0,0 +1,57 @@
using System.Collections.Generic;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
using Gearsetter.GameData;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model;
internal sealed class GearsetData
{
public unsafe GearsetData(IDataManager dataManager, RaptureGearsetModule.GearsetEntry* gearset, string name)
{
Id = gearset->Id;
ClassJob = (EClassJob)gearset->ClassJob;
Name = name;
MainHand = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.MainHand);
OffHand = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.OffHand);
Head = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Head);
Body = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Body);
Hands = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Hands);
Legs = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Legs);
Feet = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Feet);
Ears = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Ears);
Neck = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Neck);
Wrists = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Wrists);
RingLeft = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.RingLeft);
RingRight = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.RingRight);
}
private static unsafe EquipmentItem? GetItem(IDataManager dataManager, RaptureGearsetModule.GearsetEntry* gearset,
RaptureGearsetModule.GearsetItemIndex index)
{
var gearsetItem = gearset->GetItem(index);
if (gearsetItem.ItemId == 0)
return null;
var item = dataManager.GetExcelSheet<Item>()!.GetRow(gearsetItem.ItemId % 1_000_000)!;
return new EquipmentItem(item, gearsetItem.ItemId > 1_000_000);
}
public byte Id { get; }
public EClassJob ClassJob { get; }
public string Name { get; }
public EquipmentItem? MainHand { get; }
public EquipmentItem? OffHand { get; }
public EquipmentItem? Head { get; }
public EquipmentItem? Body { get; }
public EquipmentItem? Hands { get; }
public EquipmentItem? Legs { get; }
public EquipmentItem? Feet { get; }
public EquipmentItem? Ears { get; set; }
public EquipmentItem? Neck { get; set; }
public EquipmentItem? Wrists { get; }
public EquipmentItem? RingLeft { get; }
public EquipmentItem? RingRight { get; }
}

View File

@ -0,0 +1,10 @@
using Gearsetter.GameData;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model;
internal sealed record InventoryItem(Item Item, bool Hq, MateriaStats MateriaStats, EClassJob ClassJob)
: BaseItem(Item, Hq, MateriaStats)
{
}

View File

@ -0,0 +1,203 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Gearsetter.GameData;
using LLib.GameData;
namespace Gearsetter.Model;
internal sealed class ItemList
{
private static readonly ReadOnlyDictionary<uint, byte> PreferredItems = new Dictionary<uint, byte>()
{
{ 16039, 50 },
{ 24589, 70 },
{ 33648, 80 },
{ 41081, 90 },
}.AsReadOnly();
public required EClassJob ClassJob { get; init; }
public required EEquipSlotCategory EquipSlotCategory { get; init; }
public required uint ItemUiCategory { get; init; }
public required List<BaseItem> Items { get; set; }
public EBaseParam PrimaryStat { get; set; }
public IReadOnlyList<EBaseParam> SubstatPriorities { get; set; } = new List<EBaseParam>();
public void Sort()
{
Items = Items
.OrderDescending(new ItemComparer(SubstatPriorities))
.ToList();
}
public void UpdateStats(Dictionary<EClassJob, EBaseParam> primaryStats, Configuration configuration)
{
if (ClassJob.IsTank())
SubstatPriorities = configuration.StatPriorityTanks;
else if (ClassJob.IsHealer())
SubstatPriorities = configuration.StatPriorityHealer;
else if (ClassJob.IsMelee())
SubstatPriorities = configuration.StatPriorityMelee;
else if (ClassJob.IsPhysicalRanged())
SubstatPriorities = configuration.StatPriorityPhysicalRanged;
else if (ClassJob.IsCaster())
SubstatPriorities = configuration.StatPriorityCaster;
else if (ClassJob.IsCrafter())
SubstatPriorities = configuration.StatPriorityCrafter;
else if (ClassJob.IsGatherer())
SubstatPriorities = configuration.StatPriorityGatherer;
else
SubstatPriorities = [];
if (primaryStats.TryGetValue(ClassJob, out EBaseParam primaryStat))
{
PrimaryStat = primaryStat;
Items = Items
.Where(x => x is EquipmentItem)
.Cast<EquipmentItem>()
.Select(x => x with { PrimaryStat = x.Stats.Get(primaryStat) })
.Cast<BaseItem>()
.ToList();
}
}
public void ApplyFromInventory(Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems,
bool includeWithoutMateria)
{
foreach (var inventoryItem in inventoryItems)
{
var basicItem = Items.SingleOrDefault(x =>
x.ItemId == inventoryItem.Key.ItemId && x.Hq == inventoryItem.Key.Hq);
if (basicItem == null)
continue;
foreach (var materias in inventoryItem.Value)
{
if (includeWithoutMateria || materias.Values.Count > 0)
Items.Add(
new InventoryItem(basicItem.Item, basicItem.Hq, materias, basicItem.ClassJob)
{
PrimaryStat = basicItem.Stats.Get(PrimaryStat)
});
}
}
Sort();
}
public void ClearFromInventory()
{
Items.RemoveAll(x => x is InventoryItem);
}
private sealed class ItemComparer(IReadOnlyList<EBaseParam> substatPriorities) : IComparer<BaseItem>
{
public int Compare(BaseItem? a, BaseItem? b)
{
ArgumentNullException.ThrowIfNull(a);
ArgumentNullException.ThrowIfNull(b);
// weapons: most damage wins
int damageA = a.Damage;
int damageB = b.Damage;
if (damageA != 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
//
// we pretend every gear item has at least 1 primary stat to ensure weathered items are sorted last(ish),
// where they would otherwise get sorted as better-than-shire items (while that may be correct, it's also
// stupid)
int primaryStatA = Math.Max(1, a.PrimaryStat);
int primaryStatB = Math.Max(1, b.PrimaryStat);
if (primaryStatA != primaryStatB)
return primaryStatA.CompareTo(primaryStatB);
// gear: vitality wins
int vitalityA = a.Stats.Get(EBaseParam.Vitality);
int vitalityB = b.Stats.Get(EBaseParam.Vitality);
if (vitalityA != vitalityB)
return vitalityA.CompareTo(vitalityB);
// sum of relevant substats
int sumOfSubstatsA = substatPriorities.Sum(x => a.Stats.Get(x));
int sumOfSubstatsB = substatPriorities.Sum(x => b.Stats.Get(x));
// some relics have no substats in the sheets, since they can be allocated dynamically
// they are -generally- better/equal to any other weapon on that ilvl
if (sumOfSubstatsA == 0 && a.IsCombatRelicWithoutSubstats())
sumOfSubstatsA = int.MaxValue;
if (sumOfSubstatsB == 0 && b.IsCombatRelicWithoutSubstats())
sumOfSubstatsB = int.MaxValue;
if (sumOfSubstatsA != sumOfSubstatsB)
return sumOfSubstatsA.CompareTo(sumOfSubstatsB);
// level-based sorting
if (a.Level != b.Level)
return a.Level.CompareTo(b.Level);
if (a.ItemLevel != b.ItemLevel)
return a.ItemLevel.CompareTo(b.ItemLevel);
if (a.Rarity != b.Rarity)
{
// aetherial items aren't "special" enough to be sorted higher than normal gear
int rarityA = a.Rarity;
int rarityB = b.Rarity;
if (rarityA == 7)
rarityA = 1;
if (rarityB == 7)
rarityB = 1;
return rarityA.CompareTo(rarityB);
}
// individual substats
foreach (EBaseParam substat in substatPriorities)
{
int substatA = a.Stats.Get(substat);
int substatB = b.Stats.Get(substat);
if (substatA != substatB)
return substatA.CompareTo(substatB);
}
// fallback
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;
}
}
}
}

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using Gearsetter.GameData;
namespace Gearsetter.Model;
internal sealed class MateriaStat(EBaseParam baseParam, short[] values)
{
public EBaseParam BaseParam { get; } = baseParam;
public List<short> Values { get; } = values.ToList();
}

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Gearsetter.GameData;
namespace Gearsetter.Model;
internal sealed class MateriaStats : IEquatable<MateriaStats>
{
private readonly List<(EBaseParam, short)> _list;
public MateriaStats(IEnumerable<(MateriaStat Stat, byte Grade)> materias)
{
foreach (var materia in materias)
{
if (Values.TryGetValue(materia.Stat.BaseParam, out short value))
Values[materia.Stat.BaseParam] = (short)(value + materia.Stat.Values[materia.Grade]);
else
Values[materia.Stat.BaseParam] = materia.Stat.Values[materia.Grade];
++Count;
}
_list = Enum.GetValues<EBaseParam>()
.Select(x => (x, Values.GetValueOrDefault(x, (short)0)))
.Where(x => x.Item2 > 0)
.ToList();
}
public Dictionary<EBaseParam, short> Values { get; } = new();
public byte Count { get; }
public override bool Equals(object? obj)
{
return ReferenceEquals(this, obj) || obj is MateriaStats other && Equals(other);
}
public override int GetHashCode()
{
return _list.GetHashCode();
}
public bool Equals(MateriaStats? other)
{
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}"))}]";
}
}

View File

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

View File

@ -0,0 +1,29 @@
using Dalamud.Plugin;
using ImGuiNET;
using LLib.ImGui;
namespace Gearsetter.Windows;
internal sealed class ConfigWindow : LWindow
{
private readonly IDalamudPluginInterface _pluginInterface;
private readonly Configuration _configuration;
public ConfigWindow(IDalamudPluginInterface pluginInterface, Configuration configuration)
: base("Gearsetter - Config###GearsetterConfig", ImGuiWindowFlags.AlwaysAutoResize)
{
_pluginInterface = pluginInterface;
_configuration = configuration;
}
public override void Draw()
{
bool showRecommendationsWhenEnteringGcArea = _configuration.ShowRecommendationsWhenEnteringGcArea;
if (ImGui.Checkbox("Show recommendations when entering Grand Company area",
ref showRecommendationsWhenEnteringGcArea))
{
_configuration.ShowRecommendationsWhenEnteringGcArea = showRecommendationsWhenEnteringGcArea;
_pluginInterface.SavePluginConfig(_configuration);
}
}
}

View File

@ -0,0 +1,250 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Interface.Colors;
using Dalamud.Plugin.Services;
using Gearsetter.GameData;
using Gearsetter.Model;
using ImGuiNET;
using LLib.GameData;
using LLib.ImGui;
namespace Gearsetter.Windows;
internal sealed class EquipmentBrowserWindow : LWindow
{
private readonly GearsetterPlugin _plugin;
private readonly GameDataHolder _dataHolder;
private readonly IClientState _clientState;
private readonly IChatGui _chatGui;
private readonly string[] _classJobNames;
private readonly EClassJob[] _classJobIds;
private EClassJob _selectedClassJob = EClassJob.Paladin;
private EEquipSlotCategory _selectedEquipmentCategory = EEquipSlotCategory.None;
private string[] _equipmentCategoryNames = [];
private EEquipSlotCategory[] _equipmentCategoryIds = [];
private bool _onlyShowOwnedItems;
private bool _onlyShowEquippableItems;
private bool _hideNormalQualityItems = true;
public EquipmentBrowserWindow(GearsetterPlugin plugin, GameDataHolder dataHolder, IClientState clientState,
IChatGui chatGui)
: base("Equipment Browser###GearsetterBrowser")
{
_plugin = plugin;
_dataHolder = dataHolder;
_clientState = clientState;
_chatGui = chatGui;
_classJobNames = dataHolder.ClassJobNames
.Where(x => x.ClassJob.AsJob() == x.ClassJob)
.Select(x => x.Name)
.ToArray();
_classJobIds = dataHolder.ClassJobNames
.Where(x => x.ClassJob.AsJob() == x.ClassJob)
.Select(x => x.ClassJob)
.ToArray();
UpdateEquipmentCategories();
Size = new Vector2(800, 500);
SizeCondition = ImGuiCond.FirstUseEver;
SizeConstraints = new WindowSizeConstraints
{
MinimumSize = new Vector2(800, 500)
};
}
public override void OnOpen()
{
if (_clientState.LocalPlayer != null)
_selectedClassJob = ((EClassJob)_clientState.LocalPlayer.ClassJob.Id).AsJob();
UpdateEquipmentCategories();
}
public override bool DrawConditions()
{
return _clientState.IsLoggedIn;
}
public override unsafe void Draw()
{
int currentClassJob = Array.IndexOf(_classJobIds, _selectedClassJob);
if (currentClassJob == -1)
{
_selectedClassJob = EClassJob.Paladin;
currentClassJob = Array.IndexOf(_classJobIds, _selectedClassJob);
UpdateEquipmentCategories();
}
if (ImGui.Combo("Class/Job", ref currentClassJob, _classJobNames, _classJobNames.Length))
{
_selectedClassJob = _classJobIds[currentClassJob];
UpdateEquipmentCategories();
}
int currentCategory = Array.IndexOf(_equipmentCategoryIds, _selectedEquipmentCategory);
if (currentCategory == -1)
{
if (_equipmentCategoryIds.Length == 0)
return;
_selectedEquipmentCategory = _equipmentCategoryIds[0];
currentCategory = 0;
}
if (ImGui.Combo("Category", ref currentCategory, _equipmentCategoryNames, _equipmentCategoryNames.Length))
_selectedEquipmentCategory = _equipmentCategoryIds[currentCategory];
var itemList = _dataHolder.GetItemList(_selectedClassJob, _selectedEquipmentCategory);
if (itemList == null)
return;
ImGui.Checkbox("Only show items matching your level", ref _onlyShowEquippableItems);
ImGui.SameLine();
ImGui.Checkbox("Only show owned items", ref _onlyShowOwnedItems);
ImGui.SameLine();
ImGui.Checkbox("Hide normal quality items", ref _hideNormalQualityItems);
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> ownedItems = _plugin.GetAllInventoryItems();
try
{
itemList.ApplyFromInventory(ownedItems, _onlyShowOwnedItems);
byte maxLevel = byte.MaxValue;
if (_onlyShowEquippableItems)
maxLevel = _plugin.GetLevel(_selectedClassJob);
bool includeDamage = _selectedEquipmentCategory is EEquipSlotCategory.OneHandedMainHand
or EEquipSlotCategory.Shield
or EEquipSlotCategory.TwoHandedMainHand
&& !itemList.ClassJob.IsCrafter()
&& !itemList.ClassJob.IsGatherer();
var hoverColorPtr = ImGui.GetStyleColorVec4(ImGuiCol.HeaderHovered);
var hoverColor = new Vector4(hoverColorPtr->X, hoverColorPtr->Y, hoverColorPtr->Z, 0.3f);
if (ImGui.BeginTable("ItemList", 2 + (includeDamage ? 1 : 0) + itemList.SubstatPriorities.Count,
ImGuiTableFlags.Borders | ImGuiTableFlags.Resizable))
{
ImGui.TableSetupColumn("Name", ImGuiTableColumnFlags.None, 300);
ImGui.TableSetupColumn("Level", ImGuiTableColumnFlags.WidthFixed, 50);
if (includeDamage)
ImGui.TableSetupColumn("Damage", ImGuiTableColumnFlags.WidthFixed, 50);
foreach (var substat in itemList.SubstatPriorities)
ImGui.TableSetupColumn(_dataHolder.StatNames.GetValueOrDefault(substat, substat.ToString()),
ImGuiTableColumnFlags.WidthFixed, 50);
ImGui.TableHeadersRow();
ImGui.PushStyleColor(ImGuiCol.HeaderHovered, hoverColor);
foreach (var item in itemList.Items.DistinctBy(x => new
{ x.ItemId, x.Hq, Materia = x.MateriaStats?.GetHashCode() }))
{
if (item is not InventoryItem)
{
if (_onlyShowOwnedItems)
continue;
}
if (item.Level > maxLevel)
continue;
if (_hideNormalQualityItems && item.CanBeHq && !item.Hq)
continue;
ImGui.TableNextRow();
if (ImGui.TableNextColumn())
{
Vector4? color = item.Rarity switch
{
2 => ImGuiColors.ParsedGreen,
3 => ImGuiColors.ParsedBlue,
4 => ImGuiColors.ParsedPurple,
7 => ImGuiColors.ParsedPink,
_ => null,
};
string name = item.Name;
if (item.Hq)
name += $" {SeIconChar.HighQuality.ToIconString()}";
if (item is InventoryItem { MateriaStats: not null } inventoryItem)
name +=
$" {string.Join("", Enumerable.Repeat(SeIconChar.Circle.ToIconString(), inventoryItem.MateriaStats!.Count))}";
if (color != null)
ImGui.PushStyleColor(ImGuiCol.Text, color.Value);
ImGui.Selectable(name, false, ImGuiSelectableFlags.SpanAllColumns);
if (color != null)
ImGui.PopStyleColor();
if (ImGui.IsItemClicked())
{
try
{
_chatGui.Print(SeString.CreateItemLink(item.ItemId, item.Hq));
}
catch (Exception)
{
// doesn't matter, just nice-to-have
}
}
}
if (ImGui.TableNextColumn())
{
if (item.Level >= 50 && item.Level % 10 == 0)
ImGui.Text(string.Create(CultureInfo.InvariantCulture, $"{item.Level} ({item.ItemLevel})"));
else
ImGui.Text(item.Level.ToString(CultureInfo.InvariantCulture));
}
if (includeDamage && ImGui.TableNextColumn())
ImGui.Text(item.Damage.ToString(CultureInfo.CurrentCulture));
foreach (EBaseParam substat in itemList.SubstatPriorities)
{
if (ImGui.TableNextColumn())
{
var estat = item.Stats.GetEquipment(substat);
var mstat = item.Stats.GetMateria(substat);
if (estat == 0 && mstat == 0)
ImGui.Text("-");
else if (mstat == 0)
ImGui.Text(string.Create(CultureInfo.InvariantCulture, $"{estat}"));
else
ImGui.Text(string.Create(CultureInfo.InvariantCulture, $"{estat} +{mstat}"));
}
}
}
ImGui.PopStyleColor();
ImGui.EndTable();
}
}
finally
{
itemList.ClearFromInventory();
}
}
private void UpdateEquipmentCategories()
{
var categories = _dataHolder.GetItemListsForJob(_selectedClassJob);
_equipmentCategoryNames = categories.Select(x => x.UiCategoryName).ToArray();
_equipmentCategoryIds = categories.Select(x => x.EquipSlotCategory).ToArray();
if (_equipmentCategoryIds.Length > 0 && !_equipmentCategoryIds.Contains(_selectedEquipmentCategory))
_selectedEquipmentCategory = _equipmentCategoryIds[0];
else if (_equipmentCategoryIds.Length == 0)
_selectedEquipmentCategory = EEquipSlotCategory.None;
}
}

View File

@ -4,9 +4,83 @@
"net8.0-windows7.0": {
"DalamudPackager": {
"type": "Direct",
"requested": "[2.1.12, )",
"resolved": "2.1.12",
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
"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, )"
}
}
}
}

1
LLib Submodule

@ -0,0 +1 @@
Subproject commit 9db9f95b8cd3f36262b5b4b14f12b7331d3c7279