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: rerolling rivens (#806)

a10bdeb4
Sainan <sainan@calamity.inc>
提交于

代码差异

6 个文件 +111 -14
Modified package-lock.json +4 -4
@@ -12,7 +12,7 @@
12 12 "copyfiles": "^2.4.1",
13 13 "express": "^5",
14 14 "mongoose": "^8.9.4",
15 "warframe-public-export-plus": "^0.5.23",
15 "warframe-public-export-plus": "^0.5.24",
16 16 "warframe-riven-info": "^0.1.2",
17 17 "winston": "^3.17.0",
18 18 "winston-daily-rotate-file": "^5.0.0"
@@ -3778,9 +3778,9 @@
3778 3778 }
3779 3779 },
3780 3780 "node_modules/warframe-public-export-plus": {
3781 "version": "0.5.23",
3782 "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.23.tgz",
3783 "integrity": "sha512-AJLivzXpon+UDm+SYq3wIXiP4OXCDOgXvCG1VLawJrHW3VDff+NpsUJApBPA4S8oZ8N8NPyBVKBvuoF2Pplaeg=="
3781 "version": "0.5.24",
3782 "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.24.tgz",
3783 "integrity": "sha512-GHjOxFcfPaLbhs/1Adgk6y3qPJ7ptBO/sW2oQ4aSdDj68oETkDjHwDQrn4eFjaYKGOmVwAzVDPMgLKWaD/fmKg=="
3784 3784 },
3785 3785 "node_modules/warframe-riven-info": {
3786 3786 "version": "0.1.2",
Modified package.json +1 -1
@@ -16,7 +16,7 @@
16 16 "copyfiles": "^2.4.1",
17 17 "express": "^5",
18 18 "mongoose": "^8.9.4",
19 "warframe-public-export-plus": "^0.5.23",
19 "warframe-public-export-plus": "^0.5.24",
20 20 "warframe-riven-info": "^0.1.2",
21 21 "winston": "^3.17.0",
22 22 "winston-daily-rotate-file": "^5.0.0"
Modified src/controllers/api/rerollRandomModController.ts +98 -5
@@ -1,9 +1,102 @@
1 import { logger } from "@/src/utils/logger";
2 1 import { RequestHandler } from "express";
2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 import { addMiscItems, getInventory } from "@/src/services/inventoryService";
4 import { getJSONfromString } from "@/src/helpers/stringHelpers";
5 import { ExportUpgrades } from "warframe-public-export-plus";
6 import { getRandomElement } from "@/src/services/rngService";
3 7
4 const rerollRandomModController: RequestHandler = (_req, res) => {
5 logger.debug("RerollRandomMod Request", { info: _req.body.toString("hex").replace(/(.)(.)/g, "$1$2 ") });
6 res.json({});
8 export const rerollRandomModController: RequestHandler = async (req, res) => {
9 const accountId = await getAccountIdForRequest(req);
10 const request = getJSONfromString(String(req.body)) as RerollRandomModRequest;
11 if ("ItemIds" in request) {
12 const inventory = await getInventory(accountId, "Upgrades MiscItems");
13 const upgrade = inventory.Upgrades.id(request.ItemIds[0])!;
14 const fingerprint = JSON.parse(upgrade.UpgradeFingerprint!) as IUnveiledRivenFingerprint;
15
16 fingerprint.rerolls ??= 0;
17 const kuvaCost = fingerprint.rerolls < rerollCosts.length ? rerollCosts[fingerprint.rerolls] : 3500;
18 addMiscItems(inventory, [
19 {
20 ItemType: "/Lotus/Types/Items/MiscItems/Kuva",
21 ItemCount: kuvaCost * -1
22 }
23 ]);
24
25 fingerprint.rerolls++;
26 upgrade.UpgradeFingerprint = JSON.stringify(fingerprint);
27
28 randomiseStats(upgrade.ItemType, fingerprint);
29 upgrade.PendingRerollFingerprint = JSON.stringify(fingerprint);
30
31 await inventory.save();
32
33 res.json({
34 changes: [
35 {
36 ItemId: { $oid: request.ItemIds[0] },
37 UpgradeFingerprint: upgrade.UpgradeFingerprint,
38 PendingRerollFingerprint: upgrade.PendingRerollFingerprint
39 }
40 ],
41 cost: kuvaCost
42 });
43 } else {
44 const inventory = await getInventory(accountId, "Upgrades");
45 const upgrade = inventory.Upgrades.id(request.ItemId)!;
46 if (request.CommitReroll && upgrade.PendingRerollFingerprint) {
47 upgrade.UpgradeFingerprint = upgrade.PendingRerollFingerprint;
48 }
49 upgrade.PendingRerollFingerprint = undefined;
50 await inventory.save();
51 res.send(upgrade.UpgradeFingerprint);
52 }
53 };
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(meta.upgradeEntries!.filter(x => x.canBeCurse));
71 fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
72 }
7 73 };
8 74
9 export { rerollRandomModController };
75 type RerollRandomModRequest = LetsGoGamblingRequest | AwDangitRequest;
76
77 interface LetsGoGamblingRequest {
78 ItemIds: string[];
79 }
80
81 interface AwDangitRequest {
82 ItemId: string;
83 CommitReroll: boolean;
84 }
85
86 interface IUnveiledRivenFingerprint {
87 compat: string;
88 lim: number;
89 lvl: number;
90 lvlReq: 0;
91 rerolls?: number;
92 pol: string;
93 buffs: IRivenStat[];
94 curses: IRivenStat[];
95 }
96
97 interface IRivenStat {
98 Tag: string;
99 Value: number;
100 }
101
102 const rerollCosts = [900, 1000, 1200, 1400, 1700, 2000, 2350, 2750, 3150];
Modified src/models/inventoryModels/inventoryModel.ts +2 -2
@@ -288,10 +288,10 @@ RawUpgrades.set("toJSON", {
288 288 }
289 289 });
290 290
291 //TODO: find out what this is
292 const upgradesSchema = new Schema(
291 const upgradesSchema = new Schema<ICrewShipSalvagedWeaponSkin>(
293 292 {
294 293 UpgradeFingerprint: String,
294 PendingRerollFingerprint: { type: String, required: false },
295 295 ItemType: String
296 296 },
297 297 { id: false }
Modified src/services/inventoryService.ts +5 -2
@@ -96,8 +96,11 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
96 96 }
97 97 };
98 98
99 export const getInventory = async (accountOwnerId: string): Promise<TInventoryDatabaseDocument> => {
100 const inventory = await Inventory.findOne({ accountOwnerId: accountOwnerId });
99 export const getInventory = async (
100 accountOwnerId: string,
101 projection: string | undefined = undefined
102 ): Promise<TInventoryDatabaseDocument> => {
103 const inventory = await Inventory.findOne({ accountOwnerId: accountOwnerId }, projection);
101 104
102 105 if (!inventory) {
103 106 throw new Error(`Didn't find an inventory for ${accountOwnerId}`);
Modified src/types/inventoryTypes/inventoryTypes.ts +1 -0
@@ -420,6 +420,7 @@ export interface ISlots {
420 420 export interface ICrewShipSalvagedWeaponSkin {
421 421 ItemType: string;
422 422 UpgradeFingerprint?: string;
423 PendingRerollFingerprint?: string;
423 424 ItemId?: IOid;
424 425 _id?: Types.ObjectId;
425 426 }