forked from OpenWF/SpaceNinjaServer
		
	fix: endo pickups (#359)
This commit is contained in:
		
							parent
							
								
									015619110c
								
							
						
					
					
						commit
						d0b8c8a1d3
					
				@ -4,6 +4,7 @@ import { combineRewardAndLootInventory, getRewards } from "@/src/services/missio
 | 
			
		||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { IMissionInventoryUpdateRequest } from "@/src/types/requestTypes";
 | 
			
		||||
import { logger } from "@/src/utils/logger";
 | 
			
		||||
/*
 | 
			
		||||
**** INPUT ****
 | 
			
		||||
- [ ]  crossPlaySetting
 | 
			
		||||
@ -52,6 +53,8 @@ const missionInventoryUpdateController: RequestHandler = async (req, res): Promi
 | 
			
		||||
        // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
 | 
			
		||||
        const lootInventory = getJSONfromString(req.body.toString()) as IMissionInventoryUpdateRequest;
 | 
			
		||||
 | 
			
		||||
        logger.debug("missionInventoryUpdate with lootInventory =", lootInventory);
 | 
			
		||||
 | 
			
		||||
        const { InventoryChanges, MissionRewards } = getRewards(lootInventory);
 | 
			
		||||
 | 
			
		||||
        const { combinedInventoryChanges, TotalCredits, CreditsBonus, MissionCredits, FusionPoints } =
 | 
			
		||||
@ -66,7 +69,7 @@ const missionInventoryUpdateController: RequestHandler = async (req, res): Promi
 | 
			
		||||
            TotalCredits,
 | 
			
		||||
            CreditsBonus,
 | 
			
		||||
            MissionCredits,
 | 
			
		||||
            ...(FusionPoints !== undefined && { FusionPoints })
 | 
			
		||||
            FusionPoints
 | 
			
		||||
        });
 | 
			
		||||
    } catch (err) {
 | 
			
		||||
        console.error("Error parsing JSON data:", err);
 | 
			
		||||
 | 
			
		||||
@ -54,12 +54,22 @@ const combineRewardAndLootInventory = (
 | 
			
		||||
    const missionCredits = lootInventory.RegularCredits || 0;
 | 
			
		||||
    const creditsBonus = rewardInventory.RegularCredits || 0;
 | 
			
		||||
    const totalCredits = missionCredits + creditsBonus;
 | 
			
		||||
    const FusionPoints = (lootInventory.FusionPoints || 0) + (rewardInventory.FusionPoints || 0) || undefined;
 | 
			
		||||
    let FusionPoints = rewardInventory.FusionPoints || 0;
 | 
			
		||||
 | 
			
		||||
    // Discharge Endo picked up during the mission
 | 
			
		||||
    if (lootInventory.FusionBundles) {
 | 
			
		||||
        for (const fusionBundle of lootInventory.FusionBundles) {
 | 
			
		||||
            if (fusionBundle.ItemType in fusionBundles) {
 | 
			
		||||
                FusionPoints += fusionBundles[fusionBundle.ItemType] * fusionBundle.ItemCount;
 | 
			
		||||
            } else {
 | 
			
		||||
                logger.error(`unknown fusion bundle: ${fusionBundle.ItemType}`);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        lootInventory.FusionBundles = undefined;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    lootInventory.RegularCredits = totalCredits;
 | 
			
		||||
    if (FusionPoints) {
 | 
			
		||||
    lootInventory.FusionPoints = FusionPoints;
 | 
			
		||||
    }
 | 
			
		||||
    inventoryFields.forEach((field: IInventoryFieldType) => {
 | 
			
		||||
        if (rewardInventory[field] && !lootInventory[field]) {
 | 
			
		||||
            lootInventory[field] = [];
 | 
			
		||||
@ -72,7 +82,7 @@ const combineRewardAndLootInventory = (
 | 
			
		||||
        TotalCredits: [totalCredits, totalCredits],
 | 
			
		||||
        CreditsBonus: [creditsBonus, creditsBonus],
 | 
			
		||||
        MissionCredits: [missionCredits, missionCredits],
 | 
			
		||||
        ...(FusionPoints !== undefined && { FusionPoints })
 | 
			
		||||
        FusionPoints: FusionPoints
 | 
			
		||||
    };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -123,8 +133,9 @@ const creditBundles: Record<string, number> = {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const fusionBundles: Record<string, number> = {
 | 
			
		||||
    "/Lotus/StoreItems/Upgrades/Mods/FusionBundles/UncommonFusionBundle": 50,
 | 
			
		||||
    "/Lotus/StoreItems/Upgrades/Mods/FusionBundles/RareFusionBundle": 80
 | 
			
		||||
    "/Lotus/Upgrades/Mods/FusionBundles/CommonFusionBundle": 15,
 | 
			
		||||
    "/Lotus/Upgrades/Mods/FusionBundles/UncommonFusionBundle": 50,
 | 
			
		||||
    "/Lotus/Upgrades/Mods/FusionBundles/RareFusionBundle": 80
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const formatRewardsToInventoryType = (
 | 
			
		||||
@ -136,12 +147,12 @@ const formatRewardsToInventoryType = (
 | 
			
		||||
        if (reward.type in creditBundles) {
 | 
			
		||||
            InventoryChanges.RegularCredits ??= 0;
 | 
			
		||||
            InventoryChanges.RegularCredits += creditBundles[reward.type] * reward.itemCount;
 | 
			
		||||
        } else if (reward.type in fusionBundles) {
 | 
			
		||||
            InventoryChanges.FusionPoints ??= 0;
 | 
			
		||||
            InventoryChanges.FusionPoints += fusionBundles[reward.type] * reward.itemCount;
 | 
			
		||||
        } else {
 | 
			
		||||
            const type = reward.type.replace("/Lotus/StoreItems/", "/Lotus/");
 | 
			
		||||
            if (type in ExportUpgrades) {
 | 
			
		||||
            if (type in fusionBundles) {
 | 
			
		||||
                InventoryChanges.FusionPoints ??= 0;
 | 
			
		||||
                InventoryChanges.FusionPoints += fusionBundles[type] * reward.itemCount;
 | 
			
		||||
            } else if (type in ExportUpgrades) {
 | 
			
		||||
                addRewardResponse(InventoryChanges, MissionRewards, type, reward.itemCount, "RawUpgrades");
 | 
			
		||||
            } else if (type in ExportGear) {
 | 
			
		||||
                addRewardResponse(InventoryChanges, MissionRewards, type, reward.itemCount, "Consumables");
 | 
			
		||||
 | 
			
		||||
@ -7,6 +7,7 @@ import {
 | 
			
		||||
    ICrewShipSalvagedWeaponSkin,
 | 
			
		||||
    IEvolutionProgress,
 | 
			
		||||
    IMiscItem,
 | 
			
		||||
    ITypeCount,
 | 
			
		||||
    IMission,
 | 
			
		||||
    IRawUpgrade,
 | 
			
		||||
    ISeasonChallenge
 | 
			
		||||
@ -45,6 +46,7 @@ export interface IMissionInventoryUpdateRequest {
 | 
			
		||||
    Pistols?: IEquipmentClient[];
 | 
			
		||||
    Suits?: IEquipmentClient[];
 | 
			
		||||
    Melee?: IEquipmentClient[];
 | 
			
		||||
    FusionBundles?: ITypeCount[];
 | 
			
		||||
    RawUpgrades?: IRawUpgrade[];
 | 
			
		||||
    MiscItems?: IMiscItem[];
 | 
			
		||||
    Consumables?: IConsumable[];
 | 
			
		||||
@ -52,9 +54,10 @@ export interface IMissionInventoryUpdateRequest {
 | 
			
		||||
    RegularCredits?: number;
 | 
			
		||||
    ChallengeProgress?: IChallengeProgress[];
 | 
			
		||||
    RewardInfo?: IMissionInventoryUpdateRequestRewardInfo;
 | 
			
		||||
    FusionPoints?: number;
 | 
			
		||||
    Missions?: IMission;
 | 
			
		||||
    EvolutionProgress?: IEvolutionProgress[];
 | 
			
		||||
 | 
			
		||||
    FusionPoints?: number; // Not a part of the request, but we put it in this struct as an intermediate storage.
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IMissionInventoryUpdateRequestRewardInfo {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user