feat: transmutation #1112
@ -1,10 +1,9 @@
 | 
			
		||||
import { toOid } from "@/src/helpers/inventoryHelpers";
 | 
			
		||||
import { IRivenChallenge, rivenRawToRealWeighted } from "@/src/helpers/rivenHelper";
 | 
			
		||||
import { createVeiledRivenFingerprint, rivenRawToRealWeighted } from "@/src/helpers/rivenHelper";
 | 
			
		||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
			
		||||
import { addMods, getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { getRandomElement, getRandomInt, getRandomReward } from "@/src/services/rngService";
 | 
			
		||||
import { logger } from "@/src/utils/logger";
 | 
			
		||||
import { getRandomElement } from "@/src/services/rngService";
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { ExportUpgrades } from "warframe-public-export-plus";
 | 
			
		||||
 | 
			
		||||
@ -19,39 +18,17 @@ export const activateRandomModController: RequestHandler = async (req, res) => {
 | 
			
		||||
        }
 | 
			
		||||
    ]);
 | 
			
		||||
    const rivenType = getRandomElement(rivenRawToRealWeighted[request.ItemType]);
 | 
			
		||||
    const challenge = getRandomElement(ExportUpgrades[rivenType].availableChallenges!);
 | 
			
		||||
    const fingerprintChallenge: IRivenChallenge = {
 | 
			
		||||
        Type: challenge.fullName,
 | 
			
		||||
        Progress: 0,
 | 
			
		||||
        Required: getRandomInt(challenge.countRange[0], challenge.countRange[1])
 | 
			
		||||
    };
 | 
			
		||||
    if (Math.random() < challenge.complicationChance) {
 | 
			
		||||
        const complications: { type: string; probability: number }[] = [];
 | 
			
		||||
        for (const complication of challenge.complications) {
 | 
			
		||||
            complications.push({
 | 
			
		||||
                type: complication.fullName,
 | 
			
		||||
                probability: complication.weight
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        fingerprintChallenge.Complication = getRandomReward(complications)!.type;
 | 
			
		||||
        logger.debug(
 | 
			
		||||
            `riven rolled challenge ${fingerprintChallenge.Type} with complication ${fingerprintChallenge.Complication}`
 | 
			
		||||
        );
 | 
			
		||||
        const complication = challenge.complications.find(x => x.fullName == fingerprintChallenge.Complication)!;
 | 
			
		||||
        fingerprintChallenge.Required *= complication.countMultiplier;
 | 
			
		||||
    } else {
 | 
			
		||||
        logger.debug(`riven rolled challenge ${fingerprintChallenge.Type}`);
 | 
			
		||||
    }
 | 
			
		||||
    const fingerprint = createVeiledRivenFingerprint(ExportUpgrades[rivenType]);
 | 
			
		||||
    const upgradeIndex =
 | 
			
		||||
        inventory.Upgrades.push({
 | 
			
		||||
            ItemType: rivenType,
 | 
			
		||||
            UpgradeFingerprint: JSON.stringify({ challenge: fingerprintChallenge })
 | 
			
		||||
            UpgradeFingerprint: JSON.stringify(fingerprint)
 | 
			
		||||
        }) - 1;
 | 
			
		||||
    await inventory.save();
 | 
			
		||||
    // For some reason, in this response, the UpgradeFingerprint is simply a nested object and not a string
 | 
			
		||||
    res.json({
 | 
			
		||||
        NewMod: {
 | 
			
		||||
            UpgradeFingerprint: { challenge: fingerprintChallenge },
 | 
			
		||||
            UpgradeFingerprint: fingerprint,
 | 
			
		||||
            ItemType: inventory.Upgrades[upgradeIndex].ItemType,
 | 
			
		||||
            ItemId: toOid(inventory.Upgrades[upgradeIndex]._id)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
import { IUpgrade } from "warframe-public-export-plus";
 | 
			
		||||
import { getRandomElement, getRandomInt } from "../services/rngService";
 | 
			
		||||
import { getRandomElement, getRandomInt, getRandomReward } from "../services/rngService";
 | 
			
		||||
 | 
			
		||||
export type RivenFingerprint = IVeiledRivenFingerprint | IUnveiledRivenFingerprint;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,28 @@ interface IRivenStat {
 | 
			
		||||
    Value: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const createVeiledRivenFingerprint = (meta: IUpgrade): IVeiledRivenFingerprint => {
 | 
			
		||||
    const challenge = getRandomElement(meta.availableChallenges!);
 | 
			
		||||
    const fingerprintChallenge: IRivenChallenge = {
 | 
			
		||||
        Type: challenge.fullName,
 | 
			
		||||
        Progress: 0,
 | 
			
		||||
        Required: getRandomInt(challenge.countRange[0], challenge.countRange[1])
 | 
			
		||||
    };
 | 
			
		||||
    if (Math.random() < challenge.complicationChance) {
 | 
			
		||||
        const complications: { type: string; probability: number }[] = [];
 | 
			
		||||
        for (const complication of challenge.complications) {
 | 
			
		||||
            complications.push({
 | 
			
		||||
                type: complication.fullName,
 | 
			
		||||
                probability: complication.weight
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        fingerprintChallenge.Complication = getRandomReward(complications)!.type;
 | 
			
		||||
        const complication = challenge.complications.find(x => x.fullName == fingerprintChallenge.Complication)!;
 | 
			
		||||
        fingerprintChallenge.Required *= complication.countMultiplier;
 | 
			
		||||
    }
 | 
			
		||||
    return { challenge: fingerprintChallenge };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const createUnveiledRivenFingerprint = (meta: IUpgrade): IUnveiledRivenFingerprint => {
 | 
			
		||||
    const fingerprint: IUnveiledRivenFingerprint = {
 | 
			
		||||
        compat: getRandomElement(meta.compatibleItems!),
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user