From 7a7a664c28b6d6d385aae223fc55a953c182ac3e Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Wed, 25 Jun 2025 22:24:28 +0200 Subject: [PATCH] feat: claimJunctionChallengeReward --- package-lock.json | 8 ++--- package.json | 2 +- .../claimJunctionChallengeRewardController.ts | 35 +++++++++++++++++++ src/models/inventoryModels/inventoryModel.ts | 9 +++-- src/routes/api.ts | 2 ++ src/types/inventoryTypes/inventoryTypes.ts | 4 ++- 6 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 src/controllers/api/claimJunctionChallengeRewardController.ts diff --git a/package-lock.json b/package-lock.json index 70184b5e..95e79ce3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "ncp": "^2.0.0", "typescript": "^5.5", "undici": "^7.10.0", - "warframe-public-export-plus": "^0.5.70", + "warframe-public-export-plus": "^0.5.71", "warframe-riven-info": "^0.1.2", "winston": "^3.17.0", "winston-daily-rotate-file": "^5.0.0", @@ -3396,9 +3396,9 @@ } }, "node_modules/warframe-public-export-plus": { - "version": "0.5.70", - "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.70.tgz", - "integrity": "sha512-d5dQ/a0rakQnW9tl1HitST8439jDvEgMhkkntQIw7HmdM7s7mvIxvaYSl5wjlYawpUVfGyvGBdZVoAJ7kkQRWw==" + "version": "0.5.71", + "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.71.tgz", + "integrity": "sha512-TCS2wPRsBzuURJlIMDhygAHaLsKVZ7dGuC73WZ/iMyn3gKVwA98nnaIj24D+UceWS08fwq4ilWAfUzHJd6X29A==" }, "node_modules/warframe-riven-info": { "version": "0.1.2", diff --git a/package.json b/package.json index 063cd966..5c59233d 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "ncp": "^2.0.0", "typescript": "^5.5", "undici": "^7.10.0", - "warframe-public-export-plus": "^0.5.70", + "warframe-public-export-plus": "^0.5.71", "warframe-riven-info": "^0.1.2", "winston": "^3.17.0", "winston-daily-rotate-file": "^5.0.0", diff --git a/src/controllers/api/claimJunctionChallengeRewardController.ts b/src/controllers/api/claimJunctionChallengeRewardController.ts new file mode 100644 index 00000000..849126cb --- /dev/null +++ b/src/controllers/api/claimJunctionChallengeRewardController.ts @@ -0,0 +1,35 @@ +import { getJSONfromString } from "@/src/helpers/stringHelpers"; +import { combineInventoryChanges, getInventory } from "@/src/services/inventoryService"; +import { getAccountIdForRequest } from "@/src/services/loginService"; +import { handleStoreItemAcquisition } from "@/src/services/purchaseService"; +import { RequestHandler } from "express"; +import { ExportChallenges } from "warframe-public-export-plus"; + +export const claimJunctionChallengeRewardController: RequestHandler = async (req, res) => { + const accountId = await getAccountIdForRequest(req); + const inventory = await getInventory(accountId); + const data = getJSONfromString(String(req.body)); + const challengeProgress = inventory.ChallengeProgress.find(x => x.Name == data.Challenge)!; + if (challengeProgress.ReceivedJunctionReward) { + throw new Error(`attempt to double-claim junction reward`); + } + challengeProgress.ReceivedJunctionReward = true; + inventory.ClaimedJunctionChallengeRewards ??= []; + inventory.ClaimedJunctionChallengeRewards.push(data.Challenge); + const challengeMeta = Object.entries(ExportChallenges).find(arr => arr[0].endsWith("/" + data.Challenge))![1]; + const inventoryChanges = {}; + for (const reward of challengeMeta.countedRewards!) { + combineInventoryChanges( + inventoryChanges, + (await handleStoreItemAcquisition(reward.StoreItem, inventory, reward.ItemCount)).InventoryChanges + ); + } + await inventory.save(); + res.json({ + inventoryChanges: inventoryChanges // Yeah, it's "inventoryChanges" in the response here. + }); +}; + +interface IClaimJunctionChallengeRewardRequest { + Challenge: string; +} diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index 9b91c7ca..cd597bb4 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -483,8 +483,9 @@ personalGoalProgressSchema.set("toJSON", { const challengeProgressSchema = new Schema( { Progress: Number, - Name: String, - Completed: [String] + Completed: { type: [String], default: undefined }, + ReceivedJunctionReward: Boolean, + Name: { type: String, required: true } }, { _id: false } ); @@ -1777,7 +1778,9 @@ const inventorySchema = new Schema( BrandedSuits: { type: [Schema.Types.ObjectId], default: undefined }, LockedWeaponGroup: { type: lockedWeaponGroupSchema, default: undefined }, - HubNpcCustomizations: { type: [hubNpcCustomizationSchema], default: undefined } + HubNpcCustomizations: { type: [hubNpcCustomizationSchema], default: undefined }, + + ClaimedJunctionChallengeRewards: { type: [String], default: undefined } }, { timestamps: { createdAt: "Created", updatedAt: false } } ); diff --git a/src/routes/api.ts b/src/routes/api.ts index 63df81d0..2a3255cf 100644 --- a/src/routes/api.ts +++ b/src/routes/api.ts @@ -19,6 +19,7 @@ import { changeDojoRootController } from "@/src/controllers/api/changeDojoRootCo import { changeGuildRankController } from "@/src/controllers/api/changeGuildRankController"; import { checkDailyMissionBonusController } from "@/src/controllers/api/checkDailyMissionBonusController"; import { claimCompletedRecipeController } from "@/src/controllers/api/claimCompletedRecipeController"; +import { claimJunctionChallengeRewardController } from "@/src/controllers/api/claimJunctionChallengeRewardController"; import { claimLibraryDailyTaskRewardController } from "@/src/controllers/api/claimLibraryDailyTaskRewardController"; import { clearDialogueHistoryController } from "@/src/controllers/api/clearDialogueHistoryController"; import { clearNewEpisodeRewardController } from "@/src/controllers/api/clearNewEpisodeRewardController"; @@ -237,6 +238,7 @@ apiRouter.post("/artifacts.php", artifactsController); apiRouter.post("/artifactTransmutation.php", artifactTransmutationController); apiRouter.post("/changeDojoRoot.php", changeDojoRootController); apiRouter.post("/claimCompletedRecipe.php", claimCompletedRecipeController); +apiRouter.post("/claimJunctionChallengeReward.php", claimJunctionChallengeRewardController); apiRouter.post("/clearDialogueHistory.php", clearDialogueHistoryController); apiRouter.post("/clearNewEpisodeReward.php", clearNewEpisodeRewardController); apiRouter.post("/commitStoryModeDecision.php", (_req, res) => { res.end(); }); // U14 (maybe wanna actually unlock the ship features?) diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index 30aced6b..4c4a9821 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -380,6 +380,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu LockedWeaponGroup?: ILockedWeaponGroupClient; HubNpcCustomizations?: IHubNpcCustomization[]; Ship?: IOrbiter; // U22 and below, response only + ClaimedJunctionChallengeRewards?: string[]; // U39 } export interface IAffiliation { @@ -448,8 +449,9 @@ export interface IVendorPurchaseHistoryEntryDatabase { export interface IChallengeProgress { Progress: number; - Name: string; Completed?: string[]; + ReceivedJunctionReward?: boolean; // U39 + Name: string; } export interface ICollectibleEntry { -- 2.47.2