forked from OpenWF/SpaceNinjaServer
		
	feat: unveil riven with cipher (#992)
Related to #722 Reviewed-on: OpenWF/SpaceNinjaServer#992 Co-authored-by: Sainan <sainan@calamity.inc> Co-committed-by: Sainan <sainan@calamity.inc>
This commit is contained in:
		
							parent
							
								
									84d7b5a62e
								
							
						
					
					
						commit
						837e041db8
					
				
							
								
								
									
										56
									
								
								src/controllers/api/completeRandomModChallengeController.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								src/controllers/api/completeRandomModChallengeController.ts
									
									
									
									
									
										Normal file
									
								
							@ -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<ICompleteRandomModChallengeRequest>(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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -2,8 +2,8 @@ import { RequestHandler } from "express";
 | 
				
			|||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { addMiscItems, getInventory } from "@/src/services/inventoryService";
 | 
					import { addMiscItems, getInventory } from "@/src/services/inventoryService";
 | 
				
			||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
					import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
				
			||||||
 | 
					import { IUnveiledRivenFingerprint, randomiseRivenStats } from "@/src/helpers/rivenFingerprintHelper";
 | 
				
			||||||
import { ExportUpgrades } from "warframe-public-export-plus";
 | 
					import { ExportUpgrades } from "warframe-public-export-plus";
 | 
				
			||||||
import { getRandomElement } from "@/src/services/rngService";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const rerollRandomModController: RequestHandler = async (req, res) => {
 | 
					export const rerollRandomModController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
@ -25,7 +25,7 @@ export const rerollRandomModController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
        fingerprint.rerolls++;
 | 
					        fingerprint.rerolls++;
 | 
				
			||||||
        upgrade.UpgradeFingerprint = JSON.stringify(fingerprint);
 | 
					        upgrade.UpgradeFingerprint = JSON.stringify(fingerprint);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        randomiseStats(upgrade.ItemType, fingerprint);
 | 
					        randomiseRivenStats(ExportUpgrades[upgrade.ItemType], fingerprint);
 | 
				
			||||||
        upgrade.PendingRerollFingerprint = JSON.stringify(fingerprint);
 | 
					        upgrade.PendingRerollFingerprint = JSON.stringify(fingerprint);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await inventory.save();
 | 
					        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;
 | 
					type RerollRandomModRequest = LetsGoGamblingRequest | AwDangitRequest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface LetsGoGamblingRequest {
 | 
					interface LetsGoGamblingRequest {
 | 
				
			||||||
@ -85,20 +63,4 @@ interface AwDangitRequest {
 | 
				
			|||||||
    CommitReroll: boolean;
 | 
					    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];
 | 
					const rerollCosts = [900, 1000, 1200, 1400, 1700, 2000, 2350, 2750, 3150];
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										38
									
								
								src/helpers/rivenFingerprintHelper.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/helpers/rivenFingerprintHelper.ts
									
									
									
									
									
										Normal file
									
								
							@ -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) });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@ -8,6 +8,7 @@ import { changeDojoRootController } from "@/src/controllers/api/changeDojoRootCo
 | 
				
			|||||||
import { checkDailyMissionBonusController } from "@/src/controllers/api/checkDailyMissionBonusController";
 | 
					import { checkDailyMissionBonusController } from "@/src/controllers/api/checkDailyMissionBonusController";
 | 
				
			||||||
import { claimCompletedRecipeController } from "@/src/controllers/api/claimCompletedRecipeController";
 | 
					import { claimCompletedRecipeController } from "@/src/controllers/api/claimCompletedRecipeController";
 | 
				
			||||||
import { clearDialogueHistoryController } from "@/src/controllers/api/clearDialogueHistoryController";
 | 
					import { clearDialogueHistoryController } from "@/src/controllers/api/clearDialogueHistoryController";
 | 
				
			||||||
 | 
					import { completeRandomModChallengeController } from "@/src/controllers/api/completeRandomModChallengeController";
 | 
				
			||||||
import { createGuildController } from "@/src/controllers/api/createGuildController";
 | 
					import { createGuildController } from "@/src/controllers/api/createGuildController";
 | 
				
			||||||
import { creditsController } from "@/src/controllers/api/creditsController";
 | 
					import { creditsController } from "@/src/controllers/api/creditsController";
 | 
				
			||||||
import { deleteSessionController } from "@/src/controllers/api/deleteSessionController";
 | 
					import { deleteSessionController } from "@/src/controllers/api/deleteSessionController";
 | 
				
			||||||
@ -133,6 +134,7 @@ apiRouter.post("/artifacts.php", artifactsController);
 | 
				
			|||||||
apiRouter.post("/changeDojoRoot.php", changeDojoRootController);
 | 
					apiRouter.post("/changeDojoRoot.php", changeDojoRootController);
 | 
				
			||||||
apiRouter.post("/claimCompletedRecipe.php", claimCompletedRecipeController);
 | 
					apiRouter.post("/claimCompletedRecipe.php", claimCompletedRecipeController);
 | 
				
			||||||
apiRouter.post("/clearDialogueHistory.php", clearDialogueHistoryController);
 | 
					apiRouter.post("/clearDialogueHistory.php", clearDialogueHistoryController);
 | 
				
			||||||
 | 
					apiRouter.post("/completeRandomModChallenge.php", completeRandomModChallengeController);
 | 
				
			||||||
apiRouter.post("/createGuild.php", createGuildController);
 | 
					apiRouter.post("/createGuild.php", createGuildController);
 | 
				
			||||||
apiRouter.post("/endlessXp.php", endlessXpController);
 | 
					apiRouter.post("/endlessXp.php", endlessXpController);
 | 
				
			||||||
apiRouter.post("/evolveWeapon.php", evolveWeaponController);
 | 
					apiRouter.post("/evolveWeapon.php", evolveWeaponController);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user