2024-12-22 20:37:02 +01:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2025-01-17 05:27:12 +01:00
|
|
|
import { addMiscItems, getInventory, getStandingLimit, updateStandingLimit } from "@/src/services/inventoryService";
|
2024-12-22 20:37:02 +01:00
|
|
|
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
|
|
|
|
import { IOid } from "@/src/types/commonTypes";
|
2025-01-17 14:43:33 +01:00
|
|
|
import { ExportSyndicates } from "warframe-public-export-plus";
|
|
|
|
import { getMaxStanding } from "@/src/helpers/syndicateStandingHelper";
|
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];
|
|
|
|
|
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-01-13 17:57:59 +01:00
|
|
|
let syndicate = inventory.Affiliations.find(x => x.Tag == request.Operation.AffiliationTag);
|
|
|
|
if (!syndicate) {
|
|
|
|
syndicate =
|
2025-01-17 05:27:12 +01:00
|
|
|
inventory.Affiliations[
|
|
|
|
inventory.Affiliations.push({ Tag: request.Operation.AffiliationTag, Standing: 0 }) - 1
|
|
|
|
];
|
2024-12-22 20:37:02 +01:00
|
|
|
}
|
|
|
|
|
2025-01-17 05:27:12 +01:00
|
|
|
const max = getMaxStanding(syndicateMeta, syndicate.Title ?? 0);
|
2025-01-13 17:57:59 +01:00
|
|
|
if (syndicate.Standing + gainedStanding > max) {
|
|
|
|
gainedStanding = max - syndicate.Standing;
|
|
|
|
}
|
2025-01-19 12:30:27 +01:00
|
|
|
|
|
|
|
if (syndicateMeta.medallionsCappedByDailyLimit) {
|
|
|
|
if (gainedStanding > getStandingLimit(inventory, syndicateMeta.dailyLimitBin)) {
|
|
|
|
gainedStanding = getStandingLimit(inventory, syndicateMeta.dailyLimitBin);
|
|
|
|
}
|
|
|
|
updateStandingLimit(inventory, syndicateMeta.dailyLimitBin, gainedStanding);
|
2025-01-17 05:27:12 +01:00
|
|
|
}
|
2025-01-13 17:57:59 +01:00
|
|
|
|
|
|
|
syndicate.Standing += gainedStanding;
|
|
|
|
|
2024-12-22 20:37:02 +01:00
|
|
|
await inventory.save();
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
InventoryChanges: {
|
|
|
|
MiscItems: request.Operation.Items
|
|
|
|
},
|
|
|
|
AffiliationMods: [
|
|
|
|
{
|
|
|
|
Tag: request.Operation.AffiliationTag,
|
|
|
|
Standing: gainedStanding
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
interface ISyndicateStandingBonusRequest {
|
|
|
|
Operation: {
|
|
|
|
AffiliationTag: string;
|
|
|
|
AlternateBonusReward: ""; // ???
|
|
|
|
Items: IMiscItem[];
|
|
|
|
};
|
|
|
|
ModularWeaponId: IOid; // Seems to just be "000000000000000000000000", also note there's a "Category" query field
|
|
|
|
}
|