diff --git a/AutoDuty/AutoDuty.cs b/AutoDuty/AutoDuty.cs index bf38fdfb..c2655515 100644 --- a/AutoDuty/AutoDuty.cs +++ b/AutoDuty/AutoDuty.cs @@ -255,7 +255,7 @@ public AutoDuty() AssemblyDirectoryInfo = AssemblyFileInfo.Directory; Version = - ((PluginInterface.IsDev ? new Version(0,0,0, 253) : + ((PluginInterface.IsDev ? new Version(0,0,0, 254) : PluginInterface.IsTesting ? PluginInterface.Manifest.TestingAssemblyVersion ?? PluginInterface.Manifest.AssemblyVersion : PluginInterface.Manifest.AssemblyVersion)!).Revision; if (!_configDirectory.Exists) diff --git a/AutoDuty/Helpers/DesynthHelper.cs b/AutoDuty/Helpers/DesynthHelper.cs index 943735df..10367b01 100644 --- a/AutoDuty/Helpers/DesynthHelper.cs +++ b/AutoDuty/Helpers/DesynthHelper.cs @@ -10,6 +10,13 @@ namespace AutoDuty.Helpers { using Lumina.Excel.Sheets; + using System; + using System.Collections.Generic; + using System.Linq; + using Windows; + using ECommons.ExcelServices; + using ECommons.MathHelpers; + using FFXIVClientStructs.FFXIV.Client.UI.Misc; internal class DesynthHelper : ActiveHelperBase { @@ -24,11 +31,14 @@ internal class DesynthHelper : ActiveHelperBase internal override void Start() { _maxDesynthLevel = PlayerHelper.GetMaxDesynthLevel(); - base.Start(); + if(this.NextCategory(true)) + base.Start(); } private float _maxDesynthLevel = 1; + private AgentSalvage.SalvageItemCategory curCategory; + protected override unsafe void HelperUpdate(IFramework framework) { if (Plugin.States.HasFlag(PluginState.Navigating) || Plugin.InDungeon) @@ -66,7 +76,7 @@ protected override unsafe void HelperUpdate(IFramework framework) AddonHelper.FireCallBack(addonSalvageDialog, true, 0, false); return; } - + if (!GenericHelpers.TryGetAddonByName("SalvageItemSelector", out var addonSalvageItemSelector)) { AgentSalvage.Instance()->AgentInterface.Show(); @@ -76,19 +86,22 @@ protected override unsafe void HelperUpdate(IFramework framework) else if (GenericHelpers.IsAddonReady((AtkUnitBase*)addonSalvageItemSelector) && addonSalvageItemSelector->IsReady) { AgentSalvage.Instance()->ItemListRefresh(true); - if (AgentSalvage.Instance()->SelectedCategory != AgentSalvage.SalvageItemCategory.InventoryEquipment) + if (AgentSalvage.Instance()->SelectedCategory != this.curCategory) { - DebugLog("Switching Category"); - AddonHelper.FireCallBack((AtkUnitBase*)addonSalvageItemSelector, true, 11, 0); + DebugLog("Switching Category to " + this.curCategory); + AgentSalvage.Instance()->SelectedCategory = this.curCategory; return; } else if (addonSalvageItemSelector->ItemCount > 0) { + HashSet? gearsetItemIds = null; + var foundOne = false; for (int i = 0; i < AgentSalvage.Instance()->ItemCount; i++) { - var item = AgentSalvage.Instance()->ItemList[i]; - var itemId = InventoryManager.Instance()->GetInventorySlot(item.InventoryType, (int)item.InventorySlot)->ItemId; + var item = AgentSalvage.Instance()->ItemList[i]; + InventoryItem* inventoryItem = InventoryManager.Instance()->GetInventorySlot(item.InventoryType, (int)item.InventorySlot); + var itemId = inventoryItem->ItemId; if (itemId == 10146) continue; @@ -96,10 +109,31 @@ protected override unsafe void HelperUpdate(IFramework framework) var itemLevel = itemSheetRow?.LevelItem.ValueNullable?.RowId; var desynthLevel = PlayerHelper.GetDesynthLevel(item.ClassJob); - if (itemLevel == null || itemSheetRow == null) continue; + if (itemLevel == null || itemSheetRow == null || desynthLevel <= 0) continue; if (!Plugin.Configuration.AutoDesynthSkillUp || (desynthLevel < itemLevel + Plugin.Configuration.AutoDesynthSkillUpLimit && desynthLevel < _maxDesynthLevel)) { + if (Plugin.Configuration.AutoDesynthNoGearset) + { + if (gearsetItemIds == null) + { + gearsetItemIds = []; + + RaptureGearsetModule* gearsetModule = RaptureGearsetModule.Instance(); + byte num = gearsetModule->NumGearsets; + for (byte j = 0; j < num; j++) + { + foreach (RaptureGearsetModule.GearsetEntry entry in gearsetModule->Entries) + foreach (RaptureGearsetModule.GearsetItem gearsetItem in entry.Items) + gearsetItemIds.Add(gearsetItem.ItemId); + } + } + + if (gearsetItemIds.Contains(itemId)) + continue; + } + + DebugLog($"Salvaging Item({i}): {itemSheetRow.Value.Name.ToString()} with iLvl {itemLevel} because our desynth level is {desynthLevel}"); foundOne = true; AddonHelper.FireCallBack((AtkUnitBase*)addonSalvageItemSelector, true, 12, i); @@ -108,19 +142,40 @@ protected override unsafe void HelperUpdate(IFramework framework) } if (!foundOne) + { + if (!this.NextCategory()) + { + addonSalvageItemSelector->Close(true); + DebugLog("Desynth Finished"); + Stop(); + } + } + } + else + { + if (!this.NextCategory()) { addonSalvageItemSelector->Close(true); DebugLog("Desynth Finished"); Stop(); } } - else + } + } + + public bool NextCategory(bool reset = false) + { + AgentSalvage.SalvageItemCategory[]? categories = Enum.GetValues(); + for (int i = reset ? 0 : (int) this.curCategory + 1; i < categories.Length; i++) + { + if(Bitmask.IsBitSet(Plugin.Configuration.AutoDesynthCategories, i)) { - addonSalvageItemSelector->Close(true); - DebugLog("Desynth Finished"); - Stop(); + this.curCategory = categories[i]; + return true; } } + + return false; } } }