fix: endo pickups (#359)

This commit is contained in:
Sainan 2024-06-22 17:56:36 +02:00 committed by GitHub
parent 015619110c
commit d0b8c8a1d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import { combineRewardAndLootInventory, getRewards } from "@/src/services/missio
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 { IMissionInventoryUpdateRequest } from "@/src/types/requestTypes"; import { IMissionInventoryUpdateRequest } from "@/src/types/requestTypes";
import { logger } from "@/src/utils/logger";
/* /*
**** INPUT **** **** INPUT ****
- [ ] crossPlaySetting - [ ] 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 // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
const lootInventory = getJSONfromString(req.body.toString()) as IMissionInventoryUpdateRequest; const lootInventory = getJSONfromString(req.body.toString()) as IMissionInventoryUpdateRequest;
logger.debug("missionInventoryUpdate with lootInventory =", lootInventory);
const { InventoryChanges, MissionRewards } = getRewards(lootInventory); const { InventoryChanges, MissionRewards } = getRewards(lootInventory);
const { combinedInventoryChanges, TotalCredits, CreditsBonus, MissionCredits, FusionPoints } = const { combinedInventoryChanges, TotalCredits, CreditsBonus, MissionCredits, FusionPoints } =
@ -66,7 +69,7 @@ const missionInventoryUpdateController: RequestHandler = async (req, res): Promi
TotalCredits, TotalCredits,
CreditsBonus, CreditsBonus,
MissionCredits, MissionCredits,
...(FusionPoints !== undefined && { FusionPoints }) FusionPoints
}); });
} catch (err) { } catch (err) {
console.error("Error parsing JSON data:", err); console.error("Error parsing JSON data:", err);

View File

@ -54,12 +54,22 @@ const combineRewardAndLootInventory = (
const missionCredits = lootInventory.RegularCredits || 0; const missionCredits = lootInventory.RegularCredits || 0;
const creditsBonus = rewardInventory.RegularCredits || 0; const creditsBonus = rewardInventory.RegularCredits || 0;
const totalCredits = missionCredits + creditsBonus; 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; lootInventory.RegularCredits = totalCredits;
if (FusionPoints) { lootInventory.FusionPoints = FusionPoints;
lootInventory.FusionPoints = FusionPoints;
}
inventoryFields.forEach((field: IInventoryFieldType) => { inventoryFields.forEach((field: IInventoryFieldType) => {
if (rewardInventory[field] && !lootInventory[field]) { if (rewardInventory[field] && !lootInventory[field]) {
lootInventory[field] = []; lootInventory[field] = [];
@ -72,7 +82,7 @@ const combineRewardAndLootInventory = (
TotalCredits: [totalCredits, totalCredits], TotalCredits: [totalCredits, totalCredits],
CreditsBonus: [creditsBonus, creditsBonus], CreditsBonus: [creditsBonus, creditsBonus],
MissionCredits: [missionCredits, missionCredits], MissionCredits: [missionCredits, missionCredits],
...(FusionPoints !== undefined && { FusionPoints }) FusionPoints: FusionPoints
}; };
}; };
@ -123,8 +133,9 @@ const creditBundles: Record<string, number> = {
}; };
const fusionBundles: Record<string, number> = { const fusionBundles: Record<string, number> = {
"/Lotus/StoreItems/Upgrades/Mods/FusionBundles/UncommonFusionBundle": 50, "/Lotus/Upgrades/Mods/FusionBundles/CommonFusionBundle": 15,
"/Lotus/StoreItems/Upgrades/Mods/FusionBundles/RareFusionBundle": 80 "/Lotus/Upgrades/Mods/FusionBundles/UncommonFusionBundle": 50,
"/Lotus/Upgrades/Mods/FusionBundles/RareFusionBundle": 80
}; };
const formatRewardsToInventoryType = ( const formatRewardsToInventoryType = (
@ -136,12 +147,12 @@ const formatRewardsToInventoryType = (
if (reward.type in creditBundles) { if (reward.type in creditBundles) {
InventoryChanges.RegularCredits ??= 0; InventoryChanges.RegularCredits ??= 0;
InventoryChanges.RegularCredits += creditBundles[reward.type] * reward.itemCount; InventoryChanges.RegularCredits += creditBundles[reward.type] * reward.itemCount;
} else if (reward.type in fusionBundles) {
InventoryChanges.FusionPoints ??= 0;
InventoryChanges.FusionPoints += fusionBundles[reward.type] * reward.itemCount;
} else { } else {
const type = reward.type.replace("/Lotus/StoreItems/", "/Lotus/"); 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"); addRewardResponse(InventoryChanges, MissionRewards, type, reward.itemCount, "RawUpgrades");
} else if (type in ExportGear) { } else if (type in ExportGear) {
addRewardResponse(InventoryChanges, MissionRewards, type, reward.itemCount, "Consumables"); addRewardResponse(InventoryChanges, MissionRewards, type, reward.itemCount, "Consumables");

View File

@ -7,6 +7,7 @@ import {
ICrewShipSalvagedWeaponSkin, ICrewShipSalvagedWeaponSkin,
IEvolutionProgress, IEvolutionProgress,
IMiscItem, IMiscItem,
ITypeCount,
IMission, IMission,
IRawUpgrade, IRawUpgrade,
ISeasonChallenge ISeasonChallenge
@ -45,6 +46,7 @@ export interface IMissionInventoryUpdateRequest {
Pistols?: IEquipmentClient[]; Pistols?: IEquipmentClient[];
Suits?: IEquipmentClient[]; Suits?: IEquipmentClient[];
Melee?: IEquipmentClient[]; Melee?: IEquipmentClient[];
FusionBundles?: ITypeCount[];
RawUpgrades?: IRawUpgrade[]; RawUpgrades?: IRawUpgrade[];
MiscItems?: IMiscItem[]; MiscItems?: IMiscItem[];
Consumables?: IConsumable[]; Consumables?: IConsumable[];
@ -52,9 +54,10 @@ export interface IMissionInventoryUpdateRequest {
RegularCredits?: number; RegularCredits?: number;
ChallengeProgress?: IChallengeProgress[]; ChallengeProgress?: IChallengeProgress[];
RewardInfo?: IMissionInventoryUpdateRequestRewardInfo; RewardInfo?: IMissionInventoryUpdateRequestRewardInfo;
FusionPoints?: number;
Missions?: IMission; Missions?: IMission;
EvolutionProgress?: IEvolutionProgress[]; EvolutionProgress?: IEvolutionProgress[];
FusionPoints?: number; // Not a part of the request, but we put it in this struct as an intermediate storage.
} }
export interface IMissionInventoryUpdateRequestRewardInfo { export interface IMissionInventoryUpdateRequestRewardInfo {