fix: remove syndicate sacrifices from inventory (#735)
This commit is contained in:
parent
3a4eea379d
commit
2c875caddc
@ -1,29 +1,21 @@
|
|||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||||
import { ExportSyndicates } from "warframe-public-export-plus";
|
import { ExportSyndicates, ISyndicateSacrifice } from "warframe-public-export-plus";
|
||||||
import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
|
import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
|
||||||
import { getInventory } from "@/src/services/inventoryService";
|
import { addMiscItems, combineInventoryChanges, getInventory, updateCurrency } from "@/src/services/inventoryService";
|
||||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
||||||
|
|
||||||
export const syndicateSacrificeController: RequestHandler = async (request, response) => {
|
export const syndicateSacrificeController: RequestHandler = async (request, response) => {
|
||||||
const accountId = await getAccountIdForRequest(request);
|
const accountId = await getAccountIdForRequest(request);
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const data = getJSONfromString(String(request.body)) as ISyndicateSacrifice;
|
const data = getJSONfromString(String(request.body)) as ISyndicateSacrificeRequest;
|
||||||
|
|
||||||
let syndicate = inventory.Affiliations.find(x => x.Tag == data.AffiliationTag);
|
let syndicate = inventory.Affiliations.find(x => x.Tag == data.AffiliationTag);
|
||||||
if (!syndicate) {
|
if (!syndicate) {
|
||||||
syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: data.AffiliationTag, Standing: 0 }) - 1];
|
syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: data.AffiliationTag, Standing: 0 }) - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
let reward: string | undefined;
|
|
||||||
|
|
||||||
const manifest = ExportSyndicates[data.AffiliationTag];
|
|
||||||
if (manifest?.initiationReward && data.SacrificeLevel == 0) {
|
|
||||||
reward = manifest.initiationReward;
|
|
||||||
syndicate.Initiated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const level = data.SacrificeLevel - (syndicate.Title ?? 0);
|
const level = data.SacrificeLevel - (syndicate.Title ?? 0);
|
||||||
const res: ISyndicateSacrificeResponse = {
|
const res: ISyndicateSacrificeResponse = {
|
||||||
AffiliationTag: data.AffiliationTag,
|
AffiliationTag: data.AffiliationTag,
|
||||||
@ -33,18 +25,43 @@ export const syndicateSacrificeController: RequestHandler = async (request, resp
|
|||||||
NewEpisodeReward: syndicate?.Tag == "RadioLegionIntermission9Syndicate"
|
NewEpisodeReward: syndicate?.Tag == "RadioLegionIntermission9Syndicate"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const manifest = ExportSyndicates[data.AffiliationTag];
|
||||||
|
let sacrifice: ISyndicateSacrifice | undefined;
|
||||||
|
let reward: string | undefined;
|
||||||
|
if (data.SacrificeLevel == 0) {
|
||||||
|
sacrifice = manifest.initiationSacrifice;
|
||||||
|
reward = manifest.initiationReward;
|
||||||
|
syndicate.Initiated = true;
|
||||||
|
} else {
|
||||||
|
sacrifice = manifest.titles?.find(x => x.level == data.SacrificeLevel)?.sacrifice;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sacrifice) {
|
||||||
|
res.InventoryChanges = { ...updateCurrency(inventory, sacrifice.credits, false) };
|
||||||
|
|
||||||
|
const miscItemChanges = sacrifice.items.map(x => ({
|
||||||
|
ItemType: x.ItemType,
|
||||||
|
ItemCount: x.ItemCount * -1
|
||||||
|
}));
|
||||||
|
addMiscItems(inventory, miscItemChanges);
|
||||||
|
res.InventoryChanges.MiscItems = miscItemChanges;
|
||||||
|
}
|
||||||
|
|
||||||
if (syndicate?.Title !== undefined) syndicate.Title += 1;
|
if (syndicate?.Title !== undefined) syndicate.Title += 1;
|
||||||
|
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
|
|
||||||
if (reward) {
|
if (reward) {
|
||||||
res.InventoryChanges = (await handleStoreItemAcquisition(reward, accountId)).InventoryChanges;
|
combineInventoryChanges(
|
||||||
|
res.InventoryChanges,
|
||||||
|
(await handleStoreItemAcquisition(reward, accountId)).InventoryChanges
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
response.json(res);
|
response.json(res);
|
||||||
};
|
};
|
||||||
|
|
||||||
interface ISyndicateSacrifice {
|
interface ISyndicateSacrificeRequest {
|
||||||
AffiliationTag: string;
|
AffiliationTag: string;
|
||||||
SacrificeLevel: number;
|
SacrificeLevel: number;
|
||||||
AllowMultiple: boolean;
|
AllowMultiple: boolean;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user