fix(webui): add items
This commit is contained in:
parent
3cd66391b6
commit
6ac2cb8456
@ -1,7 +1,5 @@
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { addEquipment, addPowerSuit, addMechSuit, getInventory, updateSlots } from "@/src/services/inventoryService";
|
||||
import { SlotNames } from "@/src/types/purchaseTypes";
|
||||
import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { getInventory, addItem } from "@/src/services/inventoryService";
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
export const addItemsController: RequestHandler = async (req, res) => {
|
||||
@ -9,52 +7,13 @@ export const addItemsController: RequestHandler = async (req, res) => {
|
||||
const requests = req.body as IAddItemRequest[];
|
||||
const inventory = await getInventory(accountId);
|
||||
for (const request of requests) {
|
||||
updateSlots(inventory, productCategoryToSlotName[request.type], 0, 1);
|
||||
switch (request.type) {
|
||||
case ItemType.Suits:
|
||||
addPowerSuit(inventory, request.internalName);
|
||||
break;
|
||||
|
||||
case ItemType.MechSuits:
|
||||
addMechSuit(inventory, request.internalName);
|
||||
break;
|
||||
|
||||
default:
|
||||
addEquipment(inventory, request.type, request.internalName);
|
||||
break;
|
||||
}
|
||||
await addItem(inventory, request.ItemType, request.ItemCount);
|
||||
}
|
||||
await inventory.save();
|
||||
res.end();
|
||||
};
|
||||
|
||||
const productCategoryToSlotName: Record<ItemType, SlotNames> = {
|
||||
Suits: InventorySlot.SUITS,
|
||||
Pistols: InventorySlot.WEAPONS,
|
||||
Melee: InventorySlot.WEAPONS,
|
||||
LongGuns: InventorySlot.WEAPONS,
|
||||
SpaceSuits: InventorySlot.SPACESUITS,
|
||||
SpaceGuns: InventorySlot.SPACESUITS,
|
||||
SpaceMelee: InventorySlot.SPACESUITS,
|
||||
Sentinels: InventorySlot.SENTINELS,
|
||||
SentinelWeapons: InventorySlot.SENTINELS,
|
||||
MechSuits: InventorySlot.MECHSUITS
|
||||
};
|
||||
|
||||
enum ItemType {
|
||||
Suits = "Suits",
|
||||
SpaceSuits = "SpaceSuits",
|
||||
LongGuns = "LongGuns",
|
||||
Pistols = "Pistols",
|
||||
Melee = "Melee",
|
||||
SpaceGuns = "SpaceGuns",
|
||||
SpaceMelee = "SpaceMelee",
|
||||
SentinelWeapons = "SentinelWeapons",
|
||||
Sentinels = "Sentinels",
|
||||
MechSuits = "MechSuits"
|
||||
}
|
||||
|
||||
interface IAddItemRequest {
|
||||
type: ItemType;
|
||||
internalName: string;
|
||||
ItemType: string;
|
||||
ItemCount: number;
|
||||
}
|
||||
|
@ -366,6 +366,21 @@ export const addItem = async (
|
||||
}
|
||||
};
|
||||
}
|
||||
case "Upgrades": {
|
||||
// Needed to add Traumatic Peculiar
|
||||
const changes = [
|
||||
{
|
||||
ItemType: typeName,
|
||||
ItemCount: quantity
|
||||
}
|
||||
];
|
||||
addMods(inventory, changes);
|
||||
return {
|
||||
InventoryChanges: {
|
||||
RawUpgrades: changes
|
||||
}
|
||||
};
|
||||
}
|
||||
case "Types":
|
||||
switch (typeName.substr(1).split("/")[2]) {
|
||||
case "Sentinels": {
|
||||
|
@ -528,8 +528,8 @@ function doAcquireEquipment(category) {
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify([
|
||||
{
|
||||
type: category,
|
||||
internalName: uniqueName
|
||||
ItemType: uniqueName,
|
||||
ItemCount: 1
|
||||
}
|
||||
])
|
||||
});
|
||||
@ -566,7 +566,7 @@ function addMissingEquipment(categories) {
|
||||
"#" + category + "-list [data-item-type='" + elm.getAttribute("data-key") + "']"
|
||||
)
|
||||
) {
|
||||
requests.push({ type: category, internalName: elm.getAttribute("data-key") });
|
||||
requests.push({ ItemType: elm.getAttribute("data-key"), ItemCount: 1 });
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -734,16 +734,14 @@ function doAcquireMiscItems() {
|
||||
const [category, uniqueName] = data.split(":");
|
||||
revalidateAuthz(() => {
|
||||
$.post({
|
||||
url: "/api/missionInventoryUpdate.php?" + window.authz,
|
||||
contentType: "text/plain",
|
||||
data: JSON.stringify({
|
||||
[category]: [
|
||||
{
|
||||
ItemType: uniqueName,
|
||||
ItemCount: parseInt($("#miscitem-count").val())
|
||||
}
|
||||
]
|
||||
})
|
||||
url: "/custom/addItems?" + window.authz,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify([
|
||||
{
|
||||
ItemType: uniqueName,
|
||||
ItemCount: parseInt($("#miscitem-count").val())
|
||||
}
|
||||
])
|
||||
}).done(function () {
|
||||
alert("Successfully added.");
|
||||
});
|
||||
@ -771,16 +769,14 @@ function doAcquireRiven() {
|
||||
revalidateAuthz(() => {
|
||||
// Add riven type to inventory
|
||||
$.post({
|
||||
url: "/api/missionInventoryUpdate.php?" + window.authz,
|
||||
contentType: "text/plain",
|
||||
data: JSON.stringify({
|
||||
RawUpgrades: [
|
||||
{
|
||||
ItemType: uniqueName,
|
||||
ItemCount: 1
|
||||
}
|
||||
]
|
||||
})
|
||||
url: "/custom/addItems?" + window.authz,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify([
|
||||
{
|
||||
ItemType: uniqueName,
|
||||
ItemCount: 1
|
||||
}
|
||||
])
|
||||
}).done(function () {
|
||||
// Get riven's assigned id
|
||||
$.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1").done(data => {
|
||||
@ -845,16 +841,14 @@ function doAcquireMod() {
|
||||
}
|
||||
revalidateAuthz(() => {
|
||||
$.post({
|
||||
url: "/api/missionInventoryUpdate.php?" + window.authz,
|
||||
contentType: "text/plain",
|
||||
data: JSON.stringify({
|
||||
RawUpgrades: [
|
||||
{
|
||||
ItemType: uniqueName,
|
||||
ItemCount: parseInt($("#mod-count").val())
|
||||
}
|
||||
]
|
||||
})
|
||||
url: "/custom/addItems?" + window.authz,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify([
|
||||
{
|
||||
ItemType: uniqueName,
|
||||
ItemCount: parseInt($("#mod-count").val())
|
||||
}
|
||||
])
|
||||
}).done(function () {
|
||||
document.getElementById("mod-to-acquire").value = "";
|
||||
updateInventory();
|
||||
@ -1033,14 +1027,14 @@ function doAddAllMods() {
|
||||
window.confirm("Are you sure you want to add " + modsAll.length + " mods to your account?")
|
||||
) {
|
||||
$.post({
|
||||
url: "/api/missionInventoryUpdate.php?" + window.authz,
|
||||
contentType: "text/plain",
|
||||
data: JSON.stringify({
|
||||
RawUpgrades: modsAll.map(mod => ({
|
||||
url: "/custom/addItems?" + window.authz,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(
|
||||
modsAll.map(mod => ({
|
||||
ItemType: mod,
|
||||
ItemCount: 21 // To fully upgrade certain arcanes
|
||||
}))
|
||||
})
|
||||
)
|
||||
}).done(function () {
|
||||
updateInventory();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user