From 011d7b3fb1d79798be724a257e90e111645de567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 18 Sep 2022 10:16:32 +0200 Subject: [PATCH] implement auto wish --- onlinetichu-counter.js | 73 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/onlinetichu-counter.js b/onlinetichu-counter.js index 5378c53..b0419f9 100644 --- a/onlinetichu-counter.js +++ b/onlinetichu-counter.js @@ -1,6 +1,6 @@ // ==UserScript== // @name onlinetichu.com card counter -// @version 1.1.1 +// @version 1.2 // @description automatically count cards at onlinetichu.com // @match *://*.onlinetichu.com/Site/Game/Table/* // @author Maximilian Keßler @@ -107,6 +107,12 @@ function injectCounter() { davidProtectionButton.type = "button"; davidProtectionButton.innerHTML = 'David protection: Off'; + var autoWishButton = document.createElement('button'); + autoWishButton.className = "btn btn-info btn-xs"; + autoWishButton.id = "autoWish"; + autoWishButton.type = "button"; + autoWishButton.innerHTML = 'Auto Wish: Off'; + var showRemainingButton = document.createElement('button'); showRemainingButton.className = "btn btn-info btn-xs"; showRemainingButton.id = "showRemaining"; @@ -122,6 +128,7 @@ function injectCounter() { controlButtonsRight.appendChild(showRemainingButton); controlButtonsRight.appendChild(showCountedCardsButton); controlButtonsLeft.appendChild(davidProtectionButton); + controlButtonsLeft.appendChild(autoWishButton); controlBar.appendChild(controlButtonsLeft); controlBar.appendChild(controlButtonsRight); @@ -207,23 +214,33 @@ function injectCounter() { $showCountedCards: $('#showCountedCards'), $showCountedCardsValue: $('#showCountedCardsValue'), $davidProtection: $('#davidProtection'), + $autoWishValue: $('#autoWishValue'), + $autoWish: $('#autoWish'), $davidProtectionValue: $('#davidProtectionValue'), $playedHigh: $('#playedHigh'), $playedLow: $('#playedLow'), $counterField: $('#counterField'), + // dynamic game state allCards: {}, playedCards: {}, totalPlayed: [], exchangedTo: {}, exchangedFrom: {}, + handCardShuffle: [], + + // config values, triggered with buttons smartFold: true, showCardCounter: false, showRemaining: true, showCountedCards: false, - bombAfterFold: null, davidProtection: false, + autoWish: false, + shuffleCards: true, + + // dynamic feature state davidProtectionTriggered: true, + bombAfterFold: null, // to implement util: { displayCardsHtmlString: function(cards) { @@ -272,6 +289,25 @@ function injectCounter() { action: { + selectAutoWish: function() { + if (otc.exchangedTo['east'] == null) { + return; + } + val = 0; + if (otc.exchangedTo['east'].Shape < 4 ) { + val = otc.exchangedTo['east'].Value; + } else if (otc.exchangedTo['east'].Shape == 5) { + val = 14; // wish for ace by default if we gave a dog to the right + } + button = document.getElementById("askCard_" + val); + button.click(); + }, + + deSelectAutoWish: function() { + button = document.getElementById("asCard_0"); + button.click(); + }, + handlePlayedCard: function(card) { index = 0; // special cards have Shapes 4,5,6,7. We group them at value 1 @@ -304,11 +340,17 @@ function injectCounter() { } }, - resetPlayedCards: function() { + reset: function() { for(let i = 1; i < 15; i++) { otc.playedCards[i] = []; } + dirs = ['east', 'north', 'west']; + for (i in dirs) { + exchangedTo[dirs[i]] = null; + exchangedFrom[dirs[i]] = null; + } otc.totalPlayed = []; + otc.handCardShuffle = []; }, drawPlayedCards: function() { @@ -379,6 +421,17 @@ function injectCounter() { } }); + otc.$autoWish.click(function () { + otc.autoWish = !otc.autoWish; + if (otc.autoWish) { + otc.$autoWishValue.text(otc.$autoWishValue.data('on')); + otc.action.selectAutoWish(); + } else { + otc.$autoWishValue.text(otc.$autoWishValue.data('off')); + otc.action.deSelectAutoWish(); + } + }); + otc.$showRemaining.click(function () { otc.showRemaining = !otc.showRemaining; if (otc.showRemaining) { @@ -393,7 +446,7 @@ function injectCounter() { otc.$playedCards[i] = $('#playedCards' + i); } - otc.action.resetPlayedCards(); + otc.action.reset(); otc.util.populateAllCards(); // overwrite functionality of fold button @@ -422,11 +475,11 @@ function injectCounter() { message = arguments[0]; // console.log('detected table state change event'); - // console.log(message.Table.Status); + console.log(message.Table.Status); // reset played cards at start of round - if(message.Table.Status == 'WaitForNextCards') { - otc.action.resetPlayedCards(); + if(message.Table.Status == 'WaitForNextCards' && otc.totalPlayed.length != 0) { + otc.action.reset(); } if(message.Table.Status == 'Playing') { @@ -500,6 +553,12 @@ function injectCounter() { console.log(otc.exchangedTo); + if(otc.autoWish) { + otc.action.selectAutoWish(); + } else { + otc.action.deSelectAutoWish(); + } + var result = cachedFunction.apply(this, arguments); return result; }