Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import type { Quest } from "@spt-aki/models/eft/common/IPmcData";
- import type { IAkiProfile } from "@spt-aki/models/eft/profile/IAkiProfile";
- /**
- * Some generic utils
- */
- const indexBy =
- <T>(getId: (q: T) => string) =>
- (quests: T[]) => {
- const indexedQuests: Record<string, T> = {};
- quests.forEach((q) => {
- indexedQuests[getId(q)] = q;
- });
- return indexedQuests;
- };
- const indexQuestsById = indexBy<Quest>((q) => q.qid);
- const indexIds = indexBy<string>((id) => id);
- /**
- * A helper (curried) function that create a started quest status
- */
- const createStartedQuestStatus = (startTime: number) => (qid: string) => {
- return {
- qid,
- startTime,
- status: "Started",
- completeConditions: [],
- };
- };
- /**
- * This should work fine but I suggest to avoid applying this systematically on all profiles (on the delayedLoad).
- * Prefer hack the gameStart method on GameCallbacks instance to only apply this on the concerned profile.
- */
- const autoAcceptQuests = (
- profile: IAkiProfile,
- questIdsToAccept: string[]
- ): void => {
- const pmc = profile.characters.pmc;
- if (pmc && pmc.Quests) {
- const indexedProfileQuests = indexQuestsById(pmc.Quests);
- const indexedIdsToAccept = indexIds(questIdsToAccept);
- const timeInSeconds = Math.floor(Date.now() / 1000);
- // when not found: create new quests status
- const newQuestsStatus = questIdsToAccept
- .filter((qid) => !indexedProfileQuests[qid])
- .map(createStartedQuestStatus(timeInSeconds));
- // all quests we want to auto-accept may have the `AvailableForStart` status, so we replace it by a new `Started` quest status
- const updatedQuestsStatus = pmc.Quests.map((q) => {
- if (indexedIdsToAccept[q.qid] && q.status === "AvailableForStart") {
- return createStartedQuestStatus(timeInSeconds)(q.qid);
- }
- return q;
- });
- pmc.Quests = [...updatedQuestsStatus, ...newQuestsStatus];
- }
- };
Add Comment
Please, Sign In to add comment