@@ -31,17 +31,12 @@ public JobManager(DdonGameServer server)
3131 _Server = server ;
3232 }
3333
34- public ( IPacketStructure ? jobRes , IPacketStructure ? itemNtc , IPacketStructure ? jobNtc ) SetJob ( GameClient client , CharacterCommon common , JobId jobId , DbConnection ? connectionIn = null )
34+ public ( IPacketStructure jobRes , IPacketStructure ? itemNtc , IPacketStructure ? jobNtc ) SetJob ( GameClient client , CharacterCommon common , JobId jobId , DbConnection ? connectionIn = null )
3535 {
3636 // TODO: Reject job change if there's no primary and secondary weapon for the new job in storage
3737 // (or give a lvl 1 weapon for free?)
3838
39- var totalSlots = common . Equipment . GetItems ( EquipType . Performance )
40- . Concat ( common . Equipment . GetItems ( EquipType . Visual ) )
41- . Where ( x => x != null )
42- . ToList ( )
43- . Count ;
44- if ( totalSlots > client . Character . Storage . GetStorage ( StorageType . StorageBoxNormal ) . EmptySlots ( ) )
39+ if ( ! HasEmptySlotsForTemplateSwap ( client , common , common . Job , jobId ) )
4540 {
4641 return ( new S2CJobChangeJobRes ( )
4742 {
@@ -293,6 +288,36 @@ private List<CDataItemUpdateResult> SwapEquipmentAndStorage(GameClient client, C
293288 return itemUpdateResultList ;
294289 }
295290
291+ private static bool HasEmptySlotsForTemplateSwap ( GameClient client , CharacterCommon common , JobId oldJobId , JobId newJobId )
292+ {
293+ var availableSlots = client . Character . Storage . GetStorage ( StorageType . StorageBoxNormal ) . EmptySlots ( ) ;
294+
295+ var neededSlots = common . Equipment . GetItems ( EquipType . Performance )
296+ . Concat ( common . Equipment . GetItems ( EquipType . Visual ) )
297+ . Where ( x => x != null )
298+ . ToList ( )
299+ . Count ;
300+
301+ // If the item isn't moving, it doesn't need a space in the box.
302+ foreach ( var equipType in new List < EquipType > ( ) { EquipType . Performance , EquipType . Visual } )
303+ {
304+ List < Item ? > oldEquipment = common . Equipment . GetItems ( equipType ) ;
305+ List < Item ? > newEquipmentTemplate = common . EquipmentTemplate . GetEquipment ( newJobId , equipType ) ;
306+
307+ for ( int i = 0 ; i < oldEquipment . Count ; i ++ )
308+ {
309+ if ( oldEquipment [ i ] != null && newEquipmentTemplate [ i ] != null && oldEquipment [ i ] == newEquipmentTemplate [ i ] )
310+ {
311+ neededSlots -- ;
312+ }
313+ }
314+ }
315+
316+ // TODO: Account for one-to-one swaps, as well as jewelry shuffling order.
317+
318+ return neededSlots <= availableSlots ;
319+ }
320+
296321 public void UnlockSkill ( IDatabase database , GameClient client , CharacterCommon character , JobId job , uint skillId , byte skillLv )
297322 {
298323 // Check if there is a learned skill of the same ID (This unlock is a level upgrade)
0 commit comments