implement auto wish
This commit is contained in:
parent
1da4f5ae36
commit
011d7b3fb1
1 changed files with 66 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name onlinetichu.com card counter
|
// @name onlinetichu.com card counter
|
||||||
// @version 1.1.1
|
// @version 1.2
|
||||||
// @description automatically count cards at onlinetichu.com
|
// @description automatically count cards at onlinetichu.com
|
||||||
// @match *://*.onlinetichu.com/Site/Game/Table/*
|
// @match *://*.onlinetichu.com/Site/Game/Table/*
|
||||||
// @author Maximilian Keßler
|
// @author Maximilian Keßler
|
||||||
|
@ -107,6 +107,12 @@ function injectCounter() {
|
||||||
davidProtectionButton.type = "button";
|
davidProtectionButton.type = "button";
|
||||||
davidProtectionButton.innerHTML = 'David protection: <span id="davidProtectionValue" data-on="On" data-off="Off">Off</span>';
|
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');
|
var showRemainingButton = document.createElement('button');
|
||||||
showRemainingButton.className = "btn btn-info btn-xs";
|
showRemainingButton.className = "btn btn-info btn-xs";
|
||||||
showRemainingButton.id = "showRemaining";
|
showRemainingButton.id = "showRemaining";
|
||||||
|
@ -122,6 +128,7 @@ function injectCounter() {
|
||||||
controlButtonsRight.appendChild(showRemainingButton);
|
controlButtonsRight.appendChild(showRemainingButton);
|
||||||
controlButtonsRight.appendChild(showCountedCardsButton);
|
controlButtonsRight.appendChild(showCountedCardsButton);
|
||||||
controlButtonsLeft.appendChild(davidProtectionButton);
|
controlButtonsLeft.appendChild(davidProtectionButton);
|
||||||
|
controlButtonsLeft.appendChild(autoWishButton);
|
||||||
|
|
||||||
controlBar.appendChild(controlButtonsLeft);
|
controlBar.appendChild(controlButtonsLeft);
|
||||||
controlBar.appendChild(controlButtonsRight);
|
controlBar.appendChild(controlButtonsRight);
|
||||||
|
@ -207,23 +214,33 @@ function injectCounter() {
|
||||||
$showCountedCards: $('#showCountedCards'),
|
$showCountedCards: $('#showCountedCards'),
|
||||||
$showCountedCardsValue: $('#showCountedCardsValue'),
|
$showCountedCardsValue: $('#showCountedCardsValue'),
|
||||||
$davidProtection: $('#davidProtection'),
|
$davidProtection: $('#davidProtection'),
|
||||||
|
$autoWishValue: $('#autoWishValue'),
|
||||||
|
$autoWish: $('#autoWish'),
|
||||||
$davidProtectionValue: $('#davidProtectionValue'),
|
$davidProtectionValue: $('#davidProtectionValue'),
|
||||||
$playedHigh: $('#playedHigh'),
|
$playedHigh: $('#playedHigh'),
|
||||||
$playedLow: $('#playedLow'),
|
$playedLow: $('#playedLow'),
|
||||||
$counterField: $('#counterField'),
|
$counterField: $('#counterField'),
|
||||||
|
|
||||||
|
// dynamic game state
|
||||||
allCards: {},
|
allCards: {},
|
||||||
playedCards: {},
|
playedCards: {},
|
||||||
totalPlayed: [],
|
totalPlayed: [],
|
||||||
exchangedTo: {},
|
exchangedTo: {},
|
||||||
exchangedFrom: {},
|
exchangedFrom: {},
|
||||||
|
handCardShuffle: [],
|
||||||
|
|
||||||
|
// config values, triggered with buttons
|
||||||
smartFold: true,
|
smartFold: true,
|
||||||
showCardCounter: false,
|
showCardCounter: false,
|
||||||
showRemaining: true,
|
showRemaining: true,
|
||||||
showCountedCards: false,
|
showCountedCards: false,
|
||||||
bombAfterFold: null,
|
|
||||||
davidProtection: false,
|
davidProtection: false,
|
||||||
|
autoWish: false,
|
||||||
|
shuffleCards: true,
|
||||||
|
|
||||||
|
// dynamic feature state
|
||||||
davidProtectionTriggered: true,
|
davidProtectionTriggered: true,
|
||||||
|
bombAfterFold: null, // to implement
|
||||||
|
|
||||||
util: {
|
util: {
|
||||||
displayCardsHtmlString: function(cards) {
|
displayCardsHtmlString: function(cards) {
|
||||||
|
@ -272,6 +289,25 @@ function injectCounter() {
|
||||||
|
|
||||||
action: {
|
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) {
|
handlePlayedCard: function(card) {
|
||||||
index = 0;
|
index = 0;
|
||||||
// special cards have Shapes 4,5,6,7. We group them at value 1
|
// 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++) {
|
for(let i = 1; i < 15; i++) {
|
||||||
otc.playedCards[i] = [];
|
otc.playedCards[i] = [];
|
||||||
}
|
}
|
||||||
|
dirs = ['east', 'north', 'west'];
|
||||||
|
for (i in dirs) {
|
||||||
|
exchangedTo[dirs[i]] = null;
|
||||||
|
exchangedFrom[dirs[i]] = null;
|
||||||
|
}
|
||||||
otc.totalPlayed = [];
|
otc.totalPlayed = [];
|
||||||
|
otc.handCardShuffle = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
drawPlayedCards: function() {
|
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.click(function () {
|
||||||
otc.showRemaining = !otc.showRemaining;
|
otc.showRemaining = !otc.showRemaining;
|
||||||
if (otc.showRemaining) {
|
if (otc.showRemaining) {
|
||||||
|
@ -393,7 +446,7 @@ function injectCounter() {
|
||||||
otc.$playedCards[i] = $('#playedCards' + i);
|
otc.$playedCards[i] = $('#playedCards' + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
otc.action.resetPlayedCards();
|
otc.action.reset();
|
||||||
otc.util.populateAllCards();
|
otc.util.populateAllCards();
|
||||||
|
|
||||||
// overwrite functionality of fold button
|
// overwrite functionality of fold button
|
||||||
|
@ -422,11 +475,11 @@ function injectCounter() {
|
||||||
message = arguments[0];
|
message = arguments[0];
|
||||||
|
|
||||||
// console.log('detected table state change event');
|
// console.log('detected table state change event');
|
||||||
// console.log(message.Table.Status);
|
console.log(message.Table.Status);
|
||||||
|
|
||||||
// reset played cards at start of round
|
// reset played cards at start of round
|
||||||
if(message.Table.Status == 'WaitForNextCards') {
|
if(message.Table.Status == 'WaitForNextCards' && otc.totalPlayed.length != 0) {
|
||||||
otc.action.resetPlayedCards();
|
otc.action.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(message.Table.Status == 'Playing') {
|
if(message.Table.Status == 'Playing') {
|
||||||
|
@ -500,6 +553,12 @@ function injectCounter() {
|
||||||
|
|
||||||
console.log(otc.exchangedTo);
|
console.log(otc.exchangedTo);
|
||||||
|
|
||||||
|
if(otc.autoWish) {
|
||||||
|
otc.action.selectAutoWish();
|
||||||
|
} else {
|
||||||
|
otc.action.deSelectAutoWish();
|
||||||
|
}
|
||||||
|
|
||||||
var result = cachedFunction.apply(this, arguments);
|
var result = cachedFunction.apply(this, arguments);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue