feat(stats): Ollie's Crash Course Rewards #1260
@ -1,6 +1,6 @@
|
||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { getStats, updateStats } from "@/src/services/statsService";
|
||||
import { updateStats } from "@/src/services/statsService";
|
||||
import { IStatsUpdate } from "@/src/types/statTypes";
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
@ -8,8 +8,7 @@ const uploadController: RequestHandler = async (req, res) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { PS, ...payload } = getJSONfromString<IStatsUpdate>(String(req.body));
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const playerStats = await getStats(accountId);
|
||||
await updateStats(playerStats, payload);
|
||||
await updateStats(accountId, payload);
|
||||
res.status(200).end();
|
||||
};
|
||||
|
||||
|
@ -9,7 +9,8 @@ import {
|
||||
IUploadEntry,
|
||||
IWeapon
|
||||
} from "@/src/types/statTypes";
|
||||
import { logger } from "../utils/logger";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
import { addEmailItem, getInventory } from "@/src/services/inventoryService";
|
||||
|
||||
export const createStats = async (accountId: string): Promise<TStatsDatabaseDocument> => {
|
||||
const stats = new Stats({ accountOwnerId: accountId });
|
||||
@ -25,8 +26,9 @@ export const getStats = async (accountOwnerId: string): Promise<TStatsDatabaseDo
|
||||
return stats;
|
||||
};
|
||||
|
||||
export const updateStats = async (playerStats: TStatsDatabaseDocument, payload: IStatsUpdate): Promise<void> => {
|
||||
export const updateStats = async (accountOwnerId: string, payload: IStatsUpdate): Promise<void> => {
|
||||
const unknownCategories: Record<string, string[]> = {};
|
||||
const playerStats = await getStats(accountOwnerId);
|
||||
|
||||
for (const [action, actionData] of Object.entries(payload)) {
|
||||
switch (action) {
|
||||
@ -308,12 +310,30 @@ export const updateStats = async (playerStats: TStatsDatabaseDocument, payload:
|
||||
case "ZephyrScore":
|
||||
case "SentinelGameScore":
|
||||
case "CaliberChicksScore":
|
||||
case "OlliesCrashCourseScore":
|
||||
case "DojoObstacleScore":
|
||||
playerStats[category] ??= 0;
|
||||
if (data > playerStats[category]) playerStats[category] = data;
|
||||
break;
|
||||
|
||||
case "OlliesCrashCourseScore":
|
||||
playerStats[category] ??= 0;
|
||||
if (!playerStats[category]) {
|
||||
const inventory = await getInventory(accountOwnerId, "EmailItems");
|
||||
await addEmailItem(
|
||||
inventory,
|
||||
"/Lotus/Types/Items/EmailItems/PlayedOlliesCrashCourseEmailItem"
|
||||
);
|
||||
}
|
||||
if (data >= 9991000 && playerStats[category] < 9991000) {
|
||||
const inventory = await getInventory(accountOwnerId, "EmailItems");
|
||||
await addEmailItem(
|
||||
inventory,
|
||||
"/Lotus/Types/Items/EmailItems/BeatOlliesCrashCourseInNinetySecEmailItem"
|
||||
);
|
||||
}
|
||||
if (data > playerStats[category]) playerStats[category] = data;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!ignoredCategories.includes(category)) {
|
||||
if (!unknownCategories[action]) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user