返回提交历史
Modified
src/controllers/api/inventorySlotsController.ts
+1
-0
Modified
src/services/importService.ts
+1
-2
Modified
src/services/inventoryService.ts
+6
-7
Modified
src/services/itemDataService.ts
+24
-0
Modified
src/services/purchaseService.ts
+17
-25
Modified
src/types/inventoryTypes/inventoryTypes.ts
+3
-2
Modified
src/types/purchaseTypes.ts
+4
-21
XFEstudio/SpaceNinjaServer
feat: handle inventory slots in getPrice (#4234)
Closes #4231 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4234 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
a6f14935
代码差异
7 个文件
+56
-57
@@ -28,6 +28,7 @@ export const inventorySlotsController: RequestHandler = async (req, res) => {
28
28
case eInventorySlot.SUITS:
29
29
case eInventorySlot.MECHSUITS:
30
30
case eInventorySlot.PVE_LOADOUTS:
31
case eInventorySlot.PVP_LOADOUTS:
31
32
case eInventorySlot.CREWMEMBERS:
32
33
price = 20;
33
34
amount = 1;
@@ -37,7 +37,7 @@ import type {
37
37
INemesisBaseDatabase,
38
38
IFusionTreasure
39
39
} from "../types/inventoryTypes/inventoryTypes.ts";
40
import { equipmentKeys, type IStepSequencerDatabase } from "../types/inventoryTypes/inventoryTypes.ts";
40
import { equipmentKeys, slotNames, type IStepSequencerDatabase } from "../types/inventoryTypes/inventoryTypes.ts";
41
41
import type { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel.ts";
42
42
import type {
43
43
ILoadoutConfigClient,
@@ -45,7 +45,6 @@ import type {
45
45
ILoadoutDatabase,
46
46
ILoadOutPresets
47
47
} from "../types/saveLoadoutTypes.ts";
48
import { slotNames } from "../types/purchaseTypes.ts";
49
48
import {
50
49
eStatus,
51
50
type ICrewShipMemberClient,
@@ -2,8 +2,7 @@ import type { TInventoryDatabaseDocument } from "../models/inventoryModels/inven
2
2
import { Inventory } from "../models/inventoryModels/inventoryModel.ts";
3
3
import { config } from "./configService.ts";
4
4
import { Types } from "mongoose";
5
import type { SlotNames, IInventoryChanges, IBinChanges, IAffiliationMods } from "../types/purchaseTypes.ts";
6
import { slotNames } from "../types/purchaseTypes.ts";
5
import type { IInventoryChanges, IBinChanges, IAffiliationMods } from "../types/purchaseTypes.ts";
7
6
import type {
8
7
IChallengeProgress,
9
8
IMiscItem,
@@ -31,7 +30,7 @@ import type {
31
30
ICollectibleEntry,
32
31
TInventorySlot
33
32
} from "../types/inventoryTypes/inventoryTypes.ts";
34
import { eInventorySlot, equipmentKeys } from "../types/inventoryTypes/inventoryTypes.ts";
33
import { eInventorySlot, equipmentKeys, slotNames } from "../types/inventoryTypes/inventoryTypes.ts";
35
34
import type { IGenericUpdate, IUpdateNodeIntrosResponse } from "../types/genericUpdateTypes.ts";
36
35
import type { IGoalsProgress, IKeyChainRequest, IMissionInventoryUpdateRequest } from "../types/requestTypes.ts";
37
36
import { logger } from "../utils/logger.ts";
@@ -404,9 +403,9 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
404
403
for (const item of right) {
405
404
left.push(item);
406
405
}
407
} else if (slotNames.indexOf(key as SlotNames) != -1) {
408
const left = InventoryChanges[key as SlotNames]!;
409
const right = delta[key as SlotNames]!;
406
} else if (slotNames.indexOf(key as TInventorySlot) != -1) {
407
const left = InventoryChanges[key as TInventorySlot]!;
408
const right = delta[key as TInventorySlot]!;
410
409
if (right.count) {
411
410
left.count ??= 0;
412
411
left.count += right.count;
@@ -1700,7 +1699,7 @@ export const addKubrowPetPrint = (
1700
1699
);
1701
1700
};
1702
1701
1703
export const updateSlots = <ST extends SlotNames>(
1702
export const updateSlots = <ST extends TInventorySlot>(
1704
1703
inventory: Pick<TInventoryDatabaseDocument, ST>,
1705
1704
slotName: ST,
1706
1705
slotAmount: number,
@@ -77,6 +77,7 @@ import { getWorldState } from "./worldStateService.ts";
77
77
import { promises as fs } from "fs";
78
78
import path from "path";
79
79
import { BL_LATEST } from "../constants/gameVersions.ts";
80
import type { TInventorySlot } from "../types/inventoryTypes/inventoryTypes.ts";
80
81
81
82
export type WeaponTypeInternal =
82
83
| "LongGuns"
@@ -3166,6 +3167,22 @@ const u7WeaponCosts: Record<string, number> = {
3166
3167
"/Lotus/Weapons/Tenno/Melee/Staff/Staff": 15_000
3167
3168
};
3168
3169
3170
export const slotPurchaseData: Record<string, { bin: TInventorySlot; price: number | undefined; amount: number }> = {
3171
SuitSlotItem: { bin: "SuitBin", price: 20, amount: 1 },
3172
TwoSentinelSlotItem: { bin: "SentinelBin", price: 12, amount: 2 },
3173
WeaponSlotItem: { bin: "WeaponBin", price: undefined, amount: 1 },
3174
TwoWeaponSlotItem: { bin: "WeaponBin", price: 12, amount: 2 },
3175
SpaceSuitSlotItem: { bin: "SpaceSuitBin", price: 12, amount: 1 },
3176
TwoSpaceWeaponSlotItem: { bin: "SpaceWeaponBin", price: 12, amount: 2 },
3177
MechSlotItem: { bin: "MechBin", price: 20, amount: 1 },
3178
TwoOperatorWeaponSlotItem: { bin: "OperatorAmpBin", price: 12, amount: 2 },
3179
RandomModSlotItem: { bin: "RandomModBin", price: 60, amount: 3 },
3180
TwoCrewShipSalvageSlotItem: { bin: "CrewShipSalvageBin", price: 12, amount: 2 },
3181
CrewMemberSlotItem: { bin: "CrewMemberBin", price: 20, amount: 1 },
3182
PvPLoadoutSlotItem: { bin: "PvpBonusLoadoutBin", price: undefined, amount: 1 },
3183
KubrowSlotItem: { bin: "PetBin", price: 10, amount: 1 }
3184
};
3185
3169
3186
export const getPrice = (
3170
3187
storeItemName: string,
3171
3188
quantity: number = 1,
@@ -3196,6 +3213,13 @@ export const getPrice = (
3196
3213
return u7WeaponCosts[internalName];
3197
3214
}
3198
3215
3216
if (usePremium) {
3217
const internalNameShort = internalName.substring(internalName.lastIndexOf("/") + 1);
3218
if (internalNameShort in slotPurchaseData && slotPurchaseData[internalNameShort].price !== undefined) {
3219
return slotPurchaseData[internalNameShort].price;
3220
}
3221
}
3222
3199
3223
// Hardcoded sale in this version
3200
3224
if (
3201
3225
usePremium &&
@@ -15,8 +15,7 @@ import type {
15
15
IPurchaseRequest,
16
16
IPurchaseResponse,
17
17
IInventoryChanges,
18
IPurchaseParams,
19
SlotNames
18
IPurchaseParams
20
19
} from "../types/purchaseTypes.ts";
21
20
import { ePurchaseSource } from "../types/purchaseTypes.ts";
22
21
import { logger } from "../utils/logger.ts";
@@ -30,7 +29,15 @@ import {
30
29
ExportVendors
31
30
} from "warframe-public-export-plus";
32
31
import type { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel.ts";
33
import { fromStoreItem, getBoosterPack, getBundle, getPrice, getSyndicate, toStoreItem } from "./itemDataService.ts";
32
import {
33
fromStoreItem,
34
getBoosterPack,
35
getBundle,
36
getPrice,
37
getSyndicate,
38
slotPurchaseData,
39
toStoreItem
40
} from "./itemDataService.ts";
34
41
import { DailyDeal } from "../models/worldStateModel.ts";
35
42
import { fromMongoDate, fromOid, toMongoDate } from "../helpers/inventoryHelpers.ts";
36
43
import { Guild } from "../models/guildModel.ts";
@@ -570,22 +577,6 @@ export const handleStoreItemAcquisition = async (
570
577
return purchaseResponse;
571
578
};
572
579
573
const slotPurchaseNameToSlotName: Record<string, { name: SlotNames; purchaseQuantity: number }> = {
574
SuitSlotItem: { name: "SuitBin", purchaseQuantity: 1 },
575
TwoSentinelSlotItem: { name: "SentinelBin", purchaseQuantity: 2 },
576
WeaponSlotItem: { name: "WeaponBin", purchaseQuantity: 1 },
577
TwoWeaponSlotItem: { name: "WeaponBin", purchaseQuantity: 2 },
578
SpaceSuitSlotItem: { name: "SpaceSuitBin", purchaseQuantity: 1 },
579
TwoSpaceWeaponSlotItem: { name: "SpaceWeaponBin", purchaseQuantity: 2 },
580
MechSlotItem: { name: "MechBin", purchaseQuantity: 1 },
581
TwoOperatorWeaponSlotItem: { name: "OperatorAmpBin", purchaseQuantity: 2 },
582
RandomModSlotItem: { name: "RandomModBin", purchaseQuantity: 3 },
583
TwoCrewShipSalvageSlotItem: { name: "CrewShipSalvageBin", purchaseQuantity: 2 },
584
CrewMemberSlotItem: { name: "CrewMemberBin", purchaseQuantity: 1 },
585
PvPLoadoutSlotItem: { name: "PvpBonusLoadoutBin", purchaseQuantity: 1 },
586
KubrowSlotItem: { name: "PetBin", purchaseQuantity: 1 }
587
};
588
589
580
// // extra = everything above the base +2 slots (depending on slot type)
590
581
// // new slot above base = extra + 1 and slots +1
591
582
// // new frame = slots -1
@@ -598,23 +589,24 @@ const handleSlotPurchase = (
598
589
): IPurchaseResponse => {
599
590
logger.debug(`slot name ${slotPurchaseNameFull}`);
600
591
const slotPurchaseName = slotPurchaseNameFull.substring(slotPurchaseNameFull.lastIndexOf("/") + 1);
601
if (!(slotPurchaseName in slotPurchaseNameToSlotName)) {
592
if (!(slotPurchaseName in slotPurchaseData)) {
602
593
throw new Error(`invalid slot purchase name ${slotPurchaseName}`);
603
594
}
604
595
logger.debug(`slot purchase name ${slotPurchaseName}`);
605
596
606
const slotName = slotPurchaseNameToSlotName[slotPurchaseName].name;
597
const data = slotPurchaseData[slotPurchaseName];
598
607
599
let slotsPurchased = quantity;
608
600
if (!ignorePurchaseQuantity) {
609
slotsPurchased *= slotPurchaseNameToSlotName[slotPurchaseName].purchaseQuantity;
601
slotsPurchased *= data.amount;
610
602
}
611
603
612
updateSlots(inventory, slotName, slotsPurchased, slotsPurchased);
604
updateSlots(inventory, data.bin, slotsPurchased, slotsPurchased);
613
605
614
logger.debug(`added ${slotsPurchased} slot ${slotName}`);
606
logger.debug(`added ${slotsPurchased} slot ${data.bin}`);
615
607
616
608
const inventoryChanges: IInventoryChanges = {};
617
inventoryChanges[slotName] = {
609
inventoryChanges[data.bin] = {
618
610
count: 0,
619
611
platinum: 1,
620
612
Slots: slotsPurchased,
@@ -28,7 +28,6 @@ import type {
28
28
} from "../equipmentTypes.ts";
29
29
import type { ILoadoutConfigClientLegacy, ILoadOutPresets } from "../saveLoadoutTypes.ts";
30
30
import type { CalendarSeasonType } from "../worldStateTypes.ts";
31
import type { SlotNames } from "../purchaseTypes.ts";
32
31
import type { IPendingTradeClient } from "../tradingTypes.ts";
33
32
34
33
type InventoryDatabaseEquipment = {
@@ -368,7 +367,7 @@ type InventoryClientEquipment = {
368
367
};
369
368
370
369
type InventorySlots = {
371
[_ in SlotNames]: ISlots;
370
[_ in TInventorySlot]: ISlots;
372
371
};
373
372
374
373
export interface IInventoryAccolades {
@@ -708,6 +707,7 @@ export const eInventorySlot = {
708
707
SPACEWEAPONS: "SpaceWeaponBin",
709
708
MECHSUITS: "MechBin",
710
709
PVE_LOADOUTS: "PveBonusLoadoutBin",
710
PVP_LOADOUTS: "PvpBonusLoadoutBin",
711
711
SENTINELS: "SentinelBin",
712
712
AMPS: "OperatorAmpBin",
713
713
RJ_COMPONENT_AND_ARMAMENTS: "CrewShipSalvageBin",
@@ -716,6 +716,7 @@ export const eInventorySlot = {
716
716
PETS: "PetBin"
717
717
} as const;
718
718
export type TInventorySlot = (typeof eInventorySlot)[keyof typeof eInventorySlot];
719
export const slotNames = Object.values(eInventorySlot);
719
720
720
721
export interface ISlots {
721
722
Extra?: number;
@@ -15,7 +15,8 @@ import type {
15
15
IRawUpgrade,
16
16
IFocusUpgrade,
17
17
IFocusLoadoutClient,
18
IWeaponSkinClient
18
IWeaponSkinClient,
19
TInventorySlot
19
20
} from "./inventoryTypes/inventoryTypes.ts";
20
21
21
22
export const ePurchaseSource = {
@@ -77,7 +78,7 @@ export interface IPurchaseParams {
77
78
}
78
79
79
80
export type IInventoryChanges = {
80
[_ in SlotNames]?: IBinChanges;
81
[_ in TInventorySlot]?: IBinChanges;
81
82
} & {
82
83
[_ in TEquipmentKey]?: IEquipmentClient[];
83
84
} & {
@@ -108,7 +109,7 @@ export type IInventoryChanges = {
108
109
} & Record<
109
110
Exclude<
110
111
string,
111
| SlotNames
112
| TInventorySlot
112
113
| TEquipmentKey
113
114
| "RegularCredits"
114
115
| "PremiumCredits"
@@ -143,21 +144,3 @@ export type IBinChanges = {
143
144
Slots: number;
144
145
Extra?: number;
145
146
};
146
147
export const slotNames = [
148
"SuitBin",
149
"WeaponBin",
150
"MechBin",
151
"PveBonusLoadoutBin",
152
"PvpBonusLoadoutBin",
153
"SentinelBin",
154
"SpaceSuitBin",
155
"SpaceWeaponBin",
156
"OperatorAmpBin",
157
"RandomModBin",
158
"CrewShipSalvageBin",
159
"CrewMemberBin",
160
"PetBin"
161
] as const;
162
163
export type SlotNames = (typeof slotNames)[number];