mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:50:43 -05:00
Updated sortModKeys()
to use mount-specific mod sorting, prioritises the scope before additional mounts
Fixed null ref exceptions due to some items lacking `slots` objects
This commit is contained in:
parent
e8c3b69975
commit
9ef8206517
@ -374,7 +374,7 @@ export class BotEquipmentModGenerator {
|
|||||||
const randomisationSettings = this.botHelper.getBotRandomizationDetails(request.botData.level, botEquipConfig);
|
const randomisationSettings = this.botHelper.getBotRandomizationDetails(request.botData.level, botEquipConfig);
|
||||||
|
|
||||||
// Iterate over mod pool and choose mods to attach
|
// Iterate over mod pool and choose mods to attach
|
||||||
const sortedModKeys = this.sortModKeys(Object.keys(compatibleModsPool));
|
const sortedModKeys = this.sortModKeys(Object.keys(compatibleModsPool), request.parentTemplate._id);
|
||||||
for (const modSlot of sortedModKeys) {
|
for (const modSlot of sortedModKeys) {
|
||||||
// Check weapon has slot for mod to fit in
|
// Check weapon has slot for mod to fit in
|
||||||
const modsParentSlot = this.getModItemSlotFromDb(modSlot, request.parentTemplate);
|
const modsParentSlot = this.getModItemSlotFromDb(modSlot, request.parentTemplate);
|
||||||
@ -665,13 +665,15 @@ export class BotEquipmentModGenerator {
|
|||||||
/**
|
/**
|
||||||
* Sort mod slots into an ordering that maximises chance of a successful weapon generation
|
* Sort mod slots into an ordering that maximises chance of a successful weapon generation
|
||||||
* @param unsortedSlotKeys Array of mod slot strings to sort
|
* @param unsortedSlotKeys Array of mod slot strings to sort
|
||||||
|
* @param itemTplWithKeysToSort The Tpl of the item with mod keys being sorted
|
||||||
* @returns Sorted array
|
* @returns Sorted array
|
||||||
*/
|
*/
|
||||||
protected sortModKeys(unsortedSlotKeys: string[]): string[] {
|
protected sortModKeys(unsortedSlotKeys: string[], itemTplWithKeysToSort: string): string[] {
|
||||||
// No need to sort with only 1 item in array
|
// No need to sort with only 1 item in array
|
||||||
if (unsortedSlotKeys.length <= 1) {
|
if (unsortedSlotKeys.length <= 1) {
|
||||||
return unsortedSlotKeys;
|
return unsortedSlotKeys;
|
||||||
}
|
}
|
||||||
|
const isMount = this.itemHelper.isOfBaseclass(itemTplWithKeysToSort, BaseClasses.MOUNT);
|
||||||
|
|
||||||
const sortedKeys: string[] = [];
|
const sortedKeys: string[] = [];
|
||||||
const modRecieverKey = "mod_reciever";
|
const modRecieverKey = "mod_reciever";
|
||||||
@ -683,50 +685,69 @@ export class BotEquipmentModGenerator {
|
|||||||
const modHandguardKey = "mod_handguard";
|
const modHandguardKey = "mod_handguard";
|
||||||
const modMountKey = "mod_mount";
|
const modMountKey = "mod_mount";
|
||||||
const modScopeKey = "mod_scope";
|
const modScopeKey = "mod_scope";
|
||||||
|
const modScope000Key = "mod_scope_000";
|
||||||
|
|
||||||
if (unsortedSlotKeys.includes(modHandguardKey)) {
|
// Mounts are a special case, they need scopes first before more mounts
|
||||||
sortedKeys.push(modHandguardKey);
|
if (isMount) {
|
||||||
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modHandguardKey), 1);
|
if (unsortedSlotKeys.includes(modScope000Key)) {
|
||||||
}
|
sortedKeys.push(modScope000Key);
|
||||||
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modScope000Key), 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (unsortedSlotKeys.includes(modBarrelKey)) {
|
if (unsortedSlotKeys.includes(modScopeKey)) {
|
||||||
sortedKeys.push(modBarrelKey);
|
sortedKeys.push(modScopeKey);
|
||||||
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modBarrelKey), 1);
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modScopeKey), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unsortedSlotKeys.includes(modMount001Key)) {
|
if (unsortedSlotKeys.includes(modMountKey)) {
|
||||||
sortedKeys.push(modMount001Key);
|
sortedKeys.push(modMountKey);
|
||||||
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modMount001Key), 1);
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modMountKey), 1);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (unsortedSlotKeys.includes(modHandguardKey)) {
|
||||||
|
sortedKeys.push(modHandguardKey);
|
||||||
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modHandguardKey), 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (unsortedSlotKeys.includes(modRecieverKey)) {
|
if (unsortedSlotKeys.includes(modBarrelKey)) {
|
||||||
sortedKeys.push(modRecieverKey);
|
sortedKeys.push(modBarrelKey);
|
||||||
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modRecieverKey), 1);
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modBarrelKey), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unsortedSlotKeys.includes(modPistolGrip)) {
|
if (unsortedSlotKeys.includes(modMount001Key)) {
|
||||||
sortedKeys.push(modPistolGrip);
|
sortedKeys.push(modMount001Key);
|
||||||
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modPistolGrip), 1);
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modMount001Key), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unsortedSlotKeys.includes(modGasBlockKey)) {
|
if (unsortedSlotKeys.includes(modRecieverKey)) {
|
||||||
sortedKeys.push(modGasBlockKey);
|
sortedKeys.push(modRecieverKey);
|
||||||
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modGasBlockKey), 1);
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modRecieverKey), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unsortedSlotKeys.includes(modStockKey)) {
|
if (unsortedSlotKeys.includes(modPistolGrip)) {
|
||||||
sortedKeys.push(modStockKey);
|
sortedKeys.push(modPistolGrip);
|
||||||
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modStockKey), 1);
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modPistolGrip), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unsortedSlotKeys.includes(modMountKey)) {
|
if (unsortedSlotKeys.includes(modGasBlockKey)) {
|
||||||
sortedKeys.push(modMountKey);
|
sortedKeys.push(modGasBlockKey);
|
||||||
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modMountKey), 1);
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modGasBlockKey), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unsortedSlotKeys.includes(modScopeKey)) {
|
if (unsortedSlotKeys.includes(modStockKey)) {
|
||||||
sortedKeys.push(modScopeKey);
|
sortedKeys.push(modStockKey);
|
||||||
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modScopeKey), 1);
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modStockKey), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unsortedSlotKeys.includes(modMountKey)) {
|
||||||
|
sortedKeys.push(modMountKey);
|
||||||
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modMountKey), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unsortedSlotKeys.includes(modScopeKey)) {
|
||||||
|
sortedKeys.push(modScopeKey);
|
||||||
|
unsortedSlotKeys.splice(unsortedSlotKeys.indexOf(modScopeKey), 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sortedKeys.push(...unsortedSlotKeys);
|
sortedKeys.push(...unsortedSlotKeys);
|
||||||
|
@ -118,7 +118,7 @@ export class BotWeaponModLimitService {
|
|||||||
// Mount has one slot and its for a mod_scope
|
// Mount has one slot and its for a mod_scope
|
||||||
if (
|
if (
|
||||||
modLimits.scope.count >= modLimits.scopeMax &&
|
modLimits.scope.count >= modLimits.scopeMax &&
|
||||||
modTemplate._props.Slots.length === 1 &&
|
modTemplate._props.Slots?.length === 1 &&
|
||||||
this.itemHelper.isOfBaseclass(modTemplate._id, BaseClasses.MOUNT) &&
|
this.itemHelper.isOfBaseclass(modTemplate._id, BaseClasses.MOUNT) &&
|
||||||
!this.itemHelper.isOfBaseclass(modsParent._id, BaseClasses.MOUNT) &&
|
!this.itemHelper.isOfBaseclass(modsParent._id, BaseClasses.MOUNT) &&
|
||||||
modTemplate._props.Slots.some((slot) => slot._name === "mod_scope")
|
modTemplate._props.Slots.some((slot) => slot._name === "mod_scope")
|
||||||
@ -140,7 +140,7 @@ export class BotWeaponModLimitService {
|
|||||||
// Mod is a mount that can hold only flashlights ad limit is reached (dont want to add empty mounts if limit is reached)
|
// Mod is a mount that can hold only flashlights ad limit is reached (dont want to add empty mounts if limit is reached)
|
||||||
if (
|
if (
|
||||||
modLimits.scope.count >= modLimits.scopeMax &&
|
modLimits.scope.count >= modLimits.scopeMax &&
|
||||||
modTemplate._props.Slots.length === 1 &&
|
modTemplate._props.Slots?.length === 1 &&
|
||||||
this.itemHelper.isOfBaseclass(modTemplate._id, BaseClasses.MOUNT) &&
|
this.itemHelper.isOfBaseclass(modTemplate._id, BaseClasses.MOUNT) &&
|
||||||
modTemplate._props.Slots.some((slot) => slot._name === "mod_flashlight")
|
modTemplate._props.Slots.some((slot) => slot._name === "mod_flashlight")
|
||||||
) {
|
) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user