PokeBot/util/settings.lua

102 lines
2.1 KiB
Lua
Raw Normal View History

2015-04-06 01:18:46 -07:00
local Settings = {}
2014-07-12 18:47:39 -07:00
2015-04-07 19:06:29 -07:00
local Textbox = require "action.textbox"
2015-04-13 01:18:28 -07:00
local Strategies = require "ai.strategies"
2015-04-07 19:06:29 -07:00
2015-04-08 01:51:38 -07:00
local Bridge = require "util.bridge"
local Input = require "util.input"
2015-04-06 01:18:46 -07:00
local Memory = require "util.memory"
local Menu = require "util.menu"
2014-07-12 18:47:39 -07:00
2015-04-08 01:51:38 -07:00
local START_WAIT = 99
local yellow = YELLOW
2014-07-12 18:47:39 -07:00
local settings_menu
if yellow then
2014-07-12 18:47:39 -07:00
settings_menu = 93
else
settings_menu = 94
end
local desired = {}
if yellow then
2014-07-12 18:47:39 -07:00
desired.text_speed = 1
desired.battle_animation = 128
desired.battle_style = 64
else
desired.text_speed = 1
desired.battle_animation = 10
-- desired.battle_style =
end
local function isEnabled(name)
if yellow then
2014-07-12 18:47:39 -07:00
local matching = {
text_speed = 0xF,
battle_animation = 128,
battle_style = 64
}
2015-04-06 01:18:46 -07:00
local settingMask = Memory.value("setting", "yellow_bitmask", true)
2014-07-12 18:47:39 -07:00
return bit.band(settingMask, matching[name]) == desired[name]
else
2015-04-06 01:18:46 -07:00
return Memory.value("setting", name) == desired[name]
2014-07-12 18:47:39 -07:00
end
end
2015-04-07 19:06:29 -07:00
-- PUBLIC
2015-04-06 01:18:46 -07:00
function Settings.set(...)
2014-07-12 18:47:39 -07:00
for i,name in ipairs(arg) do
if not isEnabled(name) then
2015-04-06 01:18:46 -07:00
if Menu.open(settings_menu, 1) then
Menu.setOption(name, desired[name])
2014-07-12 18:47:39 -07:00
end
return false
end
end
2015-04-06 01:18:46 -07:00
return Menu.cancel(settings_menu)
2014-07-12 18:47:39 -07:00
end
2015-04-08 01:51:38 -07:00
function Settings.startNewAdventure(startWait)
2015-04-07 19:06:29 -07:00
local startMenu, withBattleStyle
if yellow then
startMenu = Memory.raw(0x0F95) == 0
withBattleStyle = "battle_style"
else
startMenu = Memory.value("player", "name") ~= 0
end
if startMenu and Menu.getCol() ~= 0 then
if Settings.set("text_speed", "battle_animation", withBattleStyle) then
Menu.select(0)
end
2015-04-08 01:51:38 -07:00
elseif math.random(0, startWait) == 0 then
2015-04-07 19:06:29 -07:00
Input.press("Start")
end
end
function Settings.choosePlayerNames()
local name
if Memory.value("player", "name2") == 80 then
name = "E"
else
name = "B"
end
Textbox.name(name, true)
end
function Settings.pollForResponse(forcedName)
2015-04-07 19:06:29 -07:00
local response = Bridge.process()
if not INTERNAL or Strategies.replay then
response = forcedName
elseif response then
response = tonumber(response)
end
2015-04-07 19:06:29 -07:00
if response then
Bridge.polling = false
Textbox.setName(response)
2015-04-07 19:06:29 -07:00
end
end
2015-04-06 01:18:46 -07:00
return Settings