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

XFESpaceNinjaServer

A simple server for a small space ninja game

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

XFEstudio/XFESpaceNinjaServer

feat: handle defaultUpgrades for moas and hounds (#1012)

Closes #997 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1012 Co-authored-by: Sainan <sainan@calamity.inc> Co-committed-by: Sainan <sainan@calamity.inc>

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

代码差异

2 个文件 +36 -17
Modified src/controllers/api/modularWeaponCraftingController.ts +13 -3
@@ -2,7 +2,14 @@ import { RequestHandler } from "express";
2 2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 3 import { getJSONfromString } from "@/src/helpers/stringHelpers";
4 4 import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
5 import { getInventory, updateCurrency, addEquipment, addMiscItems } from "@/src/services/inventoryService";
5 import {
6 getInventory,
7 updateCurrency,
8 addEquipment,
9 addMiscItems,
10 applyDefaultUpgrades
11 } from "@/src/services/inventoryService";
12 import { ExportWeapons } from "warframe-public-export-plus";
6 13
7 14 const modularWeaponTypes: Record<string, TEquipmentKey> = {
8 15 "/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimary": "LongGuns",
@@ -36,8 +43,11 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
36 43 const category = modularWeaponTypes[data.WeaponType];
37 44 const inventory = await getInventory(accountId);
38 45
46 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
47 const configs = applyDefaultUpgrades(inventory, ExportWeapons[data.Parts[0]]?.defaultUpgrades);
48
39 49 // Give weapon
40 const weapon = addEquipment(inventory, category, data.WeaponType, data.Parts);
50 const inventoryChanges = addEquipment(inventory, category, data.WeaponType, data.Parts, {}, { Configs: configs });
41 51
42 52 // Remove credits & parts
43 53 const miscItemChanges = [];
@@ -58,8 +68,8 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
58 68 // Tell client what we did
59 69 res.json({
60 70 InventoryChanges: {
71 ...inventoryChanges,
61 72 ...currencyChanges,
62 [category]: [weapon],
63 73 MiscItems: miscItemChanges
64 74 }
65 75 });
Modified src/services/inventoryService.ts +23 -14
@@ -52,6 +52,7 @@ import {
52 52 ExportSyndicates,
53 53 ExportUpgrades,
54 54 ExportWeapons,
55 IDefaultUpgrade,
55 56 TStandingLimitBin
56 57 } from "warframe-public-export-plus";
57 58 import { createShip } from "./shipService";
@@ -532,23 +533,15 @@ export const addItems = async (
532 533 return inventoryChanges;
533 534 };
534 535
535 //TODO: maybe genericMethod for all the add methods, they share a lot of logic
536 export const addSentinel = (
536 export const applyDefaultUpgrades = (
537 537 inventory: TInventoryDatabaseDocument,
538 sentinelName: string,
539 inventoryChanges: IInventoryChanges = {}
540 ): IInventoryChanges => {
541 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
542 if (ExportSentinels[sentinelName]?.defaultWeapon) {
543 addSentinelWeapon(inventory, ExportSentinels[sentinelName].defaultWeapon, inventoryChanges);
544 }
545
538 defaultUpgrades: IDefaultUpgrade[] | undefined
539 ): IItemConfig[] => {
546 540 const modsToGive: IRawUpgrade[] = [];
547 541 const configs: IItemConfig[] = [];
548 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
549 if (ExportSentinels[sentinelName]?.defaultUpgrades) {
542 if (defaultUpgrades) {
550 543 const upgrades = [];
551 for (const defaultUpgrade of ExportSentinels[sentinelName].defaultUpgrades) {
544 for (const defaultUpgrade of defaultUpgrades) {
552 545 modsToGive.push({ ItemType: defaultUpgrade.ItemType, ItemCount: 1 });
553 546 if (defaultUpgrade.Slot != -1) {
554 547 upgrades[defaultUpgrade.Slot] = defaultUpgrade.ItemType;
@@ -558,8 +551,24 @@ export const addSentinel = (
558 551 configs.push({ Upgrades: upgrades });
559 552 }
560 553 }
561
562 554 addMods(inventory, modsToGive);
555 return configs;
556 };
557
558 //TODO: maybe genericMethod for all the add methods, they share a lot of logic
559 export const addSentinel = (
560 inventory: TInventoryDatabaseDocument,
561 sentinelName: string,
562 inventoryChanges: IInventoryChanges = {}
563 ): IInventoryChanges => {
564 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
565 if (ExportSentinels[sentinelName]?.defaultWeapon) {
566 addSentinelWeapon(inventory, ExportSentinels[sentinelName].defaultWeapon, inventoryChanges);
567 }
568
569 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
570 const configs: IItemConfig[] = applyDefaultUpgrades(inventory, ExportSentinels[sentinelName]?.defaultUpgrades);
571
563 572 const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0 }) - 1;
564 573 inventoryChanges.Sentinels ??= [];
565 574 inventoryChanges.Sentinels.push(inventory.Sentinels[sentinelIndex].toJSON<IEquipmentClient>());