XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

feat: unveil riven with cipher (#992)

Related to #722 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/992 Co-authored-by: Sainan <sainan@calamity.inc> Co-committed-by: Sainan <sainan@calamity.inc>

837e041d
Sainan <sainan@calamity.inc>
提交于

代码差异

4 个文件 +98 -40
Added src/controllers/api/completeRandomModChallengeController.ts +56 -0
@@ -0,0 +1,56 @@
1 import { RequestHandler } from "express";
2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 import { addMiscItems, getInventory, updateCurrency } from "@/src/services/inventoryService";
4 import { IInventoryChanges } from "@/src/types/purchaseTypes";
5 import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
6 import { getJSONfromString } from "@/src/helpers/stringHelpers";
7 import { IUnveiledRivenFingerprint, randomiseRivenStats } from "@/src/helpers/rivenFingerprintHelper";
8 import { getRandomElement, getRandomInt } from "@/src/services/rngService";
9 import { ExportUpgrades } from "warframe-public-export-plus";
10
11 export const completeRandomModChallengeController: RequestHandler = async (req, res) => {
12 const accountId = await getAccountIdForRequest(req);
13 const inventory = await getInventory(accountId);
14 const request = getJSONfromString<ICompleteRandomModChallengeRequest>(String(req.body));
15 let inventoryChanges: IInventoryChanges = {};
16
17 // Remove 20 plat or riven cipher
18 if ((req.query.p as string) == "1") {
19 inventoryChanges = { ...updateCurrency(inventory, 20, true) };
20 } else {
21 const miscItemChanges: IMiscItem[] = [
22 {
23 ItemType: "/Lotus/Types/Items/MiscItems/RivenIdentifier",
24 ItemCount: -1
25 }
26 ];
27 addMiscItems(inventory, miscItemChanges);
28 inventoryChanges.MiscItems = miscItemChanges;
29 }
30
31 // Update riven fingerprint to a randomised unveiled state
32 const upgrade = inventory.Upgrades.id(request.ItemId)!;
33 const meta = ExportUpgrades[upgrade.ItemType];
34 const fingerprint: IUnveiledRivenFingerprint = {
35 compat: getRandomElement(meta.compatibleItems!),
36 lim: 0,
37 lvl: 0,
38 lvlReq: getRandomInt(8, 16),
39 pol: getRandomElement(["AP_ATTACK", "AP_DEFENSE", "AP_TACTIC"]),
40 buffs: [],
41 curses: []
42 };
43 randomiseRivenStats(meta, fingerprint);
44 upgrade.UpgradeFingerprint = JSON.stringify(fingerprint);
45
46 await inventory.save();
47
48 res.json({
49 InventoryChanges: inventoryChanges,
50 Fingerprint: upgrade.UpgradeFingerprint
51 });
52 };
53
54 interface ICompleteRandomModChallengeRequest {
55 ItemId: string;
56 }
Modified src/controllers/api/rerollRandomModController.ts +2 -40
@@ -2,8 +2,8 @@ import { RequestHandler } from "express";
2 2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 3 import { addMiscItems, getInventory } from "@/src/services/inventoryService";
4 4 import { getJSONfromString } from "@/src/helpers/stringHelpers";
5 import { IUnveiledRivenFingerprint, randomiseRivenStats } from "@/src/helpers/rivenFingerprintHelper";
5 6 import { ExportUpgrades } from "warframe-public-export-plus";
6 import { getRandomElement } from "@/src/services/rngService";
7 7
8 8 export const rerollRandomModController: RequestHandler = async (req, res) => {
9 9 const accountId = await getAccountIdForRequest(req);
@@ -25,7 +25,7 @@ export const rerollRandomModController: RequestHandler = async (req, res) => {
25 25 fingerprint.rerolls++;
26 26 upgrade.UpgradeFingerprint = JSON.stringify(fingerprint);
27 27
28 randomiseStats(upgrade.ItemType, fingerprint);
28 randomiseRivenStats(ExportUpgrades[upgrade.ItemType], fingerprint);
29 29 upgrade.PendingRerollFingerprint = JSON.stringify(fingerprint);
30 30
31 31 await inventory.save();
@@ -52,28 +52,6 @@ export const rerollRandomModController: RequestHandler = async (req, res) => {
52 52 }
53 53 };
54 54
55 const randomiseStats = (randomModType: string, fingerprint: IUnveiledRivenFingerprint): void => {
56 const meta = ExportUpgrades[randomModType];
57
58 fingerprint.buffs = [];
59 const numBuffs = 2 + Math.trunc(Math.random() * 2); // 2 or 3
60 const buffEntries = meta.upgradeEntries!.filter(x => x.canBeBuff);
61 for (let i = 0; i != numBuffs; ++i) {
62 const buffIndex = Math.trunc(Math.random() * buffEntries.length);
63 const entry = buffEntries[buffIndex];
64 fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
65 buffEntries.splice(buffIndex, 1);
66 }
67
68 fingerprint.curses = [];
69 if (Math.random() < 0.5) {
70 const entry = getRandomElement(
71 meta.upgradeEntries!.filter(x => x.canBeCurse && !fingerprint.buffs.find(y => y.Tag == x.tag))
72 );
73 fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
74 }
75 };
76
77 55 type RerollRandomModRequest = LetsGoGamblingRequest | AwDangitRequest;
78 56
79 57 interface LetsGoGamblingRequest {
@@ -85,20 +63,4 @@ interface AwDangitRequest {
85 63 CommitReroll: boolean;
86 64 }
87 65
88 interface IUnveiledRivenFingerprint {
89 compat: string;
90 lim: number;
91 lvl: number;
92 lvlReq: 0;
93 rerolls?: number;
94 pol: string;
95 buffs: IRivenStat[];
96 curses: IRivenStat[];
97 }
98
99 interface IRivenStat {
100 Tag: string;
101 Value: number;
102 }
103
104 66 const rerollCosts = [900, 1000, 1200, 1400, 1700, 2000, 2350, 2750, 3150];
Added src/helpers/rivenFingerprintHelper.ts +38 -0
@@ -0,0 +1,38 @@
1 import { IUpgrade } from "warframe-public-export-plus";
2 import { getRandomElement } from "../services/rngService";
3
4 export interface IUnveiledRivenFingerprint {
5 compat: string;
6 lim: 0;
7 lvl: number;
8 lvlReq: number;
9 rerolls?: number;
10 pol: string;
11 buffs: IRivenStat[];
12 curses: IRivenStat[];
13 }
14
15 interface IRivenStat {
16 Tag: string;
17 Value: number;
18 }
19
20 export const randomiseRivenStats = (meta: IUpgrade, fingerprint: IUnveiledRivenFingerprint): void => {
21 fingerprint.buffs = [];
22 const numBuffs = 2 + Math.trunc(Math.random() * 2); // 2 or 3
23 const buffEntries = meta.upgradeEntries!.filter(x => x.canBeBuff);
24 for (let i = 0; i != numBuffs; ++i) {
25 const buffIndex = Math.trunc(Math.random() * buffEntries.length);
26 const entry = buffEntries[buffIndex];
27 fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
28 buffEntries.splice(buffIndex, 1);
29 }
30
31 fingerprint.curses = [];
32 if (Math.random() < 0.5) {
33 const entry = getRandomElement(
34 meta.upgradeEntries!.filter(x => x.canBeCurse && !fingerprint.buffs.find(y => y.Tag == x.tag))
35 );
36 fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
37 }
38 };
Modified src/routes/api.ts +2 -0
@@ -8,6 +8,7 @@ import { changeDojoRootController } from "@/src/controllers/api/changeDojoRootCo
8 8 import { checkDailyMissionBonusController } from "@/src/controllers/api/checkDailyMissionBonusController";
9 9 import { claimCompletedRecipeController } from "@/src/controllers/api/claimCompletedRecipeController";
10 10 import { clearDialogueHistoryController } from "@/src/controllers/api/clearDialogueHistoryController";
11 import { completeRandomModChallengeController } from "@/src/controllers/api/completeRandomModChallengeController";
11 12 import { createGuildController } from "@/src/controllers/api/createGuildController";
12 13 import { creditsController } from "@/src/controllers/api/creditsController";
13 14 import { deleteSessionController } from "@/src/controllers/api/deleteSessionController";
@@ -133,6 +134,7 @@ apiRouter.post("/artifacts.php", artifactsController);
133 134 apiRouter.post("/changeDojoRoot.php", changeDojoRootController);
134 135 apiRouter.post("/claimCompletedRecipe.php", claimCompletedRecipeController);
135 136 apiRouter.post("/clearDialogueHistory.php", clearDialogueHistoryController);
137 apiRouter.post("/completeRandomModChallenge.php", completeRandomModChallengeController);
136 138 apiRouter.post("/createGuild.php", createGuildController);
137 139 apiRouter.post("/endlessXp.php", endlessXpController);
138 140 apiRouter.post("/evolveWeapon.php", evolveWeaponController);