/***** INCLUDES ********************************************************/ include library.sui; include library.utils; include library.money; include library.prose; include library.gambling; /***** INHERITS ********************************************************/ inherits gambling.base.wheel; /***** CONSTANTS *******************************************************/ const string GAME_TYPE = "roulette"; const int[] RED_NUMBERS = { 1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36 }; /***** TRIGGERS ********************************************************/ trigger OnInitialize() { cleanupWheelGame(self); string gameType = GAME_TYPE; if ( hasObjVar(self, gambling.VAR_PREDEFINED_TYPE) ) gameType = getStringObjVar(self, gambling.VAR_PREDEFINED_TYPE); gambling.initializeTable(self, gameType); return SCRIPT_CONTINUE; } /***** HANDLERS ********************************************************/ messageHandler handleBetPlaced() { if ( params == null || params.isEmpty() ) return SCRIPT_CONTINUE; obj_id player = params.getObjId(money.DICT_PLAYER_ID); if ( !isIdValid(player) ) return SCRIPT_CONTINUE; int ret = params.getInt(money.DICT_CODE); int amt = params.getInt(money.DICT_TOTAL); if ( ret == money.RET_FAIL || amt < 1 ) { dictionary d = new dictionary(); d.put("player", player); messageTo(self, "handleBetFailed", d, 0, false); return SCRIPT_CONTINUE; } string arg = params.getString("arg"); if ( arg != null && !arg.equals("") ) { if ( isValidBet(self, arg) ) { //close pid string scriptvar_pid = gambling.VAR_GAME_PLAYERS + "." + player + ".pid"; if ( utils.hasScriptVar(self, scriptvar_pid) ) { int oldpid = utils.getIntScriptVar(self, scriptvar_pid); sui.closeSUI(player, oldpid); utils.removeScriptVar(self, scriptvar_pid); } CustomerServiceLog("gambling", getGameTime() + ": (" + player + ") " + getName(player) + " bets " + amt + "cr on '" + arg + "'"); int playerIdx = gambling.getGamePlayerIndex(self, player); if ( playerIdx < 0 ) return SCRIPT_CONTINUE; string ovpath = gambling.VAR_GAME_PLAYERS + "." + playerIdx + ".bet." + arg; if ( hasObjVar(self, ovpath) ) { amt += getIntObjVar(self, ovpath); int maxBet = getIntObjVar(self, gambling.VAR_TABLE_BET_MAX); if ( maxBet > 0 && amt > maxBet ) { int refund = amt - maxBet; sendSystemMessageTestingOnly(player, "The maximum bet for this station is " + maxBet + " credits."); sendSystemMessageTestingOnly(player, "Bet Refund (over-bet): " + refund + " credits"); transferBankCreditsTo(self, player, refund, "noHandler", "noHandler", new dictionary()); CustomerServiceLog("gambling", getGameTime() + ": (" + player + ") " + getName(player) + " overbet -> processing refund!"); CustomerServiceLog("gambling", getGameTime() + ": (" + player + ") " + getName(player) + " refund results: total=" + amt + " refund=" + refund + " updated bet="+maxBet); amt = maxBet; } } setObjVar(self, ovpath, amt); dictionary d = new dictionary(); d.put("player", player); messageTo(self, "handleRequestUpdatedUI", d, 0f, false); return SCRIPT_CONTINUE; } } sendSystemMessageTestingOnly(player, "Roulette: /bet <1-36,0,00,red,black,odd,even,high,low>"); sendSystemMessageTestingOnly(player, "Bet Refund: " + amt + " credits"); transferBankCreditsTo(self, player, amt, "noHandler", "noHandler", new dictionary()); return SCRIPT_CONTINUE; } messageHandler handleWheelSpinning() { if ( params == null || params.isEmpty() ) return SCRIPT_CONTINUE; obj_id[] players = getObjIdArrayObjVar(self, gambling.VAR_TABLE_PLAYERS); if ( players == null || players.length == 0 ) return SCRIPT_CONTINUE; int cnt = params.getInt("cnt"); cnt--; params.put("cnt", cnt); if ( cnt > 0 ) { float delay = 5f; switch ( cnt ) { case 2: for ( int i = 0; i < players.length; i++ ) sendSystemMessage(players[i], new string_id(gambling.STF_INTERFACE, "wheel_begin_slow")); break; case 1: int result = getResult(); string sResult = getResultString(result); prose_package pp = prose.getPackage(new string_id(gambling.STF_INTERFACE, "prose_wheel_slow"), sResult, getResultColor(result)); for ( int i = 0; i < players.length; i++ ) sendSystemMessageProse(players[i], pp); params.put("result", result); delay = 10f; break; default: for ( int i = 0; i < players.length; i++ ) sendSystemMessage(players[i], new string_id(gambling.STF_INTERFACE, "wheel_spinning")); break; } messageTo(self, "handleWheelSpinning", params, delay, false); } else { prose_package pp = null; //get new result int result = getResult(); string newResult = getResultString(result); params.put("result", result); pp = prose.getPackage(new string_id(gambling.STF_INTERFACE, "prose_result_change"), newResult, getResultColor(result)); if ( pp != null ) { for ( int i = 0; i < players.length; i++ ) sendSystemMessageProse(players[i], pp); } messageTo(self, "handleParseResults", params, 1f, false); } return SCRIPT_CONTINUE; } messageHandler handleParseResults() { if ( params == null || params.isEmpty() ) return SCRIPT_CONTINUE; obj_id[] players = getObjIdArrayObjVar(self, gambling.VAR_GAME_PLAYERS_IDS); if ( players == null || players.length == 0 ) return SCRIPT_CONTINUE; int result = params.getInt("result"); string sResult = getResultString(result); string resultColor = getResultColor(result); CustomerServiceLog("gambling", getGameTime() + ": (" + self + ") " + utils.getStringName(self) + " processing results..."); CustomerServiceLog("gambling", getGameTime() + ": (" + self + ") " + utils.getStringName(self) + " results: raw="+result+" sResult="+sResult+" color="+resultColor); for ( int i = 0; i < players.length; i++ ) { int total = 0; //NOTE: payouts should include a bet refund! CustomerServiceLog("gambling", getGameTime() + ": player = " + players[i] + " : " + getName(players[i])); int playerIdx = gambling.getGamePlayerIndex(self, players[i]); if ( playerIdx > -1 ) { //check direct hit bets string ovpath = gambling.VAR_GAME_PLAYERS + "." + playerIdx + ".bet." + sResult; if ( hasObjVar(self, ovpath) ) { int spotBet = getIntObjVar(self, ovpath); int spotPayout = (spotBet * 36) + spotBet; total += spotPayout; CustomerServiceLog("gambling", getGameTime() + ": (" + players[i] + ") has spot bet -> payout = " + spotPayout); } //check color bets if ( result > 0 ) { ovpath = gambling.VAR_GAME_PLAYERS + "." + playerIdx + ".bet." + resultColor; if ( hasObjVar(self, ovpath) ) { int colorBet = getIntObjVar(self, ovpath); int colorPayout = 2*colorBet; total += colorPayout; CustomerServiceLog("gambling", getGameTime() + ": (" + players[i] + ") has color bet -> payout = " + colorPayout); } } //check even-odd bets if ( result > 0 ) { if ( result % 2 == 0 ) //even ovpath = gambling.VAR_GAME_PLAYERS + "." + playerIdx + ".bet.even"; else ovpath = gambling.VAR_GAME_PLAYERS + "." + playerIdx + ".bet.odd"; if ( hasObjVar(self, ovpath) ) { int evenOddBet = getIntObjVar(self, ovpath); int evenOddPayout = 2*evenOddBet; total += evenOddPayout; CustomerServiceLog("gambling", getGameTime() + ": (" + players[i] + ") has even/odd bet -> payout = " + evenOddPayout); } } //check high-low bets if ( result > 0 ) { if ( result > 18 ) //high ovpath = gambling.VAR_GAME_PLAYERS + "." + playerIdx + ".bet.high"; else ovpath = gambling.VAR_GAME_PLAYERS + "." + playerIdx + ".bet.low"; if ( hasObjVar(self, ovpath) ) { int hiLoBet = getIntObjVar(self, ovpath); int hiLoPayout = 2*hiLoBet; total += hiLoPayout; CustomerServiceLog("gambling", getGameTime() + ": (" + players[i] + ") has hi/low bet -> payout = " + hiLoPayout); } } } CustomerServiceLog("gambling", getGameTime() + ": (" + players[i] + ") total payout = " + total); if ( total > 0 ) { //payout a winner!! dictionary d = new dictionary(); d.put("player", players[i]); d.put("payout", total); transferBankCreditsFromNamedAccount(money.ACCT_ROULETTE, players[i], total, "handleGamblingPayout", "noHandler", d); } else { sendSystemMessageTestingOnly(players[i], "Sorry, you did not win this round. Please try again."); } } cleanupWheelGame(self); messageTo(self, "handleDelayedRestart", null, 10f, false); return SCRIPT_CONTINUE; } /***** FUNCTIONS ********************************************************/ boolean isValidBet(obj_id self, string arg) { if ( !isIdValid(self) || arg == null || arg.equals("") ) return false; if ( arg.equals("red") || arg.equals("black") || arg.equals("00") ) return true; if ( arg.equals("even") || arg.equals("odd") || arg.equals("high") || arg.equals("low") ) return true; int tmp = utils.stringToInt(arg); if ( tmp >= 0 && tmp <= 36 ) return true; return false; } int getResult() { return rand(-1,36); } string getResultString(int roll) { if ( roll == -1 ) return "00"; else return Integer.toString(roll); } string getResultString() { return getResultString(getResult()); } string getResultColor(int result) { if ( result == 0 || result == -1 ) return "green"; if ( utils.getElementPositionInArray(RED_NUMBERS, result) > -1 ) return "red"; return "black"; } void cleanupWheelGame(obj_id self) { int bank = getBankBalance(self); if ( bank > 0 ) transferBankCreditsToNamedAccount(self, money.ACCT_ROULETTE, bank, "noHandler", "noHandler", new dictionary()); obj_id[] players = getObjIdArrayObjVar(self, gambling.VAR_GAME_PLAYERS_IDS); if ( players != null && players.length > 0 ) { for ( int i = 0; i < players.length; i++ ) { int idx = gambling.getGamePlayerIndex(self, players[i]); //string ovpath = gambling.VAR_GAME_PLAYERS + "." + players[i] + ".pid"; string ovpath = gambling.VAR_GAME_PLAYERS + "." + players[i] + ".pid"; if ( utils.hasScriptVar(self, ovpath) ) { int oldpid = utils.getIntScriptVar(self, ovpath); sui.closeSUI(players[i], oldpid); } //ovpath = gambling.VAR_GAME_PLAYERS + "." + players[i] + ".bet"; ovpath = gambling.VAR_GAME_PLAYERS + "." + idx + ".bet"; if ( !hasObjVar(self, ovpath) ) { gambling.removeTablePlayer(self, players[i], ""); } } } removeObjVar(self, gambling.VAR_GAME_BASE); }