Improve armor quest rewards

Attempt to return the armor preset found in globals.json first as this has default plates, if that fails construct item outselves based on mods _requried properties
This commit is contained in:
Dev 2024-01-10 10:04:09 +00:00
parent 55eae60329
commit 297bc2786a
2 changed files with 41 additions and 12 deletions

View File

@ -71,8 +71,8 @@ export class PresetHelper
} }
/** /**
* Get the default preset for passed in weapon id * Get the default preset for passed in item id
* @param templateId Weapon id to get preset for * @param templateId Item id to get preset for
* @returns Null if no default preset, otherwise IPreset * @returns Null if no default preset, otherwise IPreset
*/ */
public getDefaultPreset(templateId: string): IPreset public getDefaultPreset(templateId: string): IPreset

View File

@ -3,6 +3,7 @@ import { inject, injectable } from "tsyringe";
import { DialogueHelper } from "@spt-aki/helpers/DialogueHelper"; import { DialogueHelper } from "@spt-aki/helpers/DialogueHelper";
import { ItemHelper } from "@spt-aki/helpers/ItemHelper"; import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
import { PaymentHelper } from "@spt-aki/helpers/PaymentHelper"; import { PaymentHelper } from "@spt-aki/helpers/PaymentHelper";
import { PresetHelper } from "@spt-aki/helpers/PresetHelper";
import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper"; import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper";
import { QuestConditionHelper } from "@spt-aki/helpers/QuestConditionHelper"; import { QuestConditionHelper } from "@spt-aki/helpers/QuestConditionHelper";
import { RagfairServerHelper } from "@spt-aki/helpers/RagfairServerHelper"; import { RagfairServerHelper } from "@spt-aki/helpers/RagfairServerHelper";
@ -14,7 +15,6 @@ 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";
@ -53,6 +53,7 @@ export class QuestHelper
@inject("PaymentHelper") protected paymentHelper: PaymentHelper, @inject("PaymentHelper") protected paymentHelper: PaymentHelper,
@inject("LocalisationService") protected localisationService: LocalisationService, @inject("LocalisationService") protected localisationService: LocalisationService,
@inject("TraderHelper") protected traderHelper: TraderHelper, @inject("TraderHelper") protected traderHelper: TraderHelper,
@inject("PresetHelper") protected presetHelper: PresetHelper,
@inject("MailSendService") protected mailSendService: MailSendService, @inject("MailSendService") protected mailSendService: MailSendService,
@inject("ConfigServer") protected configServer: ConfigServer, @inject("ConfigServer") protected configServer: ConfigServer,
) )
@ -260,17 +261,17 @@ export class QuestHelper
*/ */
protected processReward(questReward: IQuestReward): Item[] protected processReward(questReward: IQuestReward): Item[]
{ {
/** item with mods to return */
let rewardItems: Item[] = []; let rewardItems: Item[] = [];
let targets: Item[] = []; let targets: Item[] = [];
const mods: Item[] = []; const mods: Item[] = [];
const rootItem = questReward.items[0]; const rootItem = questReward.items[0];
// Is armor item that needs inserts // Is armor item that needs inserts / plates
if (questReward.items.length === 1 && this.itemHelper.itemCanRequireArmorInserts(rootItem._tpl)) if (questReward.items.length === 1 && this.itemHelper.itemCanRequireArmorInserts(rootItem._tpl))
{ {
// Add required child mods only to the reward array before being processed below // Attempt to pull default preset from globals and add child items to reward
const itemDbData = this.itemHelper.getItem(rootItem._tpl)[1]; this.generateArmorRewardChildSlots(rootItem, questReward);
questReward.items = this.itemHelper.addChildSlotItems(questReward.items, itemDbData, null, true);
} }
for (const item of questReward.items) for (const item of questReward.items)
@ -283,13 +284,13 @@ export class QuestHelper
item.upd.SpawnedInSession = true; item.upd.SpawnedInSession = true;
// Separate base item and mods, fix stacks // Separate base item from mods, fix stacks
if (item._id === questReward.target) if (item._id === questReward.target) // Is base reward item
{ {
if ( if (
(item.parentId !== undefined) && (item.parentId === "hideout") (item.parentId !== undefined) && (item.parentId === "hideout") // Has parentId of hideout
&& (item.upd !== undefined) && (item.upd.StackObjectsCount !== undefined) && (item.upd !== undefined) && (item.upd.StackObjectsCount !== undefined) // Has upd with stackobject count
&& (item.upd.StackObjectsCount > 1) && (item.upd.StackObjectsCount > 1) // More than 1 item in stack
) )
{ {
item.upd.StackObjectsCount = 1; item.upd.StackObjectsCount = 1;
@ -304,6 +305,7 @@ export class QuestHelper
} }
else else
{ {
// Is child mod
mods.push(item); mods.push(item);
} }
} }
@ -327,6 +329,33 @@ export class QuestHelper
return rewardItems; return rewardItems;
} }
/**
* Add missing mod items to a quest armor reward
* @param originalRewardRootItem Original armor reward item from IQuestReward.items object
* @param questReward Armor reward from quest
*/
protected generateArmorRewardChildSlots(originalRewardRootItem: Item, questReward: IQuestReward): void
{
// Look for a default preset from globals for armor
const defaultPreset = this.presetHelper.getDefaultPreset(originalRewardRootItem._tpl);
if (defaultPreset)
{
// Preset exists, use mods to hydrate reward item
questReward.items = this.jsonUtil.clone(defaultPreset._items);
// Remap target id to the new presets id
questReward.target = questReward.items.find(item => item._tpl === originalRewardRootItem._tpl)._id;
return;
}
this.logger.warning(`Unable to find default preset for armor ${originalRewardRootItem._tpl}, adding mods manually`);
const itemDbData = this.itemHelper.getItem(originalRewardRootItem._tpl)[1];
// Hydrate reward with only 'required' mods - necessary for things like helmets otherwise you end up with nvgs/visors etc
questReward.items = this.itemHelper.addChildSlotItems(questReward.items, itemDbData, null, true);
}
/** /**
* Gets a flat list of reward items for the given quest at a specific state (e.g. Fail/Success) * Gets a flat list of reward items for the given quest at a specific state (e.g. Fail/Success)
* @param quest quest to get rewards for * @param quest quest to get rewards for