XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

chore: auto-detect cycle duration for auto-generated vendors (#2077)

This also fixes the "time left to trade" showing incorrectly for fishmonger "daily special" vendors Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2077 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

1ac71a9b
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

1 个文件 +24 -10
Modified src/services/serversideVendorsService.ts +24 -10
@@ -3,7 +3,7 @@ import { catBreadHash } from "@/src/helpers/stringHelpers";
3 3 import { mixSeeds, SRng } from "@/src/services/rngService";
4 4 import { IMongoDate } from "@/src/types/commonTypes";
5 5 import { IItemManifest, IVendorInfo, IVendorManifest } from "@/src/types/vendorTypes";
6 import { ExportVendors, IRange } from "warframe-public-export-plus";
6 import { ExportVendors, IRange, IVendor } from "warframe-public-export-plus";
7 7
8 8 import ArchimedeanVendorManifest from "@/static/fixed_responses/getVendorInfo/ArchimedeanVendorManifest.json";
9 9 import DeimosEntratiFragmentVendorProductsManifest from "@/static/fixed_responses/getVendorInfo/DeimosEntratiFragmentVendorProductsManifest.json";
@@ -81,12 +81,6 @@ const generatableVendors: IGeneratableVendorInfo[] = [
81 81 WeaponUpgradeValueAttenuationExponent: 2.25,
82 82 cycleOffset: 1744934400_000,
83 83 cycleDuration: 4 * unixTimesInMs.day
84 },
85 {
86 _id: { $oid: "61ba123467e5d37975aeeb03" },
87 TypeName: "/Lotus/Types/Game/VendorManifests/Hubs/GuildAdvertisementVendorManifest",
88 RandomSeedType: "VRST_FLAVOUR_TEXT",
89 cycleDuration: unixTimesInMs.week // TODO: Auto-detect this based on the items, so we don't need to specify it explicitly.
90 84 }
91 85 // {
92 86 // _id: { $oid: "5dbb4c41e966f7886c3ce939" },
@@ -98,6 +92,25 @@ const getVendorOid = (typeName: string): string => {
98 92 return "5be4a159b144f3cd" + catBreadHash(typeName).toString(16).padStart(8, "0");
99 93 };
100 94
95 // https://stackoverflow.com/a/17445304
96 const gcd = (a: number, b: number): number => {
97 return b ? gcd(b, a % b) : a;
98 };
99
100 const getCycleDuration = (manifest: IVendor): number => {
101 let dur = 0;
102 for (const item of manifest.items) {
103 if (typeof item.durationHours != "number") {
104 dur = 1;
105 break;
106 }
107 if (dur != item.durationHours) {
108 dur = gcd(dur, item.durationHours);
109 }
110 }
111 return dur * unixTimesInMs.hour;
112 };
113
101 114 export const getVendorManifestByTypeName = (typeName: string): IVendorManifest | undefined => {
102 115 for (const vendorManifest of rawVendorManifests) {
103 116 if (vendorManifest.VendorInfo.TypeName == typeName) {
@@ -110,11 +123,12 @@ export const getVendorManifestByTypeName = (typeName: string): IVendorManifest |
110 123 }
111 124 }
112 125 if (typeName in ExportVendors) {
126 const manifest = ExportVendors[typeName];
113 127 return generateVendorManifest({
114 128 _id: { $oid: getVendorOid(typeName) },
115 129 TypeName: typeName,
116 RandomSeedType: ExportVendors[typeName].randomSeedType,
117 cycleDuration: unixTimesInMs.hour
130 RandomSeedType: manifest.randomSeedType,
131 cycleDuration: getCycleDuration(manifest)
118 132 });
119 133 }
120 134 return undefined;
@@ -138,7 +152,7 @@ export const getVendorManifestByOid = (oid: string): IVendorManifest | undefined
138 152 _id: { $oid: typeNameOid },
139 153 TypeName: typeName,
140 154 RandomSeedType: manifest.randomSeedType,
141 cycleDuration: unixTimesInMs.hour
155 cycleDuration: getCycleDuration(manifest)
142 156 });
143 157 }
144 158 }