diff --git a/package-lock.json b/package-lock.json index 331f4168..52d5f73e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "copyfiles": "^2.4.1", "express": "^5.0.0-beta.3", "mongoose": "^8.9.2", - "warframe-public-export-plus": "^0.5.7", + "warframe-public-export-plus": "^0.5.8", "warframe-riven-info": "^0.1.2", "winston": "^3.17.0", "winston-daily-rotate-file": "^5.0.0" @@ -3877,9 +3877,9 @@ } }, "node_modules/warframe-public-export-plus": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.7.tgz", - "integrity": "sha512-5cT48YPZCJ/KGCtAK4hGtaE6709CYIPzCJUI/8odJxntnUfe2R3Np+T8+iw431H2mVA+4CF9ByhvicODhdBPLw==" + "version": "0.5.8", + "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.8.tgz", + "integrity": "sha512-ZhHrKIkI6nhjKDlxhrNcfN8r2Yc9g+eeKLS6+9w7gzC4NscIt6TU8tH8bfjJTDeo6nRrzt88szX1/Oo3WnUY4Q==" }, "node_modules/warframe-riven-info": { "version": "0.1.2", diff --git a/package.json b/package.json index d8b2b2bf..3e4ac173 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "copyfiles": "^2.4.1", "express": "^5.0.0-beta.3", "mongoose": "^8.9.2", - "warframe-public-export-plus": "^0.5.7", + "warframe-public-export-plus": "^0.5.8", "warframe-riven-info": "^0.1.2", "winston": "^3.17.0", "winston-daily-rotate-file": "^5.0.0" diff --git a/src/controllers/api/infestedFoundryController.ts b/src/controllers/api/infestedFoundryController.ts index cbfa0fa8..cf363a72 100644 --- a/src/controllers/api/infestedFoundryController.ts +++ b/src/controllers/api/infestedFoundryController.ts @@ -3,6 +3,8 @@ import { getAccountIdForRequest } from "@/src/services/loginService"; import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { getInventory, addMiscItems } from "@/src/services/inventoryService"; import { IOid } from "@/src/types/commonTypes"; +import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes"; +import { ExportMisc } from "warframe-public-export-plus"; // eslint-disable-next-line @typescript-eslint/no-misused-promises export const infestedFoundryController: RequestHandler = async (req, res) => { @@ -53,6 +55,57 @@ export const infestedFoundryController: RequestHandler = async (req, res) => { break; } + case "c": { + // consume items + const request = getJSONfromString(String(req.body)) as IHelminthFeedRequest; + const inventory = await getInventory(accountId); + inventory.InfestedFoundry ??= {}; + inventory.InfestedFoundry.Resources ??= []; + inventory.InfestedFoundry.XP ??= 0; + + const miscItemChanges: IMiscItem[] = []; + let totalPercentagePointsGained = 0; + + for (const contribution of request.ResourceContributions) { + const snack = ExportMisc.helminthSnacks[contribution.ItemType]; + + // Note: Currently ignoring loss of apetite + totalPercentagePointsGained += snack.gain / 0.01; + const resource = inventory.InfestedFoundry.Resources.find(x => x.ItemType == snack.type); + if (resource) { + resource.Count += Math.trunc(snack.gain * 1000); + } else { + inventory.InfestedFoundry.Resources.push({ + ItemType: snack.type, + Count: Math.trunc(snack.gain * 1000) + }); + } + + // tally items for removal + const change = miscItemChanges.find(x => x.ItemType == contribution.ItemType); + if (change) { + change.ItemCount -= snack.count; + } else { + miscItemChanges.push({ ItemType: contribution.ItemType, ItemCount: snack.count * -1 }); + } + } + + inventory.InfestedFoundry.XP += 666 * totalPercentagePointsGained; + addMiscItems(inventory, miscItemChanges); + await inventory.save(); + + res.json({ + InventoryChanges: { + InfestedFoundry: { + XP: inventory.InfestedFoundry.XP, + Resources: inventory.InfestedFoundry.Resources + } + }, + MiscItems: miscItemChanges + }); + break; + } + case "o": // offerings update // {"OfferingsIndex":540,"SuitTypes":["/Lotus/Powersuits/PaxDuviricus/PaxDuviricusBaseSuit","/Lotus/Powersuits/Nezha/NezhaBaseSuit","/Lotus/Powersuits/Devourer/DevourerBaseSuit"],"Extra":false} res.status(404).end(); @@ -74,6 +127,13 @@ interface IHelminthNameRequest { newName: string; } +interface IHelminthFeedRequest { + ResourceContributions: { + ItemType: string; + Date: number; // unix timestamp + }[]; +} + const colorToShard: Record = { ACC_RED: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalAmar", ACC_RED_MYTHIC: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalAmarMythic", diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index 41df80c4..6094e0ea 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -25,6 +25,7 @@ import { IPlayerSkills, ISettings, IInfestedFoundry, + IHelminthResource, IConsumedSuit, IQuestProgress, IQuestKeyDatabase, @@ -454,10 +455,12 @@ const consumedSchuitsSchema = new Schema({ c: colorSchema }); +const helminthResourceSchema = new Schema({ ItemType: String, Count: Number }, { _id: false }); + const infestedFoundrySchema = new Schema( { Name: String, - Resources: { type: [typeCountSchema], default: undefined }, + Resources: { type: [helminthResourceSchema], default: undefined }, Slots: Number, XP: Number, ConsumedSuits: { type: [consumedSchuitsSchema], default: undefined }, diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index b3259209..bf76b33c 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -524,9 +524,15 @@ export interface IFusionTreasure { Sockets: number; } +// Like ITypeCount except 'Count' instead of 'ItemCount' +export interface IHelminthResource { + ItemType: string; + Count: number; +} + export interface IInfestedFoundry { Name?: string; - Resources?: ITypeCount[]; + Resources?: IHelminthResource[]; Slots?: number; XP?: number; ConsumedSuits?: IConsumedSuit[];