feat: dojo room energy & capacity costs & gains #633
							
								
								
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -12,7 +12,7 @@
 | 
				
			|||||||
        "copyfiles": "^2.4.1",
 | 
					        "copyfiles": "^2.4.1",
 | 
				
			||||||
        "express": "^5",
 | 
					        "express": "^5",
 | 
				
			||||||
        "mongoose": "^8.9.2",
 | 
					        "mongoose": "^8.9.2",
 | 
				
			||||||
        "warframe-public-export-plus": "^0.5.13",
 | 
					        "warframe-public-export-plus": "^0.5.14",
 | 
				
			||||||
        "warframe-riven-info": "^0.1.2",
 | 
					        "warframe-riven-info": "^0.1.2",
 | 
				
			||||||
        "winston": "^3.17.0",
 | 
					        "winston": "^3.17.0",
 | 
				
			||||||
        "winston-daily-rotate-file": "^5.0.0"
 | 
					        "winston-daily-rotate-file": "^5.0.0"
 | 
				
			||||||
@ -3877,9 +3877,9 @@
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/warframe-public-export-plus": {
 | 
					    "node_modules/warframe-public-export-plus": {
 | 
				
			||||||
      "version": "0.5.13",
 | 
					      "version": "0.5.14",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.13.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.14.tgz",
 | 
				
			||||||
      "integrity": "sha512-iyiaEsgZGQMU29jDag+Pq1z2q0/Zj4bCzTMtoZCSFtNUiZOPYwzjBmbYsDN0FO/yUoHu2dboW0lEYsdaofTEDQ=="
 | 
					      "integrity": "sha512-G6Jrs1PoETheYQjN2Mm6qVZeiIS5h2U8e+nHC3fPDVhLz3gZkbZShDOTCJ3JNAlP1NFrFYoBqUc6gMmN0Z9Acg=="
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/warframe-riven-info": {
 | 
					    "node_modules/warframe-riven-info": {
 | 
				
			||||||
      "version": "0.1.2",
 | 
					      "version": "0.1.2",
 | 
				
			||||||
 | 
				
			|||||||
@ -16,7 +16,7 @@
 | 
				
			|||||||
    "copyfiles": "^2.4.1",
 | 
					    "copyfiles": "^2.4.1",
 | 
				
			||||||
    "express": "^5",
 | 
					    "express": "^5",
 | 
				
			||||||
    "mongoose": "^8.9.2",
 | 
					    "mongoose": "^8.9.2",
 | 
				
			||||||
    "warframe-public-export-plus": "^0.5.13",
 | 
					    "warframe-public-export-plus": "^0.5.14",
 | 
				
			||||||
    "warframe-riven-info": "^0.1.2",
 | 
					    "warframe-riven-info": "^0.1.2",
 | 
				
			||||||
    "winston": "^3.17.0",
 | 
					    "winston": "^3.17.0",
 | 
				
			||||||
    "winston-daily-rotate-file": "^5.0.0"
 | 
					    "winston-daily-rotate-file": "^5.0.0"
 | 
				
			||||||
 | 
				
			|||||||
@ -33,8 +33,8 @@ export const getGuildDojoController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
        FixedContributions: true,
 | 
					        FixedContributions: true,
 | 
				
			||||||
        DojoRevision: 1,
 | 
					        DojoRevision: 1,
 | 
				
			||||||
        RevisionTime: Math.round(Date.now() / 1000),
 | 
					        RevisionTime: Math.round(Date.now() / 1000),
 | 
				
			||||||
        Energy: 5,
 | 
					        Energy: guild.DojoEnergy,
 | 
				
			||||||
        Capacity: 100,
 | 
					        Capacity: guild.DojoCapacity,
 | 
				
			||||||
        DojoRequestStatus: 0,
 | 
					        DojoRequestStatus: 0,
 | 
				
			||||||
        DojoComponents: []
 | 
					        DojoComponents: []
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
				
			|||||||
@ -1,13 +1,21 @@
 | 
				
			|||||||
import { getGuildForRequest } from "@/src/services/guildService";
 | 
					import { getGuildForRequest } from "@/src/services/guildService";
 | 
				
			||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
 | 
					import { ExportDojoRecipes } from "warframe-public-export-plus";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const queueDojoComponentDestructionController: RequestHandler = async (req, res) => {
 | 
					export const queueDojoComponentDestructionController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const guild = await getGuildForRequest(req);
 | 
					    const guild = await getGuildForRequest(req);
 | 
				
			||||||
    const componentId = req.query.componentId as string;
 | 
					    const componentId = req.query.componentId as string;
 | 
				
			||||||
    guild.DojoComponents!.splice(
 | 
					    const component = guild.DojoComponents!.splice(
 | 
				
			||||||
        guild.DojoComponents!.findIndex(x => x._id.toString() === componentId),
 | 
					        guild.DojoComponents!.findIndex(x => x._id.toString() === componentId),
 | 
				
			||||||
        1
 | 
					        1
 | 
				
			||||||
    );
 | 
					    )[0];
 | 
				
			||||||
 | 
					    if (component) {
 | 
				
			||||||
 | 
					        const room = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf);
 | 
				
			||||||
 | 
					        if (room) {
 | 
				
			||||||
 | 
					            guild.DojoCapacity -= room.capacity;
 | 
				
			||||||
 | 
					            guild.DojoEnergy -= room.energy;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    await guild.save();
 | 
					    await guild.save();
 | 
				
			||||||
    res.json({
 | 
					    res.json({
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 | 
				|||||||
        DojoRequestStatus: 1
 | 
					        DojoRequestStatus: 1
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@ import { RequestHandler } from "express";
 | 
				
			|||||||
import { IDojoComponentClient } from "@/src/types/guildTypes";
 | 
					import { IDojoComponentClient } from "@/src/types/guildTypes";
 | 
				
			||||||
import { getGuildForRequest } from "@/src/services/guildService";
 | 
					import { getGuildForRequest } from "@/src/services/guildService";
 | 
				
			||||||
import { Types } from "mongoose";
 | 
					import { Types } from "mongoose";
 | 
				
			||||||
 | 
					import { ExportDojoRecipes } from "warframe-public-export-plus";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface IStartDojoRecipeRequest {
 | 
					interface IStartDojoRecipeRequest {
 | 
				
			||||||
    PlacedComponent: IDojoComponentClient;
 | 
					    PlacedComponent: IDojoComponentClient;
 | 
				
			||||||
@ -12,6 +13,13 @@ export const startDojoRecipeController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
    const guild = await getGuildForRequest(req);
 | 
					    const guild = await getGuildForRequest(req);
 | 
				
			||||||
    // At this point, we know that a member of the guild is making this request. Assuming they are allowed to start a build.
 | 
					    // At this point, we know that a member of the guild is making this request. Assuming they are allowed to start a build.
 | 
				
			||||||
    const request = JSON.parse(String(req.body)) as IStartDojoRecipeRequest;
 | 
					    const request = JSON.parse(String(req.body)) as IStartDojoRecipeRequest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const room = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == request.PlacedComponent.pf);
 | 
				
			||||||
 | 
					    if (room) {
 | 
				
			||||||
 | 
					        guild.DojoCapacity += room.capacity;
 | 
				
			||||||
 | 
					        guild.DojoEnergy += room.energy;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    guild.DojoComponents!.push({
 | 
					    guild.DojoComponents!.push({
 | 
				
			||||||
        _id: new Types.ObjectId(),
 | 
					        _id: new Types.ObjectId(),
 | 
				
			||||||
        pf: request.PlacedComponent.pf,
 | 
					        pf: request.PlacedComponent.pf,
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,9 @@ const dojoComponentSchema = new Schema<IDojoComponentDatabase>({
 | 
				
			|||||||
const guildSchema = new Schema<IGuildDatabase>(
 | 
					const guildSchema = new Schema<IGuildDatabase>(
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Name: { type: String, required: true },
 | 
					        Name: { type: String, required: true },
 | 
				
			||||||
        DojoComponents: [dojoComponentSchema]
 | 
					        DojoComponents: [dojoComponentSchema],
 | 
				
			||||||
 | 
					        DojoCapacity: { type: Number, default: 100 },
 | 
				
			||||||
 | 
					        DojoEnergy: { type: Number, default: 5 }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    { id: false }
 | 
					    { id: false }
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,8 @@ export interface IGuild {
 | 
				
			|||||||
export interface IGuildDatabase extends IGuild {
 | 
					export interface IGuildDatabase extends IGuild {
 | 
				
			||||||
    _id: Types.ObjectId;
 | 
					    _id: Types.ObjectId;
 | 
				
			||||||
    DojoComponents?: IDojoComponentDatabase[];
 | 
					    DojoComponents?: IDojoComponentDatabase[];
 | 
				
			||||||
 | 
					    DojoCapacity: number;
 | 
				
			||||||
 | 
					    DojoEnergy: number;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface ICreateGuildRequest {
 | 
					export interface ICreateGuildRequest {
 | 
				
			||||||
@ -30,7 +32,7 @@ export interface IDojoClient {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export interface IDojoComponentClient {
 | 
					export interface IDojoComponentClient {
 | 
				
			||||||
    id: IOid;
 | 
					    id: IOid;
 | 
				
			||||||
    pf: string;
 | 
					    pf: string; // Prefab (.level)
 | 
				
			||||||
    ppf: string;
 | 
					    ppf: string;
 | 
				
			||||||
    pi?: IOid; // Parent ID. N/A to root.
 | 
					    pi?: IOid; // Parent ID. N/A to root.
 | 
				
			||||||
    op?: string; // "Open Portal"? N/A to root.
 | 
					    op?: string; // "Open Portal"? N/A to root.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	
🛠️ Refactor suggestion
Validate post-destruction capacity and energy bounds.
If a destroyed room’s capacity or energy is higher than the guild’s current capacity or energy, you might end up with negative values. Consider adding a floor check or validation.