SpaceNinjaServer/src/controllers/api/missionInventoryUpdateController.ts

103 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";
import { addMissionInventoryUpdates, addMissionRewards } from "@/src/services/missionInventoryUpdateService";
2025-01-24 14:13:21 +01:00
import { getInventory } from "@/src/services/inventoryService";
import { getInventoryResponse } from "./inventoryController";
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
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
*/
//move credit calc in here, return MissionRewards: [] if no reward info
2025-01-24 14:13:21 +01:00
export const missionInventoryUpdateController: RequestHandler = async (req, res): Promise<void> => {
2024-05-28 13:45:06 +02:00
const accountId = await getAccountIdForRequest(req);
const missionReport = getJSONfromString<IMissionInventoryUpdateRequest>((req.body as string).toString());
logger.debug("mission report:", missionReport);
const inventory = await getInventory(accountId);
const firstCompletion = missionReport.SortieId
? inventory.CompletedSorties.indexOf(missionReport.SortieId) == -1
: false;
const inventoryUpdates = await addMissionInventoryUpdates(inventory, missionReport);
if (
missionReport.MissionStatus !== "GS_SUCCESS" &&
!(missionReport.RewardInfo?.jobId || missionReport.RewardInfo?.challengeMissionId)
) {
await inventory.save();
const inventoryResponse = await getInventoryResponse(inventory, true);
res.json({
InventoryJson: JSON.stringify(inventoryResponse),
MissionRewards: []
});
return;
2025-01-24 14:13:21 +01:00
}
const { MissionRewards, inventoryChanges, credits, AffiliationMods, SyndicateXPItemReward } =
await addMissionRewards(inventory, missionReport, firstCompletion);
2025-01-24 14:13:21 +01:00
await inventory.save();
const inventoryResponse = await getInventoryResponse(inventory, true);
2025-01-24 14:13:21 +01:00
//TODO: figure out when to send inventory. it is needed for many cases.
res.json({
InventoryJson: JSON.stringify(inventoryResponse),
2025-01-24 14:13:21 +01:00
InventoryChanges: inventoryChanges,
MissionRewards,
...credits,
...inventoryUpdates,
FusionPoints: inventoryChanges?.FusionPoints,
SyndicateXPItemReward,
AffiliationMods
2025-01-24 14:13:21 +01:00
});
2023-06-01 17:08:05 -07:00
};
/*
**** OUTPUT ****
- [x] InventoryJson
- [x] MissionRewards
- [x] TotalCredits
- [x] CreditsBonus
- [x] MissionCredits
- [x] InventoryChanges
- [x] FusionPoints
*/