2024-05-28 13:45:06 +02:00
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2023-09-11 13:20:07 +02:00
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
|
|
|
import { getInventory } from "@/src/services/inventoryService";
|
|
|
|
import { IMongoDate } from "@/src/types/commonTypes";
|
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { unixTimesInMs } from "@/src/constants/timeConstants";
|
2024-12-30 00:09:03 +01:00
|
|
|
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
2025-03-17 12:23:17 -07:00
|
|
|
import { createMessage } from "@/src/services/inboxService";
|
2025-04-06 06:04:44 -07:00
|
|
|
import { config } from "@/src/services/configService";
|
2023-09-11 13:20:07 +02:00
|
|
|
|
|
|
|
interface ITrainingResultsRequest {
|
|
|
|
numLevelsGained: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ITrainingResultsResponse {
|
|
|
|
NewTrainingDate: IMongoDate;
|
|
|
|
NewLevel: number;
|
2024-12-30 00:09:03 +01:00
|
|
|
InventoryChanges: IInventoryChanges;
|
2023-09-11 13:20:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const trainingResultController: RequestHandler = async (req, res): Promise<void> => {
|
2024-05-28 13:45:06 +02:00
|
|
|
const accountId = await getAccountIdForRequest(req);
|
2023-09-11 13:20:07 +02:00
|
|
|
|
2025-01-24 14:27:10 +01:00
|
|
|
const trainingResults = getJSONfromString<ITrainingResultsRequest>(String(req.body));
|
2023-09-11 13:20:07 +02:00
|
|
|
|
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
|
|
|
|
if (trainingResults.numLevelsGained == 1) {
|
2025-04-06 06:04:44 -07:00
|
|
|
let time = Date.now();
|
|
|
|
if (!config.noMasteryRankUpCooldown) {
|
|
|
|
time += unixTimesInMs.hour * 23;
|
|
|
|
}
|
|
|
|
inventory.TrainingDate = new Date(time);
|
|
|
|
|
2023-09-11 13:20:07 +02:00
|
|
|
inventory.PlayerLevel += 1;
|
2025-03-17 12:23:17 -07:00
|
|
|
|
|
|
|
await createMessage(accountId, [
|
|
|
|
{
|
|
|
|
sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
|
|
|
|
msg: "/Lotus/Language/Inbox/MasteryRewardMsg",
|
|
|
|
arg: [
|
|
|
|
{
|
|
|
|
Key: "NEW_RANK",
|
|
|
|
Tag: inventory.PlayerLevel
|
|
|
|
}
|
|
|
|
],
|
|
|
|
att: [
|
|
|
|
`/Lotus/Types/Items/ShipDecos/MasteryTrophies/Rank${inventory.PlayerLevel.toString().padStart(2, "0")}Trophy`
|
|
|
|
],
|
|
|
|
sub: "/Lotus/Language/Inbox/MasteryRewardTitle",
|
|
|
|
icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
|
|
|
|
highPriority: true
|
|
|
|
}
|
|
|
|
]);
|
2023-09-11 13:20:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const changedinventory = await inventory.save();
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
NewTrainingDate: {
|
|
|
|
$date: { $numberLong: changedinventory.TrainingDate.getTime().toString() }
|
|
|
|
},
|
|
|
|
NewLevel: trainingResults.numLevelsGained == 1 ? changedinventory.PlayerLevel : inventory.PlayerLevel,
|
2024-12-30 00:09:03 +01:00
|
|
|
InventoryChanges: {}
|
2023-09-11 13:20:07 +02:00
|
|
|
} satisfies ITrainingResultsResponse);
|
|
|
|
};
|
|
|
|
|
|
|
|
export { trainingResultController };
|