1010namespace AutoDuty . Helpers
1111{
1212 using Lumina . Excel . Sheets ;
13+ using System ;
14+ using System . Collections . Generic ;
15+ using System . Linq ;
16+ using Windows ;
17+ using ECommons . ExcelServices ;
18+ using ECommons . MathHelpers ;
19+ using FFXIVClientStructs . FFXIV . Client . UI . Misc ;
1320
1421 internal class DesynthHelper : ActiveHelperBase < DesynthHelper >
1522 {
@@ -24,11 +31,14 @@ internal class DesynthHelper : ActiveHelperBase<DesynthHelper>
2431 internal override void Start ( )
2532 {
2633 _maxDesynthLevel = PlayerHelper . GetMaxDesynthLevel ( ) ;
27- base . Start ( ) ;
34+ if ( this . NextCategory ( true ) )
35+ base . Start ( ) ;
2836 }
2937
3038 private float _maxDesynthLevel = 1 ;
3139
40+ private AgentSalvage . SalvageItemCategory curCategory ;
41+
3242 protected override unsafe void HelperUpdate ( IFramework framework )
3343 {
3444 if ( Plugin . States . HasFlag ( PluginState . Navigating ) || Plugin . InDungeon )
@@ -66,7 +76,7 @@ protected override unsafe void HelperUpdate(IFramework framework)
6676 AddonHelper . FireCallBack ( addonSalvageDialog , true , 0 , false ) ;
6777 return ;
6878 }
69-
79+
7080 if ( ! GenericHelpers . TryGetAddonByName < AddonSalvageItemSelector > ( "SalvageItemSelector" , out var addonSalvageItemSelector ) )
7181 {
7282 AgentSalvage . Instance ( ) ->AgentInterface . Show ( ) ;
@@ -76,30 +86,54 @@ protected override unsafe void HelperUpdate(IFramework framework)
7686 else if ( GenericHelpers . IsAddonReady ( ( AtkUnitBase * ) addonSalvageItemSelector ) && addonSalvageItemSelector ->IsReady )
7787 {
7888 AgentSalvage . Instance ( ) ->ItemListRefresh ( true ) ;
79- if ( AgentSalvage . Instance ( ) ->SelectedCategory != AgentSalvage . SalvageItemCategory . InventoryEquipment )
89+ if ( AgentSalvage . Instance ( ) ->SelectedCategory != this . curCategory )
8090 {
81- DebugLog ( "Switching Category" ) ;
82- AddonHelper . FireCallBack ( ( AtkUnitBase * ) addonSalvageItemSelector , true , 11 , 0 ) ;
91+ DebugLog ( "Switching Category to " + this . curCategory ) ;
92+ AgentSalvage . Instance ( ) -> SelectedCategory = this . curCategory ;
8393 return ;
8494 }
8595 else if ( addonSalvageItemSelector ->ItemCount > 0 )
8696 {
97+ HashSet < uint > ? gearsetItemIds = null ;
98+
8799 var foundOne = false ;
88100 for ( int i = 0 ; i < AgentSalvage . Instance ( ) ->ItemCount ; i ++ )
89101 {
90- var item = AgentSalvage . Instance ( ) ->ItemList [ i ] ;
91- var itemId = InventoryManager . Instance ( ) ->GetInventorySlot ( item . InventoryType , ( int ) item . InventorySlot ) ->ItemId ;
102+ var item = AgentSalvage . Instance ( ) ->ItemList [ i ] ;
103+ InventoryItem * inventoryItem = InventoryManager . Instance ( ) ->GetInventorySlot ( item . InventoryType , ( int ) item . InventorySlot ) ;
104+ var itemId = inventoryItem ->ItemId ;
92105
93106 if ( itemId == 10146 ) continue ;
94107
95108 var itemSheetRow = Svc . Data . Excel . GetSheet < Item > ( ) ? . GetRow ( itemId ) ;
96109 var itemLevel = itemSheetRow ? . LevelItem . ValueNullable ? . RowId ;
97110 var desynthLevel = PlayerHelper . GetDesynthLevel ( item . ClassJob ) ;
98111
99- if ( itemLevel == null || itemSheetRow == null ) continue ;
112+ if ( itemLevel == null || itemSheetRow == null || desynthLevel <= 0 ) continue ;
100113
101114 if ( ! Plugin . Configuration . AutoDesynthSkillUp || ( desynthLevel < itemLevel + Plugin . Configuration . AutoDesynthSkillUpLimit && desynthLevel < _maxDesynthLevel ) )
102115 {
116+ if ( Plugin . Configuration . AutoDesynthNoGearset )
117+ {
118+ if ( gearsetItemIds == null )
119+ {
120+ gearsetItemIds = [ ] ;
121+
122+ RaptureGearsetModule * gearsetModule = RaptureGearsetModule . Instance ( ) ;
123+ byte num = gearsetModule ->NumGearsets ;
124+ for ( byte j = 0 ; j < num ; j ++ )
125+ {
126+ foreach ( RaptureGearsetModule . GearsetEntry entry in gearsetModule ->Entries )
127+ foreach ( RaptureGearsetModule . GearsetItem gearsetItem in entry . Items )
128+ gearsetItemIds . Add ( gearsetItem . ItemId ) ;
129+ }
130+ }
131+
132+ if ( gearsetItemIds . Contains ( itemId ) )
133+ continue ;
134+ }
135+
136+
103137 DebugLog ( $ "Salvaging Item({ i } ): { itemSheetRow . Value . Name . ToString ( ) } with iLvl { itemLevel } because our desynth level is { desynthLevel } ") ;
104138 foundOne = true ;
105139 AddonHelper . FireCallBack ( ( AtkUnitBase * ) addonSalvageItemSelector , true , 12 , i ) ;
@@ -108,19 +142,40 @@ protected override unsafe void HelperUpdate(IFramework framework)
108142 }
109143
110144 if ( ! foundOne )
145+ {
146+ if ( ! this . NextCategory ( ) )
147+ {
148+ addonSalvageItemSelector ->Close ( true ) ;
149+ DebugLog ( "Desynth Finished" ) ;
150+ Stop ( ) ;
151+ }
152+ }
153+ }
154+ else
155+ {
156+ if ( ! this . NextCategory ( ) )
111157 {
112158 addonSalvageItemSelector ->Close ( true ) ;
113159 DebugLog ( "Desynth Finished" ) ;
114160 Stop ( ) ;
115161 }
116162 }
117- else
163+ }
164+ }
165+
166+ public bool NextCategory ( bool reset = false )
167+ {
168+ AgentSalvage . SalvageItemCategory [ ] ? categories = Enum . GetValues < AgentSalvage . SalvageItemCategory > ( ) ;
169+ for ( int i = reset ? 0 : ( int ) this . curCategory + 1 ; i < categories . Length ; i ++ )
170+ {
171+ if ( Bitmask . IsBitSet ( Plugin . Configuration . AutoDesynthCategories , i ) )
118172 {
119- addonSalvageItemSelector ->Close ( true ) ;
120- DebugLog ( "Desynth Finished" ) ;
121- Stop ( ) ;
173+ this . curCategory = categories [ i ] ;
174+ return true ;
122175 }
123176 }
177+
178+ return false ;
124179 }
125180 }
126181}
0 commit comments