Fix issue with armors as quest rewards not being sent with soft inserts

Centralised a soft insert check into `ItemHelper`

Add extra base types to `generateGearPool()` in equipment bot pool service
This commit is contained in:
Dev 2024-01-09 16:49:59 +00:00
parent 68f3ee013c
commit a9c36ec205
6 changed files with 28 additions and 6 deletions

View File

@ -344,7 +344,7 @@ export class BotLootGenerator
this.randomiseAmmoStackSize(isPmc, itemToAddTemplate, itemsToAdd[0]); this.randomiseAmmoStackSize(isPmc, itemToAddTemplate, itemsToAdd[0]);
} }
// Must add soft inserts/plates // Must add soft inserts/plates
else if (this.itemHelper.isOfBaseclasses(itemToAddTemplate._id, [BaseClasses.ARMOR, BaseClasses.HEADWEAR, BaseClasses.VEST])) else if (this.itemHelper.itemCanRequireArmorInserts(itemToAddTemplate._id))
{ {
itemsToAdd = this.itemHelper.addChildSlotItems(itemsToAdd, itemToAddTemplate, null, true); itemsToAdd = this.itemHelper.addChildSlotItems(itemsToAdd, itemToAddTemplate, null, true);
} }

View File

@ -861,7 +861,7 @@ export class LocationGenerator
); );
itemWithMods.push(...magazineItem); itemWithMods.push(...magazineItem);
} }
else if (this.itemHelper.isOfBaseclasses(chosenTpl, [BaseClasses.VEST, BaseClasses.ARMOR, BaseClasses.HEADWEAR])) else if (this.itemHelper.itemCanRequireArmorInserts(chosenTpl))
{ {
itemWithMods.push({ itemWithMods.push({
_id: this.objectId.generate(), _id: this.objectId.generate(),
@ -1071,7 +1071,7 @@ export class LocationGenerator
// Replace existing magazine with above array // Replace existing magazine with above array
items.splice(items.indexOf(items[0]), 1, ...magazineWithCartridges); items.splice(items.indexOf(items[0]), 1, ...magazineWithCartridges);
} }
else if (this.itemHelper.isOfBaseclasses(chosenTpl, [BaseClasses.VEST, BaseClasses.ARMOR, BaseClasses.HEADWEAR])) else if (this.itemHelper.itemCanRequireArmorInserts(chosenTpl))
{ {
if (itemTemplate._props.Slots?.length > 0) if (itemTemplate._props.Slots?.length > 0)
{ {

View File

@ -98,6 +98,18 @@ export class ItemHelper
return this.itemBaseClassService.itemHasBaseClass(tpl, baseClassTpls); return this.itemBaseClassService.itemHasBaseClass(tpl, baseClassTpls);
} }
/**
* Does the provided item have the chance to require soft armor inserts
* Only applies to helmets/vest/armors.
* Not all head gear needs them
* @param itemTpl item to check
* @returns Does item have the possibility ot need soft inserts
*/
public itemCanRequireArmorInserts(itemTpl: string): boolean
{
return this.isOfBaseclasses(itemTpl, [BaseClasses.HEADWEAR, BaseClasses.VEST, BaseClasses.ARMOR]);
}
/** /**
* Returns the item price based on the handbook or as a fallback from the prices.json if the item is not * Returns the item price based on the handbook or as a fallback from the prices.json if the item is not
* found in the handbook. If the price can't be found at all return 0 * found in the handbook. If the price can't be found at all return 0

View File

@ -14,6 +14,7 @@ import { IQuest, IQuestCondition, IQuestReward } from "@spt-aki/models/eft/commo
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse"; import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
import { IAcceptQuestRequestData } from "@spt-aki/models/eft/quests/IAcceptQuestRequestData"; import { IAcceptQuestRequestData } from "@spt-aki/models/eft/quests/IAcceptQuestRequestData";
import { IFailQuestRequestData } from "@spt-aki/models/eft/quests/IFailQuestRequestData"; import { IFailQuestRequestData } from "@spt-aki/models/eft/quests/IFailQuestRequestData";
import { BaseClasses } from "@spt-aki/models/enums/BaseClasses";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { MessageType } from "@spt-aki/models/enums/MessageType"; import { MessageType } from "@spt-aki/models/enums/MessageType";
import { QuestRewardType } from "@spt-aki/models/enums/QuestRewardType"; import { QuestRewardType } from "@spt-aki/models/enums/QuestRewardType";
@ -262,6 +263,15 @@ export class QuestHelper
let rewardItems: Item[] = []; let rewardItems: Item[] = [];
let targets: Item[] = []; let targets: Item[] = [];
const mods: Item[] = []; const mods: Item[] = [];
const rootItem = questReward.items[0];
// Is armor item that needs inserts
if (questReward.items.length === 1 && this.itemHelper.itemCanRequireArmorInserts(rootItem._tpl))
{
// Add required child mods only to the reward array before being processed below
const itemDbData = this.itemHelper.getItem(rootItem._tpl)[1];
questReward.items = this.itemHelper.addChildSlotItems(questReward.items, itemDbData, null, true);
}
for (const item of questReward.items) for (const item of questReward.items)
{ {
@ -273,7 +283,7 @@ export class QuestHelper
item.upd.SpawnedInSession = true; item.upd.SpawnedInSession = true;
// separate base item and mods, fix stacks // Separate base item and mods, fix stacks
if (item._id === questReward.target) if (item._id === questReward.target)
{ {
if ( if (

View File

@ -201,7 +201,7 @@ export class BotEquipmentModPoolService
protected generateGearPool(): void protected generateGearPool(): void
{ {
const gear = Object.values(this.databaseServer.getTables().templates.items).filter((x) => const gear = Object.values(this.databaseServer.getTables().templates.items).filter((x) =>
x._type === "Item" && this.itemHelper.isOfBaseclasses(x._id, [BaseClasses.ARMORED_EQUIPMENT, BaseClasses.VEST]) x._type === "Item" && this.itemHelper.isOfBaseclasses(x._id, [BaseClasses.ARMORED_EQUIPMENT, BaseClasses.VEST, BaseClasses.ARMOR, BaseClasses.HEADWEAR])
); );
this.generatePool(gear, "gear"); this.generatePool(gear, "gear");

View File

@ -481,7 +481,7 @@ export class FenceService
rootItemToPush.upd.UnlimitedCount = false; rootItemToPush.upd.UnlimitedCount = false;
// Need to add mods to armors so they dont show as red in the trade screen // Need to add mods to armors so they dont show as red in the trade screen
if (this.itemHelper.isOfBaseclasses(rootItemToPush._tpl, [BaseClasses.HEADWEAR, BaseClasses.VEST, BaseClasses.ARMOR])) if (this.itemHelper.itemCanRequireArmorInserts(rootItemToPush._tpl))
{ {
this.addModsToArmorModSlots(itemsToPush, itemDbDetails); this.addModsToArmorModSlots(itemsToPush, itemDbDetails);
} }