返回提交历史
Modified
src/controllers/api/inventoryController.ts
+5
-8
Modified
src/services/inventoryService.ts
+30
-25
Modified
src/services/purchaseService.ts
+10
-1
XFEstudio/SpaceNinjaServer
fix: market acquisition of kubrow eggs pre-u40 (#3800)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3800 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
961404f7
代码差异
3 个文件
+45
-34
@@ -27,7 +27,8 @@ import {
27
27
cleanupInventory,
28
28
createLibraryDailyTask,
29
29
ensureUserHasFounderHonoria,
30
getCalendarProgress
30
getCalendarProgress,
31
PRE_U40_MAX_KUBROW_EGGS
31
32
} from "../../services/inventoryService.ts";
32
33
import { logger } from "../../utils/logger.ts";
33
34
import { addString } from "../../helpers/stringHelpers.ts";
@@ -548,22 +549,18 @@ export const getInventoryResponse = async (
548
549
inventoryResponse.Nemesis = undefined;
549
550
}
550
551
551
// U40 migrated from KubrowPetEggs with ItemType /Lotus/Types/Game/KubrowPet/Eggs/KubrowPetEggItem to MiscItems with ItemType /Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg
552
// so translate it back for older versions
552
// U40 migrated KubrowPetEggs to MiscItems so translate it back for older versions
553
553
if (version_compare(buildLabel, gameToBuildVersion["40.0.0"]) < 0) {
554
554
inventoryResponse.KubrowPetEggs = [];
555
555
const index = inventoryResponse.MiscItems.findIndex(
556
556
x => x.ItemType == "/Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg"
557
557
);
558
558
if (index != -1) {
559
const numKubrowEggs = Math.min(
560
inventoryResponse.MiscItems[index].ItemCount,
561
100 // capped to avoid sending an overly large array
562
);
559
const numKubrowEggs = Math.min(inventoryResponse.MiscItems[index].ItemCount, PRE_U40_MAX_KUBROW_EGGS);
563
560
inventoryResponse.MiscItems.splice(index, 1);
564
561
for (let i = 0; i != numKubrowEggs; ++i) {
565
562
inventoryResponse.KubrowPetEggs.push({
566
ItemType: "/Lotus/Types/Game/KubrowPet/Eggs/KubrowPetEggItem",
563
ItemType: "/Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg",
567
564
ExpirationDate: toMongoDate2(2000000000000, buildLabel),
568
565
ItemId: toOid2(i.toString().padStart(24, "0"), buildLabel)
569
566
});
@@ -484,6 +484,8 @@ export const freeUpSlot = (inventory: TInventoryDatabaseDocument, bin: Inventory
484
484
updateSlots(inventory, bin, 1, 0);
485
485
};
486
486
487
export const PRE_U40_MAX_KUBROW_EGGS = 100; // capped to avoid sending an overly large array
488
487
489
export const addItem = async (
488
490
inventory: TInventoryDatabaseDocument,
489
491
typeName: string,
@@ -521,6 +523,33 @@ export const addItem = async (
521
523
} satisfies IMiscItem
522
524
];
523
525
addMiscItems(inventory, miscItemChanges);
526
527
if (
528
buildLabel &&
529
typeName == "/Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg" &&
530
version_compare(buildLabel, gameToBuildVersion["40.0.0"]) < 0
531
) {
532
if (quantity < 0 || quantity > 100) {
533
throw new Error(
534
`unexpected acquisition quantity of KubrowPetEggs: got ${quantity}, expected 0..100`
535
);
536
}
537
const idBase = Math.min(
538
inventory.MiscItems.find(x => x.ItemType == "/Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg")
539
?.ItemCount ?? 0,
540
PRE_U40_MAX_KUBROW_EGGS
541
);
542
const changes: IKubrowPetEgg[] = [];
543
for (let i = 0; i != quantity; ++i) {
544
changes.push({
545
ItemType: "/Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg",
546
ExpirationDate: toMongoDate2(2000000000000, buildLabel),
547
ItemId: toOid2((idBase + i).toString().padStart(24, "0"), buildLabel)
548
});
549
}
550
return { KubrowPetEggs: changes };
551
}
552
524
553
return {
525
554
MiscItems: miscItemChanges
526
555
};
@@ -1061,33 +1090,9 @@ export const addItem = async (
1061
1090
);
1062
1091
}
1063
1092
return inventoryChanges;
1064
} else if (typeName == "/Lotus/Types/Game/KubrowPet/Eggs/KubrowPetEggItem") {
1065
// pre-U40 acquisition
1066
if (quantity < 0 || quantity > 100) {
1067
throw new Error(
1068
`unexpected acquisition quantity of KubrowPetEggs: got ${quantity}, expected 0..100`
1069
);
1070
}
1071
const idBase = Math.min(
1072
inventory.MiscItems.find(
1073
x => x.ItemType == "/Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg"
1074
)?.ItemCount ?? 0,
1075
100
1076
);
1077
// add to inventory as a MiscItem
1078
addMiscItem(inventory, "/Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg", quantity);
1079
// but give the client the expected response format
1080
const changes: IKubrowPetEgg[] = [];
1081
for (let i = 0; i != quantity; ++i) {
1082
changes.push({
1083
ItemType: "/Lotus/Types/Game/KubrowPet/Eggs/KubrowPetEggItem",
1084
ExpirationDate: toMongoDate2(2000000000000, buildLabel),
1085
ItemId: toOid2((idBase + i).toString().padStart(24, "0"), buildLabel)
1086
});
1087
}
1088
return { KubrowPetEggs: changes };
1089
1093
} else if (
1090
1094
typeName != "/Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg" &&
1095
typeName != "/Lotus/Types/Game/KubrowPet/Eggs/KubrowPetEggItem" &&
1091
1096
typeName != "/Lotus/Types/Game/KubrowPet/BlankTraitPrint" &&
1092
1097
typeName != "/Lotus/Types/Game/KubrowPet/ImprintedTraitPrint"
1093
1098
) {
@@ -739,7 +739,16 @@ const handleTypesPurchase = async (
739
739
switch (typeCategory) {
740
740
default:
741
741
return {
742
InventoryChanges: await addItem(inventory, typesName, quantity, premiumPurchase, seed, undefined, true)
742
InventoryChanges: await addItem(
743
inventory,
744
typesName,
745
quantity,
746
premiumPurchase,
747
seed,
748
undefined,
749
true,
750
buildLabel
751
)
743
752
};
744
753
case "BoosterPacks":
745
754
return handleBoosterPackPurchase(typesName, inventory, quantity, buildLabel);