what the plat
This commit is contained in:
parent
dd99e8782c
commit
f197facd72
@ -7,5 +7,6 @@
|
||||
"skipStoryModeChoice": true,
|
||||
"skipTutorial": true,
|
||||
"testMission": true,
|
||||
"testQuestKey": true
|
||||
"testQuestKey": true,
|
||||
"infinitePlatinum": false
|
||||
}
|
||||
|
@ -1,7 +1,27 @@
|
||||
import { RequestHandler } from "express";
|
||||
import config from "@/config.json";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
import { parseString } from "@/src/helpers/general";
|
||||
|
||||
const getCreditsController: RequestHandler = (_req, res) => {
|
||||
res.json({ RegularCredits: 42069, TradesRemaining: 1, PremiumCreditsFree: 42069, PremiumCredits: 42069 });
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
export const getCreditsController: RequestHandler = async (req, res) => {
|
||||
if (config.infinitePlatinum) {
|
||||
res.json({
|
||||
RegularCredits: 999999999,
|
||||
TradesRemaining: 999999999,
|
||||
PremiumCreditsFree: 999999999,
|
||||
PremiumCredits: 999999999
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const accountId = parseString(req.query.accountId);
|
||||
|
||||
const inventory = await getInventory(accountId);
|
||||
res.json({
|
||||
RegularCredits: inventory.RegularCredits,
|
||||
TradesRemaining: inventory.TradesRemaining,
|
||||
PremiumCreditsFree: inventory.PremiumCreditsFree,
|
||||
PremiumCredits: inventory.PremiumCredits
|
||||
});
|
||||
};
|
||||
|
||||
export { getCreditsController };
|
||||
|
24
src/controllers/api/inventorySlotsController.ts
Normal file
24
src/controllers/api/inventorySlotsController.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { parseString } from "@/src/helpers/general";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
export interface IInventoryChanges {
|
||||
InventoryChanges: { [key: string]: unknown };
|
||||
}
|
||||
|
||||
export interface IInventorySlotsRequest {
|
||||
Bin: "PveBonusLoadoutBin";
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
export const inventorySlotsController: RequestHandler = async (req, res) => {
|
||||
const accountId = parseString(req.query.accountId);
|
||||
//const body = req.body as IInventorySlotsRequest;
|
||||
|
||||
//check which slot was purchased
|
||||
|
||||
const inventory = await getInventory(accountId);
|
||||
|
||||
//add slots
|
||||
res.json({ InventoryChanges: { PremiumCreditsFree: -20, PremiumCredits: -20 } } satisfies IInventoryChanges);
|
||||
};
|
@ -5,7 +5,7 @@ import { handleInventoryItemConfigChange } from "@/src/services/saveLoadoutServi
|
||||
import { parseString } from "@/src/helpers/general";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
const saveLoadoutController: RequestHandler = async (req, res) => {
|
||||
export const saveLoadoutController: RequestHandler = async (req, res) => {
|
||||
//validate here
|
||||
const accountId = parseString(req.query.accountId);
|
||||
|
||||
@ -15,13 +15,19 @@ const saveLoadoutController: RequestHandler = async (req, res) => {
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { UpgradeVer, ...equipmentChanges } = body;
|
||||
await handleInventoryItemConfigChange(equipmentChanges, accountId);
|
||||
const newLoadoutId = await handleInventoryItemConfigChange(equipmentChanges, accountId);
|
||||
|
||||
//send back new loadout id, if new loadout was added
|
||||
if (newLoadoutId) {
|
||||
res.send(newLoadoutId);
|
||||
}
|
||||
res.status(200).end();
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
console.log("error in saveLoadoutController", error.message);
|
||||
res.status(400).json({ error: error.message });
|
||||
} else {
|
||||
res.status(400).json({ error: "unknown error" });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export { saveLoadoutController };
|
||||
|
@ -1,3 +1,7 @@
|
||||
export const isEmptyObject = (obj: unknown): boolean => {
|
||||
return Boolean(obj && Object.keys(obj).length === 0 && obj.constructor === Object);
|
||||
};
|
||||
|
||||
const isString = (text: unknown): text is string => {
|
||||
return typeof text === "string" || text instanceof String;
|
||||
};
|
||||
|
@ -34,6 +34,7 @@ import { artifactsController } from "../controllers/api/artifactsController";
|
||||
import express from "express";
|
||||
import { setBootLocationController } from "@/src/controllers/api/setBootLocationController";
|
||||
import { focusController } from "@/src/controllers/api/focusController";
|
||||
import { inventorySlotsController } from "@/src/controllers/api/inventorySlotsController";
|
||||
|
||||
const apiRouter = express.Router();
|
||||
|
||||
@ -61,6 +62,7 @@ apiRouter.get("/logout.php", logoutController);
|
||||
apiRouter.get("/setBootLocation.php", setBootLocationController);
|
||||
|
||||
// post
|
||||
apiRouter.post("/inventorySlots.php", inventorySlotsController);
|
||||
apiRouter.post("/focus.php", focusController);
|
||||
apiRouter.post("/artifacts.php", artifactsController);
|
||||
apiRouter.post("/findSessions.php", findSessionsController);
|
||||
|
@ -8,10 +8,8 @@ import {
|
||||
import { LoadoutModel } from "@/src/models/inventoryModels/loadoutModel";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
import { IOid } from "@/src/types/commonTypes";
|
||||
|
||||
export const isEmptyObject = (obj: unknown): boolean => {
|
||||
return Boolean(obj && Object.keys(obj).length === 0 && obj.constructor === Object);
|
||||
};
|
||||
import { Types } from "mongoose";
|
||||
import { isEmptyObject } from "@/src/helpers/general";
|
||||
|
||||
//TODO: setup default items on account creation or like originally in giveStartingItems.php
|
||||
|
||||
@ -24,7 +22,7 @@ itemconfig has multiple config ids
|
||||
export const handleInventoryItemConfigChange = async (
|
||||
equipmentChanges: ISaveLoadoutRequestNoUpgradeVer,
|
||||
accountId: string
|
||||
) => {
|
||||
): Promise<string | void> => {
|
||||
const inventory = await getInventory(accountId);
|
||||
|
||||
for (const [_equipmentName, _equipment] of Object.entries(equipmentChanges)) {
|
||||
@ -40,7 +38,7 @@ export const handleInventoryItemConfigChange = async (
|
||||
case "AdultOperatorLoadOuts": {
|
||||
const operatorConfig = equipment as IOperatorConfigEntry;
|
||||
const operatorLoadout = inventory[equipmentName];
|
||||
//console.log("loadout received", equipmentName, operatorConfig);
|
||||
console.log("operator loadout received", equipmentName, operatorConfig);
|
||||
// all non-empty entries are one loadout slot
|
||||
for (const [loadoutId, loadoutConfig] of Object.entries(operatorConfig)) {
|
||||
// console.log("loadoutId", loadoutId, "loadoutconfig", loadoutConfig);
|
||||
@ -60,12 +58,13 @@ export const handleInventoryItemConfigChange = async (
|
||||
break;
|
||||
}
|
||||
case "LoadOuts": {
|
||||
//console.log("loadout received");
|
||||
console.log("loadout received");
|
||||
const loadout = await LoadoutModel.findOne({ loadoutOwnerId: accountId });
|
||||
if (!loadout) {
|
||||
throw new Error("loadout not found");
|
||||
}
|
||||
|
||||
let newLoadoutId: Types.ObjectId | undefined;
|
||||
for (const [_loadoutSlot, _loadout] of Object.entries(equipment)) {
|
||||
const loadoutSlot = _loadoutSlot as keyof ILoadoutClient;
|
||||
const newLoadout = _loadout as ILoadoutEntry;
|
||||
@ -84,6 +83,16 @@ export const handleInventoryItemConfigChange = async (
|
||||
// if no config with this id exists, create a new one
|
||||
if (!oldLoadoutConfig) {
|
||||
const { ItemId, ...loadoutConfigItemIdRemoved } = loadoutConfig;
|
||||
|
||||
//save the new object id and assign it for every ffff return at the end
|
||||
if (ItemId.$oid === "ffffffffffffffffffffffff") {
|
||||
if (!newLoadoutId) {
|
||||
newLoadoutId = new Types.ObjectId();
|
||||
}
|
||||
loadout[loadoutSlot].push({ _id: newLoadoutId, ...loadoutConfigItemIdRemoved });
|
||||
continue;
|
||||
}
|
||||
|
||||
loadout[loadoutSlot].push({
|
||||
_id: ItemId.$oid,
|
||||
...loadoutConfigItemIdRemoved
|
||||
@ -101,6 +110,11 @@ export const handleInventoryItemConfigChange = async (
|
||||
}
|
||||
}
|
||||
await loadout.save();
|
||||
|
||||
//only return an id if a new loadout was added
|
||||
if (newLoadoutId) {
|
||||
return newLoadoutId.toString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "LongGuns":
|
||||
@ -112,7 +126,7 @@ export const handleInventoryItemConfigChange = async (
|
||||
case "DrifterMelee":
|
||||
case "Sentinels":
|
||||
case "Horses": {
|
||||
//console.log("general Item config saved", equipmentName, equipment);
|
||||
console.log("general Item config saved", equipmentName, equipment);
|
||||
|
||||
const itemEntries = equipment as IItemEntry;
|
||||
for (const [itemId, itemConfigEntries] of Object.entries(itemEntries)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user