diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..afd0aa8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +stream/* diff --git a/action/textbox.lua b/action/textbox.lua index 707d184..4050996 100644 --- a/action/textbox.lua +++ b/action/textbox.lua @@ -42,7 +42,8 @@ function textbox.name(letter, randomize) end end else - -- TODO cancel more when menu isn't up + -- TODO cancel when menu isn't up + -- if (memory.value("menu", "current") == 7) then if (memory.raw(0x10B7) == 3) then input.press("A", 2) elseif (randomize) then diff --git a/action/walk.lua b/action/walk.lua index 4df5bfc..7e5ff60 100644 --- a/action/walk.lua +++ b/action/walk.lua @@ -24,6 +24,11 @@ local function setPath(index, region) path = paths[index] end +local function completeStep(region) + stepIdx = stepIdx + 1 + return walk.traverse(region) +end + -- Helper functions function dir(px, py, dx, dy) @@ -50,11 +55,6 @@ function step(dx, dy) end walk.step = step -local function completeStep(region) - stepIdx = stepIdx + 1 - return walk.traverse(region) -end - -- Table functions function walk.reset() diff --git a/ai/combat.lua b/ai/combat.lua index c4e8d56..4e8d380 100644 --- a/ai/combat.lua +++ b/ai/combat.lua @@ -291,7 +291,7 @@ local function isSleeping() end combat.isSleeping = isSleeping --- Combat AI functions +-- Combat AI function combat.factorPP(enabled) enablePP = enabled diff --git a/main.lua b/main.lua index 7a6e4e5..996b643 100644 --- a/main.lua +++ b/main.lua @@ -1,15 +1,15 @@ -- Customization settings -GAME_NAME = "red" -- Only currently supported option -RESET_FOR_TIME = true -- Set to false if you just want to see the bot finish a run +GAME_NAME = "red" -- Only currently supported option +RESET_FOR_TIME = true -- Set to false if you just want to see the bot finish a run -local CUSTOM_SEED = nil -- Set to a known seed to replay it, or leave nil for random ones -local PAINT_ON = true -- Displays contextual information while the bot runs +local CUSTOM_SEED = nil -- Set to a known seed to replay it, or leave nil for random runs +local PAINT_ON = true -- Display contextual information while the bot runs -- Start code (hard hats on) local START_WAIT = 99 -local VERSION = "1.0" +local VERSION = "1.1" local battle = require "action.battle" local textbox = require "action.textbox" @@ -29,7 +29,8 @@ local settings = require "util.settings" local pokemon = require "storage.pokemon" -local YELLOW = GAME_NAME == "yellow" +YELLOW = GAME_NAME == "yellow" +INTERNAL = false local hasAlreadyStartedPlaying = false local inBattle, oldSecs @@ -58,7 +59,7 @@ end local function choosePlayerNames() local name if (memory.value("player", "name2") == 80) then - name = "W" + name = "E" else name = "B" end @@ -84,6 +85,7 @@ local function resetAll() running = false previousPartySize = 0 -- client.speedmode = 200 + if (CUSTOM_SEED) then strategies.seed = CUSTOM_SEED print("RUNNING WITH A FIXED SEED ("..strategies.seed.."), every run will play out identically!") @@ -96,7 +98,11 @@ end -- Execute print("Welcome to PokeBot "..GAME_NAME.." version "..VERSION) -local productionMode = not walk.init() and false +STREAMING_MODE = not walk.init() +if STREAMING_MODE then + RESET_FOR_TIME = true +end +-- STREAMING_MODE = false --TODO disable if (CUSTOM_SEED) then client.reboot_core() else @@ -108,12 +114,14 @@ if (RESET_FOR_TIME and hasAlreadyStartedPlaying) then RESET_FOR_TIME = false print("Disabling time-limit resets as the game is already running. Please reset the emulator and restart the script if you'd like to go for a fast time.") end -if (productionMode) then +if (STREAMING_MODE) then bridge.init() else input.setDebug(true) end +-- Main loop + local previousMap while true do @@ -122,6 +130,16 @@ while true do input.clear() previousMap = currentMap end + if (strategies.frames) then + if (memory.value("game", "battle") == 0) then + strategies.frames = strategies.frames + 1 + end + gui.text(0, 80, strategies.frames) + end + if (bridge.polling) then + pollForResponse() + end + if (not input.update()) then if (not utils.ingame()) then if (currentMap == 0) then @@ -171,6 +189,10 @@ while true do inBattle = false end local currentHP = pokemon.index(0, "hp") + -- if (currentHP ~= lastHP) then + -- bridge.hp(currentHP, pokemon.index(0, "max_hp")) + -- lastHP = currentHP + -- end if (currentHP == 0 and not strategies.canDie and pokemon.index(0) > 0) then strategies.death(currentMap) elseif (walk.strategy) then @@ -187,7 +209,13 @@ while true do end end - if (PAINT_ON) then + if (STREAMING_MODE) then + local newSecs = memory.raw(0xDA44) + if (newSecs ~= oldSecs and (newSecs > 0 or memory.raw(0xDA45) > 0)) then + bridge.time(paint.elapsedTime()) + oldSecs = newSecs + end + elseif (PAINT_ON) then paint.draw(currentMap) end diff --git a/util/bridge.lua b/util/bridge.lua index 461ee81..641a7fc 100644 --- a/util/bridge.lua +++ b/util/bridge.lua @@ -1,5 +1,10 @@ local bridge = {} +local socket +if INTERNAL then + socket = require("socket") +end + local utils = require("util.utils") local client = nil @@ -11,19 +16,19 @@ local function send(prefix, body) if (body) then message = message..","..body end - client:send(message..'\n') + client:send(message.."\n") return true end end local function readln() if (client) then - local s, status, partial = client:receive('*l') + local s, status, partial = client:receive("*l") if status == "closed" then client = nil return nil end - if s and s ~= '' then + if s and s ~= "" then return s end end @@ -32,10 +37,22 @@ end -- Wrapper functions function bridge.init() + if socket then + -- io.popen("java -jar Main.jar") + client = socket.connect("127.0.0.1", 13378) + if (client) then + client:settimeout(0.005) + client:setoption("keepalive", true) + print("Connected to Java!"); + return true + else + print("Error connecting to Java!"); + end + end end function bridge.tweet(message) -- Two of the same tweet in a row will only send one - print('tweet::'..message) + print("tweet::"..message) return send("tweet", message) end @@ -64,17 +81,17 @@ function bridge.stats(message) end function bridge.command(command) - return send("livesplit_command", command) + return send("livesplit_command", command); end function bridge.comparisonTime() - return send("livesplit_getcomparisontime") + return send("livesplit_getcomparisontime"); end function bridge.process() local response = readln() if (response) then - -- print('>'..response) + -- print(">"..response) if (response:find("name:")) then return response:gsub("name:", "") else