implement auto wish

This commit is contained in:
Maximilian Keßler 2022-09-18 10:16:32 +02:00
parent 1da4f5ae36
commit 011d7b3fb1
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -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: <span id="davidProtectionValue" data-on="On" data-off="Off">Off</span>';
var autoWishButton = document.createElement('button');
autoWishButton.className = "btn btn-info btn-xs";
autoWishButton.id = "autoWish";
autoWishButton.type = "button";
autoWishButton.innerHTML = 'Auto Wish: <span id="autoWishValue" data-on="On" data-off="Off">Off</span>';
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;
}