diff --git a/RestoolsBBWatchReloaded.js b/RestoolsBBWatchReloaded.js index f6e125a..2bad013 100644 --- a/RestoolsBBWatchReloaded.js +++ b/RestoolsBBWatchReloaded.js @@ -1,7 +1,7 @@ // ==UserScript== // @name IITC plugin: ResTools BB Watch Reloaded // @namespace https://git.martinvylet.cz/vykend/ResTools-BB-Watch-Reloaded -// @version 0.5 +// @version 0.6 // @description Scan window for BBs on ornamented portals, then check results // @author vikend // @icon @@ -85,8 +85,8 @@ function wrapper(plugin_info) const timezoneOffsetHours = window.plugin.restoolsBBWatchReloaded.timezone; // Assuming the offset is stored in hours const offsetMilliseconds = timezoneOffsetHours * 60 * 60 * 1000; // Convert offset to milliseconds const currentTimeWithOffset = new Date(currentTime.getTime() + offsetMilliseconds); - const currentTimeString = currentTimeWithOffset.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); - const currentTimePlus5Minutes = (new Date(currentTimeWithOffset.getTime() + 5 * 60000)).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); + const currentTimeString = currentTimeWithOffset.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false }); + const currentTimePlus5Minutes = (new Date(currentTimeWithOffset.getTime() + 5 * 60000)).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false }); let currentWave = 0; let battleOver = false; @@ -154,7 +154,7 @@ function wrapper(plugin_info) console.log("BBWatchReloaded: According to timetable anomaly haven't started yet, skipping"); return; } - if (waveNo > 7) { + if (waveNo >= 7) { console.log("BBWatchReloaded: According to timetable anomaly already ended, skipping"); return; } @@ -206,15 +206,16 @@ function wrapper(plugin_info) for (let i in results) { let portal = results[i]; if (ornamented.find((obj) => obj.Guid === portal.Guid)) { + var foundObj = ornamented.find((obj) => obj.Guid === portal.Guid); if (portal.IsWinnerRes) { resWin++; - if (portal.IsVolatile) { + if (foundObj.IsVolatile) { resVolatiles++; } } else if (portal.IsWinnerEnl) { enlWin++; - if (portal.IsVolatile) { + if (foundObj.IsVolatile) { enlVolatiles++; } } @@ -235,13 +236,20 @@ function wrapper(plugin_info) { let waves = []; for (let i in window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS) { + var volatiles = 0; + + for (var j = 0; j < window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length; j++) { + if (window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0][j].IsVolatile === true) { + volatiles++; + } + } let results = window.plugin.restoolsBBWatchReloaded.computeBeacons(i); let wave = { WaveNumber: Number(i) +1, - volatilesCount: 0, + volatilesCount: volatiles, beaconCount: window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length, - PercentageRes: window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length/results.resWin, - PercentageEnl: window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length/results.enlWin, + PercentageRes: (results.resWin/window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length)*100, + PercentageEnl: (results.enlWin/window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length)*100, BeaconsWonRes: results.resWin, BeaconsWonResVolatiles: results.resVolatiles, BeaconsWonEnl: results.enlWin, @@ -260,7 +268,12 @@ function wrapper(plugin_info) window.plugin.restoolsBBWatchReloaded.loadStorage = function() { if (localStorage[window.plugin.restoolsBBWatchReloaded.BB_STORAGE] != undefined) { - return JSON.parse(localStorage[window.plugin.restoolsBBWatchReloaded.BB_STORAGE]); + if (JSON.parse(localStorage[window.plugin.restoolsBBWatchReloaded.BB_STORAGE]) != null) { + return JSON.parse(localStorage[window.plugin.restoolsBBWatchReloaded.BB_STORAGE]); + } + else { + return window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS; + } } else { return window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS; @@ -282,7 +295,7 @@ function wrapper(plugin_info) let htmlBegin = `
| `+ wave.WaveNumber +` | `+ wave.beaconCount + " (" + wave.volatilesCount + ")" + ` | -`+ wave.PercentageRes +` | -`+ wave.PercentageEnl +` | +`+ wave.PercentageRes.toFixed(2) +` | +`+ wave.PercentageEnl.toFixed(2) +` | `+ wave.BeaconsWonRes + " (" + wave.BeaconsWonResVolatiles + ")" + ` | `+ wave.BeaconsWonEnl + " (" + wave.BeaconsWonEnlVolatiles + ")" + ` |