feat: custom item names (#307)

This commit is contained in:
Sainan 2024-06-16 21:49:41 +02:00 committed by GitHub
parent 96fa616f3d
commit b3794821c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 109 additions and 41 deletions

View File

@ -0,0 +1,27 @@
import { RequestHandler } from "express";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { getInventory, updateCurrency } from "@/src/services/inventoryService";
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
interface INameWeaponRequest {
ItemName: string;
}
export const nameWeaponController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const body = getJSONfromString(req.body.toString()) as INameWeaponRequest;
const item = inventory[req.query.Category as string as TEquipmentKey].find(
item => item._id.toString() == (req.query.ItemId as string)
)!;
if (body.ItemName != "") {
item.ItemName = body.ItemName;
} else {
item.ItemName = undefined;
}
await inventory.save();
res.json({
InventoryChanges: await updateCurrency("webui" in req.query ? 0 : 15, true, accountId)
});
};

View File

@ -1,7 +1,7 @@
import { RequestHandler } from "express";
import { IUpgradesRequest } from "@/src/types/requestTypes";
import { FocusSchool, IEquipmentDatabase } from "@/src/types/inventoryTypes/commonInventoryTypes";
import { IMiscItem, IEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
import { IMiscItem, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { addMiscItems, getInventory, updateCurrency } from "@/src/services/inventoryService";
@ -28,7 +28,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
switch (operation.UpgradeRequirement) {
case "/Lotus/Types/Items/MiscItems/OrokinReactor":
case "/Lotus/Types/Items/MiscItems/OrokinCatalyst":
for (const item of inventory[payload.ItemCategory as IEquipmentKey] as IEquipmentDatabase[]) {
for (const item of inventory[payload.ItemCategory as TEquipmentKey] as IEquipmentDatabase[]) {
if (item._id.toString() == payload.ItemId.$oid) {
item.Features ??= 0;
item.Features |= 1;
@ -38,7 +38,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
break;
case "/Lotus/Types/Items/MiscItems/UtilityUnlocker":
case "/Lotus/Types/Items/MiscItems/WeaponUtilityUnlocker":
for (const item of inventory[payload.ItemCategory as IEquipmentKey] as IEquipmentDatabase[]) {
for (const item of inventory[payload.ItemCategory as TEquipmentKey] as IEquipmentDatabase[]) {
if (item._id.toString() == payload.ItemId.$oid) {
item.Features ??= 0;
item.Features |= 2;
@ -49,7 +49,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
case "/Lotus/Types/Items/MiscItems/WeaponPrimaryArcaneUnlocker":
case "/Lotus/Types/Items/MiscItems/WeaponSecondaryArcaneUnlocker":
case "/Lotus/Types/Items/MiscItems/WeaponMeleeArcaneUnlocker":
for (const item of inventory[payload.ItemCategory as IEquipmentKey] as IEquipmentDatabase[]) {
for (const item of inventory[payload.ItemCategory as TEquipmentKey] as IEquipmentDatabase[]) {
if (item._id.toString() == payload.ItemId.$oid) {
item.Features ??= 0;
item.Features |= 32;
@ -61,7 +61,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
case "/Lotus/Types/Items/MiscItems/FormaUmbra":
case "/Lotus/Types/Items/MiscItems/FormaAura":
case "/Lotus/Types/Items/MiscItems/FormaStance":
for (const item of inventory[payload.ItemCategory as IEquipmentKey] as IEquipmentDatabase[]) {
for (const item of inventory[payload.ItemCategory as TEquipmentKey] as IEquipmentDatabase[]) {
if (item._id.toString() == payload.ItemId.$oid) {
item.XP = 0;
setSlotPolarity(item, operation.PolarizeSlot, operation.PolarizeValue);
@ -72,7 +72,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
}
break;
case "/Lotus/Types/Items/MiscItems/ModSlotUnlocker":
for (const item of inventory[payload.ItemCategory as IEquipmentKey] as IEquipmentDatabase[]) {
for (const item of inventory[payload.ItemCategory as TEquipmentKey] as IEquipmentDatabase[]) {
if (item._id.toString() == payload.ItemId.$oid) {
item.ModSlotPurchases ??= 0;
item.ModSlotPurchases += 1;
@ -87,7 +87,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
}
break;
case "/Lotus/Types/Items/MiscItems/CustomizationSlotUnlocker":
for (const item of inventory[payload.ItemCategory as IEquipmentKey] as IEquipmentDatabase[]) {
for (const item of inventory[payload.ItemCategory as TEquipmentKey] as IEquipmentDatabase[]) {
if (item._id.toString() == payload.ItemId.$oid) {
item.CustomizationSlotPurchases ??= 0;
item.CustomizationSlotPurchases += 1;
@ -103,7 +103,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
break;
case "":
console.assert(operation.OperationType == "UOT_SWAP_POLARITY");
for (const item of inventory[payload.ItemCategory as IEquipmentKey] as IEquipmentDatabase[]) {
for (const item of inventory[payload.ItemCategory as TEquipmentKey] as IEquipmentDatabase[]) {
if (item._id.toString() == payload.ItemId.$oid) {
for (let i = 0; i != operation.PolarityRemap.length; ++i) {
if (operation.PolarityRemap[i].Slot != i) {

View File

@ -55,6 +55,7 @@ import { getGuildDojoController } from "@/src/controllers/api/getGuildDojoContro
import { syndicateSacrificeController } from "../controllers/api/syndicateSacrificeController";
import { startDojoRecipeController } from "@/src/controllers/api/startDojoRecipeController";
import { queueDojoComponentDestructionController } from "@/src/controllers/api/queueDojoComponentDestructionController";
import { nameWeaponController } from "@/src/controllers/api/nameWeaponController";
const apiRouter = express.Router();
@ -120,5 +121,6 @@ apiRouter.post("/upgrades.php", upgradesController);
apiRouter.post("/guildTech.php", guildTechController);
apiRouter.post("/syndicateSacrifice.php", syndicateSacrificeController);
apiRouter.post("/startDojoRecipe.php", startDojoRecipeController);
apiRouter.post("/nameWeapon.php", nameWeaponController);
export { apiRouter };

View File

@ -59,7 +59,7 @@ export interface ITypeCount {
ItemCount: number;
}
export type IEquipmentKey =
export type TEquipmentKey =
| "Suits"
| "LongGuns"
| "Pistols"

View File

@ -132,6 +132,9 @@ function updateInventory() {
{
const td = document.createElement("td");
td.textContent = itemMap[item.ItemType]?.name ?? item.ItemType;
if (item.ItemName) {
td.textContent = item.ItemName + " (" + td.textContent + ")";
}
tr.appendChild(td);
}
{
@ -144,12 +147,21 @@ function updateInventory() {
event.preventDefault();
addGearExp("Suits", item.ItemId.$oid, 1_600_000 - item.XP);
};
a.textContent = "Make Rank 30";
a.title = "Make Rank 30";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M214.6 41.4c-12.5-12.5-32.8-12.5-45.3 0l-160 160c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 141.2V448c0 17.7 14.3 32 32 32s32-14.3 32-32V141.2L329.4 246.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3l-160-160z"/></svg>`;
td.appendChild(a);
}
{
const a = document.createElement("a");
a.href = "#";
a.onclick = function (event) {
event.preventDefault();
const name = prompt("Enter new custom name:");
renameGear("Suits", item.ItemId.$oid, name);
};
a.title = "Rename";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M0 80V229.5c0 17 6.7 33.3 18.7 45.3l176 176c25 25 65.5 25 90.5 0L418.7 317.3c25-25 25-65.5 0-90.5l-176-176c-12-12-28.3-18.7-45.3-18.7H48C21.5 32 0 53.5 0 80zm112 32a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>`;
td.appendChild(a);
const span = document.createElement("span");
span.innerHTML = " &middot; ";
td.appendChild(span);
}
{
const a = document.createElement("a");
@ -158,7 +170,8 @@ function updateInventory() {
event.preventDefault();
disposeOfGear("Suits", item.ItemId.$oid);
};
a.textContent = "Remove";
a.title = "Remove";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"/></svg>`;
td.appendChild(a);
}
tr.appendChild(td);
@ -173,6 +186,9 @@ function updateInventory() {
{
const td = document.createElement("td");
td.textContent = itemMap[item.ItemType]?.name ?? item.ItemType;
if (item.ItemName) {
td.textContent = item.ItemName + " (" + td.textContent + ")";
}
tr.appendChild(td);
}
{
@ -185,12 +201,21 @@ function updateInventory() {
event.preventDefault();
addGearExp(category, item.ItemId.$oid, 800_000 - item.XP);
};
a.textContent = "Make Rank 30";
a.title = "Make Rank 30";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M214.6 41.4c-12.5-12.5-32.8-12.5-45.3 0l-160 160c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 141.2V448c0 17.7 14.3 32 32 32s32-14.3 32-32V141.2L329.4 246.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3l-160-160z"/></svg>`;
td.appendChild(a);
}
{
const a = document.createElement("a");
a.href = "#";
a.onclick = function (event) {
event.preventDefault();
const name = prompt("Enter new custom name:");
renameGear(category, item.ItemId.$oid, name);
};
a.title = "Rename";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M0 80V229.5c0 17 6.7 33.3 18.7 45.3l176 176c25 25 65.5 25 90.5 0L418.7 317.3c25-25 25-65.5 0-90.5l-176-176c-12-12-28.3-18.7-45.3-18.7H48C21.5 32 0 53.5 0 80zm112 32a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>`;
td.appendChild(a);
const span = document.createElement("span");
span.innerHTML = " &middot; ";
td.appendChild(span);
}
{
const a = document.createElement("a");
@ -199,7 +224,8 @@ function updateInventory() {
event.preventDefault();
disposeOfGear(category, item.ItemId.$oid);
};
a.textContent = "Remove";
a.title = "Remove";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"/></svg>`;
td.appendChild(a);
}
tr.appendChild(td);
@ -241,14 +267,10 @@ function updateInventory() {
})
);
a.target = "_blank";
a.textContent = "View Stats";
a.title = "View Stats";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M160 80c0-26.5 21.5-48 48-48h32c26.5 0 48 21.5 48 48V432c0 26.5-21.5 48-48 48H208c-26.5 0-48-21.5-48-48V80zM0 272c0-26.5 21.5-48 48-48H80c26.5 0 48 21.5 48 48V432c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V272zM368 96h32c26.5 0 48 21.5 48 48V432c0 26.5-21.5 48-48 48H368c-26.5 0-48-21.5-48-48V144c0-26.5 21.5-48 48-48z"/></svg>`;
td.appendChild(a);
}
{
const span = document.createElement("span");
span.innerHTML = " &middot; ";
td.appendChild(span);
}
{
const a = document.createElement("a");
a.href = "#";
@ -256,7 +278,8 @@ function updateInventory() {
event.preventDefault();
disposeOfGear("Upgrades", item.ItemId.$oid);
};
a.textContent = "Remove";
a.title = "Remove";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"/></svg>`;
td.appendChild(a);
}
tr.appendChild(td);
@ -282,12 +305,9 @@ function updateInventory() {
event.preventDefault();
setFingerprint(item.ItemType, item.ItemId, { lvl: maxRank });
};
a.textContent = "Max Rank";
a.title = "Max Rank";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M214.6 41.4c-12.5-12.5-32.8-12.5-45.3 0l-160 160c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 141.2V448c0 17.7 14.3 32 32 32s32-14.3 32-32V141.2L329.4 246.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3l-160-160z"/></svg>`;
td.appendChild(a);
const span = document.createElement("span");
span.innerHTML = " &middot; ";
td.appendChild(span);
}
{
const a = document.createElement("a");
@ -296,7 +316,8 @@ function updateInventory() {
event.preventDefault();
disposeOfGear("Upgrades", item.ItemId.$oid);
};
a.textContent = "Remove";
a.title = "Remove";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"/></svg>`;
td.appendChild(a);
}
tr.appendChild(td);
@ -327,14 +348,10 @@ function updateInventory() {
event.preventDefault();
setFingerprint(item.ItemType, item.LastAdded, { lvl: maxRank });
};
a.textContent = "Max Rank";
a.title = "Max Rank";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M214.6 41.4c-12.5-12.5-32.8-12.5-45.3 0l-160 160c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 141.2V448c0 17.7 14.3 32 32 32s32-14.3 32-32V141.2L329.4 246.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3l-160-160z"/></svg>`;
td.appendChild(a);
}
{
const span = document.createElement("span");
span.innerHTML = " &middot; ";
td.appendChild(span);
}
{
const a = document.createElement("a");
a.href = "#";
@ -342,7 +359,8 @@ function updateInventory() {
event.preventDefault();
disposeOfItems("Upgrades", item.ItemType, item.ItemCount);
};
a.textContent = "Remove";
a.title = "Remove";
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"/></svg>`;
td.appendChild(a);
}
tr.appendChild(td);
@ -432,6 +450,20 @@ function addGearExp(category, oid, xp) {
});
}
function renameGear(category, oid, name) {
revalidateAuthz(() => {
$.post({
url: "/api/nameWeapon.php?" + window.authz + "&Category=" + category + "&ItemId=" + oid + "&webui=1",
contentType: "text/plain",
data: JSON.stringify({
ItemName: name
})
}).done(function () {
updateInventory();
});
});
}
function disposeOfGear(category, oid) {
const data = {
SellCurrency: "SC_RegularCredits",

View File

@ -20,3 +20,10 @@ body:not(.logged-in) .nav-item.dropdown,
body:not(.logged-in) #refresh-note {
display: none;
}
td.text-end > a > svg {
fill: currentColor;
height: 1em;
margin-left: 0.5em;
margin-bottom: 4px; /* to centre the icon */
}