Added score estimation, cosmetic upgrades, fixed addNewPortals

This commit is contained in:
Martin Vylet
2023-05-23 15:09:36 +02:00
parent 8635194217
commit 3bc414e084

View File

@@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name IITC plugin: ResTools BB Watch Reloaded // @name IITC plugin: ResTools BB Watch Reloaded
// @namespace https://github.com/restools/BBWatchReloaded // @namespace https://github.com/restools/BBWatchReloaded
// @version 0.2 // @version 0.3
// @description Scan window for BBs on ornamented portals, then check results // @description Scan window for BBs on ornamented portals, then check results
// @author vikend // @author vikend
// @icon // @icon
@@ -146,7 +146,7 @@ function wrapper(plugin_info)
let waveNo = wave[0] -1; let waveNo = wave[0] -1;
if (waveNo < 0) { if (waveNo < 0) {
console.log("According to timetable anomaly haven't started yet, skipping"); console.log("BBWatchReloaded: According to timetable anomaly haven't started yet, skipping");
return; return;
} }
let portalsToBeAdded = []; let portalsToBeAdded = [];
@@ -169,6 +169,10 @@ function wrapper(plugin_info)
if(portal.IsWinnerRes || portal.IsWinnerEnl) { if(portal.IsWinnerRes || portal.IsWinnerEnl) {
//check if portal wasnt already added //check if portal wasnt already added
if (!(window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[waveNo][waveBattleOver].find((obj) => obj.Guid === portal.Guid))) { if (!(window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[waveNo][waveBattleOver].find((obj) => obj.Guid === portal.Guid))) {
//check if portal isnt already in portalsToBeAdded
//check if portal was added as ornamented before //check if portal was added as ornamented before
if ((window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[waveNo][0].find((obj) => obj.Guid === portal.Guid))) { if ((window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[waveNo][0].find((obj) => obj.Guid === portal.Guid))) {
portalsToBeAdded.push(portal); portalsToBeAdded.push(portal);
@@ -186,19 +190,34 @@ function wrapper(plugin_info)
let ornamented = window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[wave][0]; let ornamented = window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[wave][0];
let results = window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[wave][1]; let results = window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[wave][1];
let resWin = 0; let resWin = 0;
let resVolatiles = 0;
let enlWin = 0; let enlWin = 0;
let enlVolatiles = 0;
for (let i in results) { for (let i in results) {
let portal = results[i]; let portal = results[i];
if (ornamented.find((obj) => obj.Guid === portal.Guid)) { if (ornamented.find((obj) => obj.Guid === portal.Guid)) {
if (portal.IsWinnerRes) { if (portal.IsWinnerRes) {
resWin++; resWin++;
if (portal.IsVolatile) {
resVolatiles++;
}
} }
else if (portal.IsWinnerEnl) { else if (portal.IsWinnerEnl) {
enlWin++; enlWin++;
if (portal.IsVolatile) {
enlVolatiles++;
} }
} }
} }
return [resWin, enlWin]; }
let objResults = {
resWin: resWin,
enlWin: enlWin,
resVolatiles: resVolatiles,
enlVolatiles: enlVolatiles
}
return objResults;
} }
@@ -209,11 +228,14 @@ function wrapper(plugin_info)
let results = window.plugin.restoolsBBWatchReloaded.computeBeacons(i); let results = window.plugin.restoolsBBWatchReloaded.computeBeacons(i);
let wave = { let wave = {
WaveNumber: Number(i) +1, WaveNumber: Number(i) +1,
volatilesCount: 0,
beaconCount: window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length, beaconCount: window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length,
PercentageRes: window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length/results[0], PercentageRes: window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length/results.resWin,
PercentageEnl: window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length/results[1], PercentageEnl: window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS[i][0].length/results.enlWin,
BeaconsWonRes: results[0], BeaconsWonRes: results.resWin,
BeaconsWonEnl: results[1] BeaconsWonResVolatiles: results.resVolatiles,
BeaconsWonEnl: results.enlWin,
BeaconsWonEnlVolatiles: results.enlVolatiles
}; };
waves.push(wave); waves.push(wave);
} }
@@ -242,45 +264,58 @@ function wrapper(plugin_info)
// --- DIALOG // --- DIALOG
window.plugin.restoolsBBWatchReloaded.showDialog = function(waves) window.plugin.restoolsBBWatchReloaded.showDialog = function(waves)
{ {
let maxBeaconsWonRes = -Infinity; // Initialize with a very small value
let maxBeaconsWonEnl = -Infinity;
let htmlBegin = ` let htmlBegin = `
<div class="restoolsBBWatchReloadedDialog"> <div class="restoolsBBWatchReloadedDialog">
<table class="styled-table"> <table class="styled-table">
<thead> <thead>
<tr> <tr>
<th>Wave</th> <th>Wave</th>
<th>&#35; of BBs</th> <th>&#35; of BBs (volatiles)</th>
<th>&percnt; points RES</th> <th>&percnt; points RES</th>
<th>&percnt; points ENL</th> <th>&percnt; points ENL</th>
<th>&#35; winner RES</th> <th>&#35; winner RES (volatiles)</th>
<th>&#35; winner ENL</th> <th>&#35; winner ENL (volatiles)</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
`; `;
let htmlEnd = `
</tbody>
</table>
<a onclick="window.plugin.restoolsBBWatchReloaded.resetStorage()" title="Reset local storage (deletes data saved in your browser, do this prior to anomaly)">Reset local storage</a>
</div>
`;
let htmlBody = ``; let htmlBody = ``;
for (let waveIndex in waves) for (let waveIndex in waves)
{ {
let wave = waves[waveIndex]; let wave = waves[waveIndex];
if (wave.BeaconsWonRes > maxBeaconsWonRes) {
maxBeaconsWonRes = wave.BeaconsWonRes;
}
if (wave.BeaconsWonEnl > maxBeaconsWonEnl) {
maxBeaconsWonEnl = wave.BeaconsWonEnl;
}
htmlBody += ` htmlBody += `
<tr> <tr>
<td>`+ wave.WaveNumber +`</td> <td>`+ wave.WaveNumber +`</td>
<td>`+ wave.beaconCount +`</td> <td>`+ wave.beaconCount + " (" + wave.volatilesCount + ")" + `</td>
<td>`+ wave.PercentageRes +`</td> <td>`+ wave.PercentageRes +`</td>
<td>`+ wave.PercentageEnl +`</td> <td>`+ wave.PercentageEnl +`</td>
<td>`+ wave.BeaconsWonRes +`</td> <td>`+ wave.BeaconsWonRes + " (" + wave.BeaconsWonResVolatiles + ")" + `</td>
<td>`+ wave.BeaconsWonEnl +`</td> <td>`+ wave.BeaconsWonEnl + " (" + wave.BeaconsWonEnlVolatiles + ")" + `</td>
</tr> </tr>
`; `;
} }
let bestScore = `<p style="font-weight: bold;">BB SCORING ESTIMATE: RES ` + maxBeaconsWonRes/(maxBeaconsWonRes+maxBeaconsWonEnl) + `:` + maxBeaconsWonEnl/(maxBeaconsWonRes+maxBeaconsWonEnl)+ ` ENL</p>`;
let htmlEnd = `
</tbody>
</table>` + bestScore + `
<a onclick="window.plugin.restoolsBBWatchReloaded.resetStorage()" title="Reset local storage (deletes data saved in your browser, do this prior to anomaly)">Reset local storage</a>
<a style="float: right;" onclick="window.plugin.restoolsBBWatchReloaded.getCurrentState()" title="Refresh this dialog window">Refresh this window</a>
</div>
`;
let html = htmlBegin + htmlBody + htmlEnd; let html = htmlBegin + htmlBody + htmlEnd;
dialog({ dialog({
@@ -302,7 +337,6 @@ function wrapper(plugin_info)
setTimeout(window.plugin.restoolsBBWatchReloaded.updateCurrentState, 10 * 1000); setTimeout(window.plugin.restoolsBBWatchReloaded.updateCurrentState, 10 * 1000);
window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS = window.plugin.restoolsBBWatchReloaded.loadStorage(); window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS = window.plugin.restoolsBBWatchReloaded.loadStorage();
console.log("BBWatchReloaded: Loaded previous state"); console.log("BBWatchReloaded: Loaded previous state");
//console.log(window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS);
// Toolbox // Toolbox