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";
|
2025-01-24 21:09:34 +01:00
|
|
|
import { applyInventoryResponseOverrides } from "./inventoryController";
|
|
|
|
import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes";
|
2025-01-24 16:17:59 +01:00
|
|
|
|
2023-08-31 14:29:09 +04:00
|
|
|
/*
|
2023-09-06 14:02:54 +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
|
2023-09-06 14:02:54 +04:00
|
|
|
- [x] RewardInfo
|
2023-08-31 14:29:09 +04:00
|
|
|
- [ ] ReceivedCeremonyMsg
|
|
|
|
- [ ] LastCeremonyResetDate
|
2023-09-05 07:37:30 -05:00
|
|
|
- [ ] 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);
|
2025-01-24 14:27:10 +01:00
|
|
|
const missionReport = getJSONfromString<IMissionInventoryUpdateRequest>((req.body as string).toString());
|
2023-09-06 14:02:54 +04:00
|
|
|
|
2025-01-24 16:17:59 +01:00
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
const inventoryUpdates = addMissionInventoryUpdates(inventory, missionReport);
|
|
|
|
|
2025-01-24 14:13:21 +01:00
|
|
|
if (missionReport.MissionStatus !== "GS_SUCCESS") {
|
2025-01-24 21:09:34 +01:00
|
|
|
await inventory.save();
|
|
|
|
const inventoryResponse = inventory.toJSON<IInventoryClient>();
|
|
|
|
applyInventoryResponseOverrides(inventoryResponse, true);
|
|
|
|
res.json({
|
|
|
|
InventoryJson: JSON.stringify(inventoryResponse),
|
|
|
|
MissionRewards: []
|
|
|
|
});
|
2025-01-24 15:13:55 +01:00
|
|
|
return;
|
2025-01-24 14:13:21 +01:00
|
|
|
}
|
|
|
|
const missionRewardsResults = await addMissionRewards(inventory, missionReport);
|
|
|
|
if (!missionRewardsResults) {
|
2025-01-24 16:17:59 +01:00
|
|
|
throw new Error("Failed to add mission rewards, should not happen");
|
2023-08-31 14:29:09 +04:00
|
|
|
}
|
2025-01-24 14:13:21 +01:00
|
|
|
const { MissionRewards, inventoryChanges, missionCompletionCredits } = missionRewardsResults;
|
|
|
|
|
|
|
|
//creditBonus is not correct for mirage mission 3
|
|
|
|
const credits = calculateFinalCredits(inventory, {
|
|
|
|
missionCompletionCredits,
|
|
|
|
missionDropCredits: missionReport.RegularCredits ?? 0,
|
|
|
|
rngRewardCredits: inventoryChanges.RegularCredits as number
|
|
|
|
});
|
|
|
|
|
2025-01-24 21:09:34 +01:00
|
|
|
await inventory.save();
|
|
|
|
const inventoryResponse = inventory.toJSON<IInventoryClient>();
|
|
|
|
applyInventoryResponseOverrides(inventoryResponse, true);
|
2025-01-24 14:13:21 +01:00
|
|
|
|
|
|
|
//TODO: figure out when to send inventory. it is needed for many cases.
|
|
|
|
res.json({
|
2025-01-24 21:09:34 +01:00
|
|
|
InventoryJson: JSON.stringify(inventoryResponse),
|
2025-01-24 14:13:21 +01:00
|
|
|
InventoryChanges: inventoryChanges,
|
|
|
|
MissionRewards,
|
|
|
|
...credits,
|
|
|
|
...inventoryUpdates,
|
|
|
|
FusionPoints: inventoryChanges.FusionPoints
|
|
|
|
});
|
2023-06-01 17:08:05 -07:00
|
|
|
};
|
|
|
|
|
2023-09-06 14:02:54 +04:00
|
|
|
/*
|
|
|
|
**** OUTPUT ****
|
|
|
|
- [x] InventoryJson
|
|
|
|
- [x] MissionRewards
|
|
|
|
- [x] TotalCredits
|
|
|
|
- [x] CreditsBonus
|
|
|
|
- [x] MissionCredits
|
|
|
|
- [x] InventoryChanges
|
|
|
|
- [x] FusionPoints
|
|
|
|
*/
|