返回提交历史
Modified
src/controllers/api/sellController.ts
+28
-12
XFEstudio/SpaceNinjaServer
fix: selling items in old builds (#3023)
I'm not sure exactly which build the sell request changed in, but this solution seems to be catch-all. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3023 Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com> Co-authored-by: VoltPrime <subsonicjackal@gmail.com> Co-committed-by: VoltPrime <subsonicjackal@gmail.com>
8a0f99f5
代码差异
1 个文件
+28
-12
@@ -25,11 +25,24 @@ export const sellController: RequestHandler = async (req, res) => {
25
25
//console.log(JSON.stringify(payload, null, 2));
26
26
const accountId = await getAccountIdForRequest(req);
27
27
const requiredFields = new Set<keyof TInventoryDatabaseDocument>();
28
if (payload.SellCurrency == "SC_RegularCredits") {
28
let sellCurrency = "SC_RegularCredits";
29
if (payload.SellCurrency) {
30
sellCurrency = payload.SellCurrency;
31
} else {
32
if (payload.SellForFusionPoints || payload.SellForPrimeBucks) {
33
if (payload.SellForFusionPoints) {
34
sellCurrency = "SC_FusionPoints";
35
}
36
if (payload.SellForPrimeBucks) {
37
sellCurrency = "SC_PrimeBucks";
38
}
39
}
40
}
41
if (sellCurrency == "SC_RegularCredits") {
29
42
requiredFields.add("RegularCredits");
30
} else if (payload.SellCurrency == "SC_FusionPoints") {
43
} else if (sellCurrency == "SC_FusionPoints") {
31
44
requiredFields.add("FusionPoints");
32
} else if (payload.SellCurrency == "SC_CrewShipFusionPoints") {
45
} else if (sellCurrency == "SC_CrewShipFusionPoints") {
33
46
requiredFields.add("CrewShipFusionPoints");
34
47
} else {
35
48
requiredFields.add("MiscItems");
@@ -83,27 +96,27 @@ export const sellController: RequestHandler = async (req, res) => {
83
96
const inventory = await getInventory(accountId, Array.from(requiredFields).join(" "));
84
97
85
98
// Give currency
86
if (payload.SellCurrency == "SC_RegularCredits") {
99
if (sellCurrency == "SC_RegularCredits") {
87
100
inventory.RegularCredits += payload.SellPrice;
88
} else if (payload.SellCurrency == "SC_FusionPoints") {
101
} else if (sellCurrency == "SC_FusionPoints") {
89
102
addFusionPoints(inventory, payload.SellPrice);
90
} else if (payload.SellCurrency == "SC_CrewShipFusionPoints") {
103
} else if (sellCurrency == "SC_CrewShipFusionPoints") {
91
104
addCrewShipFusionPoints(inventory, payload.SellPrice);
92
} else if (payload.SellCurrency == "SC_PrimeBucks") {
105
} else if (sellCurrency == "SC_PrimeBucks") {
93
106
addMiscItems(inventory, [
94
107
{
95
108
ItemType: "/Lotus/Types/Items/MiscItems/PrimeBucks",
96
109
ItemCount: payload.SellPrice
97
110
}
98
111
]);
99
} else if (payload.SellCurrency == "SC_DistillPoints") {
112
} else if (sellCurrency == "SC_DistillPoints") {
100
113
addMiscItems(inventory, [
101
114
{
102
115
ItemType: "/Lotus/Types/Items/MiscItems/DistillPoints",
103
116
ItemCount: payload.SellPrice
104
117
}
105
118
]);
106
} else if (payload.SellCurrency == "SC_Resources") {
119
} else if (sellCurrency == "SC_Resources") {
107
120
// Will add appropriate MiscItems from CrewShipWeapons or CrewShipWeaponSkins
108
121
} else {
109
122
throw new Error("Unknown SellCurrency: " + payload.SellCurrency);
@@ -218,7 +231,7 @@ export const sellController: RequestHandler = async (req, res) => {
218
231
} else {
219
232
const index = inventory.CrewShipWeapons.findIndex(x => x._id.equals(sellItem.String));
220
233
if (index != -1) {
221
if (payload.SellCurrency == "SC_Resources") {
234
if (sellCurrency == "SC_Resources") {
222
235
refundPartialBuildCosts(inventory, inventory.CrewShipWeapons[index].ItemType, inventoryChanges);
223
236
}
224
237
inventory.CrewShipWeapons.splice(index, 1);
@@ -241,7 +254,7 @@ export const sellController: RequestHandler = async (req, res) => {
241
254
} else {
242
255
const index = inventory.CrewShipWeaponSkins.findIndex(x => x._id.equals(sellItem.String));
243
256
if (index != -1) {
244
if (payload.SellCurrency == "SC_Resources") {
257
if (sellCurrency == "SC_Resources") {
245
258
refundPartialBuildCosts(
246
259
inventory,
247
260
inventory.CrewShipWeaponSkins[index].ItemType,
@@ -346,7 +359,7 @@ interface ISellRequest {
346
359
WeaponSkins?: ISellItem[]; // SNS specific field
347
360
};
348
361
SellPrice: number;
349
SellCurrency:
362
SellCurrency?:
350
363
| "SC_RegularCredits"
351
364
| "SC_PrimeBucks"
352
365
| "SC_FusionPoints"
@@ -355,6 +368,9 @@ interface ISellRequest {
355
368
| "SC_Resources"
356
369
| "somethingelsewemightnotknowabout";
357
370
buildLabel: string;
371
// These are used in old builds (undetermined where it changed) instead of SellCurrency
372
SellForPrimeBucks?: boolean;
373
SellForFusionPoints?: boolean;
358
374
}
359
375
360
376
interface ISellItem {