forked from OpenWF/SpaceNinjaServer
feat(stats): Ollie's Crash Course Rewards (#1260)
Reviewed-on: OpenWF/SpaceNinjaServer#1260 Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
This commit is contained in:
parent
7d3f2e8796
commit
3c87dd56ca
@ -1,6 +1,6 @@
|
|||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
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 { IStatsUpdate } from "@/src/types/statTypes";
|
||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
|
|
||||||
@ -8,8 +8,7 @@ const uploadController: RequestHandler = async (req, res) => {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { PS, ...payload } = getJSONfromString<IStatsUpdate>(String(req.body));
|
const { PS, ...payload } = getJSONfromString<IStatsUpdate>(String(req.body));
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const playerStats = await getStats(accountId);
|
await updateStats(accountId, payload);
|
||||||
await updateStats(playerStats, payload);
|
|
||||||
res.status(200).end();
|
res.status(200).end();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,7 +9,8 @@ import {
|
|||||||
IUploadEntry,
|
IUploadEntry,
|
||||||
IWeapon
|
IWeapon
|
||||||
} from "@/src/types/statTypes";
|
} 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> => {
|
export const createStats = async (accountId: string): Promise<TStatsDatabaseDocument> => {
|
||||||
const stats = new Stats({ accountOwnerId: accountId });
|
const stats = new Stats({ accountOwnerId: accountId });
|
||||||
@ -25,8 +26,9 @@ export const getStats = async (accountOwnerId: string): Promise<TStatsDatabaseDo
|
|||||||
return stats;
|
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 unknownCategories: Record<string, string[]> = {};
|
||||||
|
const playerStats = await getStats(accountOwnerId);
|
||||||
|
|
||||||
for (const [action, actionData] of Object.entries(payload)) {
|
for (const [action, actionData] of Object.entries(payload)) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
@ -308,12 +310,30 @@ export const updateStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
case "ZephyrScore":
|
case "ZephyrScore":
|
||||||
case "SentinelGameScore":
|
case "SentinelGameScore":
|
||||||
case "CaliberChicksScore":
|
case "CaliberChicksScore":
|
||||||
case "OlliesCrashCourseScore":
|
|
||||||
case "DojoObstacleScore":
|
case "DojoObstacleScore":
|
||||||
playerStats[category] ??= 0;
|
playerStats[category] ??= 0;
|
||||||
if (data > playerStats[category]) playerStats[category] = data;
|
if (data > playerStats[category]) playerStats[category] = data;
|
||||||
break;
|
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:
|
default:
|
||||||
if (!ignoredCategories.includes(category)) {
|
if (!ignoredCategories.includes(category)) {
|
||||||
if (!unknownCategories[action]) {
|
if (!unknownCategories[action]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user