forked from OpenWF/SpaceNinjaServer
		
	chore: handle season challenge completion in missionInventoryUpdate (#1511)
Reviewed-on: OpenWF/SpaceNinjaServer#1511 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
							
								
									ef4973e694
								
							
						
					
					
						commit
						39be095818
					
				@ -1,10 +1,8 @@
 | 
				
			|||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
					import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { addChallenges, addSeasonalChallengeHistory, getInventory } from "@/src/services/inventoryService";
 | 
					import { addChallenges, getInventory } from "@/src/services/inventoryService";
 | 
				
			||||||
import { IChallengeProgress, ISeasonChallenge } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { IChallengeProgress, ISeasonChallenge } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { ExportNightwave } from "warframe-public-export-plus";
 | 
					 | 
				
			||||||
import { logger } from "@/src/utils/logger";
 | 
					 | 
				
			||||||
import { IAffiliationMods } from "@/src/types/purchaseTypes";
 | 
					import { IAffiliationMods } from "@/src/types/purchaseTypes";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const updateChallengeProgressController: RequestHandler = async (req, res) => {
 | 
					export const updateChallengeProgressController: RequestHandler = async (req, res) => {
 | 
				
			||||||
@ -12,41 +10,19 @@ export const updateChallengeProgressController: RequestHandler = async (req, res
 | 
				
			|||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory Affiliations");
 | 
					    const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory Affiliations");
 | 
				
			||||||
 | 
					    let affiliationMods: IAffiliationMods[] = [];
 | 
				
			||||||
    if (challenges.ChallengeProgress) {
 | 
					    if (challenges.ChallengeProgress) {
 | 
				
			||||||
        addChallenges(inventory, challenges.ChallengeProgress);
 | 
					        affiliationMods = addChallenges(inventory, challenges.ChallengeProgress, challenges.SeasonChallengeCompletions);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (challenges.SeasonChallengeHistory) {
 | 
					    if (challenges.SeasonChallengeHistory) {
 | 
				
			||||||
        addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory);
 | 
					        challenges.SeasonChallengeHistory.forEach(({ challenge, id }) => {
 | 
				
			||||||
    }
 | 
					            const itemIndex = inventory.SeasonChallengeHistory.findIndex(i => i.challenge === challenge);
 | 
				
			||||||
    const affiliationMods: IAffiliationMods[] = [];
 | 
					            if (itemIndex !== -1) {
 | 
				
			||||||
    if (challenges.ChallengeProgress && challenges.SeasonChallengeCompletions) {
 | 
					                inventory.SeasonChallengeHistory[itemIndex].id = id;
 | 
				
			||||||
        for (const challenge of challenges.SeasonChallengeCompletions) {
 | 
					            } else {
 | 
				
			||||||
            // Ignore challenges that weren't completed just now
 | 
					                inventory.SeasonChallengeHistory.push({ challenge, id });
 | 
				
			||||||
            if (!challenges.ChallengeProgress.find(x => challenge.challenge.indexOf(x.Name) != -1)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            const meta = ExportNightwave.challenges[challenge.challenge];
 | 
					 | 
				
			||||||
            logger.debug("Completed challenge", meta);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            let affiliation = inventory.Affiliations.find(x => x.Tag == ExportNightwave.affiliationTag);
 | 
					 | 
				
			||||||
            if (!affiliation) {
 | 
					 | 
				
			||||||
                affiliation =
 | 
					 | 
				
			||||||
                    inventory.Affiliations[
 | 
					 | 
				
			||||||
                        inventory.Affiliations.push({
 | 
					 | 
				
			||||||
                            Tag: ExportNightwave.affiliationTag,
 | 
					 | 
				
			||||||
                            Standing: 0
 | 
					 | 
				
			||||||
                        }) - 1
 | 
					 | 
				
			||||||
                    ];
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            affiliation.Standing += meta.standing;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (affiliationMods.length == 0) {
 | 
					 | 
				
			||||||
                affiliationMods.push({ Tag: ExportNightwave.affiliationTag });
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            affiliationMods[0].Standing ??= 0;
 | 
					 | 
				
			||||||
            affiliationMods[0].Standing += meta.standing;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    await inventory.save();
 | 
					    await inventory.save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
 | 
					import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
 | 
				
			||||||
import { config } from "@/src/services/configService";
 | 
					import { config } from "@/src/services/configService";
 | 
				
			||||||
import { Types } from "mongoose";
 | 
					import { Types } from "mongoose";
 | 
				
			||||||
import { SlotNames, IInventoryChanges, IBinChanges, slotNames } from "@/src/types/purchaseTypes";
 | 
					import { SlotNames, IInventoryChanges, IBinChanges, slotNames, IAffiliationMods } from "@/src/types/purchaseTypes";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    IChallengeProgress,
 | 
					    IChallengeProgress,
 | 
				
			||||||
    IFlavourItem,
 | 
					    IFlavourItem,
 | 
				
			||||||
@ -45,6 +45,7 @@ import {
 | 
				
			|||||||
    ExportGear,
 | 
					    ExportGear,
 | 
				
			||||||
    ExportKeys,
 | 
					    ExportKeys,
 | 
				
			||||||
    ExportMisc,
 | 
					    ExportMisc,
 | 
				
			||||||
 | 
					    ExportNightwave,
 | 
				
			||||||
    ExportRailjackWeapons,
 | 
					    ExportRailjackWeapons,
 | 
				
			||||||
    ExportRecipes,
 | 
					    ExportRecipes,
 | 
				
			||||||
    ExportResources,
 | 
					    ExportResources,
 | 
				
			||||||
@ -1302,35 +1303,52 @@ export const addFocusXpIncreases = (inventory: TInventoryDatabaseDocument, focus
 | 
				
			|||||||
    inventory.DailyFocus -= focusXpPlus.reduce((a, b) => a + b, 0);
 | 
					    inventory.DailyFocus -= focusXpPlus.reduce((a, b) => a + b, 0);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const addSeasonalChallengeHistory = (
 | 
					export const addChallenges = (
 | 
				
			||||||
    inventory: TInventoryDatabaseDocument,
 | 
					    inventory: TInventoryDatabaseDocument,
 | 
				
			||||||
    itemsArray: ISeasonChallenge[]
 | 
					    ChallengeProgress: IChallengeProgress[],
 | 
				
			||||||
): void => {
 | 
					    SeasonChallengeCompletions: ISeasonChallenge[] | undefined
 | 
				
			||||||
    const category = inventory.SeasonChallengeHistory;
 | 
					): IAffiliationMods[] => {
 | 
				
			||||||
 | 
					    ChallengeProgress.forEach(({ Name, Progress }) => {
 | 
				
			||||||
    itemsArray.forEach(({ challenge, id }) => {
 | 
					        const itemIndex = inventory.ChallengeProgress.findIndex(i => i.Name === Name);
 | 
				
			||||||
        const itemIndex = category.findIndex(i => i.challenge === challenge);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (itemIndex !== -1) {
 | 
					        if (itemIndex !== -1) {
 | 
				
			||||||
            category[itemIndex].id = id;
 | 
					            inventory.ChallengeProgress[itemIndex].Progress = Progress;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            category.push({ challenge, id });
 | 
					            inventory.ChallengeProgress.push({ Name, Progress });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const addChallenges = (inventory: TInventoryDatabaseDocument, itemsArray: IChallengeProgress[]): void => {
 | 
					    const affiliationMods: IAffiliationMods[] = [];
 | 
				
			||||||
    const category = inventory.ChallengeProgress;
 | 
					    if (SeasonChallengeCompletions) {
 | 
				
			||||||
 | 
					        for (const challenge of SeasonChallengeCompletions) {
 | 
				
			||||||
    itemsArray.forEach(({ Name, Progress }) => {
 | 
					            // Ignore challenges that weren't completed just now
 | 
				
			||||||
        const itemIndex = category.findIndex(i => i.Name === Name);
 | 
					            if (!ChallengeProgress.find(x => challenge.challenge.indexOf(x.Name) != -1)) {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
        if (itemIndex !== -1) {
 | 
					 | 
				
			||||||
            category[itemIndex].Progress = Progress;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            category.push({ Name, Progress });
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
    });
 | 
					
 | 
				
			||||||
 | 
					            const meta = ExportNightwave.challenges[challenge.challenge];
 | 
				
			||||||
 | 
					            logger.debug("Completed challenge", meta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            let affiliation = inventory.Affiliations.find(x => x.Tag == ExportNightwave.affiliationTag);
 | 
				
			||||||
 | 
					            if (!affiliation) {
 | 
				
			||||||
 | 
					                affiliation =
 | 
				
			||||||
 | 
					                    inventory.Affiliations[
 | 
				
			||||||
 | 
					                        inventory.Affiliations.push({
 | 
				
			||||||
 | 
					                            Tag: ExportNightwave.affiliationTag,
 | 
				
			||||||
 | 
					                            Standing: 0
 | 
				
			||||||
 | 
					                        }) - 1
 | 
				
			||||||
 | 
					                    ];
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            affiliation.Standing += meta.standing;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (affiliationMods.length == 0) {
 | 
				
			||||||
 | 
					                affiliationMods.push({ Tag: ExportNightwave.affiliationTag });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            affiliationMods[0].Standing ??= 0;
 | 
				
			||||||
 | 
					            affiliationMods[0].Standing += meta.standing;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return affiliationMods;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const addMissionComplete = (inventory: TInventoryDatabaseDocument, { Tag, Completes }: IMission): void => {
 | 
					export const addMissionComplete = (inventory: TInventoryDatabaseDocument, { Tag, Completes }: IMission): void => {
 | 
				
			||||||
 | 
				
			|||||||
@ -195,7 +195,7 @@ export const addMissionInventoryUpdates = async (
 | 
				
			|||||||
                addRecipes(inventory, value);
 | 
					                addRecipes(inventory, value);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case "ChallengeProgress":
 | 
					            case "ChallengeProgress":
 | 
				
			||||||
                addChallenges(inventory, value);
 | 
					                addChallenges(inventory, value, inventoryUpdates.SeasonChallengeCompletions);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case "FusionTreasures":
 | 
					            case "FusionTreasures":
 | 
				
			||||||
                addFusionTreasures(inventory, value);
 | 
					                addFusionTreasures(inventory, value);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user