0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00

Fixed quest reward errors on quest completion

This commit is contained in:
Chomp 2025-01-07 22:37:41 +00:00
parent 145551cf5e
commit ed6f645d93
2 changed files with 49 additions and 27 deletions

View File

@ -2,6 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { PresetHelper } from "@spt/helpers/PresetHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { QuestConditionHelper } from "@spt/helpers/QuestConditionHelper";
import { QuestRewardHelper } from "@spt/helpers/QuestRewardHelper";
import { TraderHelper } from "@spt/helpers/TraderHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Common, IQuestStatus } from "@spt/models/eft/common/tables/IBotBase";
@ -44,6 +45,7 @@ export class QuestHelper {
@inject("EventOutputHolder") protected eventOutputHolder: EventOutputHolder,
@inject("LocaleService") protected localeService: LocaleService,
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
@inject("QuestRewardHelper") protected questRewardHelper: QuestRewardHelper,
@inject("LocalisationService") protected localisationService: LocalisationService,
@inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService,
@inject("TraderHelper") protected traderHelper: TraderHelper,
@ -705,7 +707,7 @@ export class QuestHelper {
}
this.updateQuestState(pmcData, QuestStatus.Fail, failRequest.qid);
const questRewards = this.applyQuestReward(
const questRewards = this.questRewardHelper.applyQuestReward(
pmcData,
failRequest.qid,
QuestStatus.Fail,
@ -847,27 +849,6 @@ export class QuestHelper {
}
}
/**
* Does the provided quest reward have a game version requirement to be given and does it match
* @param reward Reward to check
* @param gameVersion Version of game to check reward against
* @returns True if it has requirement, false if it doesnt pass check
*/
public questRewardIsForGameEdition(reward: IQuestReward, gameVersion: string) {
if (reward.availableInGameEditions?.length > 0 && !reward.availableInGameEditions?.includes(gameVersion)) {
// Reward has edition whitelist and game version isnt in it
return false;
}
if (reward.notAvailableInGameEditions?.length > 0 && reward.notAvailableInGameEditions?.includes(gameVersion)) {
// Reward has edition blacklist and game version is in it
return false;
}
// No whitelist/blacklist or reward isnt blacklisted/whitelisted
return true;
}
/**
* Find quest with 'findItem' condition that needs the item tpl be handed in
* @param itemTpl item tpl to look for
@ -1182,7 +1163,7 @@ export class QuestHelper {
// Remove any reward that doesn't pass the game edition check
for (const rewardType of Object.keys(quest.rewards)) {
quest.rewards[rewardType] = quest.rewards[rewardType].filter((reward) =>
this.questRewardIsForGameEdition(reward, gameVersion),
this.questRewardHelper.questRewardIsForGameEdition(reward, gameVersion),
);
}
}

View File

@ -1,7 +1,6 @@
import { ItemHelper } from "@spt/helpers/ItemHelper";
import { PaymentHelper } from "@spt/helpers/PaymentHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { QuestHelper } from "@spt/helpers/QuestHelper";
import { TraderHelper } from "@spt/helpers/TraderHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { IItem } from "@spt/models/eft/common/tables/IItem";
@ -25,7 +24,6 @@ export class QuestRewardHelper {
@inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("DatabaseService") protected databaseService: DatabaseService,
@inject("EventOutputHolder") protected eventOutputHolder: EventOutputHolder,
@inject("QuestHelper") protected questHelper: QuestHelper,
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
@inject("PaymentHelper") protected paymentHelper: PaymentHelper,
@inject("LocalisationService") protected localisationService: LocalisationService,
@ -58,7 +56,7 @@ export class QuestRewardHelper {
return [];
}
let questDetails = this.questHelper.getQuestFromDb(questId, pmcProfile);
let questDetails = this.getQuestFromDb(questId, pmcProfile);
if (!questDetails) {
this.logger.warning(
this.localisationService.getText("quest-unable_to_find_quest_in_db_no_quest_rewards", questId),
@ -79,7 +77,7 @@ export class QuestRewardHelper {
const gameVersion = pmcProfile.Info.GameVersion;
for (const reward of <IQuestReward[]>questDetails.rewards[questStateAsString]) {
// Handle quest reward availability for different game versions, notAvailableInGameEditions currently not used
if (!this.questHelper.questRewardIsForGameEdition(reward, gameVersion)) {
if (!this.questRewardIsForGameEdition(reward, gameVersion)) {
continue;
}
@ -146,6 +144,49 @@ export class QuestRewardHelper {
return this.getQuestRewardItems(questDetails, state, gameVersion);
}
/**
* Does the provided quest reward have a game version requirement to be given and does it match
* @param reward Reward to check
* @param gameVersion Version of game to check reward against
* @returns True if it has requirement, false if it doesnt pass check
*/
public questRewardIsForGameEdition(reward: IQuestReward, gameVersion: string) {
if (reward.availableInGameEditions?.length > 0 && !reward.availableInGameEditions?.includes(gameVersion)) {
// Reward has edition whitelist and game version isnt in it
return false;
}
if (reward.notAvailableInGameEditions?.length > 0 && reward.notAvailableInGameEditions?.includes(gameVersion)) {
// Reward has edition blacklist and game version is in it
return false;
}
// No whitelist/blacklist or reward isnt blacklisted/whitelisted
return true;
}
/**
* Get quest by id from database (repeatables are stored in profile, check there if questId not found)
* @param questId Id of quest to find
* @param pmcData Player profile
* @returns IQuest object
*/
protected getQuestFromDb(questId: string, pmcData: IPmcData): IQuest {
// May be a repeatable quest
let quest = this.databaseService.getQuests()[questId];
if (!quest) {
// Check daily/weekly objects
for (const repeatableType of pmcData.RepeatableQuests) {
quest = <IQuest>(<unknown>repeatableType.activeQuests.find((repeatable) => repeatable._id === questId));
if (quest) {
break;
}
}
}
return quest;
}
/**
* Get players money reward bonus from profile
* @param pmcData player profile