diff --git a/src/controllers/custom/addItemsController.ts b/src/controllers/custom/addItemsController.ts index 4add37ac..ff05fc7b 100644 --- a/src/controllers/custom/addItemsController.ts +++ b/src/controllers/custom/addItemsController.ts @@ -1,14 +1,91 @@ import { getAccountIdForRequest } from "../../services/loginService.ts"; -import { getInventory, addItem } from "../../services/inventoryService.ts"; +import { + getInventory, + addItem, + addMiscItem, + addMods, + addShipDecorations, + addPowerSuit, + addEquipment, + addMechSuit, + addSentinel, + addSentinelWeapon, + addCustomization, + addSkin, + productCategoryToInventoryBin, + occupySlot +} from "../../services/inventoryService.ts"; import type { RequestHandler } from "express"; import { broadcastInventoryUpdate } from "../../services/wsService.ts"; +import { InventorySlot } from "../../types/inventoryTypes/inventoryTypes.ts"; export const addItemsController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); const requests = req.body as IAddItemRequest[]; const inventory = await getInventory(accountId); + const productCategory = (req.query.productCategory as string) || ""; for (const request of requests) { - await addItem(inventory, request.ItemType, request.ItemCount, true, undefined, request.Fingerprint, true); + switch (productCategory) { + case "MiscItems": + addMiscItem(inventory, request.ItemType, request.ItemCount); + break; + + case "RawUpgrades": + addMods(inventory, [request]); + break; + + case "ShipDecorations": + addShipDecorations(inventory, [request]); + break; + + case "Suits": + await addPowerSuit(inventory, request.ItemType); + occupySlot(inventory, InventorySlot.SUITS, true); + break; + + case "MechSuits": + await addMechSuit(inventory, request.ItemType); + occupySlot(inventory, InventorySlot.MECHSUITS, true); + break; + + case "Sentinels": + addSentinel(inventory, request.ItemType, true); + break; + + case "SentinelWeapons": + addSentinelWeapon(inventory, request.ItemType, true); + break; + + case "FlavourItems": + addCustomization(inventory, request.ItemType); + break; + + case "WeaponSkins": + addSkin(inventory, request.ItemType); + break; + + case "LongGuns": + case "Pistols": + case "Melee": + case "SpaceSuits": + case "SpaceGuns": + case "SpaceMelee": + addEquipment(inventory, productCategory, request.ItemType); + occupySlot(inventory, productCategoryToInventoryBin(productCategory) ?? InventorySlot.WEAPONS, true); + break; + + default: + await addItem( + inventory, + request.ItemType, + request.ItemCount, + true, + undefined, + request.Fingerprint, + true + ); + break; + } } await inventory.save(); res.end(); diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 17cdf370..e84d178c 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -941,7 +941,7 @@ export const applyDefaultUpgrades = ( }; //TODO: maybe genericMethod for all the add methods, they share a lot of logic -const addSentinel = ( +export const addSentinel = ( inventory: TInventoryDatabaseDocument, sentinelName: string, premiumPurchase: boolean, @@ -972,11 +972,11 @@ const addSentinel = ( return inventoryChanges; }; -const addSentinelWeapon = ( +export const addSentinelWeapon = ( inventory: TInventoryDatabaseDocument, typeName: string, premiumPurchase: boolean, - inventoryChanges: IInventoryChanges + inventoryChanges: IInventoryChanges = {} ): void => { // Sentinel weapons also occupy a slot in the sentinels bin combineInventoryChanges(inventoryChanges, occupySlot(inventory, InventorySlot.SENTINELS, premiumPurchase)); diff --git a/static/webui/index.html b/static/webui/index.html index b14e004b..e0d610bf 100644 --- a/static/webui/index.html +++ b/static/webui/index.html @@ -116,9 +116,31 @@
-

+

+ + +

