feat: implement socketing of ayatan sculptures #542

Merged
Sainan merged 2 commits from ayatan into main 2024-10-12 14:51:45 -07:00
6 changed files with 59 additions and 10 deletions

8
package-lock.json generated
View File

@ -12,7 +12,7 @@
"copyfiles": "^2.4.1",
"express": "^5.0.0-beta.3",
"mongoose": "^8.4.5",
"warframe-public-export-plus": "^0.5.1",
"warframe-public-export-plus": "^0.5.2",
"warframe-riven-info": "^0.1.1",
"winston": "^3.13.0",
"winston-daily-rotate-file": "^5.0.0"
@ -3778,9 +3778,9 @@
}
},
"node_modules/warframe-public-export-plus": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.1.tgz",
"integrity": "sha512-i9Qlh/xEqUQzLj6Dda0VB0nWkyEyWDYEnAyNTbb3IxebCLWEcizCSf3nkAae5xuKvwCvOefInOAa2YgiYwzr/A=="
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.2.tgz",
"integrity": "sha512-mv7abHis5ytlevnx9lSLwnqnv5/3t322/OKkR99Hrw+w7Qm+Ps6agZcTqNaIy6zrM1vsvWY1NnbxVe2+JIW6/Q=="
},
"node_modules/warframe-riven-info": {
"version": "0.1.1",

View File

@ -16,7 +16,7 @@
"copyfiles": "^2.4.1",
"express": "^5.0.0-beta.3",
"mongoose": "^8.4.5",
"warframe-public-export-plus": "^0.5.1",
"warframe-public-export-plus": "^0.5.2",
"warframe-riven-info": "^0.1.1",
"winston": "^3.13.0",
"winston-daily-rotate-file": "^5.0.0"

View File

@ -0,0 +1,50 @@
import { RequestHandler } from "express";
import { ExportResources } from "warframe-public-export-plus";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { addFusionTreasures, addMiscItems, getInventory } from "@/src/services/inventoryService";
import { IFusionTreasure, IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
interface IFusionTreasureRequest {
oldTreasureName: string;
newTreasureName: string;
}
const parseFusionTreasure = (name: string, count: number): IFusionTreasure => {
const arr = name.split("_");
return {
ItemType: arr[0],
Sockets: parseInt(arr[1], 16),
ItemCount: count
};
};
// eslint-disable-next-line @typescript-eslint/no-misused-promises
export const fusionTreasuresController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const request = JSON.parse(req.body.toString() as string) as IFusionTreasureRequest;
coderabbitai[bot] commented 2024-10-11 16:42:49 -07:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

⚠️ Potential issue

Consider using req.body directly and add input validation.

If body-parsing middleware is used in Express, req.body is already a parsed object. Parsing it again with JSON.parse may be unnecessary and could lead to errors.

Recommended change:

-const request = JSON.parse(req.body.toString() as string) as IFusionTreasureRequest;
+const request = req.body as IFusionTreasureRequest;

Additionally, it's important to validate the request data to ensure that oldTreasureName and newTreasureName are present and are valid strings. Consider adding validation and appropriate error handling to prevent potential runtime exceptions.

Committable suggestion was skipped due to low confidence.

_:hammer_and_wrench: Refactor suggestion_ _:warning: Potential issue_ **Consider using `req.body` directly and add input validation.** If body-parsing middleware is used in Express, `req.body` is already a parsed object. Parsing it again with `JSON.parse` may be unnecessary and could lead to errors. Recommended change: ```diff -const request = JSON.parse(req.body.toString() as string) as IFusionTreasureRequest; +const request = req.body as IFusionTreasureRequest; ``` Additionally, it's important to validate the request data to ensure that `oldTreasureName` and `newTreasureName` are present and are valid strings. Consider adding validation and appropriate error handling to prevent potential runtime exceptions. > Committable suggestion was skipped due to low confidence. <!-- This is an auto-generated reply by CodeRabbit -->
Review

Kill yourself

Kill yourself
coderabbitai[bot] commented 2024-10-11 16:47:25 -07:00 (Migrated from github.com)
Review

@Sainan, I'm sorry to hear that you're feeling this way. If there's anything I can assist you with, please let me know.

(_/)
(•_•)

@Sainan, I'm sorry to hear that you're feeling this way. If there's anything I can assist you with, please let me know. (\_/) (•_•) <!-- This is an auto-generated reply by CodeRabbit -->
const oldTreasure = parseFusionTreasure(request.oldTreasureName, -1);
const newTreasure = parseFusionTreasure(request.newTreasureName, 1);
// Swap treasures
addFusionTreasures(inventory, [oldTreasure]);
addFusionTreasures(inventory, [newTreasure]);
// Remove consumed stars
const miscItemChanges: IMiscItem[] = [];
const filledSockets = newTreasure.Sockets & ~oldTreasure.Sockets;
for (let i = 0; filledSockets >> i; ++i) {
if ((filledSockets >> i) & 1) {
coderabbitai[bot] commented 2024-10-11 16:42:49 -07:00 (Migrated from github.com)
Review

⚠️ Potential issue

Fix the loop condition to prevent incorrect termination.

The loop condition for (let i = 0; filledSockets >> i; ++i) may not function as intended. If filledSockets becomes zero after right-shifting, the loop could terminate prematurely or lead to incorrect behavior.

Consider modifying the loop condition to ensure it iterates over all bits:

-for (let i = 0; filledSockets >> i; ++i) {
+for (let i = 0; (filledSockets >> i) > 0; ++i) {

Alternatively, if the number of sockets is known (e.g., 32 bits), you could use:

for (let i = 0; i < 32; ++i) {
    if ((filledSockets >> i) & 1) {
        // ...
    }
}

This ensures the loop checks each bit position consistently.

_:warning: Potential issue_ **Fix the loop condition to prevent incorrect termination.** The loop condition `for (let i = 0; filledSockets >> i; ++i)` may not function as intended. If `filledSockets` becomes zero after right-shifting, the loop could terminate prematurely or lead to incorrect behavior. Consider modifying the loop condition to ensure it iterates over all bits: ```diff -for (let i = 0; filledSockets >> i; ++i) { +for (let i = 0; (filledSockets >> i) > 0; ++i) { ``` Alternatively, if the number of sockets is known (e.g., 32 bits), you could use: ```javascript for (let i = 0; i < 32; ++i) { if ((filledSockets >> i) & 1) { // ... } } ``` This ensures the loop checks each bit position consistently. <!-- This is an auto-generated reply by CodeRabbit -->
Review

Kill yourself

Kill yourself
coderabbitai[bot] commented 2024-10-11 16:45:53 -07:00 (Migrated from github.com)
Review

@Sainan, understood. Let me know if there's anything else I can assist you with.

(_/)
( •_•)
🌸

@Sainan, understood. Let me know if there's anything else I can assist you with. (\_/) ( •_•) 🌸 <!-- This is an auto-generated reply by CodeRabbit -->
//console.log("Socket", i, "has been filled with", ExportResources[oldTreasure.ItemType].sockets![i]);
miscItemChanges.push({
ItemType: ExportResources[oldTreasure.ItemType].sockets![i],
ItemCount: -1
});
}
}
addMiscItems(inventory, miscItemChanges);
await inventory.save();
res.end();
};

View File

@ -36,7 +36,7 @@ const getItemListsController: RequestHandler = (_req, res) => {
}
for (const [uniqueName, item] of Object.entries(ExportResources)) {
miscitems.push({
uniqueName: "MiscItems:" + uniqueName,
uniqueName: item.productCategory + ":" + uniqueName,
name: getEnglishString(item.name)
});
}

View File

@ -11,6 +11,7 @@ import { dronesController } from "@/src/controllers/api/dronesController";
import { evolveWeaponController } from "@/src/controllers/api/evolveWeaponController";
import { findSessionsController } from "@/src/controllers/api/findSessionsController";
import { focusController } from "@/src/controllers/api/focusController";
import { fusionTreasuresController } from "@/src/controllers/api/fusionTreasuresController";
import { genericUpdateController } from "@/src/controllers/api/genericUpdateController";
import { getAllianceController } from "@/src/controllers/api/getAllianceController";
import { getCreditsController } from "@/src/controllers/api/getCreditsController";
@ -109,6 +110,7 @@ apiRouter.post("/createGuild.php", createGuildController);
apiRouter.post("/evolveWeapon.php", evolveWeaponController);
apiRouter.post("/findSessions.php", findSessionsController);
apiRouter.post("/focus.php", focusController);
apiRouter.post("/fusionTreasures.php", fusionTreasuresController);
apiRouter.post("/genericUpdate.php", genericUpdateController);
apiRouter.post("/getAlliance.php", getAllianceController);
apiRouter.post("/gildWeapon.php", gildWeaponController);

View File

@ -657,10 +657,7 @@ export const addFusionTreasures = (
) => {
const { FusionTreasures } = inventory;
itemsArray?.forEach(({ ItemType, ItemCount, Sockets }) => {
const itemIndex = FusionTreasures.findIndex(i => {
i.ItemType === ItemType;
i.Sockets === Sockets;
});
const itemIndex = FusionTreasures.findIndex(i => i.ItemType == ItemType && (i.Sockets || 0) == (Sockets || 0));
if (itemIndex !== -1) {
FusionTreasures[itemIndex].ItemCount += ItemCount;