Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AutoDuty/AutoDuty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
79 changes: 67 additions & 12 deletions AutoDuty/Helpers/DesynthHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DesynthHelper>
{
Expand All @@ -24,11 +31,14 @@ internal class DesynthHelper : ActiveHelperBase<DesynthHelper>
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)
Expand Down Expand Up @@ -66,7 +76,7 @@ protected override unsafe void HelperUpdate(IFramework framework)
AddonHelper.FireCallBack(addonSalvageDialog, true, 0, false);
return;
}

if (!GenericHelpers.TryGetAddonByName<AddonSalvageItemSelector>("SalvageItemSelector", out var addonSalvageItemSelector))
{
AgentSalvage.Instance()->AgentInterface.Show();
Expand All @@ -76,30 +86,54 @@ 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<uint>? 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;

var itemSheetRow = Svc.Data.Excel.GetSheet<Item>()?.GetRow(itemId);
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);
Expand All @@ -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<AgentSalvage.SalvageItemCategory>();
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;
}
}
}