mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-17 21:23:54 +01:00
MISC: Add threshold for warning about system clock (#1463)
This commit is contained in:
parent
f18d28fc6e
commit
055b4bd7bc
@ -46,8 +46,13 @@ import { SnackbarEvents } from "./ui/React/Snackbar";
|
|||||||
import { SaveData } from "./types";
|
import { SaveData } from "./types";
|
||||||
import { Go } from "./Go/Go";
|
import { Go } from "./Go/Go";
|
||||||
|
|
||||||
function showWarningAboutSystemClock() {
|
// Only show warning if the time diff is greater than this value.
|
||||||
AlertEvents.emit("Warning: The system clock moved backward.");
|
const thresholdOfTimeDiffForShowingWarningAboutSystemClock = CONSTANTS.MillisecondsPerFiveMinutes;
|
||||||
|
|
||||||
|
function showWarningAboutSystemClock(timeDiff: number) {
|
||||||
|
AlertEvents.emit(
|
||||||
|
`Warning: The system clock moved backward: ${convertTimeMsToTimeElapsedString(Math.abs(timeDiff))}.`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Game engine. Handles the main game loop. */
|
/** Game engine. Handles the main game loop. */
|
||||||
@ -253,11 +258,14 @@ const Engine: {
|
|||||||
const lastUpdate = Player.lastUpdate;
|
const lastUpdate = Player.lastUpdate;
|
||||||
let timeOffline = Engine._lastUpdate - lastUpdate;
|
let timeOffline = Engine._lastUpdate - lastUpdate;
|
||||||
if (timeOffline < 0) {
|
if (timeOffline < 0) {
|
||||||
timeOffline = 0;
|
if (Math.abs(timeOffline) > thresholdOfTimeDiffForShowingWarningAboutSystemClock) {
|
||||||
|
const timeDiff = timeOffline;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
showWarningAboutSystemClock();
|
showWarningAboutSystemClock(timeDiff);
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
|
timeOffline = 0;
|
||||||
|
}
|
||||||
const numCyclesOffline = Math.floor(timeOffline / CONSTANTS.MilliPerCycle);
|
const numCyclesOffline = Math.floor(timeOffline / CONSTANTS.MilliPerCycle);
|
||||||
|
|
||||||
// Calculate the number of chances for a contract the player had whilst offline
|
// Calculate the number of chances for a contract the player had whilst offline
|
||||||
@ -404,10 +412,12 @@ const Engine: {
|
|||||||
const _thisUpdate = new Date().getTime();
|
const _thisUpdate = new Date().getTime();
|
||||||
let diff = _thisUpdate - Engine._lastUpdate;
|
let diff = _thisUpdate - Engine._lastUpdate;
|
||||||
if (diff < 0) {
|
if (diff < 0) {
|
||||||
|
if (Math.abs(diff) > thresholdOfTimeDiffForShowingWarningAboutSystemClock) {
|
||||||
|
showWarningAboutSystemClock(diff);
|
||||||
|
}
|
||||||
diff = 0;
|
diff = 0;
|
||||||
Engine._lastUpdate = _thisUpdate;
|
Engine._lastUpdate = _thisUpdate;
|
||||||
Player.lastUpdate = _thisUpdate;
|
Player.lastUpdate = _thisUpdate;
|
||||||
showWarningAboutSystemClock();
|
|
||||||
}
|
}
|
||||||
const offset = diff % CONSTANTS.MilliPerCycle;
|
const offset = diff % CONSTANTS.MilliPerCycle;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user