Last active
September 23, 2022 15:26
-
-
Save at15four2020/18a570bcc14c234b59d76e511aba05d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof FFBot == "undefined") { | |
FFBot = (function() { | |
if (typeof PrivateChatManager == 'undefined') { | |
load("https://gist.githubusercontent.com/at15four2020/7a380485e641fb48e9a30593869c1150/raw/PrivateChatManager.gprog.js") | |
} | |
if (typeof BlockProgramming == 'undefined') { | |
load('https://gist.github.com/at15four2020/6b405f224d91fa50975546031f764aec/raw/BlockProgramming.gprog.js') | |
} | |
let chat | |
let myId | |
let areas = [] | |
let setupStep = 0 | |
let setupArea | |
// 0: not in setup | |
// 1: myId - {out:GetSelectedBadges}{i:[id here]} | |
// 2: use the tri lever - {out:UseFurniture}{i:[uid here]}{i:0} | |
// 3: click at the 1st tri place: {out:MoveAvatar}{i:[x here]}{i:[y here]} | |
// 4: click at the 2st tri place: {out:MoveAvatar}{i:[x here]}{i:[y here]} | |
// 5: click at the 3st tri place: {out:MoveAvatar}{i:[x here]}{i:[y here]} | |
// 6: click at the tri target: {out:MoveAvatar}{i:[x here]}{i:[y here]} | |
// 7: use the duo lever: {out:UseFurniture}{i:[uid here]}{i:0} | |
// 8: click at the 1st duo place: {out:MoveAvatar}{i:[x here]}{i:[y here]} | |
// 9: click at the 2st duo place: {out:MoveAvatar}{i:[x here]}{i:[y here]} | |
// 10: click at the duo target: {out:MoveAvatar}{i:[x here]}{i:[y here]} | |
// complete | |
const when = BlockProgramming.when | |
const object = BlockProgramming.object | |
const avatar = BlockProgramming.avatar | |
const moveTo = BlockProgramming.ACTIONS.moveTo | |
function safeSendMessage(message) { | |
if (chat) chat.sendMessage(message) | |
else print(message) | |
} | |
function initBlocks(area) { | |
if (!area) { | |
safeSendMessage("Area not defined. Need help? Type :help") | |
return | |
} | |
// tri | |
when(object(area.tri.lever).changeState()) | |
.if(avatar(myId).inPlace(area.tri.places[0].x, area.tri.places[0].y)) | |
.do(moveTo(area.tri.target.x, area.tri.target.y)) | |
when(object(area.tri.lever).changeState()) | |
.if(avatar(myId).inPlace(area.tri.places[1].x, area.tri.places[1].y)) | |
.do(moveTo(area.tri.target.x, area.tri.target.y)) | |
when(object(area.tri.lever).changeState()) | |
.if(avatar(myId).inPlace(area.tri.places[2].x, area.tri.places[2].y)) | |
.do(moveTo(area.tri.target.x, area.tri.target.y)) | |
// duo | |
when(object(area.duo.lever).changeState()) | |
.if(avatar(myId).inPlace(area.duo.places[0].x, area.duo.places[0].y)) | |
.do(moveTo(area.duo.target.x, area.duo.target.y)) | |
when(object(area.duo.lever).changeState()) | |
.if(avatar(myId).inPlace(area.duo.places[1].x, area.duo.places[1].y)) | |
.do(moveTo(area.duo.target.x, area.duo.target.y)) | |
} | |
function needsImplementation() { | |
safeSendMessage("This feature is not implemented yet.") | |
} | |
function handleHelp() { | |
needsImplementation() | |
} | |
function handleInitSetup(message, command) { | |
if (command.extra == "") { | |
safeSendMessage("Please, define the area name, like this: \":initsetup AREA_NAME\"") | |
return | |
} | |
setupStep = 1 | |
setupArea = { | |
name: command.extra, | |
tri: { | |
places: [], | |
target: {}, | |
}, | |
duo: { | |
places: [], | |
target: {}, | |
}, | |
} | |
safeSendMessage("Setup started.") | |
safeSendMessage(setupStep+"/10 First, click on your avatar. I'll grab your ID.") | |
} | |
function handleEndSetup() { | |
if (setupStep == 0) { | |
safeSendMessage("Setup not started.") | |
return | |
} | |
safeSendMessage("Setup stopped, current data discated.") | |
setupArea = {} | |
} | |
function handleStart(message, command) { | |
let area | |
areas.forEach(function(a) { if (a.name == command.extra) { area = a } }) | |
if (!area) { | |
safeSendMessage("Area "+command.extra+" not found.") | |
return | |
} | |
initBlocks(area) | |
safeSendMessage("Make sure to reenter the room.") | |
} | |
function handleStop() { | |
BlockProgramming.exit() | |
} | |
function handleExport() { | |
let result = "FFBot.importConfig(" | |
result += JSON.stringify({ | |
myId: myId, | |
areas: areas, | |
}, null, 2) | |
result += ")" | |
print(result) | |
safeSendMessage("I've sent the import code in the log, so you can copy&paste.") | |
safeSendMessage("You just have to paste it at the end of your (left) code.") | |
} | |
function handleImportConfig(config) { | |
myId = config.myId | |
areas = config.areas | |
} | |
function initCommands() { | |
if (!chat) return | |
chat.handleCommand("help", handleHelp) | |
// chat.handleCommand("h", handleHelp) | |
chat.handleCommand("initsetup", handleInitSetup) | |
// chat.handleCommand("ss", handleStartSetup) | |
chat.handleCommand("endsetup", handleEndSetup) | |
// chat.handleCommand("Ss", handleStopSetup) | |
chat.handleCommand("checkarea", handleEndSetup) | |
// chat.handleCommand("ca", handleStopSetup) | |
chat.handleCommand("start", handleStart) | |
// chat.handleCommand("s", handleStart) | |
chat.handleCommand("stop", handleStop) | |
// chat.handleCommand("S", handleStop) | |
chat.handleCommand("export", handleExport) | |
// chat.handleCommand("e", handleExport) | |
} | |
function handleSelectedBadges(message) { | |
if (setupStep != 1) return | |
message.setBlocked(true) | |
const packet = message.getPacket() | |
myId = packet.readInteger() | |
safeSendMessage("ID grabbed: "+myId) | |
setupStep = 2 | |
safeSendMessage(setupStep+"/10 Now, use the lever corresponding to the TRI match, I'll grab it's uID.") | |
} | |
function handleUseFurni(message) { | |
if (setupStep != 2 && setupStep != 7) return | |
message.setBlocked(true) | |
const packet = message.getPacket() | |
if (setupStep == 2) { | |
setupArea.tri.lever = packet.readInteger() | |
safeSendMessage("TRI lever uID grabbed: "+setupArea.tri.lever) | |
setupStep = 3 | |
safeSendMessage(setupStep+"/10 Now, click at the 1/3 tile corresponding to the TRI match, I'll grab it's coords.") | |
} else if (setupStep == 7) { | |
setupArea.duo.lever = packet.readInteger() | |
safeSendMessage("DUO lever uID grabbed: "+setupArea.duo.lever) | |
setupStep = 8 | |
safeSendMessage(setupStep+"/10 Now, click at the 1/2 tile corresponding to the DUO match, I'll grab it's coords.") | |
} | |
} | |
function handleMoveAvatar(message) { | |
if ([3, 4, 5, 6, 8, 9, 10].indexOf(setupStep) == -1) return | |
message.setBlocked(true) | |
const packet = message.getPacket() | |
if (setupStep == 3) { | |
setupArea.tri.places[0] = {} | |
setupArea.tri.places[0].x = packet.readInteger() | |
setupArea.tri.places[0].y = packet.readInteger() | |
safeSendMessage("TRI 1/3 tile coord grabbed: "+setupArea.tri.places[0].x+"x"+setupArea.tri.places[0].y) | |
setupStep = 4 | |
safeSendMessage(setupStep+"/10 Now, click at the 2/3 tile corresponding to the TRI match.") | |
} else if (setupStep == 4) { | |
setupArea.tri.places[1] = {} | |
setupArea.tri.places[1].x = packet.readInteger() | |
setupArea.tri.places[1].y = packet.readInteger() | |
safeSendMessage("TRI 2/3 tile coord grabbed: "+setupArea.tri.places[1].x+"x"+setupArea.tri.places[1].y) | |
setupStep = 5 | |
safeSendMessage(setupStep+"/10 Now, click at the 3/3 tile corresponding to the TRI match.") | |
} else if (setupStep == 5) { | |
setupArea.tri.places[2] = {} | |
setupArea.tri.places[2].x = packet.readInteger() | |
setupArea.tri.places[2].y = packet.readInteger() | |
safeSendMessage("TRI 3/3 tile coord grabbed: "+setupArea.tri.places[2].x+"x"+setupArea.tri.places[2].y) | |
setupStep = 6 | |
safeSendMessage(setupStep+"/10 Now, click at the target tile (middle tile) corresponding to the TRI match.") | |
} else if (setupStep == 6) { | |
setupArea.tri.target.x = packet.readInteger() | |
setupArea.tri.target.y = packet.readInteger() | |
safeSendMessage("TRI target tile coord grabbed: "+setupArea.tri.target.x+"x"+setupArea.tri.target.y) | |
setupStep = 7 | |
safeSendMessage(setupStep+"/10 Now, use the lever corresponding to the DUO match, I'll grab it's uID.") | |
} else if (setupStep == 8) { | |
setupArea.duo.places[0] = {} | |
setupArea.duo.places[0].x = packet.readInteger() | |
setupArea.duo.places[0].y = packet.readInteger() | |
safeSendMessage("DUO 1/2 tile coord grabbed: "+setupArea.duo.places[0].x+"x"+setupArea.duo.places[0].y) | |
setupStep = 9 | |
safeSendMessage(setupStep+"/10 Now, click at the 2/2 tile corresponding to the DUO match.") | |
} else if (setupStep == 9) { | |
setupArea.duo.places[1] = {} | |
setupArea.duo.places[1].x = packet.readInteger() | |
setupArea.duo.places[1].y = packet.readInteger() | |
safeSendMessage("DUO 2/2 tile coord grabbed: "+setupArea.duo.places[1].x+"x"+setupArea.duo.places[1].y) | |
setupStep = 10 | |
safeSendMessage(setupStep+"/10 Now, click at the target tile (middle tile) corresponding to the DUO match.") | |
} else if (setupStep == 10) { | |
setupArea.duo.target.x = packet.readInteger() | |
setupArea.duo.target.y = packet.readInteger() | |
safeSendMessage("DUO target tile coord grabbed: "+setupArea.duo.target.x+"x"+setupArea.duo.target.y) | |
setupStep = 0 | |
safeSendMessage("Setup complete. Now you can use this config with the command \":start "+setupArea.name+"\". I recommend you to export it and save the file.") | |
areas.push(setupArea) | |
setupArea = undefined | |
} | |
} | |
function initIntercepting() { | |
interceptToServer("GetSelectedBadges", handleSelectedBadges) | |
interceptToServer("UseFurniture", handleUseFurni) | |
interceptToServer("MoveAvatar", handleMoveAvatar) | |
} | |
function init() { | |
chat = PrivateChatManager("Bot FF") | |
safeSendMessage("Hi, let's win together!") | |
initCommands() | |
initIntercepting() | |
BlockProgramming.init() | |
} | |
return { | |
init: init, | |
autoStart: function(name) { handleStart(null, { extra: name } )}, | |
initSetup: handleInitSetup, | |
importConfig: handleImportConfig, | |
} | |
})() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment