Reunify streaming/distribution environments
This commit is contained in:
parent
52232581f2
commit
619c9d295e
|
@ -0,0 +1 @@
|
||||||
|
stream/*
|
|
@ -42,7 +42,8 @@ function textbox.name(letter, randomize)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
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
|
if (memory.raw(0x10B7) == 3) then
|
||||||
input.press("A", 2)
|
input.press("A", 2)
|
||||||
elseif (randomize) then
|
elseif (randomize) then
|
||||||
|
|
|
@ -24,6 +24,11 @@ local function setPath(index, region)
|
||||||
path = paths[index]
|
path = paths[index]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function completeStep(region)
|
||||||
|
stepIdx = stepIdx + 1
|
||||||
|
return walk.traverse(region)
|
||||||
|
end
|
||||||
|
|
||||||
-- Helper functions
|
-- Helper functions
|
||||||
|
|
||||||
function dir(px, py, dx, dy)
|
function dir(px, py, dx, dy)
|
||||||
|
@ -50,11 +55,6 @@ function step(dx, dy)
|
||||||
end
|
end
|
||||||
walk.step = step
|
walk.step = step
|
||||||
|
|
||||||
local function completeStep(region)
|
|
||||||
stepIdx = stepIdx + 1
|
|
||||||
return walk.traverse(region)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Table functions
|
-- Table functions
|
||||||
|
|
||||||
function walk.reset()
|
function walk.reset()
|
||||||
|
|
|
@ -291,7 +291,7 @@ local function isSleeping()
|
||||||
end
|
end
|
||||||
combat.isSleeping = isSleeping
|
combat.isSleeping = isSleeping
|
||||||
|
|
||||||
-- Combat AI functions
|
-- Combat AI
|
||||||
|
|
||||||
function combat.factorPP(enabled)
|
function combat.factorPP(enabled)
|
||||||
enablePP = enabled
|
enablePP = enabled
|
||||||
|
|
44
main.lua
44
main.lua
|
@ -3,13 +3,13 @@
|
||||||
GAME_NAME = "red" -- Only currently supported option
|
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
|
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 CUSTOM_SEED = nil -- Set to a known seed to replay it, or leave nil for random runs
|
||||||
local PAINT_ON = true -- Displays contextual information while the bot runs
|
local PAINT_ON = true -- Display contextual information while the bot runs
|
||||||
|
|
||||||
-- Start code (hard hats on)
|
-- Start code (hard hats on)
|
||||||
|
|
||||||
local START_WAIT = 99
|
local START_WAIT = 99
|
||||||
local VERSION = "1.0"
|
local VERSION = "1.1"
|
||||||
|
|
||||||
local battle = require "action.battle"
|
local battle = require "action.battle"
|
||||||
local textbox = require "action.textbox"
|
local textbox = require "action.textbox"
|
||||||
|
@ -29,7 +29,8 @@ local settings = require "util.settings"
|
||||||
|
|
||||||
local pokemon = require "storage.pokemon"
|
local pokemon = require "storage.pokemon"
|
||||||
|
|
||||||
local YELLOW = GAME_NAME == "yellow"
|
YELLOW = GAME_NAME == "yellow"
|
||||||
|
INTERNAL = false
|
||||||
|
|
||||||
local hasAlreadyStartedPlaying = false
|
local hasAlreadyStartedPlaying = false
|
||||||
local inBattle, oldSecs
|
local inBattle, oldSecs
|
||||||
|
@ -58,7 +59,7 @@ end
|
||||||
local function choosePlayerNames()
|
local function choosePlayerNames()
|
||||||
local name
|
local name
|
||||||
if (memory.value("player", "name2") == 80) then
|
if (memory.value("player", "name2") == 80) then
|
||||||
name = "W"
|
name = "E"
|
||||||
else
|
else
|
||||||
name = "B"
|
name = "B"
|
||||||
end
|
end
|
||||||
|
@ -84,6 +85,7 @@ local function resetAll()
|
||||||
running = false
|
running = false
|
||||||
previousPartySize = 0
|
previousPartySize = 0
|
||||||
-- client.speedmode = 200
|
-- client.speedmode = 200
|
||||||
|
|
||||||
if (CUSTOM_SEED) then
|
if (CUSTOM_SEED) then
|
||||||
strategies.seed = CUSTOM_SEED
|
strategies.seed = CUSTOM_SEED
|
||||||
print("RUNNING WITH A FIXED SEED ("..strategies.seed.."), every run will play out identically!")
|
print("RUNNING WITH A FIXED SEED ("..strategies.seed.."), every run will play out identically!")
|
||||||
|
@ -96,7 +98,11 @@ end
|
||||||
-- Execute
|
-- Execute
|
||||||
|
|
||||||
print("Welcome to PokeBot "..GAME_NAME.." version "..VERSION)
|
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
|
if (CUSTOM_SEED) then
|
||||||
client.reboot_core()
|
client.reboot_core()
|
||||||
else
|
else
|
||||||
|
@ -108,12 +114,14 @@ if (RESET_FOR_TIME and hasAlreadyStartedPlaying) then
|
||||||
RESET_FOR_TIME = false
|
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.")
|
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
|
end
|
||||||
if (productionMode) then
|
if (STREAMING_MODE) then
|
||||||
bridge.init()
|
bridge.init()
|
||||||
else
|
else
|
||||||
input.setDebug(true)
|
input.setDebug(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Main loop
|
||||||
|
|
||||||
local previousMap
|
local previousMap
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
|
@ -122,6 +130,16 @@ while true do
|
||||||
input.clear()
|
input.clear()
|
||||||
previousMap = currentMap
|
previousMap = currentMap
|
||||||
end
|
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 input.update()) then
|
||||||
if (not utils.ingame()) then
|
if (not utils.ingame()) then
|
||||||
if (currentMap == 0) then
|
if (currentMap == 0) then
|
||||||
|
@ -171,6 +189,10 @@ while true do
|
||||||
inBattle = false
|
inBattle = false
|
||||||
end
|
end
|
||||||
local currentHP = pokemon.index(0, "hp")
|
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
|
if (currentHP == 0 and not strategies.canDie and pokemon.index(0) > 0) then
|
||||||
strategies.death(currentMap)
|
strategies.death(currentMap)
|
||||||
elseif (walk.strategy) then
|
elseif (walk.strategy) then
|
||||||
|
@ -187,7 +209,13 @@ while true do
|
||||||
end
|
end
|
||||||
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)
|
paint.draw(currentMap)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
local bridge = {}
|
local bridge = {}
|
||||||
|
|
||||||
|
local socket
|
||||||
|
if INTERNAL then
|
||||||
|
socket = require("socket")
|
||||||
|
end
|
||||||
|
|
||||||
local utils = require("util.utils")
|
local utils = require("util.utils")
|
||||||
|
|
||||||
local client = nil
|
local client = nil
|
||||||
|
@ -11,19 +16,19 @@ local function send(prefix, body)
|
||||||
if (body) then
|
if (body) then
|
||||||
message = message..","..body
|
message = message..","..body
|
||||||
end
|
end
|
||||||
client:send(message..'\n')
|
client:send(message.."\n")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function readln()
|
local function readln()
|
||||||
if (client) then
|
if (client) then
|
||||||
local s, status, partial = client:receive('*l')
|
local s, status, partial = client:receive("*l")
|
||||||
if status == "closed" then
|
if status == "closed" then
|
||||||
client = nil
|
client = nil
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if s and s ~= '' then
|
if s and s ~= "" then
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -32,10 +37,22 @@ end
|
||||||
-- Wrapper functions
|
-- Wrapper functions
|
||||||
|
|
||||||
function bridge.init()
|
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
|
end
|
||||||
|
|
||||||
function bridge.tweet(message) -- Two of the same tweet in a row will only send one
|
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)
|
return send("tweet", message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,17 +81,17 @@ function bridge.stats(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
function bridge.command(command)
|
function bridge.command(command)
|
||||||
return send("livesplit_command", command)
|
return send("livesplit_command", command);
|
||||||
end
|
end
|
||||||
|
|
||||||
function bridge.comparisonTime()
|
function bridge.comparisonTime()
|
||||||
return send("livesplit_getcomparisontime")
|
return send("livesplit_getcomparisontime");
|
||||||
end
|
end
|
||||||
|
|
||||||
function bridge.process()
|
function bridge.process()
|
||||||
local response = readln()
|
local response = readln()
|
||||||
if (response) then
|
if (response) then
|
||||||
-- print('>'..response)
|
-- print(">"..response)
|
||||||
if (response:find("name:")) then
|
if (response:find("name:")) then
|
||||||
return response:gsub("name:", "")
|
return response:gsub("name:", "")
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue