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: base all cycles on locked time if used (#2128)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2128 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

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

代码差异

1 个文件 +16 -14
Modified src/services/worldStateService.ts +16 -14
@@ -166,8 +166,8 @@ const microplanetEndlessJobs = [
166 166
167 167 const EPOCH = 1734307200 * 1000; // Monday, Dec 16, 2024 @ 00:00 UTC+0; should logically be winter in 1999 iteration 0
168 168
169 const isBeforeNextExpectedWorldStateRefresh = (date: number): boolean => {
170 return Date.now() + 300_000 > date;
169 const isBeforeNextExpectedWorldStateRefresh = (nowMs: number, thenMs: number): boolean => {
170 return nowMs + 300_000 > thenMs;
171 171 };
172 172
173 173 const getSortieTime = (day: number): number => {
@@ -939,14 +939,16 @@ const getCalendarSeason = (week: number): ICalendarSeason => {
939 939 };
940 940
941 941 export const getWorldState = (buildLabel?: string): IWorldState => {
942 const day = Math.trunc((Date.now() - EPOCH) / 86400000);
942 const timeSecs = config.worldState?.lockTime || Math.round(Date.now() / 1000);
943 const timeMs = timeSecs * 1000;
944 const day = Math.trunc((timeMs - EPOCH) / 86400000);
943 945 const week = Math.trunc(day / 7);
944 946 const weekStart = EPOCH + week * 604800000;
945 947 const weekEnd = weekStart + 604800000;
946 948
947 949 const worldState: IWorldState = {
948 950 BuildLabel: typeof buildLabel == "string" ? buildLabel.split(" ").join("+") : buildConfig.buildLabel,
949 Time: config.worldState?.lockTime || Math.round(Date.now() / 1000),
951 Time: timeSecs,
950 952 Goals: [],
951 953 Alerts: [],
952 954 Sorties: [],
@@ -1000,11 +1002,11 @@ export const getWorldState = (buildLabel?: string): IWorldState => {
1000 1002 worldState.SeasonInfo.ActiveChallenges.push(getSeasonDailyChallenge(pools, day - 2));
1001 1003 worldState.SeasonInfo.ActiveChallenges.push(getSeasonDailyChallenge(pools, day - 1));
1002 1004 worldState.SeasonInfo.ActiveChallenges.push(getSeasonDailyChallenge(pools, day - 0));
1003 if (isBeforeNextExpectedWorldStateRefresh(EPOCH + (day + 1) * 86400000)) {
1005 if (isBeforeNextExpectedWorldStateRefresh(timeMs, EPOCH + (day + 1) * 86400000)) {
1004 1006 worldState.SeasonInfo.ActiveChallenges.push(getSeasonDailyChallenge(pools, day + 1));
1005 1007 }
1006 1008 pushWeeklyActs(worldState.SeasonInfo.ActiveChallenges, pools, week);
1007 if (isBeforeNextExpectedWorldStateRefresh(weekEnd)) {
1009 if (isBeforeNextExpectedWorldStateRefresh(timeMs, weekEnd)) {
1008 1010 pushWeeklyActs(worldState.SeasonInfo.ActiveChallenges, pools, week + 1);
1009 1011 }
1010 1012 }
@@ -1013,7 +1015,7 @@ export const getWorldState = (buildLabel?: string): IWorldState => {
1013 1015 worldState.NodeOverrides.find(x => x.Node == "SolNode802")!.Seed = new SRng(week).randomInt(0, 0xff_ffff);
1014 1016
1015 1017 // Holdfast, Cavia, & Hex bounties cycling every 2.5 hours; unfaithful implementation
1016 let bountyCycle = Math.trunc(Date.now() / 9000000);
1018 let bountyCycle = Math.trunc(timeSecs / 9000);
1017 1019 let bountyCycleEnd: number | undefined;
1018 1020 do {
1019 1021 const bountyCycleStart = bountyCycle * 9000000;
@@ -1044,7 +1046,7 @@ export const getWorldState = (buildLabel?: string): IWorldState => {
1044 1046 });
1045 1047
1046 1048 pushClassicBounties(worldState.SyndicateMissions, bountyCycle);
1047 } while (isBeforeNextExpectedWorldStateRefresh(bountyCycleEnd) && ++bountyCycle);
1049 } while (isBeforeNextExpectedWorldStateRefresh(timeMs, bountyCycleEnd) && ++bountyCycle);
1048 1050
1049 1051 if (config.worldState?.creditBoost) {
1050 1052 worldState.GlobalUpgrades.push({
@@ -1087,15 +1089,15 @@ export const getWorldState = (buildLabel?: string): IWorldState => {
1087 1089 {
1088 1090 const rollover = getSortieTime(day);
1089 1091
1090 if (Date.now() < rollover) {
1092 if (timeMs < rollover) {
1091 1093 worldState.Sorties.push(getSortie(day - 1));
1092 1094 }
1093 if (isBeforeNextExpectedWorldStateRefresh(rollover)) {
1095 if (isBeforeNextExpectedWorldStateRefresh(timeMs, rollover)) {
1094 1096 worldState.Sorties.push(getSortie(day));
1095 1097 }
1096 1098
1097 1099 // The client does not seem to respect activation for classic syndicate missions, so only pushing current ones.
1098 const sdy = Date.now() >= rollover ? day : day - 1;
1100 const sdy = timeMs >= rollover ? day : day - 1;
1099 1101 const rng = new SRng(sdy);
1100 1102 pushSyndicateMissions(worldState, sdy, rng.randomInt(0, 100_000), "ba6f84724fa48049", "ArbitersSyndicate");
1101 1103 pushSyndicateMissions(worldState, sdy, rng.randomInt(0, 100_000), "ba6f84724fa4804a", "CephalonSudaSyndicate");
@@ -1107,7 +1109,7 @@ export const getWorldState = (buildLabel?: string): IWorldState => {
1107 1109
1108 1110 // Archon Hunt cycling every week
1109 1111 worldState.LiteSorties.push(getLiteSortie(week));
1110 if (isBeforeNextExpectedWorldStateRefresh(weekEnd)) {
1112 if (isBeforeNextExpectedWorldStateRefresh(timeMs, weekEnd)) {
1111 1113 worldState.LiteSorties.push(getLiteSortie(week + 1));
1112 1114 }
1113 1115
@@ -1144,12 +1146,12 @@ export const getWorldState = (buildLabel?: string): IWorldState => {
1144 1146
1145 1147 // 1999 Calendar Season cycling every week + YearIteration every 4 weeks
1146 1148 worldState.KnownCalendarSeasons.push(getCalendarSeason(week));
1147 if (isBeforeNextExpectedWorldStateRefresh(weekEnd)) {
1149 if (isBeforeNextExpectedWorldStateRefresh(timeMs, weekEnd)) {
1148 1150 worldState.KnownCalendarSeasons.push(getCalendarSeason(week + 1));
1149 1151 }
1150 1152
1151 1153 // Sentient Anomaly cycling every 30 minutes
1152 const halfHour = Math.trunc(Date.now() / (unixTimesInMs.hour / 2));
1154 const halfHour = Math.trunc(timeMs / (unixTimesInMs.hour / 2));
1153 1155 const tmp = {
1154 1156 cavabegin: "1690761600",
1155 1157 PurchasePlatformLockEnabled: true,