use addStanding in more places
All checks were successful
Build / build (pull_request) Successful in 1m24s
All checks were successful
Build / build (pull_request) Successful in 1m24s
This commit is contained in:
parent
ef5c31993f
commit
8191d51847
@ -1,10 +1,9 @@
|
||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||
import { getMaxStanding } from "@/src/helpers/syndicateStandingHelper";
|
||||
import { addMiscItems, getInventory, getStandingLimit, updateStandingLimit } from "@/src/services/inventoryService";
|
||||
import { addMiscItems, addStanding, getInventory } from "@/src/services/inventoryService";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { RequestHandler } from "express";
|
||||
import { ExportResources, ExportSyndicates } from "warframe-public-export-plus";
|
||||
import { ExportResources } from "warframe-public-export-plus";
|
||||
|
||||
export const fishmongerController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
@ -31,25 +30,7 @@ export const fishmongerController: RequestHandler = async (req, res) => {
|
||||
miscItemChanges.push({ ItemType: fish.ItemType, ItemCount: fish.ItemCount * -1 });
|
||||
}
|
||||
addMiscItems(inventory, miscItemChanges);
|
||||
if (gainedStanding && syndicateTag) {
|
||||
let syndicate = inventory.Affiliations.find(x => x.Tag == syndicateTag);
|
||||
if (!syndicate) {
|
||||
syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: syndicateTag, Standing: 0 }) - 1];
|
||||
}
|
||||
const syndicateMeta = ExportSyndicates[syndicateTag];
|
||||
|
||||
const max = getMaxStanding(syndicateMeta, syndicate.Title ?? 0);
|
||||
if (syndicate.Standing + gainedStanding > max) {
|
||||
gainedStanding = max - syndicate.Standing;
|
||||
}
|
||||
if (gainedStanding > getStandingLimit(inventory, syndicateMeta.dailyLimitBin)) {
|
||||
gainedStanding = getStandingLimit(inventory, syndicateMeta.dailyLimitBin);
|
||||
}
|
||||
|
||||
syndicate.Standing += gainedStanding;
|
||||
|
||||
updateStandingLimit(inventory, syndicateMeta.dailyLimitBin, gainedStanding);
|
||||
}
|
||||
if (gainedStanding && syndicateTag) addStanding(inventory, syndicateTag, gainedStanding);
|
||||
await inventory.save();
|
||||
res.json({
|
||||
InventoryChanges: {
|
||||
|
@ -1,16 +1,9 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import {
|
||||
addMiscItems,
|
||||
freeUpSlot,
|
||||
getInventory,
|
||||
getStandingLimit,
|
||||
updateStandingLimit
|
||||
} from "@/src/services/inventoryService";
|
||||
import { addMiscItems, addStanding, freeUpSlot, getInventory } from "@/src/services/inventoryService";
|
||||
import { IMiscItem, InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { IOid } from "@/src/types/commonTypes";
|
||||
import { ExportSyndicates, ExportWeapons } from "warframe-public-export-plus";
|
||||
import { getMaxStanding } from "@/src/helpers/syndicateStandingHelper";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
||||
import { EquipmentFeatures } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
@ -61,38 +54,13 @@ export const syndicateStandingBonusController: RequestHandler = async (req, res)
|
||||
inventoryChanges[slotBin] = { count: -1, platinum: 0, Slots: 1 };
|
||||
}
|
||||
|
||||
let syndicate = inventory.Affiliations.find(x => x.Tag == request.Operation.AffiliationTag);
|
||||
if (!syndicate) {
|
||||
syndicate =
|
||||
inventory.Affiliations[
|
||||
inventory.Affiliations.push({ Tag: request.Operation.AffiliationTag, Standing: 0 }) - 1
|
||||
];
|
||||
}
|
||||
|
||||
const max = getMaxStanding(syndicateMeta, syndicate.Title ?? 0);
|
||||
if (syndicate.Standing + gainedStanding > max) {
|
||||
gainedStanding = max - syndicate.Standing;
|
||||
}
|
||||
|
||||
if (syndicateMeta.medallionsCappedByDailyLimit) {
|
||||
if (gainedStanding > getStandingLimit(inventory, syndicateMeta.dailyLimitBin)) {
|
||||
gainedStanding = getStandingLimit(inventory, syndicateMeta.dailyLimitBin);
|
||||
}
|
||||
updateStandingLimit(inventory, syndicateMeta.dailyLimitBin, gainedStanding);
|
||||
}
|
||||
|
||||
syndicate.Standing += gainedStanding;
|
||||
const affiliationMod = addStanding(inventory, request.Operation.AffiliationTag, gainedStanding, true);
|
||||
|
||||
await inventory.save();
|
||||
|
||||
res.json({
|
||||
InventoryChanges: inventoryChanges,
|
||||
AffiliationMods: [
|
||||
{
|
||||
Tag: request.Operation.AffiliationTag,
|
||||
Standing: gainedStanding
|
||||
}
|
||||
]
|
||||
AffiliationMods: [affiliationMod]
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -931,18 +931,14 @@ const standingLimitBinToInventoryKey: Record<
|
||||
|
||||
export const allDailyAffiliationKeys: (keyof IDailyAffiliations)[] = Object.values(standingLimitBinToInventoryKey);
|
||||
|
||||
export const getStandingLimit = (inventory: IDailyAffiliations, bin: TStandingLimitBin): number => {
|
||||
const getStandingLimit = (inventory: IDailyAffiliations, bin: TStandingLimitBin): number => {
|
||||
if (bin == "STANDING_LIMIT_BIN_NONE" || config.noDailyStandingLimits) {
|
||||
return Number.MAX_SAFE_INTEGER;
|
||||
}
|
||||
return inventory[standingLimitBinToInventoryKey[bin]];
|
||||
};
|
||||
|
||||
export const updateStandingLimit = (
|
||||
inventory: IDailyAffiliations,
|
||||
bin: TStandingLimitBin,
|
||||
subtrahend: number
|
||||
): void => {
|
||||
const updateStandingLimit = (inventory: IDailyAffiliations, bin: TStandingLimitBin, subtrahend: number): void => {
|
||||
if (bin != "STANDING_LIMIT_BIN_NONE" && !config.noDailyStandingLimits) {
|
||||
inventory[standingLimitBinToInventoryKey[bin]] -= subtrahend;
|
||||
}
|
||||
@ -951,7 +947,8 @@ export const updateStandingLimit = (
|
||||
export const addStanding = (
|
||||
inventory: TInventoryDatabaseDocument,
|
||||
syndicateTag: string,
|
||||
gainedStanding: number
|
||||
gainedStanding: number,
|
||||
isMedallion: boolean = false
|
||||
): IAffiliationMods => {
|
||||
let syndicate = inventory.Affiliations.find(x => x.Tag == syndicateTag);
|
||||
const syndicateMeta = ExportSyndicates[syndicateTag];
|
||||
@ -964,10 +961,12 @@ export const addStanding = (
|
||||
const max = getMaxStanding(syndicateMeta, syndicate.Title ?? 0);
|
||||
if (syndicate.Standing + gainedStanding > max) gainedStanding = max - syndicate.Standing;
|
||||
|
||||
if (gainedStanding > getStandingLimit(inventory, syndicateMeta.dailyLimitBin)) {
|
||||
gainedStanding = getStandingLimit(inventory, syndicateMeta.dailyLimitBin);
|
||||
if (!isMedallion || (isMedallion && syndicateMeta.medallionsCappedByDailyLimit)) {
|
||||
if (gainedStanding > getStandingLimit(inventory, syndicateMeta.dailyLimitBin)) {
|
||||
gainedStanding = getStandingLimit(inventory, syndicateMeta.dailyLimitBin);
|
||||
}
|
||||
updateStandingLimit(inventory, syndicateMeta.dailyLimitBin, gainedStanding);
|
||||
}
|
||||
updateStandingLimit(inventory, syndicateMeta.dailyLimitBin, gainedStanding);
|
||||
|
||||
syndicate.Standing += gainedStanding;
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user