- + + +
diff --git a/static/webui/script.js b/static/webui/script.js index a648b6ea..2a867de5 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -773,6 +773,9 @@ function updateInventory() { document.getElementById("typeName-tab").classList.remove("active"); document.getElementById("typeName-tab-content").classList.remove("active", "show"); document.getElementById("typeName-type").value = ""; + document.getElementById("typeName-productCategory").value = ""; + document.getElementById("typeName-count").value = 1; + document.getElementById("typeName-count").disabled = true; document.getElementById("miscItems-tab").classList.add("active"); document.getElementById("miscItems-tab-content").classList.add("active", "show"); @@ -2965,27 +2968,48 @@ function removeCountItems(uniqueName, count) { }); } +document.getElementById("typeName-productCategory").onchange = function () { + const productCategory = document.getElementById("typeName-productCategory").value; + const ItemCount = document.getElementById("typeName-count"); + if (["MiscItems", "RawUpgrades", "ShipDecorations"].includes(productCategory)) { + ItemCount.disabled = false; + } else { + ItemCount.disabled = true; + ItemCount.value = 1; + } +}; + function addItemByItemType() { const ItemType = document.getElementById("typeName-type").value; + const productCategory = document.getElementById("typeName-productCategory"); + const ItemCount = document.getElementById("typeName-count"); // Must start with "/Lotus/", contain only letters A–Z, digits 0–9, no "//", and not end with "/" if (!ItemType || !/^\/Lotus\/(?:[A-Za-z0-9]+(?:\/[A-Za-z0-9]+)*)$/.test(ItemType)) { $("#typeName-type").addClass("is-invalid").focus(); return; } + let url = "/custom/addItems?" + window.authz; + + if (productCategory.value) { + url += "&productCategory=" + productCategory.value; + } revalidateAuthz().then(() => { $.post({ - url: "/custom/addItems?" + window.authz, + url, contentType: "application/json", data: JSON.stringify([ { ItemType, - ItemCount: 1 + ItemCount: ItemCount.value } ]) }) - .done(function (_, _, jqXHR) { + .done(function (_, __, jqXHR) { if (jqXHR.status === 200) { updateInventory(); + productCategory.value = ""; + ItemCount.disabled = true; + ItemCount.value = 1; } }) .fail(function () { diff --git a/static/webui/translations/de.js b/static/webui/translations/de.js index 8f2f97a3..fe775f99 100644 --- a/static/webui/translations/de.js +++ b/static/webui/translations/de.js @@ -98,6 +98,7 @@ dict = { inventory_addItems: `Gegenstände hinzufügen`, inventory_addItemByItemType: `Roh`, inventory_addItemByItemType_warning: `Verwende diese Funktion auf eigene Gefahr. Sie kann dein Inventar beschädigen und du musst Gegenstände manuell entfernen, falls etwas schiefgeht.`, + inventory_addItemByItemType_productCategory: `[UNTRANSLATED] You can also specify productCategory, some of which will allow you to change the number of items added.`, inventory_suits: `Warframes`, inventory_longGuns: `Primärwaffen`, inventory_pistols: `Sekundärwaffen`, @@ -308,6 +309,7 @@ dict = { worldState_incompatibleWith: `Inkompatibel mit:`, enabled: `Aktiviert`, disabled: `Deaktiviert`, + notSpecified: `[UNTRANSLATED] Not specified`, worldState_we1: `Wochenende 1`, worldState_we2: `Wochenende 2`, worldState_we3: `Wochenende 3`, diff --git a/static/webui/translations/en.js b/static/webui/translations/en.js index 7a0af074..0e04914c 100644 --- a/static/webui/translations/en.js +++ b/static/webui/translations/en.js @@ -97,6 +97,7 @@ dict = { inventory_addItems: `Add Items`, inventory_addItemByItemType: `Raw`, inventory_addItemByItemType_warning: `Use this feature at your own risk. It may break your inventory, and you will need to remove items manually if something goes wrong.`, + inventory_addItemByItemType_productCategory: `You can also specify productCategory, some of which will allow you to change the number of items added.`, inventory_suits: `Warframes`, inventory_longGuns: `Primary Weapons`, inventory_pistols: `Secondary Weapons`, @@ -307,6 +308,7 @@ dict = { worldState_incompatibleWith: `Incompatible with:`, enabled: `Enabled`, disabled: `Disabled`, + notSpecified: `Not specified`, worldState_we1: `Weekend 1`, worldState_we2: `Weekend 2`, worldState_we3: `Weekend 3`, diff --git a/static/webui/translations/es.js b/static/webui/translations/es.js index 58eab8c8..011bf7a7 100644 --- a/static/webui/translations/es.js +++ b/static/webui/translations/es.js @@ -98,6 +98,7 @@ dict = { inventory_addItems: `Agregar objetos`, inventory_addItemByItemType: `Sin refinar`, inventory_addItemByItemType_warning: `Usa esta función bajo tu propio riesgo. Podría dañar tu inventario, y tendrías que eliminar los objetos manualmente si algo sale mal.`, + inventory_addItemByItemType_productCategory: `[UNTRANSLATED] You can also specify productCategory, some of which will allow you to change the number of items added.`, inventory_suits: `Warframes`, inventory_longGuns: `Armas primarias`, inventory_pistols: `Armas secundarias`, @@ -308,6 +309,7 @@ dict = { worldState_incompatibleWith: `No compatible con:`, enabled: `Activado`, disabled: `Desactivado`, + notSpecified: `[UNTRANSLATED] Not specified`, worldState_we1: `Semana 1`, worldState_we2: `Semana 2`, worldState_we3: `Semana 3`, diff --git a/static/webui/translations/fr.js b/static/webui/translations/fr.js index 3fa19019..139c0e01 100644 --- a/static/webui/translations/fr.js +++ b/static/webui/translations/fr.js @@ -98,6 +98,7 @@ dict = { inventory_addItems: `Ajouter des items`, inventory_addItemByItemType: `Brut`, inventory_addItemByItemType_warning: `Cette fonctionnalité comporte des risques. Il faudra rajouter les items manuellement si l'inventaire est compris.`, + inventory_addItemByItemType_productCategory: `[UNTRANSLATED] You can also specify productCategory, some of which will allow you to change the number of items added.`, inventory_suits: `Warframes`, inventory_longGuns: `Armes principales`, inventory_pistols: `Armes secondaires`, @@ -308,6 +309,7 @@ dict = { worldState_incompatibleWith: `Incompatible avec :`, enabled: `Activé`, disabled: `Désactivé`, + notSpecified: `[UNTRANSLATED] Not specified`, worldState_we1: `Weekend 1`, worldState_we2: `Weekend 2`, worldState_we3: `Weekend 3`, diff --git a/static/webui/translations/ru.js b/static/webui/translations/ru.js index bb80e3ed..9d22fb1b 100644 --- a/static/webui/translations/ru.js +++ b/static/webui/translations/ru.js @@ -98,6 +98,7 @@ dict = { inventory_addItems: `Добавить предметы`, inventory_addItemByItemType: `Необработанные данные`, inventory_addItemByItemType_warning: `Используйте эту функцию на свой страх и риск. Она может повредить ваш инвентарь, и в случае проблем вам придётся удалять предметы вручную.`, + inventory_addItemByItemType_productCategory: `Вы также можете указать productCategory, некоторые из них позволят вам изменить количество добавленных преметов.`, inventory_suits: `Варфреймы`, inventory_longGuns: `Основное оружие`, inventory_pistols: `Вторичное оружие`, @@ -308,6 +309,7 @@ dict = { worldState_incompatibleWith: `Несовместимо с:`, enabled: `Включено`, disabled: `Отключено`, + notSpecified: `Не указано`, worldState_we1: `Выходные 1`, worldState_we2: `Выходные 2`, worldState_we3: `Выходные 3`, diff --git a/static/webui/translations/uk.js b/static/webui/translations/uk.js index e36a9939..9293746f 100644 --- a/static/webui/translations/uk.js +++ b/static/webui/translations/uk.js @@ -98,6 +98,7 @@ dict = { inventory_addItems: `Додати предмети`, inventory_addItemByItemType: `Необроблені дані`, inventory_addItemByItemType_warning: `Використовуйте цю функцію на власний ризик. Вона може пошкодити ваше спорядження, і вам доведеться видаляти предмети вручну, якщо щось піде не так.`, + inventory_addItemByItemType_productCategory: `[UNTRANSLATED] You can also specify productCategory, some of which will allow you to change the number of items added.`, inventory_suits: `Ворфрейми`, inventory_longGuns: `Основна зброя`, inventory_pistols: `Допоміжна зброя`, @@ -308,6 +309,7 @@ dict = { worldState_incompatibleWith: `Несумісне з:`, enabled: `Увімкнено`, disabled: `Вимкнено`, + notSpecified: `[UNTRANSLATED] Not specified`, worldState_we1: `Вихідні 1`, worldState_we2: `Вихідні 2`, worldState_we3: `Вихідні 3`, diff --git a/static/webui/translations/zh.js b/static/webui/translations/zh.js index e856f8b9..b1d2d4a4 100644 --- a/static/webui/translations/zh.js +++ b/static/webui/translations/zh.js @@ -98,6 +98,7 @@ dict = { inventory_addItems: `添加物品`, inventory_addItemByItemType: `[UNTRANSLATED] Raw`, inventory_addItemByItemType_warning: `[UNTRANSLATED] Use this feature at your own risk. It may break your inventory, and you will need to remove items manually if something goes wrong.`, + inventory_addItemByItemType_productCategory: `[UNTRANSLATED] You can also specify productCategory, some of which will allow you to change the number of items added.`, inventory_suits: `战甲`, inventory_longGuns: `主要武器`, inventory_pistols: `次要武器`, @@ -308,6 +309,7 @@ dict = { worldState_incompatibleWith: `不兼容的活动:`, enabled: `启用`, disabled: `关闭/取消配置`, + notSpecified: `[UNTRANSLATED] Not specified`, worldState_we1: `活动阶段:第一周`, worldState_we2: `活动阶段:第二周`, worldState_we3: `活动阶段:第三周`,