Skip to content

Commit

Permalink
Fixed quest reward errors on quest completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Chomp committed Jan 7, 2025
1 parent 145551c commit ed6f645
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
27 changes: 4 additions & 23 deletions project/src/helpers/QuestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
);
}
}
Expand Down
49 changes: 45 additions & 4 deletions project/src/helpers/QuestRewardHelper.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ed6f645

Please sign in to comment.