SpaceNinjaServer/src/controllers/api/missionInventoryUpdateController.ts

110 lines
3.2 KiB
TypeScript
Raw Normal View History

2023-06-01 17:08:05 -07:00
import { RequestHandler } from "express";
2023-09-10 00:10:21 +04:00
import { getJSONfromString } from "@/src/helpers/stringHelpers";
2024-05-28 13:45:06 +02:00
import { getAccountIdForRequest } from "@/src/services/loginService";
2023-09-10 00:10:21 +04:00
import { IMissionInventoryUpdateRequest } from "@/src/types/requestTypes";
2025-01-24 14:13:21 +01:00
import {
addMissionInventoryUpdates,
addMissionRewards,
calculateFinalCredits
} from "@/src/services/missionInventoryUpdateService";
import { getInventory } from "@/src/services/inventoryService";
2023-08-31 14:29:09 +04:00
/*
**** INPUT ****
2023-08-31 14:29:09 +04:00
- [ ] crossPlaySetting
- [ ] rewardsMultiplier
- [ ] ActiveBoosters
- [x] LongGuns
- [x] Pistols
- [x] Suits
- [x] Melee
- [x] RawUpgrades
- [x] MiscItems
- [x] RegularCredits
- [ ] RandomUpgradesIdentified
- [ ] MissionFailed
- [ ] MissionStatus
- [ ] CurrentLoadOutIds
- [ ] AliveTime
- [ ] MissionTime
2023-09-10 00:10:21 +04:00
- [x] Missions
2023-08-31 14:29:09 +04:00
- [ ] CompletedAlerts
- [ ] LastRegionPlayed
- [ ] GameModeId
- [ ] hosts
- [x] ChallengeProgress
- [ ] SeasonChallengeHistory
2025-01-24 14:13:21 +01:00
- [ ] PS (anticheat data)
2023-08-31 14:29:09 +04:00
- [ ] ActiveDojoColorResearch
- [x] RewardInfo
2023-08-31 14:29:09 +04:00
- [ ] ReceivedCeremonyMsg
- [ ] LastCeremonyResetDate
- [ ] MissionPTS (Used to validate the mission/alive time above.)
2025-01-24 14:13:21 +01:00
- [ ] RepHash
2023-08-31 14:29:09 +04:00
- [ ] EndOfMatchUpload
- [ ] ObjectiveReached
- [ ] FpsAvg
- [ ] FpsMin
- [ ] FpsMax
- [ ] FpsSamples
*/
2023-06-01 17:08:05 -07:00
2025-01-24 14:13:21 +01:00
// eslint-disable-next-line @typescript-eslint/no-misused-promises
export const missionInventoryUpdateController: RequestHandler = async (req, res): Promise<void> => {
2024-05-28 13:45:06 +02:00
const accountId = await getAccountIdForRequest(req);
2023-08-31 14:29:09 +04:00
const missionReport = getJSONfromString<IMissionInventoryUpdateRequest>((req.body as string).toString());
2025-01-24 14:13:21 +01:00
if (missionReport.MissionStatus !== "GS_SUCCESS") {
console.log(`Mission failed: ${missionReport.RewardInfo?.node}`);
//todo: return expected response for failed mission
res.json([]);
return;
2025-01-24 14:13:21 +01:00
//duvirisadjob does not provide missionStatus
}
2024-06-22 17:56:36 +02:00
2025-01-24 14:13:21 +01:00
const inventory = await getInventory(accountId);
2025-01-24 14:13:21 +01:00
const missionRewardsResults = await addMissionRewards(inventory, missionReport);
2025-01-24 14:13:21 +01:00
if (!missionRewardsResults) {
console.error("Failed to add mission rewards");
res.status(500).json({ error: "Failed to add mission rewards" });
return;
2023-08-31 14:29:09 +04:00
}
2025-01-24 14:13:21 +01:00
const { MissionRewards, inventoryChanges, missionCompletionCredits } = missionRewardsResults;
const inventoryUpdates = addMissionInventoryUpdates(inventory, missionReport);
//todo ? can go after not awaiting
//creditBonus is not correct for mirage mission 3
const credits = calculateFinalCredits(inventory, {
missionCompletionCredits,
missionDropCredits: missionReport.RegularCredits ?? 0,
rngRewardCredits: inventoryChanges.RegularCredits as number
});
const InventoryJson = JSON.stringify((await inventory.save()).toJSON());
//TODO: figure out when to send inventory. it is needed for many cases.
res.json({
InventoryJson,
InventoryChanges: inventoryChanges,
MissionRewards,
...credits,
...inventoryUpdates,
FusionPoints: inventoryChanges.FusionPoints
});
2023-06-01 17:08:05 -07:00
};
/*
**** OUTPUT ****
- [x] InventoryJson
- [x] MissionRewards
- [x] TotalCredits
- [x] CreditsBonus
- [x] MissionCredits
- [x] InventoryChanges
- [x] FusionPoints
*/