diff --git a/onlinetichu-counter.js b/onlinetichu-counter.js index da167b2..e431512 100644 --- a/onlinetichu-counter.js +++ b/onlinetichu-counter.js @@ -216,11 +216,14 @@ function injectCounter() { playerTichuCoefficient.id = direction + 'PlayerTichuCoefficient'; playerTichuCoefficient.innerText = 'test: TC'; - playerDiv.insertBefore(playerMyLevel, playerTichu); playerDiv.insertBefore(playerTichuCoefficient, playerTichu); + playerDiv.insertBefore(playerMyLevel, playerTichu); } patchPlayerStats('south'); + patchPlayerStats('north'); + patchPlayerStats('east'); + patchPlayerStats('west'); // playedCards. // ot.$gameField.insertAfter(playedCards, ot.$gameField.lastChild); @@ -243,6 +246,18 @@ function injectCounter() { $playedHigh: $('#playedHigh'), $playedLow: $('#playedLow'), $counterField: $('#counterField'), + $playerMyLevel: { + 'east': $('#eastPlayerMyLevel'), + 'north': $('#northPlayerMyLevel'), + 'west': $('#westPlayerMyLevel'), + 'south': $('#southPlayerMyLevel'), + }, + $playerTichuCoefficient: { + 'east': $('#eastPlayerTichuCoefficient'), + 'north': $('#northPlayerTichuCoefficient'), + 'west': $('#westPlayerTichuCoefficient'), + 'south': $('#southPlayerTichuCoefficient'), + }, // dynamic game state allCards: {}, @@ -251,6 +266,7 @@ function injectCounter() { exchangedTo: {}, exchangedFrom: {}, handCardShuffle: [], + playerNames: {}, // config values, triggered with buttons smartFold: true, @@ -369,7 +385,8 @@ function injectCounter() { abandonmentRate: (generalStats.abandonments / (generalStats.games + generalStats.goldGames) * 100).toFixed(1), grandTichuUnsuccesful: lostGrand, tichuUnsuccesful: lostTichu, - tichuCoefficient: ( (generalStats.grandTichuSuccessful - lostGrand) * 200 + (generalStats.tichuSuccessful - lostTichu) * 100 ) / generalStats.rounds + tichuCoefficient: (( (generalStats.grandTichuSuccessful - lostGrand) * 200 + (generalStats.tichuSuccessful - lostTichu) * 100 ) / generalStats.rounds).toFixed(1), + oneTwoCoefficient: (200 * generalStats.oneTwo / generalStats.rounds).toFixed(1) } var userStats = { @@ -378,7 +395,10 @@ function injectCounter() { } otc.stats[user] = userStats ; - console.log(otc.stats[user]); +// console.log('Fetched stats of user ' + user); + + // update stats shown at table + otc.action.updateDisplayStats(); }); } }, @@ -463,6 +483,21 @@ function injectCounter() { otc.$playedCards[i].html(otc.util.displayCardsHtmlString(otc.playedCards[i])); } } + }, + + updateDisplayStats: function() { + dirs = ['east', 'north', 'south', 'west']; + for(i in dirs) { + stats = otc.stats[otc.playerNames[dirs[i]]]; + if (stats != undefined) { + t = 'L ' + stats.general.level + ' A ' + stats.custom.abandonmentRate + '%'; + otc.$playerMyLevel[dirs[i]].text(t); + + t = 'T ' + stats.custom.tichuCoefficient + ' O ' + stats.custom.oneTwoCoefficient; + otc.$playerTichuCoefficient[dirs[i]].text(t); + } + } + console.log('updated shown stats'); } } } @@ -571,7 +606,7 @@ 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.totalPlayed.length != 0) { @@ -585,8 +620,10 @@ function injectCounter() { otc.action.drawPlayedCards(); // console.log('reached smartFold point'); + spectator = true; $(message.Table.Players).each(function () { if (this.Username == ot.$Username.val()) { + spectator = false; // console.log('found player'); if (message.Table.Turn == this.Position) { // console.log('my turn!'); @@ -602,8 +639,23 @@ function injectCounter() { } } } + + // get stats of player if we don't have them yet) + if (otc.stats[this.Username] === undefined) { + otc.util.getStats(this.Username); + } }); + // store usernames of players for display of stats + otc.playerNames['east'] = message.Table.Players[ot.eastPlayer - 1].Username; + otc.playerNames['north'] = message.Table.Players[ot.northPlayer - 1].Username; + otc.playerNames['west'] = message.Table.Players[ot.westPlayer - 1].Username; + if (spectator) { + otc.playerNames['south'] = message.Table.Players[0].Username; + } else { + otc.playerNames['south'] = ot.$Username.val(); + } + return result; } @@ -676,8 +728,6 @@ function injectCounter() { ot.reaction.TableState = MyTableState; ot.reaction.Chat = MyChat; ot.action.ExchangeCards = MyExchangeCards; - - otc.util.getStats('Ramanujan1729'); };