From aec6a964954ec1c901912d7c2ccba0518b444ab8 Mon Sep 17 00:00:00 2001 From: Sainan Date: Tue, 18 Jun 2024 02:03:07 +0200 Subject: [PATCH] feat: modular weapon crafting (#317) --- .../api/modularWeaponCraftingController.ts | 55 +++++++++++++++++++ .../custom/getItemListsController.ts | 4 +- src/models/inventoryModels/inventoryModel.ts | 1 + src/routes/api.ts | 2 + src/services/inventoryService.ts | 15 +++-- static/webui/script.js | 6 +- 6 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 src/controllers/api/modularWeaponCraftingController.ts diff --git a/src/controllers/api/modularWeaponCraftingController.ts b/src/controllers/api/modularWeaponCraftingController.ts new file mode 100644 index 00000000..c1cd7bc8 --- /dev/null +++ b/src/controllers/api/modularWeaponCraftingController.ts @@ -0,0 +1,55 @@ +import { RequestHandler } from "express"; +import { getAccountIdForRequest } from "@/src/services/loginService"; +import { getJSONfromString } from "@/src/helpers/stringHelpers"; +import { WeaponTypeInternal } from "@/src/services/itemDataService"; +import { getInventory, updateCurrency, addWeapon, addMiscItems } from "@/src/services/inventoryService"; + +const modularWeaponTypes: Record = { + "/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimaryBeam": "LongGuns", + "/Lotus/Weapons/SolarisUnited/Secondary/LotusModularSecondary": "Pistols", + "/Lotus/Weapons/SolarisUnited/Secondary/LotusModularSecondaryBeam": "Pistols", + "/Lotus/Weapons/SolarisUnited/Secondary/LotusModularSecondaryShotgun": "Pistols", + "/Lotus/Weapons/Ostron/Melee/LotusModularWeapon": "Melee", + "/Lotus/Weapons/Sentients/OperatorAmplifiers/OperatorAmpWeapon": "OperatorAmps" +}; + +interface IModularCraftRequest { + WeaponType: string; + Parts: string[]; +} + +export const modularWeaponCraftingController: RequestHandler = async (req, res) => { + const accountId = await getAccountIdForRequest(req); + const data: IModularCraftRequest = getJSONfromString(req.body.toString()); + if (!(data.WeaponType in modularWeaponTypes)) { + throw new Error(`unknown modular weapon type: ${data.WeaponType}`); + } + const category = modularWeaponTypes[data.WeaponType]; + + // Give weapon + const weapon = await addWeapon(category, data.WeaponType, accountId, data.Parts); + + // Remove 4000 credits + const currencyChanges = await updateCurrency(4000, false, accountId); + + // Remove parts + const miscItemChanges = []; + for (const part of data.Parts) { + miscItemChanges.push({ + ItemType: part, + ItemCount: -1 + }); + } + const inventory = await getInventory(accountId); + addMiscItems(inventory, miscItemChanges); + await inventory.save(); + + // Tell client what we did + res.json({ + InventoryChanges: { + ...currencyChanges, + [category]: [weapon], + MiscItems: miscItemChanges + } + }); +}; diff --git a/src/controllers/custom/getItemListsController.ts b/src/controllers/custom/getItemListsController.ts index f10b450b..04f3568d 100644 --- a/src/controllers/custom/getItemListsController.ts +++ b/src/controllers/custom/getItemListsController.ts @@ -43,7 +43,9 @@ const getItemListsController: RequestHandler = (_req, res) => { item.category == "Misc" || item.category == "Resources" || item.category == "Fish" || - ((item as any).productCategory == "Pistols" && (item as MinWeapon).totalDamage == 0) + ((item as any).productCategory == "Pistols" && + (item as MinWeapon).totalDamage == 0 && + !item.excludeFromCodex) // exclude Zaw Strike PvP variant ) ), mods, diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index dc91ddb7..8a79f758 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -921,6 +921,7 @@ type InventoryDocumentProps = { LongGuns: Types.DocumentArray; Pistols: Types.DocumentArray; Melee: Types.DocumentArray; + OperatorAmps: Types.DocumentArray; FlavourItems: Types.DocumentArray; RawUpgrades: Types.DocumentArray; Upgrades: Types.DocumentArray; diff --git a/src/routes/api.ts b/src/routes/api.ts index 8a059bfe..014e24ab 100644 --- a/src/routes/api.ts +++ b/src/routes/api.ts @@ -56,6 +56,7 @@ import { syndicateSacrificeController } from "../controllers/api/syndicateSacrif import { startDojoRecipeController } from "@/src/controllers/api/startDojoRecipeController"; import { queueDojoComponentDestructionController } from "@/src/controllers/api/queueDojoComponentDestructionController"; import { nameWeaponController } from "@/src/controllers/api/nameWeaponController"; +import { modularWeaponCraftingController } from "@/src/controllers/api/modularWeaponCraftingController"; const apiRouter = express.Router(); @@ -122,5 +123,6 @@ apiRouter.post("/guildTech.php", guildTechController); apiRouter.post("/syndicateSacrifice.php", syndicateSacrificeController); apiRouter.post("/startDojoRecipe.php", startDojoRecipeController); apiRouter.post("/nameWeapon.php", nameWeaponController); +apiRouter.post("/modularWeaponCrafting.php", modularWeaponCraftingController); export { apiRouter }; diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 64ed6f94..c7861130 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -386,20 +386,23 @@ export const syndicateSacrifice = async ( export const addWeapon = async ( weaponType: WeaponTypeInternal, weaponName: string, - accountId: string + accountId: string, + modularParts: string[] | undefined = undefined ): Promise => { const inventory = await getInventory(accountId); let weaponIndex; switch (weaponType) { case "LongGuns": - weaponIndex = inventory.LongGuns.push({ ItemType: weaponName, Configs: [], XP: 0 }); - break; case "Pistols": - weaponIndex = inventory.Pistols.push({ ItemType: weaponName, Configs: [], XP: 0 }); - break; case "Melee": - weaponIndex = inventory.Melee.push({ ItemType: weaponName, Configs: [], XP: 0 }); + case "OperatorAmps": + weaponIndex = inventory[weaponType].push({ + ItemType: weaponName, + Configs: [], + XP: 0, + ModularParts: modularParts + }); break; default: throw new Error("unknown weapon type: " + weaponType); diff --git a/static/webui/script.js b/static/webui/script.js index 6a9d525d..bc1e8758 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -96,6 +96,10 @@ window.itemListPromise = new Promise(resolve => { "/Lotus/Weapons/Tenno/Rifle/LotusRifle": { name: "Rifle" }, "/Lotus/Weapons/Tenno/Shotgun/LotusShotgun": { name: "Shotgun" }, // Modular weapons + "/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimaryBeam": { name: "Kitgun" }, + "/Lotus/Weapons/SolarisUnited/Secondary/LotusModularSecondary": { name: "Kitgun" }, + "/Lotus/Weapons/SolarisUnited/Secondary/LotusModularSecondaryBeam": { name: "Kitgun" }, + "/Lotus/Weapons/SolarisUnited/Secondary/LotusModularSecondaryShotgun": { name: "Kitgun" }, "/Lotus/Weapons/Ostron/Melee/LotusModularWeapon": { name: "Zaw" }, // Missing in data sources "/Lotus/Upgrades/CosmeticEnhancers/Peculiars/CyoteMod": { name: "Traumatic Peculiar" } @@ -524,7 +528,7 @@ function doAcquireMiscItems() { MiscItems: [ { ItemType: uniqueName, - ItemCount: $("#miscitem-count").val() + ItemCount: parseInt($("#miscitem-count").val()) } ] })