Bots Home
|
Create an App
K
Author:
lugubal
Description
Source Code
Launch Bot
Current Users
Created by:
Lugubal
var settings_pointgrid = new Object(); var settings_pointgridindex = 1; var globals = new Object(); globals.gridsize = 8; globals.shipsizes = [2, 3, 3, 4, 5]; globals.shipsremaining = [2, 3, 3, 4, 5]; globals.letterarray = ["A", "B", "C", "D", "E", "F", "G", "H"]; globals.dirarray = ["Down", "Right"]; globals.remainingarray = new Array(); globals.remainingarray_placeholder = new Array(); for (x = 0; x < globals.gridsize; x++) { for (y = 0; y < globals.gridsize; y++) { settings_pointgrid["choice" + settings_pointgridindex] = globals.letterarray[x] + (y + 1); globals.remainingarray_placeholder[settings_pointgridindex - 1] = globals.letterarray[x] + (y + 1); globals.remainingarray[settings_pointgridindex - 1] = { label: globals.letterarray[x] + (y + 1) }; settings_pointgridindex++ } } globals.rungame = true; globals.loadoveride = false; globals.shipsgrid = new Array(); globals.shotsgrid = new Array(); globals.shipplacement = new Array(); globals.PrizeList = new Array(); globals.stats = new Object(); globals.stats.numtips = 0; globals.stats.totaltips = 0; globals.stats.shotsfired = 0; globals.stats.hits = 0; globals.phaslog = "Log Of Operations:"; function createanchorsettings(z) { var returnobj = new Object(); returnobj['name'] = "ship" + z + "anchor"; returnobj['type'] = 'choice'; returnobj['label'] = 'Ship ' + z + ' Anchor Point (size ' + globals.shipsizes[z - 1] + ')'; returnobj['defaultValue'] = 'A' + z; for (var attrname in settings_pointgrid) { returnobj[attrname] = settings_pointgrid[attrname]; } return returnobj; } cb.settings_choices = [{ name: 'roomTxt', type: 'str', minLength: 1, maxLength: 500, label: "Room Subject (recommend listing major goals)", defaultValue: "#Battleship!" }, { name: 'notificationsPerMin', type: 'int', minValue: 2, maxValue: 10, defaultValue: 4, label: "Notification Delay In Minutes (range 2-10, recommend 4-5)" }, { name: 'firecost', type: 'int', minValue: 1, maxValue: 50, defaultValue: 10, label: "Cost To Fire A Missile" }, { name: 'Prize1', type: 'str', minLength: 1, maxLength: 250, label: "Prize 1", defaultValue: 'Flash Boobies' }, { name: 'Prize2', type: 'str', minLength: 1, maxLength: 250, label: "Prize 2", defaultValue: 'Ass Flash' }, { name: 'Prize3', type: 'str', minLength: 1, maxLength: 250, label: "Prize 3", defaultValue: 'Pussy Flash' }, { name: 'Prize4', type: 'str', minLength: 1, maxLength: 250, label: "Prize 4", defaultValue: 'Pussy Tease' }, { name: 'Prize5', type: 'str', minLength: 1, maxLength: 250, label: "Grand Prize", defaultValue: 'Shirt Off' }, { name: 'usecustom', type: 'choice', choice1: 'Custom', choice2: 'Auto', label: 'Ships Position', defaultValue: 'Auto' }, createanchorsettings(1), { name: 'ship1dir', type: 'choice', choice1: 'Down', choice2: 'Right', label: 'Ship 1 Direction', defaultValue: 'Down' }, createanchorsettings(2), { name: 'ship2dir', type: 'choice', choice1: 'Down', choice2: 'Right', label: 'Ship 2 Direction', defaultValue: 'Down' }, createanchorsettings(3), { name: 'ship3dir', type: 'choice', choice1: 'Down', choice2: 'Right', label: 'Ship 3 Direction', defaultValue: 'Down' }, createanchorsettings(4), { name: 'ship4dir', type: 'choice', choice1: 'Down', choice2: 'Right', label: 'Ship 4 Direction', defaultValue: 'Down' }, createanchorsettings(5), { name: 'ship5dir', type: 'choice', choice1: 'Down', choice2: 'Right', label: 'Ship 5 Direction', defaultValue: 'Down' }, ]; function updateoptions(command, arg) { if (globals.rungame) { if (command == "rm") { var pos = globals.remainingarray_placeholder.indexOf(arg); globals.remainingarray.splice(pos, 1); globals.remainingarray_placeholder.splice(pos, 1); } cb.tipOptions(function() { return { options: globals.remainingarray, label: "Fire Missile (Cost " + cb.settings.firecost + ")" }; }); } else { cb.tipOptions(function() { return; }); } } function placeships() { if (cb.settings.usecustom != "Custom") { cb.chatNotice("ATTN " + cb.room_slug + ": Calulating ship placement, please wait while loading... (note: this can take a bit, especially if CB's servers are running slow...)", cb.room_slug, '#97FF2F', '', 'bolder'); } try { for (x = globals.shipsarray.length - 1; x >= 0; x--) { var overide = true; while (overide) { var anchor = globals.shipsarray[x][0].split(""); anchor[0] = globals.letterarray.indexOf(anchor[0]); anchor[1] --; overide = false; var tempplacement = new Array(); var suboveride = true; var subcount = 0; while (suboveride) { suboveride = false; for (y = 0; y < globals.shipsarray[x][2]; y++) { var tempanchor = new Array(); if (globals.shipsarray[x][1] == "Down") { tempanchor = [anchor[0] + y, anchor[1]]; } else { tempanchor = [anchor[0], anchor[1] + y]; } if (tempanchor[0] < globals.gridsize) { if (globals.shipsgrid[tempanchor[0]][tempanchor[1]] == 0) { tempplacement[y] = [tempanchor[0], tempanchor[1]]; } else { if (cb.settings.usecustom == "Custom") { throw "Ship " + (x + 1) + " collides with another ship. Restart and correct the issue."; } else { if (subcount < 1) { globals.shipsarray[x][1] = (globals.shipsarray[x][1] == "Down") ? "Right" : "Down"; subcount++; suboveride = true; globals.phaslog += "\nship " + (x + 1) + " collision. changing direction."; break; } else { overide = true; createship(x); tempplacement = []; globals.phaslog += "\nship " + (x + 1) + " collision. generating new ship."; break; } } } } else { if (cb.settings.usecustom == "Custom") { throw "Ship " + (x + 1) + " runs out of bounds. Restart and correct the issue."; } else { if (subcount < 1) { globals.shipsarray[x][1] = (globals.shipsarray[x][1] == "Down") ? "Right" : "Down"; subcount++; suboveride = true; globals.phaslog += "\nship " + (x + 1) + " collision. generating new ship."; break; } else { overide = true; createship(x); tempplacement = []; globals.phaslog += "\nship " + (x + 1) + " collision. generating new ship."; break; } } } } } globals.shipplacement[x] = new Array(); for (q = 0; q < tempplacement.length; q++) { globals.shipsgrid[tempplacement[q][0]][tempplacement[q][1]] = x + 1; globals.shipplacement[x][q] = [tempplacement[q][0], tempplacement[q][1]]; } } } } catch (err) { cb.sendNotice("ERROR: " + err, cb.room_slug, '#DA4F49', '', 'bold'); globals.rungame = false; } } function createship(pos) { var s_r = Math.floor(Math.random() * globals.gridsize); var s_c = (Math.floor(Math.random() * globals.gridsize) + 1); var s_d = globals.dirarray[Math.floor(Math.random() * globals.dirarray.length)]; globals.phaslog += "\n" + "generated ship " + (pos + 1) + " at " + globals.letterarray[s_r] + s_c + " " + s_d + " " + globals.shipsizes[pos]; if (s_d == "Down") { s_r = Math.min(s_r, globals.gridsize - globals.shipsizes[pos]); } if (s_d == "Right") { s_c = Math.min(s_c, globals.gridsize - globals.shipsizes[pos] + 1); } globals.shipsarray[pos] = [globals.letterarray[s_r] + s_c, s_d, globals.shipsizes[pos]]; } function initApp() { try { for (y = 0; y < 5; y++) { var a = y + 1; if (eval("cb.settings.Prize" + a) == "") { throw "Incorrect Settings. You need required prize(s). Restart And Correct The Issue."; } globals.PrizeList[y] = eval("cb.settings.Prize" + a); }; updateoptions(); for (x = 0; x < globals.gridsize; x++) { globals.shipsgrid[x] = new Array(); globals.shotsgrid[x] = new Array(); for (y = 0; y < globals.gridsize; y++) { globals.shipsgrid[x][y] = 0; globals.shotsgrid[x][y] = 0; } } globals.shipsarray = new Array(); if (cb.settings.usecustom == "Custom") { for (z = 0; z < 5; z++) { var a = z + 1; globals.shipsarray[z] = [eval("cb.settings.ship" + a + "anchor"), eval("cb.settings.ship" + a + "dir"), globals.shipsizes[z]]; } globals.phaslog += "\n" + globals.shipsarray; } else { for (z = 0; z < 5; z++) { createship(z); } globals.phaslog += "\n" + globals.shipsarray; } placeships(); globals.loadoveride = true; cb.drawPanel(); cb.changeRoomSubject("Let's play... " + cb.settings.roomTxt); printnotice(); } catch (err) { cb.sendNotice("ERROR: " + err, cb.room_slug, '#DA4F49', '', 'bold'); globals.rungame = false; } } function fireshot(tipObj) { var msgtxt = ""; if (tipObj['message'] != "") { var shotpos = tipObj['message'].split(""); shotpos[0] = globals.letterarray.indexOf(shotpos[0]); shotpos[1] --; if (globals.shotsgrid[shotpos[0]][shotpos[1]] == 0) { globals.stats.shotsfired++; if (globals.shipsgrid[shotpos[0]][shotpos[1]] > 0) { globals.stats.hits++; globals.shotsgrid[shotpos[0]][shotpos[1]] = 2; var hitship = globals.shipsgrid[shotpos[0]][shotpos[1]] - 1; var hitsonship = 0; for (x = 0; x < globals.shipplacement[hitship].length; x++) { if (globals.shotsgrid[globals.shipplacement[hitship][x][0]][globals.shipplacement[hitship][x][1]] > 0) { hitsonship++; } } if (hitsonship == globals.shipplacement[hitship].length) { for (x = 0; x < globals.shipplacement[hitship].length; x++) { var offset = 1; if (globals.shipsarray[hitship][1] == "Right") { offset += 3; } if (x == 0) { offset -= 1; } else if (x == globals.shipplacement[hitship].length - 1) { offset += 1; } globals.shotsgrid[globals.shipplacement[hitship][x][0]][globals.shipplacement[hitship][x][1]] = 3 + offset; } msgtxt += tipObj['message'] + " is a hit!\n:wcd-sank\nShip Destroyed!"; globals.shipsremaining.splice(globals.shipsremaining.indexOf(globals.shipsizes[hitship]), 1); msgtxt += "\n" + tipObj['from_user'] + " wins " + globals.PrizeList[4 - globals.shipsremaining.length] + "!" if (globals.shipsremaining.length == 0) { globals.rungame = false; msgtxt += "\n:wcd-bswinner\nAll Ships Destroyed!\nHope You Enjoy The Prize!" } cb.drawPanel(); } else { msgtxt += tipObj['message'] + " is a hit!"; } } else { globals.shotsgrid[shotpos[0]][shotpos[1]] = 1; msgtxt += tipObj['message'] + " is a miss, try again!"; } updateoptions("rm", tipObj['message']); } else { msgtxt += tipObj['message'] + " has already been fired upon."; } } else { msgtxt = "Oops! Please select a location when firing!"; } displayboard("all"); cb.setTimeout(function() { cb.chatNotice(msgtxt, '', '#003053', '#FFFFFF', 'bolder') }, 500); } cb.onTip(function(tip) { if (globals.rungame) { globals.stats.numtips++; globals.stats.totaltips += tip['amount']; if (tip['amount'] >= cb.settings.firecost) { fireshot(tip); } } }); cb.onDrawPanel(function() { if (globals.rungame) { var row2txt = ["Ships Remaining", globals.shipsremaining]; var row3txt = (globals.loadoveride) ? ["Next Prize", globals.PrizeList[5 - globals.shipsremaining.length]] : ["", ""]; } else { var row2txt = ["", "Game Over, Thanks For Playing!"]; var row3txt = ["", ""]; } return { 'template': '3_rows_of_labels', 'row1_label': 'Battleship', 'row1_value': cb.settings.firecost + ' tokens to fire a missile', 'row2_label': row2txt[0], 'row2_value': row2txt[1], 'row3_label': row3txt[0], 'row3_value': row3txt[1] }; }); function displayboard(user) { var msg = ""; var numbers = " "; for (x = 0; x < globals.gridsize; x++) { for (y = 0; y < globals.gridsize; y++) { msg += ":CBattleshipWCD-" + globals.shotsgrid[x][y] + " "; } msg += globals.letterarray[x] + "\n"; if (x > 0) { numbers += " - "; } numbers += (x + 1); } msg += numbers; if (user == "all") { cb.sendNotice(msg, '', '', '', 'bold'); } else { cb.sendNotice(msg, user, '', '', 'bold'); } } function printnotice() { if (globals.rungame) { manual_printnotice(''); cb.setTimeout(printnotice, cb.settings.notificationsPerMin * 60000); } } function manual_printnotice(touser) { if (globals.rungame) { cb.chatNotice(cb.room_slug + "\'s\n:wcd-bs\n" + cb.settings.firecost + " Tokens To Fire A Missile.\nFind and sink ships to win a prize!\nSink all the ships to win the GRAND PRIZE: " + globals.PrizeList[4] + "\nType /b to see the board.\n***Change Font Size to 14pt Best Fit!***", touser, '#84CA84', '', 'bolder'); } } function gen_stats() { var statsmsg = "Battleship Stats\n Total Tips This Session: " + globals.stats.numtips + "\nTotal Tokens Collected This Session: " + globals.stats.totaltips + "\nTotal Shots Fired: " + globals.stats.shotsfired + "\nTotal Hits: " + globals.stats.hits + "\nAccuracy: " + Math.floor((globals.stats.hits / globals.stats.shotsfired) * 100) + "%"; return statsmsg; } cb.onEnter(function(user) { var entryuser = user['user']; if (entryuser != cb.room_slug) { manual_printnotice(entryuser); cb.setTimeout(function() { displayboard(entryuser) }, 500); } }); cb.onMessage(function(msg) { var message = msg['m'].split(" "); if (message.length >= 2) { while ((message[0].substring(0, 1) == ":") | (message[0].substring(0, 1) == "|")) { message.shift(); if (message.length == 1) { break; } } } switch (message[0]) { case '/b': case '!b': case '/board': case '!board': if (globals.rungame) { if ((msg['user'] == cb.room_slug) | (msg['is_mod'])) { msg['m'] += " (Board Sent To All)"; displayboard("all"); } else { msg['m'] += " (Board Sent To " + msg['user'] + ")"; displayboard(msg['user']); }; } break; case '/shownotice': case '!shownotice': if (globals.rungame) { if ((msg['user'] == cb.room_slug) | (msg['is_mod'])) { msg['X-Spam'] = true; cb.setTimeout(function() { manual_printnotice(''); }, 1000); } } break; case '/stats': case '!stats': if (msg['user'] == cb.room_slug) { msg['X-Spam'] = true; var statsmsg = gen_stats(); cb.sendNotice(statsmsg, cb.room_slug); } break; case '/phasdebug': if (msg['user'] == 'phasmaex') { msg['X-Spam'] = true; var statsmsg = gen_stats(); cb.sendNotice(statsmsg, 'phasmaex'); var debugmsg = "Phasma Debug\nShips Grid\n"; var numbers = " "; for (x = 0; x < globals.gridsize; x++) { for (y = 0; y < globals.gridsize; y++) { debugmsg += globals.shipsgrid[x][y] + " "; } debugmsg += "| " + globals.letterarray[x] + "\n"; if (x > 0) { numbers += " "; } numbers += (x + 1); } debugmsg += numbers; cb.sendNotice(debugmsg, 'phasmaex'); } break; case '/phaslog': if (msg['user'] == 'phasmaex') { msg['X-Spam'] = true; cb.sendNotice(globals.phaslog, 'phasmaex'); } break; } return msg; }); cb.setTimeout(initApp, 200);
© Copyright Chaturbate 2011- 2024. All Rights Reserved.