feat: claimJunctionChallengeReward (#2289)
Closes #2285 Reviewed-on: OpenWF/SpaceNinjaServer#2289 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									b42182c85f
								
							
						
					
					
						commit
						c9edef39f8
					
				
							
								
								
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -22,7 +22,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",
 | 
			
		||||
@ -3388,9 +3388,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",
 | 
			
		||||
 | 
			
		||||
@ -36,7 +36,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",
 | 
			
		||||
 | 
			
		||||
@ -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<IClaimJunctionChallengeRewardRequest>(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;
 | 
			
		||||
}
 | 
			
		||||
@ -483,8 +483,9 @@ personalGoalProgressSchema.set("toJSON", {
 | 
			
		||||
const challengeProgressSchema = new Schema<IChallengeProgress>(
 | 
			
		||||
    {
 | 
			
		||||
        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<IInventoryDatabase, InventoryDocumentProps>(
 | 
			
		||||
        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 } }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
@ -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?)
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user