返回提交历史
Modified
src/controllers/api/syndicateStandingBonusController.ts
+15
-2
Modified
src/services/inventoryService.ts
+14
-13
Modified
src/services/missionInventoryUpdateService.ts
+2
-2
XFEstudio/XFESpaceNinjaServer
chore: add eStandingSource to fine-tune addStanding's behaviour (#4282)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4282 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
4d700bb3
代码差异
3 个文件
+31
-17
@@ -1,6 +1,12 @@
1
1
import type { RequestHandler } from "express";
2
2
import { getAccountForRequest, getBuildLabel } from "../../services/loginService.ts";
3
import { addMiscItems, addStanding, freeUpSlot, getInventory } from "../../services/inventoryService.ts";
3
import {
4
addMiscItems,
5
addStanding,
6
eStandingSource,
7
freeUpSlot,
8
getInventory
9
} from "../../services/inventoryService.ts";
4
10
import type { IMiscItem } from "../../types/inventoryTypes/inventoryTypes.ts";
5
11
import { eInventorySlot } from "../../types/inventoryTypes/inventoryTypes.ts";
6
12
import type { IOid } from "../../types/commonTypes.ts";
@@ -64,7 +70,14 @@ export const syndicateStandingBonusController: RequestHandler = async (req, res)
64
70
}
65
71
66
72
const affiliationMods: IAffiliationMods[] = [];
67
await addStanding(inventory, buildLabel, affiliationTag, gainedStanding, affiliationMods, true);
73
await addStanding(
74
inventory,
75
buildLabel,
76
affiliationTag,
77
gainedStanding,
78
affiliationMods,
79
eStandingSource.Medallion
80
);
68
81
69
82
await inventory.save();
70
83
@@ -1880,14 +1880,20 @@ const updateStandingLimit = (
1880
1880
}
1881
1881
};
1882
1882
1883
export const eStandingSource = {
1884
Medallion: 0,
1885
Mission: 1, // in mission report, the client provides both the affiliation & bin changes, so when using this source with addStanding, it does not update the daily cap.
1886
Misc: 2
1887
};
1888
type TStandingSource = (typeof eStandingSource)[keyof typeof eStandingSource];
1889
1883
1890
export const addStanding = async (
1884
1891
inventory: TInventoryDatabaseDocument,
1885
1892
buildLabel: string,
1886
1893
syndicateTag: string,
1887
1894
gainedStanding: number,
1888
1895
affiliationMods: IAffiliationMods[] = [],
1889
applyDailyCap: boolean = false,
1890
propagateAlignments: boolean = true
1896
source: TStandingSource = eStandingSource.Misc
1891
1897
): Promise<void> => {
1892
1898
let syndicate = inventory.Affiliations.find(x => x.Tag == syndicateTag);
1893
1899
const syndicateMeta = (await getSyndicate(syndicateTag, buildLabel))!;
@@ -1904,7 +1910,10 @@ export const addStanding = async (
1904
1910
gainedStanding = -71000 - syndicate.Standing;
1905
1911
}
1906
1912
1907
if (!applyDailyCap || syndicateMeta.medallionsCappedByDailyLimit) {
1913
if (
1914
source == eStandingSource.Misc ||
1915
(source == eStandingSource.Medallion && syndicateMeta.medallionsCappedByDailyLimit)
1916
) {
1908
1917
if (gainedStanding > getStandingLimit(inventory, syndicateMeta.dailyLimitBin)) {
1909
1918
gainedStanding = getStandingLimit(inventory, syndicateMeta.dailyLimitBin);
1910
1919
}
@@ -1919,17 +1928,9 @@ export const addStanding = async (
1919
1928
affiliationMods.push(affiliationMod);
1920
1929
1921
1930
if (syndicateMeta.alignments) {
1922
if (propagateAlignments) {
1931
if (source != eStandingSource.Mission) {
1923
1932
for (const [tag, factor] of Object.entries(syndicateMeta.alignments)) {
1924
await addStanding(
1925
inventory,
1926
buildLabel,
1927
tag,
1928
gainedStanding * factor,
1929
affiliationMods,
1930
applyDailyCap,
1931
false
1932
);
1933
await addStanding(inventory, buildLabel, tag, gainedStanding * factor, affiliationMods, source);
1933
1934
}
1934
1935
} else {
1935
1936
while (syndicate.Standing < getMinStanding(syndicateMeta, syndicate.Title ?? 0)) {
@@ -46,6 +46,7 @@ import {
46
46
combineInventoryChanges,
47
47
CurrencyType,
48
48
ensureUserHasSteelPathRewards,
49
eStandingSource,
49
50
getDialogue,
50
51
giveNemesisPetRecipe,
51
52
giveNemesisWeaponRecipe,
@@ -364,8 +365,7 @@ export const addMissionInventoryUpdates = async (
364
365
affiliation.Tag,
365
366
affiliation.Standing,
366
367
undefined,
367
false, // affiliation bin changes are handled by the client, no need to do it twice
368
false
368
eStandingSource.Mission
369
369
);
370
370
}
371
371
break;