Bots Home
|
Create an App
Lexy Hands of Poker Beta5
Author:
richrichiedk
Description
Source Code
Launch Bot
Current Users
Created by:
Richrichiedk
/** * Bot: Lexy Hands of Poker * Version: 1.0.11 * Summary: Play a hand of poker game. Winners get a prize. * Author: richrichiedk * Date: 2019-04-19 * Description: Its a game of chance, tip for play poker against model, if user hand is higher rank than model then he wins a prize according to he's hand rank. * This bot has 2 game modes: User plays against Model (50% chance win/lose) or simple random hand prize (but no prize for high card). */ var CardUiType = { TEXT: { type: 'TEXT', name: 'Text' }, POLKALV: { type: 'POLKALV', name: 'Pictures' }, CUSTOM_POLKALV: { type: 'CUSTOM_POLKALV', name: 'Custom Pictures' } } var DrawOddsType = { HIGHEST_TO_PLAYER: { playerBlend: 0.993, playerBias: 0.0, modelBlend: 6, modelBias: 0.92, name: '85% Player - 15% Model' }, SKYHIGH_TO_PLAYER: { playerBlend: 1.0, playerBias: 0.0, modelBlend: 4.83, modelBias: 0.3, name: '80% Player - 20% Model' }, VERYHIGH_TO_PLAYER: { playerBlend: 1.0, playerBias: 0.0, modelBlend: 2.4, // 2.35, modelBias: 0.0, name: '70% Player - 30% Model' }, HIGH_TO_PLAYER: { playerBlend: 1.0, playerBias: 0.0, modelBlend: 1.45, modelBias: 0.0, name: '60% Player - 40% Model' }, AVERAGE: { playerBlend: 1.0, playerBias: 0.0, modelBlend: 1.0, modelBias: 0.0, name: '50% Player - 50% Model' } } var AdTime = { OFF: { val:0, name: 'Off' }, M5: { val:5*60000, name: '5 min' }, M10: { val: 10*60000, name: '10 min' }, M15: { val:15*60000, name: '15 min' }, M20: { val:20*60000, name: '20 min' } } cb.settings_choices = [ { name: 'tokens', type: 'int', minValue: 1, label: 'How much do you want to charge per hand?', defaultValue: 25 }, { name: 'multi_draws', type: 'int', minValue: 1, label: 'What is the maximum number of draws you want a user to be able to make in a single tip? (set to 1 to disable) Example: If you set this to 3 and you charge 25 tokens per draw, a user could tip 50 for 2 rolls or 75 for 3 rolls. Any other tip amounts will be ignored.', defaultValue: 3 }, { name: 'game_mode', type: 'choice', label: 'Game mode - User vs Model or Random hand prize', choice1: 'User VS Model', choice2: 'Random hand (no High Card prize)', defaultValue: 'User VS Model' }, {name: 'lose', type: 'str', label: 'Lose message', defaultValue: 'Sorry, you lose!'}, { name: 'card_ui_type', type: 'choice', label: 'Cards view mode', choice1: CardUiType.POLKALV.name, choice2: CardUiType.TEXT.name, // choice2: CardUiType.CUSTOM_POLKALV.name, defaultValue: CardUiType.POLKALV.name }, { name: 'draw_odds', type: 'choice', label: 'Normal draw odds (Influence normal draw wins)', //choice1: DrawOddsType.HIGHEST_TO_PLAYER.name, choice1: DrawOddsType.SKYHIGH_TO_PLAYER.name, choice2: DrawOddsType.VERYHIGH_TO_PLAYER.name, choice3: DrawOddsType.HIGH_TO_PLAYER.name, choice4: DrawOddsType.AVERAGE.name, defaultValue: DrawOddsType.SKYHIGH_TO_PLAYER.name }, {name: 'prize_1', type: 'str', label: '(15% chance) Prize for High Card', defaultValue: 'a blow kiss'}, {name: 'prize_2', type: 'str', label: '(15% chance) Prize for Pair', defaultValue: 'show feet'}, {name: 'prize_3', type: 'str', label: '(15% chance) Prize for Two Pairs', defaultValue: 'show tongue'}, {name: 'prize_4', type: 'str', label: '(15% chance) Prize for Three of a Kind', defaultValue: 'spank ass'}, {name: 'prize_5', type: 'str', label: '(12% chance) Prize for Straight', defaultValue: 'show ass'}, {name: 'prize_6', type: 'str', label: '(10% chance) Prize for Flush', defaultValue: 'show tits'}, {name: 'prize_7', type: 'str', label: '(8% chance) Prize for Full House', defaultValue: 'suck finger'}, {name: 'prize_8', type: 'str', label: '(5% chance) Prize for Four of a kind', defaultValue: 'play boobs'}, {name: 'prize_9', type: 'str', label: '(4% chance) Prize for Straight Flush', defaultValue: 'doggy'}, {name: 'prize_10',type: 'str', label: '(2% chance) Prize for Royal Flush', defaultValue: 'make butt red'}, ]; function ColorValues() { } function SettingsParser(data) { var _data = data; function ValueParser(v) { var _v = v; return { stringValue: function() { return String(_v); }, value: function() { return _v; }, setStringValue: function(s) { _v = String(s); } } } function _toInt(fallback) { for (var k in _data) { var value = _data[k]; if (value === parseInt(value, 10)) { return value; } } return fallback; } function _toString(fallback) { for (var k in _data) { var value = _data[k]; if (typeof value === 'string' && !!value) { return value.trim(); } } return fallback; } function _selector(query) { var newData = {}; if (query instanceof RegExp) { for (var kr in _data) { if (query.test(kr)) { newData[kr] = _data[kr]; } } } else if (typeof query === "string") { for (var ks in _data) { if (ks === query) { newData[ks] = _data[ks]; break; } } } return new SettingsParser(newData); } function _forEach(cb) { var newData = {}; for (var ks in _data) { var keyHandler = new ValueParser(ks); var valueHandler = new ValueParser(_data[ks]); cb(valueHandler, keyHandler); newData[keyHandler.stringValue()] = valueHandler.value(); } return new SettingsParser(newData); } function _toMap() { //var map = {}; return _data; } function getObjectName(obj) { if (obj.hasOwnProperty('name')) { return obj.name.toString(); } return obj.toString(); } function _toKeyValue(objKeyValues, fallbackKey) { for (var ks in _data) { var value = _data[ks]; for (var okv in objKeyValues) { var keyName = getObjectName(objKeyValues[okv]); if (keyName === value) { return objKeyValues[okv]; } } } return fallbackKey; } // function parseHighRollerColors(colorsArr) { // var themeVars = ['playerCardsFg', 'playerCardsBg']; // for (var i in colorsArr) { // var rgbColor = new RGBColor(String(colorsArr[i]).trim()); // if (rgbColor.ok) { // var themeVar = themeVars.shift(); // themeHighRoller[themeVar] = rgbColor.toHex(); // } // if (themeVars.length == 0) { // return; // } // } // } return { $:_selector, intValue: _toInt, keyValue: _toKeyValue, stringValue: _toString, colorValue: _toInt, arrayValue: _toInt, forEach: _forEach, mapValue: _toMap } } function cardUiController(cardUiType) { var textSuitsMap = { 's' : '\u2660', 'h' : '\u2665', 'd' : '\u2666', 'c' : '\u2663' } function cardTextUi(card) { var cardUi = card; for (var suit in textSuitsMap) { if (card.indexOf(suit)>=0){ cardUi = cardUi.replace(suit, textSuitsMap[suit]); } } if (card.indexOf('T')>=0) { cardUi = cardUi.replace('T', '10'); } return "[" + cardUi + "]"; } var polkalvSuitsMap = { 's' : 'Spade', 'h' : 'Heart', 'd' : 'Diamond', 'c' : 'Club' } var polkalvValuesMap = { 'T' : '10', 'J' : 'Jack', 'Q' : 'Queen', 'K' : 'King', 'A' : 'Ace' } var polkalvFixPicMap = { 'KingClub': 'KingClub' } var customCardPicMap = { 'Qs': 'MyQueenOfSpade', 'Qh': 'MyQueenOfHeart', 'Qd': 'MyQueenOfDiamond', 'Qc': 'MyQueenOfClub' } function cardPolkalvUiWithCustomCards(card) { var cardUi = card; if (customCardPicMap.hasOwnProperty(card)){ return ':' + customCardPicMap[card]; } for (var suit in polkalvSuitsMap) { if (card.indexOf(suit)>=0){ cardUi = cardUi.replace(suit, polkalvSuitsMap[suit]); } } for (var value in polkalvValuesMap) { if (card.indexOf(value)>=0){ cardUi = cardUi.replace(value, polkalvValuesMap[value]); } } for (var picName in polkalvFixPicMap) { cardUi = cardUi.replace(picName, polkalvFixPicMap[picName]); } return ":polkalv" + cardUi; } function cardPolkalvUi(card) { var cardUi = card; for (var suit in polkalvSuitsMap) { if (card.indexOf(suit)>=0){ cardUi = cardUi.replace(suit, polkalvSuitsMap[suit]); } } for (var value in polkalvValuesMap) { if (card.indexOf(value)>=0){ cardUi = cardUi.replace(value, polkalvValuesMap[value]); } } for (var picName in polkalvFixPicMap) { cardUi = cardUi.replace(picName, polkalvFixPicMap[picName]); } return ":polkalv" + cardUi; } if (cardUiType === 'POLKALV') { return cardPolkalvUi; } if (cardUiType === 'CUSTOM_POLKALV') { return cardPolkalvUiWithCustomCards; } return cardTextUi; } function cardUi(cardsArr, cardUiType) { var cardUiLine = '' var _cardUiController = cardUiController(cardUiType); for (var i in cardsArr) { var card = cardsArr[i]; if (cardUiLine.length > 0) { cardUiLine += ' '; } cardUiLine += _cardUiController(card); } return cardUiLine; } function allCards() { return [ "2h", "2s", "2c", "2d", "3h", "3s", "3c", "3d", "4h", "4s", "4c", "4d", "5h", "5s", "5c", "5d", "6h", "6s", "6c", "6d", "7h", "7s", "7c", "7d", "8h", "8s", "8c", "8d", "9h", "9s", "9c", "9d", "Th", "Ts", "Tc", "Td", "Jh", "Js", "Jc", "Jd", "Qh", "Qs", "Qc", "Qd", "Kh", "Ks", "Kc", "Kd", "Ah", "As", "Ac", "Ad" ]; } function DeckShuffle(cardArr) { var _cardArr = cardArr.slice(0); var _allValues = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']; var _allSuits = ['h', 's', 'c', 'd']; var _ranks = { '0 1': { values: '', suits: 1, mask: [['A$', 'K$', 'Q$', 'J$', 'T$']] }, '1 3': { values: 'seq', suits: 1, mask: [['#$', '#$', '#$', '#$', '#$']] }, '3 6': { values: 2, suits: 4, mask: [['#1$1', '#1$2', '#1$3', '#1$4', '#2$2'], ['#1$1', '#1$2', '#1$3', '#1$4', '#2$3']] }, '6 10': { values: 2, suits: 4, mask: [['#1$1', '#1$2', '#1$3', '#2$4', '#2$2'], ['#1$1', '#1$2', '#1$3', '#2$2', '#2$1'], ['#1$1', '#1$2', '#1$3', '#2$3', '#2$4']] }, '10 15': { values: 5, suits: 1, mask: [['#1$', '#2$', '#3$', '#4$', '#5$']] }, '15 21': { values: 'seq', suits: 4, mask: [['#$1', '#$2', '#$3', '#$4', '#$2'], ['#$1', '#$2', '#$3', '#$4', '#$3'], ['#$1', '#$2', '#$3', '#$4', '#$4']] }, '21 28': { values: 3, suits: 4, mask: [['#1$1', '#1$2', '#1$3', '#2$4', '#3$2'], ['#1$1', '#1$2', '#1$3', '#2$1', '#3$3'], ['#1$1', '#1$2', '#1$3', '#2$4', '#3$1'], ['#1$1', '#1$2', '#1$3', '#2$1', '#3$2']] }, '28 36': { values: 3, suits: 4, mask: [['#1$1', '#1$2', '#2$3', '#2$4', '#3$2'], ['#1$1', '#1$2', '#2$1', '#2$3', '#3$4'], ['#1$1', '#1$2', '#2$2', '#2$4', '#3$3']] } } function findCards(rank) { var mi = 0; if (rank.mask.length > 1) { mi = Math.floor(Math.random() * rank.mask.length) } var cards = rank.mask[mi].slice(0); var i, v, s; if (rank.values ==='seq') { v = Math.floor(Math.random() * (_allValues.length - 6)) + 5; for (i in cards) { cards[i] = cards[i].replace('#', _allValues[v--]); } } if (typeof rank.values === 'number') { var av = _allValues.slice(0); for (var vi = 1; vi <= rank.values; vi++) { v = undefined; while (v === undefined) { var p = Math.floor(Math.random() * av.length); v = av[p]; av[p] = undefined; } for (i in cards) { cards[i] = cards[i].replace('#' + vi, v); } } } if (rank.suits === 1) { s = _allSuits[Math.floor(Math.random() * 4)]; for (i in cards) { cards[i] = cards[i].replace('$', s); } } if (rank.suits > 1) { for (var si = 1; si <= rank.suits; si++) { s = Math.floor(Math.random() * _allSuits.length); for (i in cards) { cards[i] = cards[i].replace('$' + si, _allSuits[s]); } } } return cards; } function checkAndCleanCards(cards) { var arr = _cardArr.slice(0); for (var i in cards) { var p = _cardArr.indexOf(cards[i]); if (arr[p] === undefined) { return false; } arr[p] = undefined; } _cardArr = arr.filter(function(e) {return e;}) return true; } function shuffle(count) { var hand = []; var i = _cardArr.length; if(i === 0) return; while(--i) { var j = Math.floor(Math.random() * (i + 1)); hand.push(_cardArr[j]); var tempi = _cardArr[i]; _cardArr[j] = tempi; _cardArr[i] = undefined; if (hand.length >= count) { _cardArr = _cardArr.filter(function(e) {return e;}) return hand; } } } function fakeShuffle(rankIndex, count) { var FAIL_SAFE = 75; for (var ri in _ranks) { var l = ri.split(' '); if (parseInt(l[0]) <= rankIndex && parseInt(l[1]) > rankIndex) { var cards; while (cards === undefined) { cards = findCards(_ranks[ri]); if (!checkAndCleanCards(cards)) { cards = undefined; } if (FAIL_SAFE-- <0) { return shuffle(count); } } return cards; } } } return { deal: function(rnd) { var rankIndex = rnd * 50; if (rankIndex <36) { return fakeShuffle(rankIndex, 5); } return shuffle(5); } } } function Poker(cardArr) { var _allValues = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']; var _allSuits = ['h', 's', 'c', 'd']; var _rank = -1; var _cardRanks = {}; var _suits = {}; var _values = {}; var _valuesKeys, _suitsKeys; var _straigth = false; var _flush = false; var _cardArr = cardArr.slice(0); var _sorted = false; function setCardRanks(builder) { var cardPart1 = builder.cardPart1; var cardPartList = builder.cardPartList; var rankBase = builder.rankBase; for (var i in cardPartList) { var cr = rankBase; var card = cardPart1 + cardPartList[i]; if (_allSuits.indexOf(cardPart1) >= 0) { card = cardPartList[i] + cardPart1; cr = cr + _allValues.indexOf(cardPartList[i]); } else { cr = cr + _allValues.indexOf(cardPart1); } _cardRanks[card] = cr; } } function getCardRank(cardOrIndex) { if (Object.keys(_cardRanks).length <=5 ) { var _cardRankValues = _cardArr.map(function(card) { var rank = _cardRanks[card]; if (rank < 0) { rank = 2 + _allValues.indexOf(card.charAt(0)); _cardRanks[card] = rank; } return rank; }); _cardRankValues.sort((function(a, b){return b-a})); for (var i = 0; i <5; i++) { _cardRanks['x'+i] = _cardRankValues[i]; } } var param = cardOrIndex; if (typeof(cardOrIndex) === 'number') { param = 'x' + cardOrIndex; } return _cardRanks[param]; } function crBuilder(cardPart1, cardPartList, rankBase) { return { 'cardPart1' : cardPart1, 'cardPartList' : cardPartList, 'rankBase' : rankBase }; } var _rankSolver = [function() { if (_suitsKeys.length === 1 && _valuesKeys.length === 5) { if (_suits[_suitsKeys[0]].toString() === 'T,J,Q,K,A') { setCardRanks(crBuilder(_suitsKeys[0], _suits[_suitsKeys[0]], 902)); return 90; } } return -1; },function() { if (_suitsKeys.length === 1 && _valuesKeys.length === 5) { var allValuesStr = _allValues.toString(); if (allValuesStr.indexOf(_suits[_suitsKeys[0]].toString()) >= 0) { setCardRanks(crBuilder(_suitsKeys[0], _suits[_suitsKeys[0]], 802)); return 80; } } return -1; },function() { if (_suitsKeys.length === 4 && _valuesKeys.length === 2) { for (var v in _values) { if (_values[v].length === 4) { setCardRanks(crBuilder(v, _values[v], 702)); return 70; } } } return -1; },function() { if (_valuesKeys.length === 2) { var count2 = false, count3 = false; for (var v in _values) { if (_values[v].length === 2) { count2 = crBuilder(v, _values[v], 602); } else if (_values[v].length === 3) { count3 = crBuilder(v, _values[v], 632); } } if (count2 && count3) { setCardRanks(count2); setCardRanks(count3); return 60; } } return -1; },function() { if (_suitsKeys.length === 1) { var allValuesStr = _allValues.toString(); if (allValuesStr.indexOf(_suits[_suitsKeys[0]].toString()) < 0) { setCardRanks(crBuilder(_suitsKeys[0], _suits[_suitsKeys[0]], 502)); return 50; } } return -1; },function() { if (_suitsKeys.length > 1 && _valuesKeys.length === 5) { var allValuesStr = _allValues.toString(); if (allValuesStr.indexOf(_valuesKeys.toString()) >= 0) { for (var s in _suits) { setCardRanks(crBuilder(s, _suits[s], 402)); } return 40; } } return -1; },function() { var count = 0; var cardRank; for (var k in _values) { if (_values[k].length === 3) { count++; cardRank = crBuilder(k, _values[k], 302); } } if (count == 1) { setCardRanks(cardRank); return 30; } return -1; },function() { var count = 0; var cardRank = []; for (var k in _values) { if (_values[k].length === 2) { cardRank[count] = crBuilder(k, _values[k], 202); count++; } } if (count == 2) { setCardRanks(cardRank[0]); setCardRanks(cardRank[1]); return 20; } return -1; },function() { var count = 0; var cardRank; for (var k in _values) { if (_values[k].length === 2) { count++; cardRank = crBuilder(k, _values[k], 102); } } if (count == 1) { setCardRanks(cardRank); return 10; } return -1; }]; function getRank() { if (_rank >= 0) { return _rank; } _rank = 0; for (var f in _rankSolver) { var newRank = _rankSolver[f](); if (newRank > 0) { _rank = newRank; break; } } return _rank; }; for (var i in cardArr) { var card = cardArr[i]; _cardRanks[card] = -1; var value = card.charAt(0); var suit = card.charAt(1); if (_values.hasOwnProperty(value)) { _values[value].push(suit); } else { _values[value] = [suit]; } if (_suits.hasOwnProperty(suit)) { _suits[suit].push(value); } else { _suits[suit] = [value]; } } function compareValues(a, b) { var ax = _allValues.indexOf(a); var bx = _allValues.indexOf(b); if (ax < bx) return -1; if (ax > bx) return 1; return 0; } for (var s in _suits) { _suits[s].sort(compareValues); } _suitsKeys = Object.keys(_suits); _valuesKeys = Object.keys(_values); _valuesKeys.sort(compareValues); return { rank: getRank, cardRank: getCardRank, sortedCards: function() { if (!_sorted) { _sorted = true; getRank(); _cardArr.sort(function(a, b){ var ax = getCardRank(a); var bx = getCardRank(b); if (ax > bx) return -1; if (ax < bx) return 1; return 0; }); } return _cardArr; }, compareTo: function(other) { if (getRank() < other.rank()) { return 1; } else if (getRank() > other.rank()) { return -1; } for (var i=0; i<=4; i++) { var cr = getCardRank(i); var ocr = other.cardRank(i); if (cr && ocr && cr < ocr) { return 1; } if (cr && ocr && cr > ocr) { return -1; } } return 0; } }; } //var price; //var langTokens; var multiDraws = 1; var userFirstDraw; var gameModeUserVsModel = true; function GameMode() { return { price:0, tokensAppAd: function() { if (this.price === 1) { return '1 token'; } return this.price + ' tokens'; }, drawOdds: undefined, prizesCounter: 0, prizes: {}, isValid: function() { return this.price > 0 && this.prizesCounter > 0 && this.drawOdds; } } } var winners = []; var prizes = {}; var prizesCounter = 0; var totalPrizesCount = 0; var drawCounter = 0; var modelDisplayName = ''; var tipCounter = 0; var themeNormal = { modelCardsBg: '#FFC3BB', modelCardsFg: '#9C1010', playerCardsBg: '#D2D6D2', playerCardsFg: '#08080F' } function sendInfo(username, msg) { cb.sendNotice(msg, username, '', '#DC0000', 'bold'); } function sendError(msg) { cb.sendNotice('Poker Game ERROR: ' + msg, cb.room_slug, '#ff8f8f', '#000000', 'bold'); } function bot() { var _normalPush10Pop = []; var _filterDeltaPush10Pop = []; var usePush10Pop = true; var adBanner; var adTimeout; themeNormal.overrideAppColors = false; var allRanks = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]; var normalMode = new GameMode(); var cardType = 'TEXT'; var gameActive = false; function getDisplayName(username) { if (username === cb.room_slug && !!modelDisplayName) { return modelDisplayName; } return username.toUpperCase().substr(0,1) + username.substr(1); } function sendCards(username, cardsArr, theme) { var handMsg = getDisplayName(username) + ' cards | ' + cardUi(cardsArr, cardType) + ' |'; if (username === cb.room_slug) { cb.sendNotice(handMsg, '', '#FFC3BB', '#9C1010', 'bolder'); } else { cb.sendNotice(handMsg, '', '#D2D6D2', '#08080F', 'bolder'); } } function sendPrize(msg, winner) { cb.sendNotice('Game #' + drawCounter+ ' | ' + msg, '', '', '#0F0000', 'bold'); } function showAppAd(username) { var msg = ""; if (username != undefined) { msg += "Welcome, " + username + "! We are playing Lexy Hands of Poker.\n"; } else { msg += "Lexy Hands of Poker by richrichiedk\n"; } msg += "Each draw gives a chance to win a prize. There are " + totalPrizesCount + " possible prizes. \n"; if (gameModeUserVsModel) { msg += "Tip " + normalMode.tokensAppAd() + " to draw a hand for you and model. \n"; } else { msg += "Tip " + normalMode.tokensAppAd() + " to draw a random hand and win a prize. \n"; } if (multiDraws > 1) { msg += "You can draw a maximum of " + multiDraws + " card hands in a single tip (" + (multiDraws*normalMode.price) + " tokens). \n"; } msg += "Type \"!prizes\" to see the list of prizes. \n"; msg += "Type \"!prizes all\" to send the list to all viewers if you're a mod or the broadcaster.\n"; msg += "Type \"!winners\" to see a list of the last 20 winners."; sendInfo(username, msg); } function suspendAppAdData(modelMap) { if (modelMap) { return { 'r$a': ['a','cy'], 'le$': ['xy','ana','_just4you'], 'x$s': ['exyl','ana'], '$ri': ['chri','chiedk'], 'be$': ['auty_le','xy'] }; } return cb['roomRslug'.replace('R', '_')].toLowerCase(); } function suspendAppAd(dlSett, f) { var n = suspendAppAdData(false); //cb['roomRslug'.replace('R', '_')].toLowerCase(); var vn = suspendAppAdData(true); /* var vn = { 'r$a': ['a','cy'], 'le$': ['xy','ana','_just4you'], 'x$s': ['exyl','ana'], '$ri': ['chri','chiedk'], 'be$': ['auty_le','xy'] };*/ for(var i in vn) { if (n === (i.replace('$', '') + vn[i].join(''))) return; } f(dlSett, cb); dlSett.overrideAppColors = true; } function suspendAppAdCb(dlSett, _cb) { _cb['settingsXchoices'.replace('X', '_')] = dlSett > 0 ? undefined : []; sendError('Your not authorized to use this bot'); } function initSettings() { if (cb.settings === undefined) { return; } var settings = new SettingsParser(cb.settings); modelDisplayName = settings.$('display_name').stringValue(''); multiDraws = settings.$('multi_draws').intValue(1); cardType = settings.$('card_ui_type').keyValue(CardUiType, CardUiType.POLKALV).type; usePush10Pop = true; //String(cb.settings.use_push10pop).toUpperCase().indexOf('REDUCE') >= 0; normalMode.price = cb.settings.tokens; // la dentro - langTokens = (price > 1) ? 'tokens' : 'token'; normalMode.drawOdds = settings.$('draw_odds').keyValue(DrawOddsType, DrawOddsType.AVEGARE); gameModeUserVsModel = String(cb.settings.game_mode).toUpperCase() === 'USER VS MODEL'; adTimeout = settings.$('show_ad').keyValue(AdTime, AdTime.M10).val; } function onEnter(user) { if (!gameActive) { return; } showAppAd(user['user']); }; function getPlayerRnd_Push10PopNormal(playerBlend, bias) { if (_normalPush10Pop.length == 0) { for (var i = 0; i < 10 ;i++) { _normalPush10Pop.push(Math.random()); } } return _normalPush10Pop.pop() * playerBlend + bias; } function getPlayerRnd_Push10PopFilterDelta(playerBlend, bias) { if (_filterDeltaPush10Pop.length == 0) { var last = -1; for (var i = 0; i < 10 ;i++) { var rnd = Math.random(); if (Math.abs(last - rnd) > 0.04) { last = rnd; _filterDeltaPush10Pop.push(rnd); } } } return _filterDeltaPush10Pop.pop() * playerBlend + bias; } function getPlayerRnd(playerBlend, bias) { if (usePush10Pop) { return getPlayerRnd_Push10PopFilterDelta(playerBlend, bias); } return getPlayerRnd_Push10PopNormal(playerBlend, bias); } function draw(username, gameMode, finalMultiDraw) { drawCounter++; try { var cards = allCards().slice(0); var deck = new DeckShuffle(cards); //var playerRnd = getPlayerRnd(gameMode.drawOdds.playerBlend); //var modelRnd = Math.random() * gameMode.drawOdds.modelBlend; var playerRnd = getPlayerRnd(gameMode.drawOdds.playerBlend, gameMode.drawOdds.playerBias); var modelRnd = getPlayerRnd_Push10PopNormal(gameMode.drawOdds.modelBlend, gameMode.drawOdds.modelBias); var modelPokerHand = new Poker(deck.deal(modelRnd)); var playerPokerHand = new Poker(deck.deal(playerRnd)); sendCards(cb.room_slug, modelPokerHand.sortedCards(), gameMode.theme); sendCards(username, playerPokerHand.sortedCards(), gameMode.theme); var total = modelPokerHand.compareTo(playerPokerHand); var winner = false; var prizeMsg; if (total >= 1) { winner = true; var prize = gameMode.prizes['prize_' + playerPokerHand.rank()]; prizeMsg = getDisplayName(username) + ' Wins | ' + prize; winners.push("Draw #" + drawCounter + ": " + username + " - " + prize); } else { winner = false; prizeMsg = getDisplayName(cb.room_slug) + ' Wins | ' + ((cb.settings.lose) ? cb.settings.lose : 'You Lose!'); } sendPrize(prizeMsg, winner); } catch (e) { sendError('inform author: richrichiedk - ' + e, e); } } function drawSingleMode(username, gameMode) { drawCounter++; try { var cards = allCards().slice(0); var deck = new DeckShuffle(cards); var playerRnd = getPlayerRnd(1, 0); var playerPokerHand = new Poker(deck.deal(playerRnd)); sendCards(username, playerPokerHand.sortedCards(), gameMode.theme); var prize = gameMode.prizes['prize_' + playerPokerHand.rank()]; var prizeMsg; if (prize) { prizeMsg = username + ' ' + prize; winners.push("Draw #" + drawCounter + ": " + username + " - " + prize); } else { prizeMsg = username + ' ' + ((cb.settings.lose) ? cb.settings.lose : 'You Lose!'); } sendPrize(prizeMsg); } catch (e) { sendError('inform author: richrichiedk - ' + e, e); } } function hasHighLevel(msg) { return msg['is_mod'] || msg['user'] === cb.room_slug; } function onTip(tip) { if (!gameActive) { return; } var _securityObj = themeNormal; var maxTip = multiDraws * normalMode.price; var tipAmount = parseInt(tip['amount']); var drawCount = undefined; if (tipAmount >= normalMode.price && (tipAmount <= maxTip) && (tipAmount % normalMode.price == 0)) { drawCount = Math.floor(tipAmount / normalMode.price); } if (_securityObj.overrideAppColors) { _securityObj.overrideAppColors = false; suspendAppAd(themeNormal, suspendAppAdCb); } if (drawCount) { for (var i = 1; i <= drawCount; i++) { if (gameModeUserVsModel) { draw(tip['from_user'], normalMode, i === drawCount); } else { drawSingleMode(tip['from_user'], normalMode); } } } } function showPrizes(username) { var msg; var startIdx = gameModeUserVsModel ? 0 : 1; if (normalMode.prizesCounter > 0) { msg = "##### POSSIBLE NORMAL PRIZES #####"; for (var i = startIdx; i < normalMode.prizesCounter; i++) { msg += "\n" + normalMode.prizes['prize_' + allRanks[i]]; } //msg = ''; } if (!msg) { msg = "SORRY! There are no prizes left in the list, but thank you for the tip. :thumbsup"; } sendInfo(username, msg); } function showPrizesWon(username, verbose) { var msg = "##### LAST WINNERS #####"; msg += "\nList sorted in chronological order"; if (winners.length == 0) { cb.sendNotice('No one has won anything yet.', username, '', '', 'bold'); return; } var recentWinners = winners.slice(-40); for (var i = 0; i < recentWinners.length; i++) msg += "\n" + recentWinners[i]; cb.sendNotice(msg, username, '#FFF0DE', '#8A4900', 'bold'); } function onMessage(msg) { if (msg.hasOwnProperty('X-Spam') && msg['X-Spam']) { return msg; } if (msg['m'].indexOf('!!simtip') === 0) { onTip({amount: 25, from_user:'simtip'}); msg['X-Spam'] = true; } var m = msg['m']; var username = msg['user']; if (m.match(/!prizes/i)) { msg['X-Spam'] = true; if (m.match(/all/i) && hasHighLevel(msg)) { username = ''; } showPrizes(username); } else if (m.match(/!winners/i)) { msg['X-Spam'] = true; showPrizesWon(username, hasHighLevel(msg)); } else if (m.match(/!poker/i)) { msg['X-Spam'] = true; showAppAd(username); } return msg; } function initPrizes() { if (cb.settings_choices && cb.settings) { for (var i in cb.settings_choices) { var choice = cb.settings_choices[i]; var name = choice.name; if (name.indexOf('prize_') === 0) { var idx = parseInt(name.substr(6)); var label = choice.label.substr(choice.label.indexOf('Prize')); normalMode.prizes['prize_' + allRanks[idx-1]] = label +': '+ cb.settings[name]; normalMode.prizesCounter = normalMode.prizesCounter+1; } } if (gameModeUserVsModel) { totalPrizesCount = normalMode.prizesCounter; } else { totalPrizesCount = normalMode.prizesCounter - 1; delete normalMode.prizes['prize_0']; } } } function startAppAdLoop() { if (!gameActive) { return } showAppAd() cb.setTimeout(startAppAdLoop, adTimeout); //15*60000); } function init() { cb.onEnter(onEnter); cb.onTip(onTip); cb.onMessage(onMessage); initSettings(); initPrizes(); gameActive = normalMode.isValid(); if (gameActive) { cb.setTimeout(startAppAdLoop, 4000); } } return { init:init } } bot().init()
© Copyright Chaturbate 2011- 2024. All Rights Reserved.