@@ -374,7 +374,7 @@ export class BotEquipmentModGenerator {
374
374
const randomisationSettings = this . botHelper . getBotRandomizationDetails ( request . botData . level , botEquipConfig ) ;
375
375
376
376
// Iterate over mod pool and choose mods to attach
377
- const sortedModKeys = this . sortModKeys ( Object . keys ( compatibleModsPool ) ) ;
377
+ const sortedModKeys = this . sortModKeys ( Object . keys ( compatibleModsPool ) , request . parentTemplate . _id ) ;
378
378
for ( const modSlot of sortedModKeys ) {
379
379
// Check weapon has slot for mod to fit in
380
380
const modsParentSlot = this . getModItemSlotFromDb ( modSlot , request . parentTemplate ) ;
@@ -665,13 +665,15 @@ export class BotEquipmentModGenerator {
665
665
/**
666
666
* Sort mod slots into an ordering that maximises chance of a successful weapon generation
667
667
* @param unsortedSlotKeys Array of mod slot strings to sort
668
+ * @param itemTplWithKeysToSort The Tpl of the item with mod keys being sorted
668
669
* @returns Sorted array
669
670
*/
670
- protected sortModKeys ( unsortedSlotKeys : string [ ] ) : string [ ] {
671
+ protected sortModKeys ( unsortedSlotKeys : string [ ] , itemTplWithKeysToSort : string ) : string [ ] {
671
672
// No need to sort with only 1 item in array
672
673
if ( unsortedSlotKeys . length <= 1 ) {
673
674
return unsortedSlotKeys ;
674
675
}
676
+ const isMount = this . itemHelper . isOfBaseclass ( itemTplWithKeysToSort , BaseClasses . MOUNT ) ;
675
677
676
678
const sortedKeys : string [ ] = [ ] ;
677
679
const modRecieverKey = "mod_reciever" ;
@@ -683,50 +685,69 @@ export class BotEquipmentModGenerator {
683
685
const modHandguardKey = "mod_handguard" ;
684
686
const modMountKey = "mod_mount" ;
685
687
const modScopeKey = "mod_scope" ;
688
+ const modScope000Key = "mod_scope_000" ;
686
689
687
- if ( unsortedSlotKeys . includes ( modHandguardKey ) ) {
688
- sortedKeys . push ( modHandguardKey ) ;
689
- unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modHandguardKey ) , 1 ) ;
690
- }
690
+ // Mounts are a special case, they need scopes first before more mounts
691
+ if ( isMount ) {
692
+ if ( unsortedSlotKeys . includes ( modScope000Key ) ) {
693
+ sortedKeys . push ( modScope000Key ) ;
694
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modScope000Key ) , 1 ) ;
695
+ }
691
696
692
- if ( unsortedSlotKeys . includes ( modBarrelKey ) ) {
693
- sortedKeys . push ( modBarrelKey ) ;
694
- unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modBarrelKey ) , 1 ) ;
695
- }
697
+ if ( unsortedSlotKeys . includes ( modScopeKey ) ) {
698
+ sortedKeys . push ( modScopeKey ) ;
699
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modScopeKey ) , 1 ) ;
700
+ }
696
701
697
- if ( unsortedSlotKeys . includes ( modMount001Key ) ) {
698
- sortedKeys . push ( modMount001Key ) ;
699
- unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modMount001Key ) , 1 ) ;
700
- }
702
+ if ( unsortedSlotKeys . includes ( modMountKey ) ) {
703
+ sortedKeys . push ( modMountKey ) ;
704
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modMountKey ) , 1 ) ;
705
+ }
706
+ } else {
707
+ if ( unsortedSlotKeys . includes ( modHandguardKey ) ) {
708
+ sortedKeys . push ( modHandguardKey ) ;
709
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modHandguardKey ) , 1 ) ;
710
+ }
701
711
702
- if ( unsortedSlotKeys . includes ( modRecieverKey ) ) {
703
- sortedKeys . push ( modRecieverKey ) ;
704
- unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modRecieverKey ) , 1 ) ;
705
- }
712
+ if ( unsortedSlotKeys . includes ( modBarrelKey ) ) {
713
+ sortedKeys . push ( modBarrelKey ) ;
714
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modBarrelKey ) , 1 ) ;
715
+ }
706
716
707
- if ( unsortedSlotKeys . includes ( modPistolGrip ) ) {
708
- sortedKeys . push ( modPistolGrip ) ;
709
- unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modPistolGrip ) , 1 ) ;
710
- }
717
+ if ( unsortedSlotKeys . includes ( modMount001Key ) ) {
718
+ sortedKeys . push ( modMount001Key ) ;
719
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modMount001Key ) , 1 ) ;
720
+ }
711
721
712
- if ( unsortedSlotKeys . includes ( modGasBlockKey ) ) {
713
- sortedKeys . push ( modGasBlockKey ) ;
714
- unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modGasBlockKey ) , 1 ) ;
715
- }
722
+ if ( unsortedSlotKeys . includes ( modRecieverKey ) ) {
723
+ sortedKeys . push ( modRecieverKey ) ;
724
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modRecieverKey ) , 1 ) ;
725
+ }
716
726
717
- if ( unsortedSlotKeys . includes ( modStockKey ) ) {
718
- sortedKeys . push ( modStockKey ) ;
719
- unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modStockKey ) , 1 ) ;
720
- }
727
+ if ( unsortedSlotKeys . includes ( modPistolGrip ) ) {
728
+ sortedKeys . push ( modPistolGrip ) ;
729
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modPistolGrip ) , 1 ) ;
730
+ }
721
731
722
- if ( unsortedSlotKeys . includes ( modMountKey ) ) {
723
- sortedKeys . push ( modMountKey ) ;
724
- unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modMountKey ) , 1 ) ;
725
- }
732
+ if ( unsortedSlotKeys . includes ( modGasBlockKey ) ) {
733
+ sortedKeys . push ( modGasBlockKey ) ;
734
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modGasBlockKey ) , 1 ) ;
735
+ }
726
736
727
- if ( unsortedSlotKeys . includes ( modScopeKey ) ) {
728
- sortedKeys . push ( modScopeKey ) ;
729
- unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modScopeKey ) , 1 ) ;
737
+ if ( unsortedSlotKeys . includes ( modStockKey ) ) {
738
+ sortedKeys . push ( modStockKey ) ;
739
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modStockKey ) , 1 ) ;
740
+ }
741
+
742
+ if ( unsortedSlotKeys . includes ( modMountKey ) ) {
743
+ sortedKeys . push ( modMountKey ) ;
744
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modMountKey ) , 1 ) ;
745
+ }
746
+
747
+ if ( unsortedSlotKeys . includes ( modScopeKey ) ) {
748
+ sortedKeys . push ( modScopeKey ) ;
749
+ unsortedSlotKeys . splice ( unsortedSlotKeys . indexOf ( modScopeKey ) , 1 ) ;
750
+ }
730
751
}
731
752
732
753
sortedKeys . push ( ...unsortedSlotKeys ) ;
0 commit comments