Standardize check for main battle menu

This commit is contained in:
Kyle Coburn 2015-04-24 21:03:06 -07:00
parent a5fe63e8c3
commit 7521250a5c
4 changed files with 20 additions and 17 deletions

View File

@ -79,7 +79,7 @@ local function openBattleMenu()
local col = Menu.getCol()
if battleMenu == 106 or (battleMenu == 94 and col == 5) then
return true
elseif battleMenu == 94 then
elseif Menu.onBattleSelect(battleMenu) then
local rowSelected = Memory.value("menu", "row")
if col == 9 then
if rowSelected == 1 then
@ -168,7 +168,7 @@ end
function Battle.run()
if not Battle.opponentAlive() then
Input.cancel()
elseif Memory.value("battle", "menu") ~= 94 then
elseif not Menu.onBattleSelect() then
if Memory.value("menu", "text_length") == 127 then
Input.press("B")
else
@ -226,14 +226,13 @@ function Battle.fight(move, skipBuffs)
end
function Battle.swap(target)
local battleMenu = Memory.value("battle", "menu")
if Menu.onPokemonSelect(battleMenu) then
if Menu.onPokemonSelect() then
if Menu.getCol() == 0 then
Pokemon.select(target)
else
Input.press("A")
end
elseif battleMenu == 94 then
elseif Menu.onBattleSelect() then
local selected = Memory.value("menu", "selection")
if selected == 199 then
Input.press("A", 2)

View File

@ -6,6 +6,7 @@ local Strategies
local Bridge = require "util.bridge"
local Memory = require "util.memory"
local Menu = require "util.menu"
local Paint = require "util.paint"
local Utils = require "util.utils"
@ -293,8 +294,7 @@ function Control.encounter(battleState)
if battleState > 0 then
local wildBattle = battleState == 1
local isCritical
local battleMenu = Memory.value("battle", "menu")
if battleMenu == 94 then
if Menu.onBattleSelect() then
isCritical = false
Control.missed = false
elseif Memory.double("battle", "our_hp") == 0 then

View File

@ -391,7 +391,7 @@ strategyFunctions.catchNidoran = function()
Input.cancel()
end
else
if Memory.value("battle", "menu") == 94 then
if Menu.onBattleSelect() then
local resetLimit = Strategies.getTimeRequirement("nidoran")
local catchTarget
if catchableNidoran or opponent == "spearow" then
@ -840,7 +840,7 @@ strategyFunctions.rivalSandAttack = function(data)
end
local opponent = Battle.opponent()
if Memory.value("battle", "accuracy") < 7 then
if Combat.sandAttacked() then
local sacrifice
if opponent == "pidgeotto" then
local __, turnsToKill = Combat.bestMove()

View File

@ -12,7 +12,7 @@ local alternateStart = 0
Menu.pokemon = yellow and 51 or 103
-- Private functions
-- PRIVATE
local function getRow(menuType, scrolls)
if menuType and menuType == "settings" then
@ -57,7 +57,7 @@ local function isCurrently(desired, menuType)
end
Menu.isCurrently = isCurrently
-- Menu
-- HELPERS
function Menu.getCol()
return Memory.value("menu", "column")
@ -92,7 +92,7 @@ function Menu.cancel(desired, menuType)
return false
end
-- Selections
-- SELECT
function Menu.balance(current, desired, inverted, looping, throttle)
if current == desired then
@ -141,7 +141,7 @@ function Menu.setCol(desired)
return Menu.sidle(Menu.getCol(), desired)
end
-- Options
-- OPTIONS
function Menu.setOption(name, desired)
if yellow then
@ -170,10 +170,8 @@ function Menu.setOption(name, desired)
return false
end
-- Pause menu
function Menu.hasTextbox()
return Memory.value("battle", "menu") == (yellow and 19 or 95)
function Menu.onBattleSelect()
return Memory.value("battle", "menu") == 94
end
function Menu.onPokemonSelect(battleMenu)
@ -186,6 +184,12 @@ function Menu.onPokemonSelect(battleMenu)
return battleMenu == 8 or battleMenu == 48 or battleMenu == 184 or battleMenu == 224
end
-- PAUSED
function Menu.hasTextbox()
return Memory.value("battle", "menu") == (yellow and 19 or 95)
end
function Menu.isOpened()
return Memory.value("game", "textbox") == 1
end