feat: rerolling rivens

This commit is contained in:
Sainan 2025-01-18 14:07:44 +01:00
parent f1c3dcbefc
commit 29a9fe5716
5 changed files with 108 additions and 12 deletions

8
package-lock.json generated
View File

@ -12,7 +12,7 @@
"copyfiles": "^2.4.1",
"express": "^5",
"mongoose": "^8.9.4",
"warframe-public-export-plus": "^0.5.23",
"warframe-public-export-plus": "^0.5.24",
"warframe-riven-info": "^0.1.2",
"winston": "^3.17.0",
"winston-daily-rotate-file": "^5.0.0"
@ -3778,9 +3778,9 @@
}
},
"node_modules/warframe-public-export-plus": {
"version": "0.5.23",
"resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.23.tgz",
"integrity": "sha512-AJLivzXpon+UDm+SYq3wIXiP4OXCDOgXvCG1VLawJrHW3VDff+NpsUJApBPA4S8oZ8N8NPyBVKBvuoF2Pplaeg=="
"version": "0.5.24",
"resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.24.tgz",
"integrity": "sha512-GHjOxFcfPaLbhs/1Adgk6y3qPJ7ptBO/sW2oQ4aSdDj68oETkDjHwDQrn4eFjaYKGOmVwAzVDPMgLKWaD/fmKg=="
},
"node_modules/warframe-riven-info": {
"version": "0.1.2",

View File

@ -16,7 +16,7 @@
"copyfiles": "^2.4.1",
"express": "^5",
"mongoose": "^8.9.4",
"warframe-public-export-plus": "^0.5.23",
"warframe-public-export-plus": "^0.5.24",
"warframe-riven-info": "^0.1.2",
"winston": "^3.17.0",
"winston-daily-rotate-file": "^5.0.0"

View File

@ -1,9 +1,104 @@
import { logger } from "@/src/utils/logger";
import { RequestHandler } from "express";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { addMiscItems, getInventory } from "@/src/services/inventoryService";
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { ExportUpgrades } from "warframe-public-export-plus";
import { getRandomElement } from "@/src/services/rngService";
const rerollRandomModController: RequestHandler = (_req, res) => {
logger.debug("RerollRandomMod Request", { info: _req.body.toString("hex").replace(/(.)(.)/g, "$1$2 ") });
res.json({});
export const rerollRandomModController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const request = getJSONfromString(String(req.body)) as RerollRandomModRequest;
if ("ItemIds" in request) {
const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0])!;
const fingerprint = JSON.parse(upgrade.UpgradeFingerprint!) as IUnveiledRivenFingerprint;
const kuvaCost = fingerprint.rerolls < rerollCosts.length ? rerollCosts[fingerprint.rerolls] : 3500;
addMiscItems(inventory, [
{
ItemType: "/Lotus/Types/Items/MiscItems/Kuva",
ItemCount: kuvaCost * -1
}
]);
fingerprint.rerolls++;
upgrade.UpgradeFingerprint = JSON.stringify(fingerprint);
randomiseStats(upgrade.ItemType, fingerprint);
upgrade.PendingRerollFingerprint = JSON.stringify(fingerprint);
await inventory.save();
res.json({
changes: [
{
ItemId: { $oid: request.ItemIds[0] },
UpgradeFingerprint: upgrade.UpgradeFingerprint,
PendingRerollFingerprint: upgrade.PendingRerollFingerprint
}
],
cost: kuvaCost
});
} else {
const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId)!;
if (request.CommitReroll) {
upgrade.UpgradeFingerprint = upgrade.PendingRerollFingerprint;
}
upgrade.PendingRerollFingerprint = undefined;
await inventory.save();
res.send(upgrade.UpgradeFingerprint);
}
};
export { rerollRandomModController };
const randomiseStats = (randomModType: string, fingerprint: IUnveiledRivenFingerprint): void => {
const meta = ExportUpgrades[randomModType];
fingerprint.buffs = [];
const numBuffs = 2 + Math.trunc(Math.random() * 2); // 2 or 3
for (let i = 0; i != numBuffs; ++i) {
let entry = getRandomElement(meta.upgradeEntries!);
while (!entry.canBeBuff) {
entry = getRandomElement(meta.upgradeEntries!);
}
fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
}
fingerprint.curses = [];
const numCurses = Math.trunc(Math.random() * 2); // 0 or 1
for (let i = 0; i != numCurses; ++i) {
let entry = getRandomElement(meta.upgradeEntries!);
while (!entry.canBeCurse) {
entry = getRandomElement(meta.upgradeEntries!);
}
fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
}
};
type RerollRandomModRequest = LetsGoGamblingRequest | AwDangitRequest;
interface LetsGoGamblingRequest {
ItemIds: string[];
}
interface AwDangitRequest {
ItemId: string;
CommitReroll: boolean;
}
interface IUnveiledRivenFingerprint {
compat: string;
lim: number;
lvl: number;
lvlReq: 0;
rerolls: number;
pol: string;
buffs: IRivenStat[];
curses: IRivenStat[];
}
interface IRivenStat {
Tag: string;
Value: number;
}
const rerollCosts = [900, 1000, 1200, 1400, 1700, 2000, 2350, 2750, 3150];

View File

@ -283,10 +283,10 @@ RawUpgrades.set("toJSON", {
}
});
//TODO: find out what this is
const upgradesSchema = new Schema(
const upgradesSchema = new Schema<ICrewShipSalvagedWeaponSkin>(
{
UpgradeFingerprint: String,
PendingRerollFingerprint: { type: String, required: false },
ItemType: String
},
{ id: false }

View File

@ -419,6 +419,7 @@ export interface ISlots {
export interface ICrewShipSalvagedWeaponSkin {
ItemType: string;
UpgradeFingerprint?: string;
PendingRerollFingerprint?: string;
ItemId?: IOid;
_id?: Types.ObjectId;
}