diff --git a/src/controllers/api/rerollRandomModController.ts b/src/controllers/api/rerollRandomModController.ts index 71bc8f1c..17253ded 100644 --- a/src/controllers/api/rerollRandomModController.ts +++ b/src/controllers/api/rerollRandomModController.ts @@ -2,8 +2,7 @@ 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"; +import { IUnveiledRivenFingerprint, randomiseRivenStats } from "@/src/helpers/rivenFingerprintHelper"; export const rerollRandomModController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); @@ -25,7 +24,7 @@ export const rerollRandomModController: RequestHandler = async (req, res) => { fingerprint.rerolls++; upgrade.UpgradeFingerprint = JSON.stringify(fingerprint); - randomiseStats(upgrade.ItemType, fingerprint); + randomiseRivenStats(upgrade.ItemType, fingerprint); upgrade.PendingRerollFingerprint = JSON.stringify(fingerprint); await inventory.save(); @@ -52,28 +51,6 @@ export const rerollRandomModController: RequestHandler = async (req, res) => { } }; -const randomiseStats = (randomModType: string, fingerprint: IUnveiledRivenFingerprint): void => { - const meta = ExportUpgrades[randomModType]; - - fingerprint.buffs = []; - const numBuffs = 2 + Math.trunc(Math.random() * 2); // 2 or 3 - const buffEntries = meta.upgradeEntries!.filter(x => x.canBeBuff); - for (let i = 0; i != numBuffs; ++i) { - const buffIndex = Math.trunc(Math.random() * buffEntries.length); - const entry = buffEntries[buffIndex]; - fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) }); - buffEntries.splice(buffIndex, 1); - } - - fingerprint.curses = []; - if (Math.random() < 0.5) { - const entry = getRandomElement( - meta.upgradeEntries!.filter(x => x.canBeCurse && !fingerprint.buffs.find(y => y.Tag == x.tag)) - ); - fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) }); - } -}; - type RerollRandomModRequest = LetsGoGamblingRequest | AwDangitRequest; interface LetsGoGamblingRequest { @@ -85,20 +62,4 @@ interface AwDangitRequest { 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]; diff --git a/src/helpers/rivenFingerprintHelper.ts b/src/helpers/rivenFingerprintHelper.ts new file mode 100644 index 00000000..912b911c --- /dev/null +++ b/src/helpers/rivenFingerprintHelper.ts @@ -0,0 +1,40 @@ +import { ExportUpgrades } from "warframe-public-export-plus"; +import { getRandomElement } from "../services/rngService"; + +export interface IUnveiledRivenFingerprint { + compat: string; + lim: number; + lvl: number; + lvlReq: 0; + rerolls?: number; + pol: string; + buffs: IRivenStat[]; + curses: IRivenStat[]; +} + +interface IRivenStat { + Tag: string; + Value: number; +} + +export const randomiseRivenStats = (randomModType: string, fingerprint: IUnveiledRivenFingerprint): void => { + const meta = ExportUpgrades[randomModType]; + + fingerprint.buffs = []; + const numBuffs = 2 + Math.trunc(Math.random() * 2); // 2 or 3 + const buffEntries = meta.upgradeEntries!.filter(x => x.canBeBuff); + for (let i = 0; i != numBuffs; ++i) { + const buffIndex = Math.trunc(Math.random() * buffEntries.length); + const entry = buffEntries[buffIndex]; + fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) }); + buffEntries.splice(buffIndex, 1); + } + + fingerprint.curses = []; + if (Math.random() < 0.5) { + const entry = getRandomElement( + meta.upgradeEntries!.filter(x => x.canBeCurse && !fingerprint.buffs.find(y => y.Tag == x.tag)) + ); + fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) }); + } +};