feat: gilded weapons (#410)
Co-authored-by: AMelonInsideLemon <AMelonInsideLemon@users.noreply.github.com>
This commit is contained in:
parent
34c0011abf
commit
94f6d1b941
66
src/controllers/api/gildWeaponController.ts
Normal file
66
src/controllers/api/gildWeaponController.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
import { WeaponTypeInternal } from "@/src/services/itemDataService";
|
||||
import { ArtifactPolarity, EquipmentFeatures } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
|
||||
const modularWeaponCategory: (WeaponTypeInternal | "Hoverboards")[] = [
|
||||
"LongGuns",
|
||||
"Pistols",
|
||||
"Melee",
|
||||
"OperatorAmps",
|
||||
"Hoverboards" // Not sure about hoverboards just coppied from modual crafting
|
||||
];
|
||||
|
||||
interface IGildWeaponRequest {
|
||||
ItemName: string;
|
||||
Recipe: string; // /Lotus/Weapons/SolarisUnited/LotusGildKitgunBlueprint
|
||||
PolarizeSlot?: number;
|
||||
PolarizeValue?: ArtifactPolarity;
|
||||
ItemId: string;
|
||||
Category: WeaponTypeInternal | "Hoverboards";
|
||||
}
|
||||
|
||||
// In export there no recipes for gild action, so reputation and ressources only consumed visually
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
export const gildWeaponController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const data: IGildWeaponRequest = getJSONfromString(String(req.body));
|
||||
data.ItemId = String(req.query.ItemId);
|
||||
if (!modularWeaponCategory.includes(req.query.Category as WeaponTypeInternal | "Hoverboards")) {
|
||||
throw new Error(`Unknown modular weapon Category: ${req.query.Category}`);
|
||||
}
|
||||
data.Category = req.query.Category as WeaponTypeInternal | "Hoverboards";
|
||||
|
||||
const inventory = await getInventory(accountId);
|
||||
if (!inventory[data.Category]) {
|
||||
throw new Error(`Category ${req.query.Category} not found in inventory`);
|
||||
}
|
||||
const weaponIndex = inventory[data.Category].findIndex(x => String(x._id) === data.ItemId);
|
||||
if (weaponIndex === -1) {
|
||||
throw new Error(`Weapon with ${data.ItemId} not found in category ${req.query.Category}`);
|
||||
}
|
||||
|
||||
const weapon = inventory[data.Category][weaponIndex];
|
||||
weapon.Features = EquipmentFeatures.GILDED; // maybe 9 idk if DOUBLE_CAPACITY is also given
|
||||
weapon.ItemName = data.ItemName;
|
||||
weapon.XP = 0;
|
||||
if (data.Category != "OperatorAmps" && data.PolarizeSlot && data.PolarizeValue) {
|
||||
weapon.Polarity = [
|
||||
{
|
||||
Slot: data.PolarizeSlot,
|
||||
Value: data.PolarizeValue
|
||||
}
|
||||
];
|
||||
}
|
||||
inventory[data.Category][weaponIndex] = weapon;
|
||||
await inventory.save();
|
||||
|
||||
res.json({
|
||||
InventoryChanges: {
|
||||
[data.Category]: [weapon]
|
||||
}
|
||||
});
|
||||
};
|
@ -61,6 +61,7 @@ import { updateChallengeProgressController } from "@/src/controllers/api/updateC
|
||||
import { updateSessionGetController, updateSessionPostController } from "@/src/controllers/api/updateSessionController";
|
||||
import { updateThemeController } from "../controllers/api/updateThemeController";
|
||||
import { upgradesController } from "@/src/controllers/api/upgradesController";
|
||||
import { gildWeaponController } from "../controllers/api/gildWeaponController";
|
||||
|
||||
const apiRouter = express.Router();
|
||||
|
||||
@ -106,6 +107,7 @@ apiRouter.post("/findSessions.php", findSessionsController);
|
||||
apiRouter.post("/focus.php", focusController);
|
||||
apiRouter.post("/genericUpdate.php", genericUpdateController);
|
||||
apiRouter.post("/getAlliance.php", getAllianceController);
|
||||
apiRouter.post("/gildWeapon.php", gildWeaponController);
|
||||
apiRouter.post("/guildTech.php", guildTechController);
|
||||
apiRouter.post("/hostSession.php", hostSessionController);
|
||||
apiRouter.post("/infestedFoundry.php", infestedFoundryController);
|
||||
|
@ -86,6 +86,7 @@ export enum EquipmentFeatures {
|
||||
DOUBLE_CAPACITY = 1,
|
||||
UTILITY_SLOT = 2,
|
||||
GRAVIMAG_INSTALLED = 4,
|
||||
GILDED = 8,
|
||||
ARCANE_SLOT = 32,
|
||||
INCARNON_GENESIS = 512
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user