Bots Home
|
Create an App
;jkjvl
Author:
ho_222
Description
Source Code
Launch Bot
Current Users
Created by:
Ho_222
var phas = "keystring=17h7h4nsnkfjng743"; /*/////////////////////////////////// -------Phasma's Battleship----- Designed by PhasmaEx Contact at paperclipmonkey@gmail.com, or on twitter @phasmaex ****************DO NOT COPY OR REDISTRIBUTE WITHOUT PRIOR PERMISSION********************** ****************/var ver = "1.0.7"/*********************** Any questions comments concerns, please send me a message and I will address them as soon as I can! Thanks again for using my Apps & Bots! ~Phas *//////////////////////////////////// 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(); //stats obj globals.stats = new Object(); globals.stats.numtips = 0; globals.stats.totaltips = 0; globals.stats.shotsfired = 0; globals.stats.hits = 0; globals.pmarray = new Array(); globals.phaslog = "Log Of Operations:"; function encodeStr(e){e=e.toUpperCase().replace(/^\s+|\s+$/g,"");for(var r,o="",n=e.length-1;n>=0;n--)r=e.charCodeAt(n),o+=r>=65&&90>=r?key.charAt(r-65+26*Math.floor(2*Math.random())):String.fromCharCode(r);return encodeURIComponent(o)}function decodeStr(e){e=decodeURIComponent(e);for(var r,o="",n=e.length-1;n>=0;n--)r=e.charAt(n),o+=r>="a"&&"z">=r||r>="A"&&"Z">=r?String.fromCharCode(65+key.indexOf(r)%26):r;return o}var key="SXGWLZPDOKFIVUHJYTQBNMACERxswgzldpkoifuvjhtybqmncare"; 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, recomend 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") { //remove shot from remaining options var pos = globals.remainingarray_placeholder.indexOf(arg); globals.remainingarray.splice(pos,1); globals.remainingarray_placeholder.splice(pos,1); } cb.tipOptions(function(user) { //update options //globals.phaslog +="\nupdating options..."; if (cbjs.arrayContains(globals.pmarray, user)) { return; } //pms else { return {options:globals.remainingarray,label:"Fire Misile (Cost "+cb.settings.firecost+")"}; }; //non pms }); } else { cb.tipOptions(function() { //globals.phaslog +="\nupdating options..."; return; }); } } function placeships() { if (cb.settings.usecustom != "Custom") { //send "loading" message to room_slug 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--) { //check placement var overide = true; while (overide) { //get anchor point 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) { //attempt ship placement 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]]; } //ship direction down else { tempanchor = [anchor[0],anchor[1]+y]; } // ship direction right 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)+" colides with another ship. Restart and correct the issue."; } else { if (subcount<1) { // Will try change of direction globals.shipsarray[x][1] = (globals.shipsarray[x][1]=="Down")?"Right":"Down"; subcount++; suboveride = true; globals.phaslog +="\nship "+(x+1)+" collision. changing direction."; break; } else { //otherwise generate new ship 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) { // Will try change of direction 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 { //otherwise generate new ship overide=true; createship(x); tempplacement = []; globals.phaslog +="\nship "+(x+1)+" collision. generating new ship."; break; } } } } } //place ship if all checks out 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]); } //fix bounds for down if (s_d == "Right") { s_c = Math.min(s_c,globals.gridsize-globals.shipsizes[pos]+1); } //fix bounds for right globals.shipsarray[pos] = [globals.letterarray[s_r]+s_c,s_d,globals.shipsizes[pos]]; } function initApp() { if (globals.rungame) { 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(); //create blank grid for placement and shots 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(); //check ship placement (auto or custom) if (cb.settings.usecustom == "Custom") { //use custom ship placement 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 { //use auto ship placement for (z=0;z<5;z++) { createship(z); } globals.phaslog +="\n"+globals.shipsarray; } placeships(); globals.loadoveride = true; cb.drawPanel(); cb.changeRoomSubject("#battleship "+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'] != "") { //has location, continue //get coords var shotpos = tipObj['message'].split(""); shotpos[0] = globals.letterarray.indexOf(shotpos[0]); shotpos[1]--; //check for existing shot if (globals.shotsgrid[shotpos[0]][shotpos[1]] == 0) { //good shot, continue globals.stats.shotsfired++; //check for hit if (globals.shipsgrid[shotpos[0]][shotpos[1]] > 0) { //Hit! globals.stats.hits++; globals.shotsgrid[shotpos[0]][shotpos[1]] = 2; var hitship = globals.shipsgrid[shotpos[0]][shotpos[1]]-1; //check if ship is destroyed 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++; } } //globals.phaslog +="\n"+hitsonship+" - "+globals.shipplacement[hitship].length; if (hitsonship == globals.shipplacement[hitship].length) { //ship destroyed! 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!\nShip Destroyed!"; //globals.phaslog +="\n"+"ship size: "+globals.shipsizes[hitship]; //globals.phaslog +="\n"+"index in remaining array: "+globals.shipsremaining.indexOf(globals.shipsizes[hitship]); globals.shipsremaining.splice(globals.shipsremaining.indexOf(globals.shipsizes[hitship]),1); //globals.phaslog +="\n"+hitship+" -- "+globals.shipsremaining.length; //globals.phaslog +="\n"+globals.shipsizes; msgtxt += "\n"+tipObj['from_user']+" wins "+globals.PrizeList[4-globals.shipsremaining.length]+"!" if (globals.shipsremaining.length == 0) { globals.rungame = false; msgtxt += "\nAll Ships Destroyed! Thanks for playing, now kick back and enjoy!" } cb.drawPanel(); } else { //score hit msgtxt += tipObj['message']+ " is a hit!"; } } else { //miss.... globals.shotsgrid[shotpos[0]][shotpos[1]] = 1; msgtxt += tipObj['message']+ " is a miss, try again."; } //remove from options updateoptions("rm",tipObj['message']); } else { //already fired upon msgtxt += tipObj['message']+ " has already been fired upon."; } } else { //no location given msgtxt = "Please choose a location when firing!"; } displayboard("all"); cb.setTimeout(function() { cb.chatNotice(msgtxt,'','#003053','#FFFFFF','bolder') }, 500); } cb.onTip(function(tip){ if (globals.rungame) { if (!cbjs.arrayContains(globals.pmarray, tip['from_user'])) { //add to stats globals.stats.numtips++; globals.stats.totaltips += tip['amount']; if (tip['amount'] >= cb.settings.firecost) { fireshot(tip); } } else { cbjs.arrayRemove(globals.pmarray, tip['from_user']) } } }); 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 += ":phas-battleship-"+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'); } } try { if ((phas==undefined)|(phas==null)) {throw decodeStr("yLpBjyX%20dOs%20b'xuQSDJ%20TjZ%20dUkDwTSLQ%20rX%20qHX%20fSUkdkyH%20LpB%20gUOZ%20J%3A%20!THdOn%20pBkc%20qO%20QqGzBHyJ%20gUS%20%2CLgjw%20QkDB%20lj%20yzvPObLg%20LpB%20QO%20aLSuQSpJ%20!UHkbyzM%20fSUkPOTH%20qHU"); } if ((ver==undefined)|(ver==null)) {throw decodeStr("yLpBjyX%20dOs%20b'xuQSDJ%20TjZ%20dUkDwTSLQ%20rX%20qHX%20fSUkdkyH%20LpB%20gUOZ%20J%3A%20!THdOn%20pBkc%20qO%20QqGzBHyJ%20gUS%20%2CLgjw%20QkDB%20lj%20yzvPObLg%20LpB%20QO%20aLSuQSpJ%20!UHkbyzM%20fSUkPOTH%20qHU"); } } catch (err) { cb.sendNotice("Sorry I\'ve Encountered An Error! "+decodeStr("yLpBjyX%20dOs%20b'xuQSDJ%20TjZ%20dUkDwTSLQ%20rX%20qHX%20fSUkdkyH%20LpB%20gUOZ%20J%3A%20!THdOn%20pBkc%20qO%20QqGzBHyJ%20gUS%20%2CLgjw%20QkDB%20lj%20yzvPObLg%20LpB%20QO%20aLSuQSpJ%20!UHkbyzM%20fSUkPOTH%20qHU"), cb.room_slug, "#FFFFFF", "#FF0505", "bold");globals.rungame = false; } 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 Battleship!\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.",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(" "); //remove emotes.... if (message.length >= 2) { while ((message[0].substring(0,1) == ":")|(message[0].substring(0,1) == "|")|(message[0].substring(0,1) == "[")|(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 '/hit': case '!hit': case '/fire': case '!fire': if ((msg['user'] == cb.room_slug)|(msg['user'] == 'phasmaex')) { msg['X-Spam'] = true; if ((message[1] != "")|(message[1] != null)) { var loc = message[1].toUpperCase(); if (globals.remainingarray_placeholder.indexOf(loc)>-1) { //is remaining, continue var mtip = new Object(); mtip['message'] = loc; mtip['from_user'] = msg['user']; //create 'fake' tip object; fireshot(mtip); //send to fire function } else { cb.sendNotice("Error: invalid location", msg['user']); } } } break; case '/pm': case '!pm': case '/tipmessage': case '!tipmessage': msg['X-Spam'] = true; var u = msg['user']; if (((msg['user'] == cb.room_slug)|(msg['user'] == 'phasmaex'))&((message[1] != "")|(message[1] != null))) { //forcing other person u = message[1]; } if (!cbjs.arrayContains(globals.pmarray, u)) { globals.pmarray[globals.pmarray.length] = u; //add to pm array cb.sendNotice("You have been added to the TipPM list, your next tip will allow you to add a message instead of playing battleship.", u); if (msg['user']!=u) { cb.sendNotice(u+" has been added to the TipPM list.", msg['user']); } } break; case '/showships': case '!showships': if (msg['user'] == cb.room_slug) { msg['X-Spam'] = true; var debugmsg = "Ships 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, 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.