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

chore: assert quantity is 1 if otherwise ignored in addItem (#3051)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3051 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

1b74fe4c
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

2 个文件 +74 -1
Modified src/services/inventoryService.ts +71 -1
@@ -377,6 +377,9 @@ export const addItem = async (
377 377 FusionTreasures: fusionTreasureChanges
378 378 };
379 379 } else if (ExportResources[typeName].productCategory == "Ships") {
380 if (quantity != 1) {
381 throw new Error(`unexpected acquisition quantity of Ships: got ${quantity}, expected 1`);
382 }
380 383 const oid = await createShip(inventory.accountOwnerId, typeName);
381 384 inventory.Ships.push(oid);
382 385 return {
@@ -388,6 +391,9 @@ export const addItem = async (
388 391 ]
389 392 };
390 393 } else if (ExportResources[typeName].productCategory == "CrewShips") {
394 if (quantity != 1) {
395 throw new Error(`unexpected acquisition quantity of CrewShips: got ${quantity}, expected 1`);
396 }
391 397 return {
392 398 ...(await addCrewShip(inventory, typeName)),
393 399 // fix to unlock railjack modding, item bellow supposed to be obtained from archwing quest
@@ -522,6 +528,11 @@ export const addItem = async (
522 528 if (typeName in ExportWeapons) {
523 529 const weapon = ExportWeapons[typeName];
524 530 if (weapon.totalDamage != 0) {
531 if (quantity != 1) {
532 throw new Error(
533 `unexpected acquisition quantity of ${weapon.productCategory}: got ${quantity}, expected 1`
534 );
535 }
525 536 const defaultOverwrites: Partial<IEquipmentDatabase> = {};
526 537 if (premiumPurchase) {
527 538 defaultOverwrites.Features = EquipmentFeatures.DOUBLE_CAPACITY;
@@ -578,6 +589,9 @@ export const addItem = async (
578 589 };
579 590 } else if (targetFingerprint) {
580 591 // Sister's Hound
592 if (quantity != 1) {
593 throw new Error(`unexpected acquisition quantity of MoaPets: got ${quantity}, expected 1`);
594 }
581 595 const targetFingerprintObj = JSON.parse(targetFingerprint) as INemesisPetTargetFingerprint;
582 596 const head = targetFingerprintObj.Parts[0];
583 597 const defaultOverwrites: Partial<IEquipmentDatabase> = {
@@ -653,6 +667,9 @@ export const addItem = async (
653 667 const key = ExportKeys[typeName];
654 668
655 669 if (key.chainStages) {
670 if (quantity != 1) {
671 throw new Error(`unexpected acquisition quantity of QuestKeys: got ${quantity}, expected 1`);
672 }
656 673 const key = addQuestKey(inventory, { ItemType: typeName });
657 674 if (!key) return {};
658 675 return { QuestKeys: [key] };
@@ -695,6 +712,9 @@ export const addItem = async (
695 712 if (typeName.endsWith("AugmentCard")) break;
696 713 switch (typeName.substring(1).split("/")[2]) {
697 714 default: {
715 if (quantity != 1) {
716 throw new Error(`unexpected acquisition quantity of Suits: got ${quantity}, expected 1`);
717 }
698 718 return {
699 719 ...(await addPowerSuit(inventory, typeName, {
700 720 Features: premiumPurchase ? EquipmentFeatures.DOUBLE_CAPACITY : undefined
@@ -703,6 +723,9 @@ export const addItem = async (
703 723 };
704 724 }
705 725 case "Archwing": {
726 if (quantity != 1) {
727 throw new Error(`unexpected acquisition quantity of SpaceSuits: got ${quantity}, expected 1`);
728 }
706 729 inventory.ArchwingEnabled = true;
707 730 return {
708 731 ...addSpaceSuit(
@@ -715,6 +738,9 @@ export const addItem = async (
715 738 };
716 739 }
717 740 case "EntratiMech": {
741 if (quantity != 1) {
742 throw new Error(`unexpected acquisition quantity of MechSuits: got ${quantity}, expected 1`);
743 }
718 744 return {
719 745 ...(await addMechSuit(
720 746 inventory,
@@ -747,16 +773,18 @@ export const addItem = async (
747 773
748 774 case "Boons":
749 775 // Can purchase /Lotus/Upgrades/Boons/DuviriVendorBoonItem from Acrithis, doesn't need to be added to inventory.
776 logger.debug(`acquisition of ${typeName} is not committed to inventory`);
750 777 return {};
751 778
752 779 case "Stickers":
753 780 {
754 781 const entry = inventory.RawUpgrades.find(x => x.ItemType == typeName);
755 782 if (entry && entry.ItemCount >= 10) {
783 logger.debug(`adding ${quantity} pix chip(s) instead of ${typeName}`);
756 784 const miscItemChanges = [
757 785 {
758 786 ItemType: "/Lotus/Types/Items/MiscItems/1999ConquestBucks",
759 ItemCount: 1
787 ItemCount: quantity
760 788 }
761 789 ];
762 790 addMiscItems(inventory, miscItemChanges);
@@ -779,6 +807,9 @@ export const addItem = async (
779 807 break;
780 808
781 809 case "Skins": {
810 if (quantity != 1) {
811 throw new Error(`unexpected acquisition quantity of Skins: got ${quantity}, expected 1`);
812 }
782 813 return addSkin(inventory, typeName);
783 814 }
784 815 }
@@ -787,6 +818,9 @@ export const addItem = async (
787 818 case "Types":
788 819 switch (typeName.substring(1).split("/")[2]) {
789 820 case "Sentinels": {
821 if (quantity != 1) {
822 throw new Error(`unexpected acquisition quantity of Sentinels: got ${quantity}, expected 1`);
823 }
790 824 return addSentinel(inventory, typeName, premiumPurchase);
791 825 }
792 826 case "Game": {
@@ -813,9 +847,19 @@ export const addItem = async (
813 847 typeName != "/Lotus/Types/Game/KubrowPet/BlankTraitPrint" &&
814 848 typeName != "/Lotus/Types/Game/KubrowPet/ImprintedTraitPrint"
815 849 ) {
850 if (quantity != 1) {
851 throw new Error(
852 `unexpected acquisition quantity of KubrowPet: got ${quantity}, expected 1`
853 );
854 }
816 855 return addKubrowPet(inventory, typeName, undefined, premiumPurchase);
817 856 }
818 857 } else if (typeName.startsWith("/Lotus/Types/Game/CrewShip/CrewMember/")) {
858 if (quantity != 1) {
859 throw new Error(
860 `unexpected acquisition quantity of CrewMember: got ${quantity}, expected 1`
861 );
862 }
819 863 if (!seed) {
820 864 throw new Error(`Expected crew member to have a seed`);
821 865 }
@@ -825,12 +869,22 @@ export const addItem = async (
825 869 ...occupySlot(inventory, InventorySlot.CREWMEMBERS, premiumPurchase)
826 870 };
827 871 } else if (typeName == "/Lotus/Types/Game/CrewShip/RailJack/DefaultHarness") {
872 if (quantity != 1) {
873 throw new Error(
874 `unexpected acquisition quantity of CrewShipHarness: got ${quantity}, expected 1`
875 );
876 }
828 877 return addCrewShipHarness(inventory, typeName);
829 878 }
830 879 break;
831 880 }
832 881 case "Items": {
833 882 if (typeName.substring(1).split("/")[3] == "Emotes") {
883 if (quantity != 1) {
884 throw new Error(
885 `unexpected acquisition quantity of FlavourItems: got ${quantity}, expected 1`
886 );
887 }
834 888 return addCustomization(inventory, typeName);
835 889 }
836 890 break;
@@ -840,6 +894,9 @@ export const addItem = async (
840 894 logger.warn("refusing to add Horse because account already has one");
841 895 return {};
842 896 }
897 if (quantity != 1) {
898 throw new Error(`unexpected acquisition quantity of Horses: got ${quantity}, expected 1`);
899 }
843 900 const horseIndex = inventory.Horses.push({ ItemType: typeName });
844 901 return {
845 902 Horses: [inventory.Horses[horseIndex - 1].toJSON<IEquipmentClient>()]
@@ -847,11 +904,19 @@ export const addItem = async (
847 904 }
848 905 case "Vehicles":
849 906 if (typeName == "/Lotus/Types/Vehicles/Motorcycle/MotorcyclePowerSuit") {
907 if (quantity != 1) {
908 throw new Error(`unexpected acquisition quantity of Vehicles: got ${quantity}, expected 1`);
909 }
850 910 return addMotorcycle(inventory, typeName);
851 911 }
852 912 break;
853 913 case "Lore":
854 914 if (typeName == "/Lotus/Types/Lore/Fragments/GrineerGhoulFragments/GhoulFragmentRewards") {
915 if (quantity != 1) {
916 throw new Error(
917 `unexpected acquisition quantity of LoreFragmentScans: got ${quantity}, expected 1`
918 );
919 }
855 920 const fragmentType = getRandomElement([
856 921 "/Lotus/Types/Lore/Fragments/GrineerGhoulFragments/GhoulFragmentA",
857 922 "/Lotus/Types/Lore/Fragments/GrineerGhoulFragments/GhoulFragmentB",
@@ -885,6 +950,11 @@ export const addItem = async (
885 950 case "Pistols":
886 951 case "LongGuns":
887 952 case "Melee": {
953 if (quantity != 1) {
954 throw new Error(
955 `unexpected acquisition quantity of ${productCategory}: got ${quantity}, expected 1`
956 );
957 }
888 958 const inventoryChanges = addEquipment(inventory, productCategory, typeName);
889 959 return {
890 960 ...inventoryChanges,
Modified src/services/purchaseService.ts +3 -0
@@ -554,6 +554,9 @@ const handleBoosterPackPurchase = async (
554 554 BoosterPackItems: "",
555 555 InventoryChanges: {}
556 556 };
557 if (quantity < 1) {
558 throw new Error(`invalid quantity for booster pack purchase: ${quantity}`);
559 }
557 560 if (quantity > 100) {
558 561 throw new Error(
559 562 "attempt to roll over 100 booster packs in a single go. possible but unlikely to be desirable for the user or the server."