PokeBot/action/textbox.lua

93 lines
2.0 KiB
Lua
Raw Normal View History

2014-07-12 18:47:39 -07:00
local textbox = {}
local input = require "util.input"
local memory = require "util.memory"
local menu = require "util.menu"
local utils = require "util.utils"
local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ *():;[]ab-?!mf/.,"
-- local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ *():;[]ポモ-?!♂♀/.,"
2014-07-12 18:47:39 -07:00
local nidoName = "A"
local nidoIdx = 1
local function getLetterAt(index)
return alphabet:sub(index, index)
2014-07-12 18:47:39 -07:00
end
local function getIndexForLetter(letter)
return alphabet:find(letter, 1, true)
end
function textbox.name(letter, randomize)
local inputting = memory.value("menu", "text_input") == 240
if inputting then
if memory.value("menu", "text_length") > 0 then
2014-07-12 18:47:39 -07:00
input.press("Start")
return true
end
local lidx
if letter then
2014-07-12 18:47:39 -07:00
lidx = getIndexForLetter(letter)
else
lidx = nidoIdx
end
local crow = memory.value("menu", "input_row")
local drow = math.ceil(lidx / 9)
if menu.balance(crow, drow, true, 6, true) then
2014-07-12 18:47:39 -07:00
local ccol = math.floor(memory.value("menu", "column") / 2)
local dcol = math.fmod(lidx - 1, 9)
if menu.sidle(ccol, dcol, 9, true) then
2014-07-12 18:47:39 -07:00
input.press("A")
end
end
else
-- TODO cancel when menu isn't up
-- if memory.value("menu", "current") == 7 then
if memory.raw(0x10B7) == 3 then
2014-07-12 18:47:39 -07:00
input.press("A", 2)
elseif randomize then
2014-07-12 18:47:39 -07:00
input.press("A", math.random(1, 5))
else
input.cancel()
end
end
end
function textbox.getName()
if nidoName == "a" then
return ""
end
if nidoName == "b" then
return ""
end
if nidoName == "m" then
return ""
end
if nidoName == "f" then
return ""
end
2014-07-12 18:47:39 -07:00
return nidoName
end
function textbox.setName(index)
if index >= 0 and index < #alphabet then
nidoIdx = index + 1
nidoName = getLetterAt(index)
end
2014-07-12 18:47:39 -07:00
end
function textbox.isActive()
return memory.value("game", "textbox") == 1
end
function textbox.handle()
if not textbox.isActive() then
2014-07-12 18:47:39 -07:00
return true
end
input.cancel()
end
return textbox