diff --git a/src/controllers/api/completeRandomModChallengeController.ts b/src/controllers/api/completeRandomModChallengeController.ts new file mode 100644 index 000000000..c2578eb75 --- /dev/null +++ b/src/controllers/api/completeRandomModChallengeController.ts @@ -0,0 +1,56 @@ +import { RequestHandler } from "express"; +import { getAccountIdForRequest } from "@/src/services/loginService"; +import { addMiscItems, getInventory, updateCurrency } from "@/src/services/inventoryService"; +import { IInventoryChanges } from "@/src/types/purchaseTypes"; +import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes"; +import { getJSONfromString } from "@/src/helpers/stringHelpers"; +import { IUnveiledRivenFingerprint, randomiseRivenStats } from "@/src/helpers/rivenFingerprintHelper"; +import { getRandomElement, getRandomInt } from "@/src/services/rngService"; +import { ExportUpgrades } from "warframe-public-export-plus"; + +export const completeRandomModChallengeController: RequestHandler = async (req, res) => { + const accountId = await getAccountIdForRequest(req); + const inventory = await getInventory(accountId); + const request = getJSONfromString(String(req.body)); + let inventoryChanges: IInventoryChanges = {}; + + // Remove 20 plat or riven cipher + if ((req.query.p as string) == "1") { + inventoryChanges = { ...updateCurrency(inventory, 20, true) }; + } else { + const miscItemChanges: IMiscItem[] = [ + { + ItemType: "/Lotus/Types/Items/MiscItems/RivenIdentifier", + ItemCount: -1 + } + ]; + addMiscItems(inventory, miscItemChanges); + inventoryChanges.MiscItems = miscItemChanges; + } + + // Update riven fingerprint to a randomised unveiled state + const upgrade = inventory.Upgrades.id(request.ItemId)!; + const meta = ExportUpgrades[upgrade.ItemType]; + const fingerprint: IUnveiledRivenFingerprint = { + compat: getRandomElement(meta.compatibleItems!), + lim: 0, + lvl: 0, + lvlReq: getRandomInt(8, 16), + pol: getRandomElement(["AP_ATTACK", "AP_DEFENSE", "AP_TACTIC"]), + buffs: [], + curses: [] + }; + randomiseRivenStats(meta, fingerprint); + upgrade.UpgradeFingerprint = JSON.stringify(fingerprint); + + await inventory.save(); + + res.json({ + InventoryChanges: inventoryChanges, + Fingerprint: upgrade.UpgradeFingerprint + }); +}; + +interface ICompleteRandomModChallengeRequest { + ItemId: string; +} diff --git a/src/controllers/api/rerollRandomModController.ts b/src/controllers/api/rerollRandomModController.ts index 71bc8f1c2..e35df1a84 100644 --- a/src/controllers/api/rerollRandomModController.ts +++ b/src/controllers/api/rerollRandomModController.ts @@ -2,8 +2,8 @@ import { RequestHandler } from "express"; import { getAccountIdForRequest } from "@/src/services/loginService"; import { addMiscItems, getInventory } from "@/src/services/inventoryService"; import { getJSONfromString } from "@/src/helpers/stringHelpers"; +import { IUnveiledRivenFingerprint, randomiseRivenStats } from "@/src/helpers/rivenFingerprintHelper"; import { ExportUpgrades } from "warframe-public-export-plus"; -import { getRandomElement } from "@/src/services/rngService"; export const rerollRandomModController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); @@ -25,7 +25,7 @@ export const rerollRandomModController: RequestHandler = async (req, res) => { fingerprint.rerolls++; upgrade.UpgradeFingerprint = JSON.stringify(fingerprint); - randomiseStats(upgrade.ItemType, fingerprint); + randomiseRivenStats(ExportUpgrades[upgrade.ItemType], fingerprint); upgrade.PendingRerollFingerprint = JSON.stringify(fingerprint); await inventory.save(); @@ -52,28 +52,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 +63,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 000000000..c37423919 --- /dev/null +++ b/src/helpers/rivenFingerprintHelper.ts @@ -0,0 +1,38 @@ +import { IUpgrade } from "warframe-public-export-plus"; +import { getRandomElement } from "../services/rngService"; + +export interface IUnveiledRivenFingerprint { + compat: string; + lim: 0; + lvl: number; + lvlReq: number; + rerolls?: number; + pol: string; + buffs: IRivenStat[]; + curses: IRivenStat[]; +} + +interface IRivenStat { + Tag: string; + Value: number; +} + +export const randomiseRivenStats = (meta: IUpgrade, fingerprint: IUnveiledRivenFingerprint): void => { + 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) }); + } +}; diff --git a/src/routes/api.ts b/src/routes/api.ts index 2b3e511c5..0a2c67167 100644 --- a/src/routes/api.ts +++ b/src/routes/api.ts @@ -8,6 +8,7 @@ import { changeDojoRootController } from "@/src/controllers/api/changeDojoRootCo import { checkDailyMissionBonusController } from "@/src/controllers/api/checkDailyMissionBonusController"; import { claimCompletedRecipeController } from "@/src/controllers/api/claimCompletedRecipeController"; import { clearDialogueHistoryController } from "@/src/controllers/api/clearDialogueHistoryController"; +import { completeRandomModChallengeController } from "@/src/controllers/api/completeRandomModChallengeController"; import { createGuildController } from "@/src/controllers/api/createGuildController"; import { creditsController } from "@/src/controllers/api/creditsController"; import { deleteSessionController } from "@/src/controllers/api/deleteSessionController"; @@ -133,6 +134,7 @@ apiRouter.post("/artifacts.php", artifactsController); apiRouter.post("/changeDojoRoot.php", changeDojoRootController); apiRouter.post("/claimCompletedRecipe.php", claimCompletedRecipeController); apiRouter.post("/clearDialogueHistory.php", clearDialogueHistoryController); +apiRouter.post("/completeRandomModChallenge.php", completeRandomModChallengeController); apiRouter.post("/createGuild.php", createGuildController); apiRouter.post("/endlessXp.php", endlessXpController); apiRouter.post("/evolveWeapon.php", evolveWeaponController);