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

fix(webui): add items (#863)

080b466b
Sainan <sainan@calamity.inc>
提交于

代码差异

5 个文件 +55 -87
Modified src/app.ts +2 -2
@@ -16,8 +16,8 @@ import { webuiRouter } from "@/src/routes/webui";
16 16 const app = express();
17 17
18 18 app.use(bodyParser.raw());
19 app.use(express.json());
20 app.use(bodyParser.text({ limit: "4mb" }));
19 app.use(express.json({ limit: "4mb" }));
20 app.use(bodyParser.text());
21 21 app.use(requestLogger);
22 22
23 23 app.use("/api", apiRouter);
Modified src/controllers/custom/addItemsController.ts +4 -45
@@ -1,7 +1,5 @@
1 1 import { getAccountIdForRequest } from "@/src/services/loginService";
2 import { addEquipment, addPowerSuit, addMechSuit, getInventory, updateSlots } from "@/src/services/inventoryService";
3 import { SlotNames } from "@/src/types/purchaseTypes";
4 import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
2 import { getInventory, addItem } from "@/src/services/inventoryService";
5 3 import { RequestHandler } from "express";
6 4
7 5 export const addItemsController: RequestHandler = async (req, res) => {
@@ -9,52 +7,13 @@ export const addItemsController: RequestHandler = async (req, res) => {
9 7 const requests = req.body as IAddItemRequest[];
10 8 const inventory = await getInventory(accountId);
11 9 for (const request of requests) {
12 updateSlots(inventory, productCategoryToSlotName[request.type], 0, 1);
13 switch (request.type) {
14 case ItemType.Suits:
15 addPowerSuit(inventory, request.internalName);
16 break;
17
18 case ItemType.MechSuits:
19 addMechSuit(inventory, request.internalName);
20 break;
21
22 default:
23 addEquipment(inventory, request.type, request.internalName);
24 break;
25 }
10 await addItem(inventory, request.ItemType, request.ItemCount);
26 11 }
27 12 await inventory.save();
28 13 res.end();
29 14 };
30 15
31 const productCategoryToSlotName: Record<ItemType, SlotNames> = {
32 Suits: InventorySlot.SUITS,
33 Pistols: InventorySlot.WEAPONS,
34 Melee: InventorySlot.WEAPONS,
35 LongGuns: InventorySlot.WEAPONS,
36 SpaceSuits: InventorySlot.SPACESUITS,
37 SpaceGuns: InventorySlot.SPACESUITS,
38 SpaceMelee: InventorySlot.SPACESUITS,
39 Sentinels: InventorySlot.SENTINELS,
40 SentinelWeapons: InventorySlot.SENTINELS,
41 MechSuits: InventorySlot.MECHSUITS
42 };
43
44 enum ItemType {
45 Suits = "Suits",
46 SpaceSuits = "SpaceSuits",
47 LongGuns = "LongGuns",
48 Pistols = "Pistols",
49 Melee = "Melee",
50 SpaceGuns = "SpaceGuns",
51 SpaceMelee = "SpaceMelee",
52 SentinelWeapons = "SentinelWeapons",
53 Sentinels = "Sentinels",
54 MechSuits = "MechSuits"
55 }
56
57 16 interface IAddItemRequest {
58 type: ItemType;
59 internalName: string;
17 ItemType: string;
18 ItemCount: number;
60 19 }
Modified src/controllers/custom/importController.ts +1 -1
@@ -7,7 +7,7 @@ import { RequestHandler } from "express";
7 7
8 8 export const importController: RequestHandler = async (req, res) => {
9 9 const accountId = await getAccountIdForRequest(req);
10 const request = JSON.parse(String(req.body)) as IImportRequest;
10 const request = req.body as IImportRequest;
11 11
12 12 const inventory = await getInventory(accountId);
13 13 importInventory(inventory, request.inventory);
Modified src/services/inventoryService.ts +15 -0
@@ -366,6 +366,21 @@ export const addItem = async (
366 366 }
367 367 };
368 368 }
369 case "Upgrades": {
370 // Needed to add Traumatic Peculiar
371 const changes = [
372 {
373 ItemType: typeName,
374 ItemCount: quantity
375 }
376 ];
377 addMods(inventory, changes);
378 return {
379 InventoryChanges: {
380 RawUpgrades: changes
381 }
382 };
383 }
369 384 case "Types":
370 385 switch (typeName.substr(1).split("/")[2]) {
371 386 case "Sentinels": {
Modified static/webui/script.js +33 -39
@@ -528,8 +528,8 @@ function doAcquireEquipment(category) {
528 528 contentType: "application/json",
529 529 data: JSON.stringify([
530 530 {
531 type: category,
532 internalName: uniqueName
531 ItemType: uniqueName,
532 ItemCount: 1
533 533 }
534 534 ])
535 535 });
@@ -566,7 +566,7 @@ function addMissingEquipment(categories) {
566 566 "#" + category + "-list [data-item-type='" + elm.getAttribute("data-key") + "']"
567 567 )
568 568 ) {
569 requests.push({ type: category, internalName: elm.getAttribute("data-key") });
569 requests.push({ ItemType: elm.getAttribute("data-key"), ItemCount: 1 });
570 570 }
571 571 });
572 572 });
@@ -734,16 +734,14 @@ function doAcquireMiscItems() {
734 734 const [category, uniqueName] = data.split(":");
735 735 revalidateAuthz(() => {
736 736 $.post({
737 url: "/api/missionInventoryUpdate.php?" + window.authz,
738 contentType: "text/plain",
739 data: JSON.stringify({
740 [category]: [
741 {
742 ItemType: uniqueName,
743 ItemCount: parseInt($("#miscitem-count").val())
744 }
745 ]
746 })
737 url: "/custom/addItems?" + window.authz,
738 contentType: "application/json",
739 data: JSON.stringify([
740 {
741 ItemType: uniqueName,
742 ItemCount: parseInt($("#miscitem-count").val())
743 }
744 ])
747 745 }).done(function () {
748 746 alert("Successfully added.");
749 747 });
@@ -771,16 +769,14 @@ function doAcquireRiven() {
771 769 revalidateAuthz(() => {
772 770 // Add riven type to inventory
773 771 $.post({
774 url: "/api/missionInventoryUpdate.php?" + window.authz,
775 contentType: "text/plain",
776 data: JSON.stringify({
777 RawUpgrades: [
778 {
779 ItemType: uniqueName,
780 ItemCount: 1
781 }
782 ]
783 })
772 url: "/custom/addItems?" + window.authz,
773 contentType: "application/json",
774 data: JSON.stringify([
775 {
776 ItemType: uniqueName,
777 ItemCount: 1
778 }
779 ])
784 780 }).done(function () {
785 781 // Get riven's assigned id
786 782 $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1").done(data => {
@@ -845,16 +841,14 @@ function doAcquireMod() {
845 841 }
846 842 revalidateAuthz(() => {
847 843 $.post({
848 url: "/api/missionInventoryUpdate.php?" + window.authz,
849 contentType: "text/plain",
850 data: JSON.stringify({
851 RawUpgrades: [
852 {
853 ItemType: uniqueName,
854 ItemCount: parseInt($("#mod-count").val())
855 }
856 ]
857 })
844 url: "/custom/addItems?" + window.authz,
845 contentType: "application/json",
846 data: JSON.stringify([
847 {
848 ItemType: uniqueName,
849 ItemCount: parseInt($("#mod-count").val())
850 }
851 ])
858 852 }).done(function () {
859 853 document.getElementById("mod-to-acquire").value = "";
860 854 updateInventory();
@@ -1033,14 +1027,14 @@ function doAddAllMods() {
1033 1027 window.confirm("Are you sure you want to add " + modsAll.length + " mods to your account?")
1034 1028 ) {
1035 1029 $.post({
1036 url: "/api/missionInventoryUpdate.php?" + window.authz,
1037 contentType: "text/plain",
1038 data: JSON.stringify({
1039 RawUpgrades: modsAll.map(mod => ({
1030 url: "/custom/addItems?" + window.authz,
1031 contentType: "application/json",
1032 data: JSON.stringify(
1033 modsAll.map(mod => ({
1040 1034 ItemType: mod,
1041 1035 ItemCount: 21 // To fully upgrade certain arcanes
1042 1036 }))
1043 })
1037 )
1044 1038 }).done(function () {
1045 1039 updateInventory();
1046 1040 });
@@ -1100,7 +1094,7 @@ function doImport() {
1100 1094 revalidateAuthz(() => {
1101 1095 $.post({
1102 1096 url: "/custom/import?" + window.authz,
1103 contentType: "text/plain",
1097 contentType: "application/json",
1104 1098 data: JSON.stringify({
1105 1099 inventory: JSON.parse($("#import-inventory").val())
1106 1100 })