2024-12-22 20:37:02 +01:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2025-04-12 06:13:44 -07:00
|
|
|
import { addMiscItems, addStanding, freeUpSlot, getInventory } from "@/src/services/inventoryService";
|
2025-03-13 05:25:46 -07:00
|
|
|
import { IMiscItem, InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
|
2024-12-22 20:37:02 +01:00
|
|
|
import { IOid } from "@/src/types/commonTypes";
|
2025-03-13 05:25:46 -07:00
|
|
|
import { ExportSyndicates, ExportWeapons } from "warframe-public-export-plus";
|
|
|
|
import { logger } from "@/src/utils/logger";
|
|
|
|
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
|
|
|
import { EquipmentFeatures } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
2024-12-22 20:37:02 +01:00
|
|
|
|
|
|
|
export const syndicateStandingBonusController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
const request = JSON.parse(String(req.body)) as ISyndicateStandingBonusRequest;
|
|
|
|
|
2025-01-17 05:27:12 +01:00
|
|
|
const syndicateMeta = ExportSyndicates[request.Operation.AffiliationTag];
|
|
|
|
|
2025-03-13 05:25:46 -07:00
|
|
|
// Process items
|
2024-12-22 20:37:02 +01:00
|
|
|
let gainedStanding = 0;
|
|
|
|
request.Operation.Items.forEach(item => {
|
2025-01-17 05:27:12 +01:00
|
|
|
const medallion = (syndicateMeta.medallions ?? []).find(medallion => medallion.itemType == item.ItemType);
|
2024-12-22 20:37:02 +01:00
|
|
|
if (medallion) {
|
|
|
|
gainedStanding += medallion.standing * item.ItemCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
item.ItemCount *= -1;
|
|
|
|
});
|
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
addMiscItems(inventory, request.Operation.Items);
|
2025-03-13 05:25:46 -07:00
|
|
|
const inventoryChanges: IInventoryChanges = {};
|
|
|
|
inventoryChanges.MiscItems = request.Operation.Items;
|
|
|
|
|
|
|
|
// Process modular weapon
|
|
|
|
if (request.Operation.ModularWeaponId.$oid != "000000000000000000000000") {
|
|
|
|
const category = req.query.Category as "LongGuns" | "Pistols" | "Melee" | "OperatorAmps";
|
|
|
|
const weapon = inventory[category].id(request.Operation.ModularWeaponId.$oid)!;
|
|
|
|
if (gainedStanding !== 0) {
|
|
|
|
throw new Error(`modular weapon standing bonus should be mutually exclusive`);
|
|
|
|
}
|
|
|
|
weapon.ModularParts!.forEach(part => {
|
|
|
|
const partStandingBonus = ExportWeapons[part].donationStandingBonus;
|
|
|
|
if (partStandingBonus === undefined) {
|
|
|
|
throw new Error(`no standing bonus for ${part}`);
|
|
|
|
}
|
|
|
|
logger.debug(`modular weapon part ${part} gives ${partStandingBonus} standing`);
|
|
|
|
gainedStanding += partStandingBonus;
|
|
|
|
});
|
|
|
|
if (weapon.Features && (weapon.Features & EquipmentFeatures.GILDED) != 0) {
|
|
|
|
gainedStanding *= 2;
|
|
|
|
}
|
|
|
|
inventoryChanges.RemovedIdItems = [{ ItemId: request.Operation.ModularWeaponId }];
|
|
|
|
inventory[category].pull({ _id: request.Operation.ModularWeaponId.$oid });
|
|
|
|
const slotBin = category == "OperatorAmps" ? InventorySlot.AMPS : InventorySlot.WEAPONS;
|
|
|
|
freeUpSlot(inventory, slotBin);
|
|
|
|
inventoryChanges[slotBin] = { count: -1, platinum: 0, Slots: 1 };
|
|
|
|
}
|
2024-12-22 20:37:02 +01:00
|
|
|
|
2025-04-12 06:13:44 -07:00
|
|
|
const affiliationMod = addStanding(inventory, request.Operation.AffiliationTag, gainedStanding, true);
|
2025-01-13 17:57:59 +01:00
|
|
|
|
2024-12-22 20:37:02 +01:00
|
|
|
await inventory.save();
|
|
|
|
|
|
|
|
res.json({
|
2025-03-13 05:25:46 -07:00
|
|
|
InventoryChanges: inventoryChanges,
|
2025-04-12 06:13:44 -07:00
|
|
|
AffiliationMods: [affiliationMod]
|
2024-12-22 20:37:02 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
interface ISyndicateStandingBonusRequest {
|
|
|
|
Operation: {
|
|
|
|
AffiliationTag: string;
|
|
|
|
AlternateBonusReward: ""; // ???
|
|
|
|
Items: IMiscItem[];
|
2025-03-13 05:25:46 -07:00
|
|
|
ModularWeaponId: IOid;
|
2024-12-22 20:37:02 +01:00
|
|
|
};
|
|
|
|
}
|