SpaceNinjaServer/src/controllers/api/missionInventoryUpdateController.ts

91 lines
2.9 KiB
TypeScript
Raw Normal View History

2023-06-01 17:08:05 -07:00
import { RequestHandler } from "express";
2023-08-31 14:29:09 +04:00
import { missionInventoryUpdate } from "@/src/services/inventoryService";
import { combineRewardAndLootInventory, getRewards } from "@/src/services/missionInventoryUpdateService";
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";
2024-06-22 17:56:36 +02:00
import { logger } from "@/src/utils/logger";
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
- [ ] PS (Passive anti-cheat data which includes your username, module list, process list, and system name.)
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.)
- [ ] RepHash (A hash from the replication manager/RepMgr Unknown what it does.)
2023-08-31 14:29:09 +04:00
- [ ] EndOfMatchUpload
- [ ] ObjectiveReached
- [ ] FpsAvg
- [ ] FpsMin
- [ ] FpsMax
- [ ] FpsSamples
*/
2023-06-01 17:08:05 -07:00
2023-08-31 14:29:09 +04:00
// eslint-disable-next-line @typescript-eslint/no-misused-promises
2023-09-10 00:10:21 +04:00
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
try {
2023-09-10 00:10:21 +04:00
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
const lootInventory = getJSONfromString(req.body.toString()) as IMissionInventoryUpdateRequest;
2024-06-22 17:56:36 +02:00
logger.debug("missionInventoryUpdate with lootInventory =", lootInventory);
2023-09-10 00:10:21 +04:00
const { InventoryChanges, MissionRewards } = getRewards(lootInventory);
const { combinedInventoryChanges, TotalCredits, CreditsBonus, MissionCredits, FusionPoints } =
combineRewardAndLootInventory(InventoryChanges, lootInventory);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2023-09-10 00:10:21 +04:00
const InventoryJson = JSON.stringify(await missionInventoryUpdate(combinedInventoryChanges, accountId));
res.json({
// InventoryJson, // this part will reset game data and missions will be locked
MissionRewards,
InventoryChanges,
TotalCredits,
CreditsBonus,
MissionCredits,
2024-06-22 17:56:36 +02:00
FusionPoints
});
2023-08-31 14:29:09 +04:00
} catch (err) {
console.error("Error parsing JSON data:", err);
}
2023-06-01 17:08:05 -07:00
};
/*
**** OUTPUT ****
- [x] InventoryJson
- [x] MissionRewards
- [x] TotalCredits
- [x] CreditsBonus
- [x] MissionCredits
- [x] InventoryChanges
- [x] FusionPoints
*/
2023-06-01 17:08:05 -07:00
export { missionInventoryUpdateController };