Refactor remove enclosing parenthesis from condition statements
This commit is contained in:
parent
b08d7cef82
commit
9672ed3090
|
@ -14,20 +14,20 @@ local inventory = require "storage.inventory"
|
|||
local pokemon = require "storage.pokemon"
|
||||
|
||||
local function potionsForHit(potion, currHP, maxHP)
|
||||
if (not potion) then
|
||||
if not potion then
|
||||
return
|
||||
end
|
||||
local ours, killAmount = combat.inKillRange()
|
||||
if (ours) then
|
||||
if ours then
|
||||
local potionHP
|
||||
if (potion == "full_restore") then
|
||||
if potion == "full_restore" then
|
||||
potionHP = 999
|
||||
elseif (potion == "super_potion") then
|
||||
elseif potion == "super_potion" then
|
||||
potionHP = 50
|
||||
else
|
||||
potionHP = 20
|
||||
end
|
||||
if (not currHP) then
|
||||
if not currHP then
|
||||
currHP = pokemon.index(0, "hp")
|
||||
maxHP = pokemon.index(0, "max_hp")
|
||||
end
|
||||
|
@ -37,15 +37,15 @@ end
|
|||
battle.potionsForHit = potionsForHit
|
||||
|
||||
local function recover()
|
||||
if (control.canRecover()) then
|
||||
if control.canRecover() then
|
||||
local currentHP = pokemon.index(0, "hp")
|
||||
if (currentHP > 0) then
|
||||
if currentHP > 0 then
|
||||
local maxHP = pokemon.index(0, "max_hp")
|
||||
if (currentHP < maxHP) then
|
||||
if currentHP < maxHP then
|
||||
local first, second
|
||||
if (potionIn == "full") then
|
||||
if potionIn == "full" then
|
||||
first, second = "full_restore", "super_potion"
|
||||
if (maxHP - currentHP > 54) then
|
||||
if maxHP - currentHP > 54 then
|
||||
first = "full_restore"
|
||||
second = "super_potion"
|
||||
else
|
||||
|
@ -53,7 +53,7 @@ local function recover()
|
|||
second = "full_restore"
|
||||
end
|
||||
else
|
||||
if (maxHP - currentHP > 22) then
|
||||
if maxHP - currentHP > 22 then
|
||||
first = "super_potion"
|
||||
second = "potion"
|
||||
else
|
||||
|
@ -62,16 +62,16 @@ local function recover()
|
|||
end
|
||||
end
|
||||
local potion = inventory.contains(first, second)
|
||||
if (potionsForHit(potion, currentHP, maxHP)) then
|
||||
if potionsForHit(potion, currentHP, maxHP) then
|
||||
inventory.use(potion, nil, true)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if (memory.value("battle", "paralyzed") == 64) then
|
||||
if memory.value("battle", "paralyzed") == 64 then
|
||||
local heals = inventory.contains("paralyze_heal", "full_restore")
|
||||
if (heals) then
|
||||
if heals then
|
||||
inventory.use(heals, nil, true)
|
||||
return true
|
||||
end
|
||||
|
@ -79,18 +79,18 @@ local function recover()
|
|||
end
|
||||
|
||||
local function openBattleMenu()
|
||||
if (memory.value("battle", "text") == 1) then
|
||||
if memory.value("battle", "text") == 1 then
|
||||
input.cancel()
|
||||
return false
|
||||
end
|
||||
local battleMenu = memory.value("battle", "menu")
|
||||
local col = menu.getCol()
|
||||
if (battleMenu == 106 or (battleMenu == 94 and col == 5)) then
|
||||
if battleMenu == 106 or (battleMenu == 94 and col == 5) then
|
||||
return true
|
||||
elseif (battleMenu == 94) then
|
||||
elseif battleMenu == 94 then
|
||||
local rowSelected = memory.value("menu", "row")
|
||||
if (col == 9) then
|
||||
if (rowSelected == 1) then
|
||||
if col == 9 then
|
||||
if rowSelected == 1 then
|
||||
input.press("Up")
|
||||
else
|
||||
input.press("A")
|
||||
|
@ -104,9 +104,9 @@ local function openBattleMenu()
|
|||
end
|
||||
|
||||
local function attack(attackIndex)
|
||||
if (memory.double("battle", "opponent_hp") < 1) then
|
||||
if memory.double("battle", "opponent_hp") < 1 then
|
||||
input.cancel()
|
||||
elseif (openBattleMenu()) then
|
||||
elseif openBattleMenu() then
|
||||
menu.select(attackIndex, true, false, false, false, 3)
|
||||
end
|
||||
end
|
||||
|
@ -114,15 +114,15 @@ end
|
|||
-- Table functions
|
||||
|
||||
function battle.swapMove(sidx, fidx)
|
||||
if (openBattleMenu()) then
|
||||
if openBattleMenu() then
|
||||
local selection = memory.value("menu", "selection_mode")
|
||||
local swapSelect
|
||||
if (selection == sidx) then
|
||||
if selection == sidx then
|
||||
swapSelect = fidx
|
||||
else
|
||||
swapSelect = sidx
|
||||
end
|
||||
if (menu.select(swapSelect, false, false, nil, true, 3)) then
|
||||
if menu.select(swapSelect, false, false, nil, true, 3) then
|
||||
input.press("Select")
|
||||
end
|
||||
end
|
||||
|
@ -134,10 +134,10 @@ end
|
|||
|
||||
function battle.isTrainer()
|
||||
local battleType = memory.value("game", "battle")
|
||||
if (battleType == 2) then
|
||||
if battleType == 2 then
|
||||
return true
|
||||
end
|
||||
if (battleType == 1) then
|
||||
if battleType == 1 then
|
||||
battle.run()
|
||||
else
|
||||
textbox.handle()
|
||||
|
@ -149,17 +149,17 @@ function battle.opponent()
|
|||
end
|
||||
|
||||
function battle.run()
|
||||
if (memory.double("battle", "opponent_hp") < 1) then
|
||||
if memory.double("battle", "opponent_hp") < 1 then
|
||||
input.cancel()
|
||||
elseif (memory.value("battle", "menu") ~= 94) then
|
||||
if (memory.value("menu", "text_length") == 127) then
|
||||
elseif memory.value("battle", "menu") ~= 94 then
|
||||
if memory.value("menu", "text_length") == 127 then
|
||||
input.press("B")
|
||||
else
|
||||
input.cancel()
|
||||
end
|
||||
elseif (textbox.handle()) then
|
||||
elseif textbox.handle() then
|
||||
local selected = memory.value("menu", "selection")
|
||||
if (selected == 239) then
|
||||
if selected == 239 then
|
||||
input.press("A", 2)
|
||||
else
|
||||
input.escape()
|
||||
|
@ -168,23 +168,23 @@ function battle.run()
|
|||
end
|
||||
|
||||
function battle.handleWild()
|
||||
if (memory.value("game", "battle") ~= 1) then
|
||||
if memory.value("game", "battle") ~= 1 then
|
||||
return true
|
||||
end
|
||||
battle.run()
|
||||
end
|
||||
|
||||
function battle.fight(move, isNumber, skipBuffs)
|
||||
if (move) then
|
||||
if (not isNumber) then
|
||||
if move then
|
||||
if not isNumber then
|
||||
move = pokemon.battleMove(move)
|
||||
end
|
||||
attack(move)
|
||||
else
|
||||
move = combat.bestMove()
|
||||
if (move) then
|
||||
if move then
|
||||
attack(move.midx)
|
||||
elseif (memory.value("menu", "text_length") == 127) then
|
||||
elseif memory.value("menu", "text_length") == 127 then
|
||||
input.press("B")
|
||||
else
|
||||
input.cancel()
|
||||
|
@ -194,17 +194,17 @@ end
|
|||
|
||||
function battle.swap(target)
|
||||
local battleMenu = memory.value("battle", "menu")
|
||||
if (utils.onPokemonSelect(battleMenu)) then
|
||||
if (menu.getCol() == 0) then
|
||||
if utils.onPokemonSelect(battleMenu) then
|
||||
if menu.getCol() == 0 then
|
||||
menu.select(pokemon.indexOf(target), true)
|
||||
else
|
||||
input.press("A")
|
||||
end
|
||||
elseif (battleMenu == 94) then
|
||||
elseif battleMenu == 94 then
|
||||
local selected = memory.value("menu", "selection")
|
||||
if (selected == 199) then
|
||||
if selected == 199 then
|
||||
input.press("A", 2)
|
||||
elseif (menu.getCol() == 9) then
|
||||
elseif menu.getCol() == 9 then
|
||||
input.press("Right", 0)
|
||||
else
|
||||
input.press("Up", 0)
|
||||
|
@ -216,7 +216,7 @@ end
|
|||
|
||||
function movePP(name)
|
||||
local midx = pokemon.battleMove(name)
|
||||
if (not midx) then
|
||||
if not midx then
|
||||
return 0
|
||||
end
|
||||
return memory.raw(0xD02C + midx)
|
||||
|
@ -224,21 +224,21 @@ end
|
|||
battle.pp = movePP
|
||||
|
||||
function battle.automate(moveName, skipBuffs)
|
||||
if (not recover()) then
|
||||
if not recover() then
|
||||
local state = memory.value("game", "battle")
|
||||
if (state == 0) then
|
||||
if state == 0 then
|
||||
input.cancel()
|
||||
else
|
||||
if (moveName and movePP(moveName) == 0) then
|
||||
if moveName and movePP(moveName) == 0 then
|
||||
moveName = nil
|
||||
end
|
||||
if (state == 1) then
|
||||
if (control.shouldFight()) then
|
||||
if state == 1 then
|
||||
if control.shouldFight() then
|
||||
battle.fight(moveName, false, skipBuffs)
|
||||
else
|
||||
battle.run()
|
||||
end
|
||||
elseif (state == 2) then
|
||||
elseif state == 2 then
|
||||
battle.fight(moveName, false, skipBuffs)
|
||||
end
|
||||
end
|
||||
|
@ -247,7 +247,7 @@ end
|
|||
|
||||
function battle.sacrifice(...)
|
||||
local sacrifice = pokemon.getSacrifice(...)
|
||||
if (sacrifice) then
|
||||
if sacrifice then
|
||||
battle.swap(sacrifice)
|
||||
return true
|
||||
end
|
||||
|
@ -255,17 +255,17 @@ function battle.sacrifice(...)
|
|||
end
|
||||
|
||||
function battle.redeployNidoking()
|
||||
if (pokemon.isDeployed("nidoking")) then
|
||||
if pokemon.isDeployed("nidoking") then
|
||||
return false
|
||||
end
|
||||
local battleMenu = memory.value("battle", "menu")
|
||||
if (utils.onPokemonSelect(battleMenu)) then
|
||||
if utils.onPokemonSelect(battleMenu) then
|
||||
menu.select(0, true)
|
||||
elseif (battleMenu == 95 and menu.getCol() == 1) then
|
||||
elseif battleMenu == 95 and menu.getCol() == 1 then
|
||||
input.press("A")
|
||||
else
|
||||
local __, turns = combat.bestMove()
|
||||
if (turns == 1) then
|
||||
if turns == 1 then
|
||||
forced = "sand_attack"
|
||||
end
|
||||
battle.automate(forced)
|
||||
|
|
|
@ -11,13 +11,13 @@ local inventory = require "storage.inventory"
|
|||
|
||||
function shop.transaction(options)
|
||||
local item, itemMenu, menuIdx, quantityMenu
|
||||
if (options.sell) then
|
||||
if options.sell then
|
||||
menuIdx = 1
|
||||
itemMenu = 29
|
||||
quantityMenu = 158
|
||||
for i,sit in ipairs(options.sell) do
|
||||
local idx = inventory.indexOf(sit.name)
|
||||
if (idx ~= -1) then
|
||||
if idx ~= -1 then
|
||||
item = sit
|
||||
item.index = idx
|
||||
item.amount = inventory.count(sit.name)
|
||||
|
@ -25,35 +25,35 @@ function shop.transaction(options)
|
|||
end
|
||||
end
|
||||
end
|
||||
if (not item and options.buy) then
|
||||
if not item and options.buy then
|
||||
menuIdx = 0
|
||||
itemMenu = 123
|
||||
quantityMenu = 161
|
||||
for i,bit in ipairs(options.buy) do
|
||||
local needed = (bit.amount or 1) - inventory.count(bit.name)
|
||||
if (needed > 0) then
|
||||
if needed > 0 then
|
||||
item = bit
|
||||
item.amount = needed
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if (not item) then
|
||||
if (not textbox.isActive()) then
|
||||
if not item then
|
||||
if not textbox.isActive() then
|
||||
return true
|
||||
end
|
||||
input.press("B")
|
||||
elseif (player.isFacing(options.direction or "Left")) then
|
||||
if (textbox.isActive()) then
|
||||
if (menu.isCurrently(32, "shop")) then
|
||||
elseif player.isFacing(options.direction or "Left") then
|
||||
if textbox.isActive() then
|
||||
if menu.isCurrently(32, "shop") then
|
||||
menu.select(menuIdx, true, false, "shop")
|
||||
elseif (menu.getCol() == 15) then
|
||||
elseif menu.getCol() == 15 then
|
||||
input.press("A")
|
||||
elseif (menu.isCurrently(itemMenu, "transaction")) then
|
||||
if (menu.select(item.index, "accelerate", true, "transaction", true)) then
|
||||
if (menu.isCurrently(quantityMenu, "shop")) then
|
||||
elseif menu.isCurrently(itemMenu, "transaction") then
|
||||
if menu.select(item.index, "accelerate", true, "transaction", true) then
|
||||
if menu.isCurrently(quantityMenu, "shop") then
|
||||
local currAmount = memory.value("shop", "transaction_amount")
|
||||
if (menu.balance(currAmount, item.amount, false, 99, true)) then
|
||||
if menu.balance(currAmount, item.amount, false, 99, true) then
|
||||
input.press("A")
|
||||
end
|
||||
else
|
||||
|
@ -77,20 +77,20 @@ function shop.vend(options)
|
|||
menuIdx = 0
|
||||
for i,bit in ipairs(options.buy) do
|
||||
local needed = (bit.amount or 1) - inventory.count(bit.name)
|
||||
if (needed > 0) then
|
||||
if needed > 0 then
|
||||
item = bit
|
||||
item.buy = needed
|
||||
break
|
||||
end
|
||||
end
|
||||
if (not item) then
|
||||
if (not textbox.isActive()) then
|
||||
if not item then
|
||||
if not textbox.isActive() then
|
||||
return true
|
||||
end
|
||||
input.press("B")
|
||||
elseif (player.face(options.direction)) then
|
||||
if (textbox.isActive()) then
|
||||
if (memory.value("battle", "text") > 1 and memory.value("battle", "menu") ~= 95) then
|
||||
elseif player.face(options.direction) then
|
||||
if textbox.isActive() then
|
||||
if memory.value("battle", "text") > 1 and memory.value("battle", "menu") ~= 95 then
|
||||
menu.select(item.index, true)
|
||||
else
|
||||
input.press("A")
|
||||
|
|
|
@ -20,13 +20,13 @@ 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
|
||||
if inputting then
|
||||
if memory.value("menu", "text_length") > 0 then
|
||||
input.press("Start")
|
||||
return true
|
||||
end
|
||||
local lidx
|
||||
if (letter) then
|
||||
if letter then
|
||||
lidx = getIndexForLetter(letter)
|
||||
else
|
||||
lidx = nidoIdx
|
||||
|
@ -34,19 +34,19 @@ function textbox.name(letter, randomize)
|
|||
|
||||
local crow = memory.value("menu", "input_row")
|
||||
local drow = math.ceil(lidx / 9)
|
||||
if (menu.balance(crow, drow, true, 6, true)) then
|
||||
if menu.balance(crow, drow, true, 6, true) then
|
||||
local ccol = math.floor(memory.value("menu", "column") / 2)
|
||||
local dcol = math.fmod(lidx - 1, 9)
|
||||
if (menu.sidle(ccol, dcol, 9, true)) then
|
||||
if menu.sidle(ccol, dcol, 9, true) then
|
||||
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
|
||||
-- if memory.value("menu", "current") == 7 then
|
||||
if memory.raw(0x10B7) == 3 then
|
||||
input.press("A", 2)
|
||||
elseif (randomize) then
|
||||
elseif randomize then
|
||||
input.press("A", math.random(1, 5))
|
||||
else
|
||||
input.cancel()
|
||||
|
@ -68,7 +68,7 @@ function textbox.isActive()
|
|||
end
|
||||
|
||||
function textbox.handle()
|
||||
if (not textbox.isActive()) then
|
||||
if not textbox.isActive() then
|
||||
return true
|
||||
end
|
||||
input.cancel()
|
||||
|
|
|
@ -33,11 +33,11 @@ end
|
|||
|
||||
function dir(px, py, dx, dy)
|
||||
local direction
|
||||
if (py > dy) then
|
||||
if py > dy then
|
||||
direction = "Up"
|
||||
elseif (py < dy) then
|
||||
elseif py < dy then
|
||||
direction = "Down"
|
||||
elseif (px > dx) then
|
||||
elseif px > dx then
|
||||
direction = "Left"
|
||||
else
|
||||
direction = "Right"
|
||||
|
@ -48,7 +48,7 @@ walk.dir = dir
|
|||
|
||||
function step(dx, dy)
|
||||
local px, py = player.position()
|
||||
if (px == dx and py == dy) then
|
||||
if px == dx and py == dy then
|
||||
return true
|
||||
end
|
||||
input.press(dir(px, py, dx, dy), 0)
|
||||
|
@ -69,14 +69,14 @@ end
|
|||
function walk.init()
|
||||
local region = memory.value("game", "map")
|
||||
local px, py = player.position()
|
||||
if (region == 0 and px == 0 and py == 0) then
|
||||
if region == 0 and px == 0 and py == 0 then
|
||||
return false
|
||||
end
|
||||
for tries=1,2 do
|
||||
for i,p in ipairs(paths) do
|
||||
if (i > 2 and p[1] == region) then
|
||||
if i > 2 and p[1] == region then
|
||||
local origin = p[2]
|
||||
if (tries == 2 or (origin[1] == px and origin[2] == py)) then
|
||||
if tries == 2 or (origin[1] == px and origin[2] == py) then
|
||||
setPath(i, region)
|
||||
return tries == 1
|
||||
end
|
||||
|
@ -87,7 +87,7 @@ end
|
|||
|
||||
function walk.traverse(region)
|
||||
local newIndex
|
||||
if (not path or currentMap ~= region) then
|
||||
if not path or currentMap ~= region then
|
||||
walk.strategy = nil
|
||||
setPath(pathIdx + 1, region)
|
||||
newIndex = pathIdx
|
||||
|
@ -97,12 +97,12 @@ function walk.traverse(region)
|
|||
return
|
||||
end
|
||||
local tile = path[stepIdx]
|
||||
if (tile.c) then
|
||||
if tile.c then
|
||||
control.set(tile)
|
||||
return completeStep(region)
|
||||
end
|
||||
if (tile.s) then
|
||||
if (walk.strategy) then
|
||||
if tile.s then
|
||||
if walk.strategy then
|
||||
walk.strategy = nil
|
||||
return completeStep(region)
|
||||
end
|
||||
|
@ -121,24 +121,24 @@ end
|
|||
-- Custom path
|
||||
|
||||
function walk.invertCustom(silent)
|
||||
if (not silent) then
|
||||
if not silent then
|
||||
customIdx = customIdx + customDir
|
||||
end
|
||||
customDir = customDir * -1
|
||||
end
|
||||
|
||||
function walk.custom(cpath, increment)
|
||||
if (not cpath) then
|
||||
if not cpath then
|
||||
customIdx = 1
|
||||
customDir = 1
|
||||
return
|
||||
end
|
||||
if (increment) then
|
||||
if increment then
|
||||
customIdx = customIdx + customDir
|
||||
end
|
||||
local tile = cpath[customIdx]
|
||||
if (not tile) then
|
||||
if (customIdx < 1) then
|
||||
if not tile then
|
||||
if customIdx < 1 then
|
||||
customIdx = #cpath
|
||||
else
|
||||
customIdx = 1
|
||||
|
@ -146,13 +146,13 @@ function walk.custom(cpath, increment)
|
|||
return customIdx
|
||||
end
|
||||
local t1, t2 = tile[1], tile[2]
|
||||
if (t2 == nil) then
|
||||
if (player.face(t1)) then
|
||||
if t2 == nil then
|
||||
if player.face(t1) then
|
||||
input.press("A", 2)
|
||||
end
|
||||
return t1
|
||||
end
|
||||
if (step(t1, t2)) then
|
||||
if step(t1, t2) then
|
||||
customIdx = customIdx + customDir
|
||||
end
|
||||
end
|
||||
|
|
106
ai/combat.lua
106
ai/combat.lua
|
@ -52,22 +52,22 @@ end
|
|||
combat.isDisabled = isDisabled
|
||||
|
||||
local function calcDamage(move, attacker, defender, rng)
|
||||
if (move.fixed) then
|
||||
if move.fixed then
|
||||
return move.fixed, move.fixed
|
||||
end
|
||||
if (move.power == 0 or isDisabled(move.id)) then
|
||||
if move.power == 0 or isDisabled(move.id) then
|
||||
return 0, 0
|
||||
end
|
||||
if (move.power > 9000) then
|
||||
if move.power > 9000 then
|
||||
local oid = defender.id
|
||||
if (oid ~= 14 and oid ~= 147 and oid ~= 171 and (oidd ~= 151 or memory.value("game", "map") == 120)) then -- ???
|
||||
if (memory.value("battle", "x_accuracy") == 1 and defender.speed < attacker.speed) then
|
||||
if oid ~= 14 and oid ~= 147 and oid ~= 171 and (oidd ~= 151 or memory.value("game", "map") == 120) then -- ???
|
||||
if memory.value("battle", "x_accuracy") == 1 and defender.speed < attacker.speed then
|
||||
return 9001, 9001
|
||||
end
|
||||
end
|
||||
return 0, 0
|
||||
end
|
||||
if (move.name == "Thrash" and combat.disableThrash) then
|
||||
if move.name == "Thrash" and combat.disableThrash then
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
|
@ -79,17 +79,17 @@ local function calcDamage(move, attacker, defender, rng)
|
|||
end
|
||||
local damage = floor(floor(floor(2 * attacker.level / 5 + 2) * math.max(1, attFactor) * move.power / math.max(1, defFactor)) / 50) + 2
|
||||
|
||||
if (move.move_type == attacker.type1 or move.move_type == attacker.type2) then
|
||||
if move.move_type == attacker.type1 or move.move_type == attacker.type2 then
|
||||
damage = floor(damage * 1.5) -- STAB
|
||||
end
|
||||
|
||||
local dmp = damageMultiplier[move.move_type]
|
||||
local typeEffect1, typeEffect2 = dmp[defender.type1], dmp[defender.type2]
|
||||
if (defender.type1 == defender.type2) then
|
||||
if defender.type1 == defender.type2 then
|
||||
typeEffect2 = 1
|
||||
end
|
||||
damage = floor(damage * typeEffect1 * typeEffect2)
|
||||
if (rng) then
|
||||
if rng then
|
||||
return damage, damage
|
||||
end
|
||||
return floor(damage * 217 / 255), damage
|
||||
|
@ -112,9 +112,9 @@ combat.getOpponentType = getOpponentType
|
|||
|
||||
function getOurType(ty)
|
||||
local t1 = types[memory.value("battle", "our_type1")]
|
||||
if (ty ~= 0) then
|
||||
if ty ~= 0 then
|
||||
t1 = types[memory.value("battle", "our_type2")]
|
||||
if (not t1) then
|
||||
if not t1 then
|
||||
return memory.value("battle", "opponent_type2")
|
||||
end
|
||||
end
|
||||
|
@ -128,16 +128,16 @@ combat.getOurType = getOurType
|
|||
local function getMoves(who)--Get the moveset of us [0] or them [1]
|
||||
local moves = {}
|
||||
local base
|
||||
if (who == 1) then
|
||||
if who == 1 then
|
||||
base = 0xCFED
|
||||
else
|
||||
base = 0xD01C
|
||||
end
|
||||
for idx=0, 3 do
|
||||
local val = memory.raw(base + idx)
|
||||
if (val > 0) then
|
||||
if val > 0 then
|
||||
local moveTable = movelist.get(val)
|
||||
if (who == 0) then
|
||||
if who == 0 then
|
||||
moveTable.pp = memory.raw(0xD02D + idx)
|
||||
end
|
||||
moves[idx + 1] = moveTable
|
||||
|
@ -149,11 +149,11 @@ combat.getMoves = getMoves
|
|||
|
||||
local function modPlayerStats(user, enemy, move)
|
||||
local effect = move.effects
|
||||
if (effect) then
|
||||
if effect then
|
||||
local diff = effect.diff
|
||||
local hitThem = diff < 0
|
||||
local stat = effect.stat
|
||||
if (hitThem) then
|
||||
if hitThem then
|
||||
enemy[stat] = math.max(2, enemy[stat] + diff)
|
||||
else
|
||||
user[stat] = user[stat] + diff
|
||||
|
@ -168,51 +168,51 @@ local function calcBestHit(attacker, defender, ours, rng)
|
|||
local ourMaxHit
|
||||
local ret = nil
|
||||
for idx,move in ipairs(attacker.moves) do
|
||||
if (not move.pp or move.pp > 0) then
|
||||
if not move.pp or move.pp > 0 then
|
||||
local minDmg, maxDmg = calcDamage(move, attacker, defender, rng)
|
||||
if (maxDmg) then
|
||||
if maxDmg then
|
||||
local minTurns, maxTurns
|
||||
if (maxDmg <= 0) then
|
||||
if maxDmg <= 0 then
|
||||
minTurns, maxTurns = 9999, 9999
|
||||
else
|
||||
minTurns = math.ceil(defender.hp / maxDmg)
|
||||
maxTurns = math.ceil(defender.hp / minDmg)
|
||||
end
|
||||
if (ours) then
|
||||
if ours then
|
||||
local replaces
|
||||
if (not ret or minTurns < bestMinTurns or maxTurns < bestTurns) then
|
||||
if not ret or minTurns < bestMinTurns or maxTurns < bestTurns then
|
||||
replaces = true
|
||||
elseif (maxTurns == bestTurns and move.name == "Thrash") then
|
||||
elseif maxTurns == bestTurns and move.name == "Thrash" then
|
||||
replaces = defender.hp == memory.double("battle", "opponent_max_hp")
|
||||
elseif (maxTurns == bestTurns and ret.name == "Thrash") then
|
||||
elseif maxTurns == bestTurns and ret.name == "Thrash" then
|
||||
replaces = defender.hp ~= memory.double("battle", "opponent_max_hp")
|
||||
elseif (move.fast and not ret.fast) then
|
||||
elseif move.fast and not ret.fast then
|
||||
replaces = maxTurns <= bestTurns
|
||||
elseif (ret.fast) then
|
||||
elseif ret.fast then
|
||||
replaces = maxTurns < bestTurns
|
||||
elseif (enablePP) then
|
||||
if (maxTurns < 2 or maxTurns == bestMaxTurns) then
|
||||
if (ret.name == "Earthquake" and (move.name == "Ice-Beam" or move.name == "Thunderbolt")) then
|
||||
elseif enablePP then
|
||||
if maxTurns < 2 or maxTurns == bestMaxTurns then
|
||||
if ret.name == "Earthquake" and (move.name == "Ice-Beam" or move.name == "Thunderbolt") then
|
||||
replaces = true
|
||||
elseif (move.pp > ret.pp) then
|
||||
if (ret.name == "Horn-Drill") then
|
||||
elseif move.pp > ret.pp then
|
||||
if ret.name == "Horn-Drill" then
|
||||
replaces = true
|
||||
elseif (move.name ~= "Earthquake") then
|
||||
elseif move.name ~= "Earthquake" then
|
||||
replaces = true
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif (minDmg > bestDmg) then
|
||||
elseif minDmg > bestDmg then
|
||||
replaces = true
|
||||
end
|
||||
if (replaces) then
|
||||
if replaces then
|
||||
ret = move
|
||||
bestMinTurns = minTurns
|
||||
bestTurns = maxTurns
|
||||
bestDmg = minDmg
|
||||
ourMaxHit = maxDmg
|
||||
end
|
||||
elseif (maxDmg > bestDmg) then -- Opponents automatically hit max
|
||||
elseif maxDmg > bestDmg then -- Opponents automatically hit max
|
||||
ret = move
|
||||
bestTurns = minTurns
|
||||
bestDmg = maxDmg
|
||||
|
@ -220,7 +220,7 @@ local function calcBestHit(attacker, defender, ours, rng)
|
|||
end
|
||||
end
|
||||
end
|
||||
if (ret) then
|
||||
if ret then
|
||||
ret.damage = bestDmg
|
||||
ret.maxDamage = ourMaxHit
|
||||
ret.minTurns = bestMinTurns
|
||||
|
@ -229,12 +229,12 @@ local function calcBestHit(attacker, defender, ours, rng)
|
|||
end
|
||||
|
||||
local function getBestMove(ours, enemy, draw)
|
||||
if (enemy.hp < 1) then
|
||||
if enemy.hp < 1 then
|
||||
return
|
||||
end
|
||||
local bm, bestUs = calcBestHit(ours, enemy, true)
|
||||
local jj, bestEnemy = calcBestHit(enemy, ours, false)
|
||||
if (not bm) then
|
||||
if not bm then
|
||||
return
|
||||
end
|
||||
if draw and bm.midx then
|
||||
|
@ -258,13 +258,13 @@ local function activePokemon(preset)
|
|||
}
|
||||
|
||||
local enemy
|
||||
if (preset) then
|
||||
if preset then
|
||||
enemy = opponents[preset]
|
||||
local toBoost = enemy.boost
|
||||
if (toBoost) then
|
||||
if toBoost then
|
||||
local currSpec = ours.spec
|
||||
local booster = toBoost.mp
|
||||
if ((currSpec < 140) == (booster > 1)) then
|
||||
if (currSpec < 140) == (booster > 1) then
|
||||
ours.spec = math.floor(currSpec * booster)
|
||||
end
|
||||
end
|
||||
|
@ -316,24 +316,24 @@ function combat.inKillRange(draw)
|
|||
local ours, enemy = activePokemon()
|
||||
local enemyAttack, __ = calcBestHit(enemy, ours, false)
|
||||
local __, turnsToKill = calcBestHit(ours, enemy, true)
|
||||
if (not turnsToKill or not enemyAttack) then
|
||||
if not turnsToKill or not enemyAttack then
|
||||
return false
|
||||
end
|
||||
if (draw) then
|
||||
if draw then
|
||||
gui.text(0, 21, ours.speed.." "..enemy.speed)
|
||||
gui.text(0, 28, turnsToDie.." "..ours.hp.." | "..turnsToKill.." "..enemy.hp)
|
||||
end
|
||||
local hpReq = enemyAttack.damage
|
||||
local isConfused = isConfused()
|
||||
if (isConfused) then
|
||||
if isConfused then
|
||||
hpReq = hpReq + math.floor(ours.hp * 0.2)
|
||||
end
|
||||
if (ours.hp < hpReq) then
|
||||
if ours.hp < hpReq then
|
||||
local outspeed = enemyAttack.outspeed
|
||||
if (outspeed and outspeed ~= true) then
|
||||
if outspeed and outspeed ~= true then
|
||||
outspeed = memory.value("battle", "turns") > 0
|
||||
end
|
||||
if (outspeed or isConfused or turnsToKill > 1 or ours.speed <= enemy.speed or isSleeping()) then
|
||||
if outspeed or isConfused or turnsToKill > 1 or ours.speed <= enemy.speed or isSleeping() then
|
||||
return ours, hpReq
|
||||
end
|
||||
end
|
||||
|
@ -341,12 +341,12 @@ end
|
|||
|
||||
local function getBattlePokemon()
|
||||
local ours, enemy = activePokemon()
|
||||
if (enemy.hp == 0) then
|
||||
if enemy.hp == 0 then
|
||||
return
|
||||
end
|
||||
for idx=1,4 do
|
||||
local move = ours.moves[idx]
|
||||
if (move) then
|
||||
if move then
|
||||
move.midx = idx
|
||||
end
|
||||
end
|
||||
|
@ -355,16 +355,16 @@ end
|
|||
|
||||
function combat.nonKill()
|
||||
local ours, enemy = getBattlePokemon()
|
||||
if (not enemy) then
|
||||
if not enemy then
|
||||
return
|
||||
end
|
||||
local bestDmg = -1
|
||||
local ret = nil
|
||||
for idx,move in ipairs(ours.moves) do
|
||||
if (not move.pp or move.pp > 0) then
|
||||
if not move.pp or move.pp > 0 then
|
||||
local __, maxDmg = calcDamage(move, ours, enemy, true)
|
||||
local threshold = maxDmg * 0.95
|
||||
if (threshold and threshold < enemy.hp and threshold > bestDmg) then
|
||||
if threshold and threshold < enemy.hp and threshold > bestDmg then
|
||||
ret = move
|
||||
bestDmg = threshold
|
||||
end
|
||||
|
@ -375,14 +375,14 @@ end
|
|||
|
||||
function combat.bestMove()
|
||||
local ours, enemy = getBattlePokemon()
|
||||
if (enemy) then
|
||||
if enemy then
|
||||
return getBestMove(ours, enemy)
|
||||
end
|
||||
end
|
||||
|
||||
function combat.enemyAttack()
|
||||
local ours, enemy = activePokemon()
|
||||
if (enemy.hp == 0) then
|
||||
if enemy.hp == 0 then
|
||||
return
|
||||
end
|
||||
return calcBestHit(enemy, ours, false)
|
||||
|
|
|
@ -28,14 +28,14 @@ control.battlePotion = battlePotion
|
|||
|
||||
local controlFunctions = {
|
||||
potion = function(data)
|
||||
if (data.b ~= nil) then
|
||||
if data.b ~= nil then
|
||||
battlePotion(data.b)
|
||||
end
|
||||
battleYolo = data.yolo
|
||||
end,
|
||||
|
||||
encounters = function(data)
|
||||
if (RESET_FOR_TIME) then
|
||||
if RESET_FOR_TIME then
|
||||
maxEncounters = data.limit
|
||||
extraEncounter = data.extra
|
||||
end
|
||||
|
@ -115,25 +115,25 @@ function control.canDie(enabled)
|
|||
end
|
||||
|
||||
local function isNewFight()
|
||||
if (fightEncounter < encounters and memory.double("battle", "opponent_hp") == memory.double("battle", "opponent_max_hp")) then
|
||||
if fightEncounter < encounters and memory.double("battle", "opponent_hp") == memory.double("battle", "opponent_max_hp") then
|
||||
fightEncounter = encounters
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function control.shouldFight()
|
||||
if (not shouldFight) then
|
||||
if not shouldFight then
|
||||
return false
|
||||
end
|
||||
local expTotal = pokemon.getExp()
|
||||
if (expTotal < minExp) then
|
||||
if expTotal < minExp then
|
||||
local oid = memory.value("battle", "opponent_id")
|
||||
local olvl = memory.value("battle", "opponent_level")
|
||||
for i,p in ipairs(shouldFight) do
|
||||
if (oid == pokemon.getID(p.name) and (not p.lvl or utils.match(olvl, p.lvl))) then
|
||||
if (oneHits) then
|
||||
if oid == pokemon.getID(p.name) and (not p.lvl or utils.match(olvl, p.lvl)) then
|
||||
if oneHits then
|
||||
local move = combat.bestMove()
|
||||
if (move and move.maxDamage * 0.925 < memory.double("battle", "opponent_hp")) then
|
||||
if move and move.maxDamage * 0.925 < memory.double("battle", "opponent_hp") then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
@ -144,12 +144,12 @@ function control.shouldFight()
|
|||
end
|
||||
|
||||
function control.canCatch(partySize)
|
||||
if (not partySize) then
|
||||
if not partySize then
|
||||
partySize = memory.value("player", "party_size")
|
||||
end
|
||||
local pokeballs = inventory.count("pokeball")
|
||||
local minimumCount = 4 - partySize
|
||||
if (pokeballs < minimumCount) then
|
||||
if pokeballs < minimumCount then
|
||||
require("ai.strategies").reset("Not enough PokeBalls", pokeballs)
|
||||
return false
|
||||
end
|
||||
|
@ -157,35 +157,35 @@ function control.canCatch(partySize)
|
|||
end
|
||||
|
||||
function control.shouldCatch(partySize)
|
||||
if (maxEncounters and encounters > maxEncounters) then
|
||||
if maxEncounters and encounters > maxEncounters then
|
||||
local extraCount = extraEncounter and pokemon.inParty(extraEncounter)
|
||||
if (not extraCount or encounters > maxEncounters + 1) then
|
||||
if not extraCount or encounters > maxEncounters + 1 then
|
||||
require("ai.strategies").reset("Too many encounters", encounters)
|
||||
return false
|
||||
end
|
||||
end
|
||||
if (not shouldCatch) then
|
||||
if not shouldCatch then
|
||||
return false
|
||||
end
|
||||
if (not partySize) then
|
||||
if not partySize then
|
||||
partySize = memory.value("player", "party_size")
|
||||
end
|
||||
if (partySize == 4) then
|
||||
if partySize == 4 then
|
||||
shouldCatch = nil
|
||||
return false
|
||||
end
|
||||
if (not control.canCatch(partySize)) then
|
||||
if not control.canCatch(partySize) then
|
||||
return true
|
||||
end
|
||||
local oid = memory.value("battle", "opponent_id")
|
||||
for i,poke in ipairs(shouldCatch) do
|
||||
if (oid == pokemon.getID(poke.name) and not pokemon.inParty(poke.name, poke.alt)) then
|
||||
if (not poke.lvl or utils.match(memory.value("battle", "opponent_level"), poke.lvl)) then
|
||||
if oid == pokemon.getID(poke.name) and not pokemon.inParty(poke.name, poke.alt) then
|
||||
if not poke.lvl or utils.match(memory.value("battle", "opponent_level"), poke.lvl) then
|
||||
local penultimate = poke.hp and memory.double("battle", "opponent_hp") > poke.hp
|
||||
if (penultimate) then
|
||||
if penultimate then
|
||||
penultimate = combat.nonKill()
|
||||
end
|
||||
if (penultimate) then
|
||||
if penultimate then
|
||||
require("action.battle").fight(penultimate.midx, true)
|
||||
else
|
||||
inventory.use("pokeball", nil, true)
|
||||
|
|
1222
ai/strategies.lua
1222
ai/strategies.lua
File diff suppressed because it is too large
Load Diff
76
main.lua
76
main.lua
|
@ -41,24 +41,24 @@ local criticaled = false
|
|||
|
||||
local function startNewAdventure()
|
||||
local startMenu, withBattleStyle
|
||||
if (YELLOW) then
|
||||
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
|
||||
if startMenu and menu.getCol() ~= 0 then
|
||||
if settings.set("text_speed", "battle_animation", withBattleStyle) then
|
||||
menu.select(0)
|
||||
end
|
||||
elseif (math.random(0, START_WAIT) == 0) then
|
||||
elseif math.random(0, START_WAIT) == 0 then
|
||||
input.press("Start")
|
||||
end
|
||||
end
|
||||
|
||||
local function choosePlayerNames()
|
||||
local name
|
||||
if (memory.value("player", "name2") == 80) then
|
||||
if memory.value("player", "name2") == 80 then
|
||||
name = "E"
|
||||
else
|
||||
name = "B"
|
||||
|
@ -68,7 +68,7 @@ end
|
|||
|
||||
local function pollForResponse()
|
||||
local response = bridge.process()
|
||||
if (response) then
|
||||
if response then
|
||||
bridge.polling = false
|
||||
textbox.setName(tonumber(response))
|
||||
end
|
||||
|
@ -86,7 +86,7 @@ local function resetAll()
|
|||
previousPartySize = 0
|
||||
-- client.speedmode = 200
|
||||
|
||||
if (CUSTOM_SEED) then
|
||||
if CUSTOM_SEED then
|
||||
strategies.seed = CUSTOM_SEED
|
||||
print("RUNNING WITH A FIXED SEED ("..strategies.seed.."), every run will play out identically!")
|
||||
else
|
||||
|
@ -103,18 +103,18 @@ 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()
|
||||
else
|
||||
hasAlreadyStartedPlaying = utils.ingame()
|
||||
end
|
||||
|
||||
strategies.init(hasAlreadyStartedPlaying)
|
||||
if (RESET_FOR_TIME and hasAlreadyStartedPlaying) then
|
||||
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 (STREAMING_MODE) then
|
||||
if STREAMING_MODE then
|
||||
bridge.init()
|
||||
else
|
||||
input.setDebug(true)
|
||||
|
@ -126,25 +126,25 @@ local previousMap
|
|||
|
||||
while true do
|
||||
local currentMap = memory.value("game", "map")
|
||||
if (currentMap ~= previousMap) then
|
||||
if currentMap ~= previousMap then
|
||||
input.clear()
|
||||
previousMap = currentMap
|
||||
end
|
||||
if (strategies.frames) then
|
||||
if (memory.value("game", "battle") == 0) then
|
||||
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
|
||||
if bridge.polling then
|
||||
pollForResponse()
|
||||
end
|
||||
|
||||
if (not input.update()) then
|
||||
if (not utils.ingame()) then
|
||||
if (currentMap == 0) then
|
||||
if (running) then
|
||||
if (not hasAlreadyStartedPlaying) then
|
||||
if not input.update() then
|
||||
if not utils.ingame() then
|
||||
if currentMap == 0 then
|
||||
if running then
|
||||
if not hasAlreadyStartedPlaying then
|
||||
client.reboot_core()
|
||||
hasAlreadyStartedPlaying = true
|
||||
else
|
||||
|
@ -154,7 +154,7 @@ while true do
|
|||
startNewAdventure()
|
||||
end
|
||||
else
|
||||
if (not running) then
|
||||
if not running then
|
||||
bridge.liveSplit()
|
||||
running = true
|
||||
end
|
||||
|
@ -162,11 +162,11 @@ while true do
|
|||
end
|
||||
else
|
||||
local battleState = memory.value("game", "battle")
|
||||
if (battleState > 0) then
|
||||
if (battleState == 1) then
|
||||
if (not inBattle) then
|
||||
if battleState > 0 then
|
||||
if battleState == 1 then
|
||||
if not inBattle then
|
||||
control.wildEncounter()
|
||||
if (strategies.moonEncounters) then
|
||||
if strategies.moonEncounters then
|
||||
strategies.moonEncounters = strategies.moonEncounters + 1
|
||||
end
|
||||
inBattle = true
|
||||
|
@ -174,14 +174,14 @@ while true do
|
|||
end
|
||||
local isCritical
|
||||
local battleMenu = memory.value("battle", "menu")
|
||||
if (battleMenu == 94) then
|
||||
if battleMenu == 94 then
|
||||
isCritical = false
|
||||
elseif (memory.double("battle", "our_hp") == 0) then
|
||||
if (memory.value("battle", "critical") == 1) then
|
||||
elseif memory.double("battle", "our_hp") == 0 then
|
||||
if memory.value("battle", "critical") == 1 then
|
||||
isCritical = true
|
||||
end
|
||||
end
|
||||
if (isCritical ~= nil and isCritical ~= criticaled) then
|
||||
if isCritical ~= nil and isCritical ~= criticaled then
|
||||
criticaled = isCritical
|
||||
strategies.criticaled = criticaled
|
||||
end
|
||||
|
@ -189,33 +189,33 @@ while true do
|
|||
inBattle = false
|
||||
end
|
||||
local currentHP = pokemon.index(0, "hp")
|
||||
-- if (currentHP ~= lastHP) then
|
||||
-- if currentHP ~= lastHP then
|
||||
-- bridge.hp(currentHP, pokemon.index(0, "max_hp"))
|
||||
-- lastHP = currentHP
|
||||
-- end
|
||||
if (currentHP == 0 and not control.canDie() and pokemon.index(0) > 0) then
|
||||
if currentHP == 0 and not control.canDie() and pokemon.index(0) > 0 then
|
||||
strategies.death(currentMap)
|
||||
elseif (walk.strategy) then
|
||||
if (strategies.execute(walk.strategy)) then
|
||||
elseif walk.strategy then
|
||||
if strategies.execute(walk.strategy) then
|
||||
walk.traverse(currentMap)
|
||||
end
|
||||
elseif (battleState > 0) then
|
||||
if (not control.shouldCatch(partySize)) then
|
||||
elseif battleState > 0 then
|
||||
if not control.shouldCatch(partySize) then
|
||||
battle.automate()
|
||||
end
|
||||
elseif (textbox.handle()) then
|
||||
elseif textbox.handle() then
|
||||
walk.traverse(currentMap)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (STREAMING_MODE) then
|
||||
if STREAMING_MODE then
|
||||
local newSecs = memory.raw(0xDA44)
|
||||
if (newSecs ~= oldSecs and (newSecs > 0 or memory.raw(0xDA45) > 0)) then
|
||||
if newSecs ~= oldSecs and (newSecs > 0 or memory.raw(0xDA45) > 0) then
|
||||
bridge.time(utils.elapsedTime())
|
||||
oldSecs = newSecs
|
||||
end
|
||||
elseif (PAINT_ON) then
|
||||
elseif PAINT_ON then
|
||||
paint.draw(currentMap)
|
||||
end
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ function inventory.indexOf(name)
|
|||
local searchID = items[name]
|
||||
for i=0,19 do
|
||||
local iidx = ITEM_BASE + i * 2
|
||||
if (memory.raw(iidx) == searchID) then
|
||||
if memory.raw(iidx) == searchID then
|
||||
return i
|
||||
end
|
||||
end
|
||||
|
@ -69,7 +69,7 @@ end
|
|||
|
||||
function inventory.count(name)
|
||||
local index = inventory.indexOf(name)
|
||||
if (index ~= -1) then
|
||||
if index ~= -1 then
|
||||
return memory.raw(ITEM_BASE + index * 2 + 1)
|
||||
end
|
||||
return 0
|
||||
|
@ -77,7 +77,7 @@ end
|
|||
|
||||
function inventory.contains(...)
|
||||
for i,name in ipairs(arg) do
|
||||
if (inventory.count(name) > 0) then
|
||||
if inventory.count(name) > 0 then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
@ -88,32 +88,32 @@ end
|
|||
function inventory.teach(item, poke, replaceIdx, altPoke)
|
||||
local main = memory.value("menu", "main")
|
||||
local column = menu.getCol()
|
||||
if (main == 144) then
|
||||
if (column == 5) then
|
||||
if main == 144 then
|
||||
if column == 5 then
|
||||
menu.select(replaceIdx, true)
|
||||
else
|
||||
input.press("A")
|
||||
end
|
||||
elseif (main == 128) then
|
||||
if (column == 5) then
|
||||
elseif main == 128 then
|
||||
if column == 5 then
|
||||
menu.select(inventory.indexOf(item), "accelerate", true)
|
||||
elseif (column == 11) then
|
||||
elseif column == 11 then
|
||||
menu.select(2, true)
|
||||
elseif (column == 14) then
|
||||
elseif column == 14 then
|
||||
menu.select(0, true)
|
||||
end
|
||||
elseif (main == 103) then
|
||||
elseif main == 103 then
|
||||
input.press("B")
|
||||
elseif (main == 64 or main == 96 or main == 192) then
|
||||
if (column == 5) then
|
||||
elseif main == 64 or main == 96 or main == 192 then
|
||||
if column == 5 then
|
||||
menu.select(replaceIdx, true)
|
||||
elseif (column == 14) then
|
||||
elseif column == 14 then
|
||||
input.press("A")
|
||||
elseif (column == 15) then
|
||||
elseif column == 15 then
|
||||
menu.select(0, true)
|
||||
else
|
||||
local idx = 0
|
||||
if (poke) then
|
||||
if poke then
|
||||
idx = pokemon.indexOf(poke, altPoke)
|
||||
end
|
||||
menu.select(idx, true)
|
||||
|
@ -129,12 +129,12 @@ function inventory.isFull()
|
|||
end
|
||||
|
||||
function inventory.use(item, poke, midfight)
|
||||
if (midfight) then
|
||||
if midfight then
|
||||
local battleMenu = memory.value("battle", "menu")
|
||||
if (battleMenu == 94) then
|
||||
if battleMenu == 94 then
|
||||
local rowSelected = memory.value("menu", "row")
|
||||
if (menu.getCol() == 9) then
|
||||
if (rowSelected == 0) then
|
||||
if menu.getCol() == 9 then
|
||||
if rowSelected == 0 then
|
||||
input.press("Down")
|
||||
else
|
||||
input.press("A")
|
||||
|
@ -142,11 +142,11 @@ function inventory.use(item, poke, midfight)
|
|||
else
|
||||
input.press("Left")
|
||||
end
|
||||
elseif (battleMenu == 233) then
|
||||
elseif battleMenu == 233 then
|
||||
menu.select(inventory.indexOf(item), "accelerate", true)
|
||||
elseif (utils.onPokemonSelect(battleMenu)) then
|
||||
if (poke) then
|
||||
if (type(poke) == "string") then
|
||||
elseif utils.onPokemonSelect(battleMenu) then
|
||||
if poke then
|
||||
if type(poke) == "string" then
|
||||
poke = pokemon.indexOf(poke)
|
||||
end
|
||||
menu.select(poke, true)
|
||||
|
@ -161,35 +161,35 @@ function inventory.use(item, poke, midfight)
|
|||
|
||||
local main = memory.value("menu", "main")
|
||||
local column = menu.getCol()
|
||||
if (main == 144) then
|
||||
if (memory.value("battle", "menu") == 95) then
|
||||
if main == 144 then
|
||||
if memory.value("battle", "menu") == 95 then
|
||||
input.press("B")
|
||||
else
|
||||
local idx = 0
|
||||
if (poke) then
|
||||
if poke then
|
||||
idx = pokemon.indexOf(poke)
|
||||
end
|
||||
menu.select(idx, true)
|
||||
end
|
||||
elseif (main == 128 or main == 60) then
|
||||
if (column == 5) then
|
||||
elseif main == 128 or main == 60 then
|
||||
if column == 5 then
|
||||
menu.select(inventory.indexOf(item), "accelerate", true)
|
||||
elseif (column == 11) then
|
||||
elseif column == 11 then
|
||||
menu.select(2, true)
|
||||
elseif (column == 14) then
|
||||
elseif column == 14 then
|
||||
menu.select(0, true)
|
||||
else
|
||||
local index = 0
|
||||
if (poke) then
|
||||
if poke then
|
||||
index = pokemon.indexOf(poke)
|
||||
end
|
||||
menu.select(index, true)
|
||||
end
|
||||
elseif (main == 228) then
|
||||
if (column == 14 and memory.value("battle", "menu") == 95) then
|
||||
elseif main == 228 then
|
||||
if column == 14 and memory.value("battle", "menu") == 95 then
|
||||
input.press("B")
|
||||
end
|
||||
elseif (main == 103) then
|
||||
elseif main == 103 then
|
||||
input.press("B")
|
||||
else
|
||||
return false
|
||||
|
|
|
@ -90,7 +90,7 @@ end
|
|||
|
||||
local function index(index, offset)
|
||||
local double
|
||||
if (not offset) then
|
||||
if not offset then
|
||||
offset = 0
|
||||
else
|
||||
local dataTable = data[offset]
|
||||
|
@ -99,7 +99,7 @@ local function index(index, offset)
|
|||
end
|
||||
local address = getAddress(index) + offset
|
||||
local value = memory.raw(address)
|
||||
if (double) then
|
||||
if double then
|
||||
value = value + memory.raw(address + 1)
|
||||
end
|
||||
return value
|
||||
|
@ -111,7 +111,7 @@ local function indexOf(...)
|
|||
local pid = pokeIDs[name]
|
||||
for i=0,5 do
|
||||
local atIdx = index(i)
|
||||
if (atIdx == pid) then
|
||||
if atIdx == pid then
|
||||
return i
|
||||
end
|
||||
end
|
||||
|
@ -125,7 +125,7 @@ pokemon.indexOf = indexOf
|
|||
function pokemon.battleMove(name)
|
||||
local mid = moveList[name]
|
||||
for i=1,4 do
|
||||
if (mid == memory.raw(0xD01B + i)) then
|
||||
if mid == memory.raw(0xD01B + i) then
|
||||
return i
|
||||
end
|
||||
end
|
||||
|
@ -133,7 +133,7 @@ end
|
|||
|
||||
function pokemon.moveIndex(move, pokemon)
|
||||
local pokemonIdx
|
||||
if (pokemon) then
|
||||
if pokemon then
|
||||
pokemonIdx = indexOf(pokemon)
|
||||
else
|
||||
pokemonIdx = 0
|
||||
|
@ -141,7 +141,7 @@ function pokemon.moveIndex(move, pokemon)
|
|||
local address = getAddress(pokemonIdx) + 7
|
||||
local mid = moveList[move]
|
||||
for i=1,4 do
|
||||
if (mid == memory.raw(address + i)) then
|
||||
if mid == memory.raw(address + i) then
|
||||
return i
|
||||
end
|
||||
end
|
||||
|
@ -157,7 +157,7 @@ end
|
|||
|
||||
function pokemon.getName(id)
|
||||
for name,pid in pairs(pokeIDs) do
|
||||
if (pid == id) then
|
||||
if pid == id then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
@ -166,7 +166,7 @@ end
|
|||
function pokemon.getSacrifice(...)
|
||||
for i,name in ipairs(arg) do
|
||||
local pokemonIndex = indexOf(name)
|
||||
if (pokemonIndex ~= -1 and index(pokemonIndex, "hp") > 0) then
|
||||
if pokemonIndex ~= -1 and index(pokemonIndex, "hp") > 0 then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
@ -174,7 +174,7 @@ end
|
|||
|
||||
function pokemon.inParty(...)
|
||||
for i,name in ipairs(arg) do
|
||||
if (indexOf(name) ~= -1) then
|
||||
if indexOf(name) ~= -1 then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
@ -185,7 +185,7 @@ function pokemon.forMove(move)
|
|||
for i=0,5 do
|
||||
local address = getAddress(i)
|
||||
for j=8,11 do
|
||||
if (memory.raw(address + j) == moveID) then
|
||||
if memory.raw(address + j) == moveID then
|
||||
return i
|
||||
end
|
||||
end
|
||||
|
@ -199,9 +199,9 @@ end
|
|||
|
||||
function pokemon.updateParty()
|
||||
local partySize = memory.value("player", "party_size")
|
||||
if (partySize ~= previousPartySize) then
|
||||
if partySize ~= previousPartySize then
|
||||
local poke = pokemon.inParty("oddish", "paras", "spearow", "pidgey", "nidoran", "squirtle")
|
||||
if (poke) then
|
||||
if poke then
|
||||
bridge.caught(poke)
|
||||
previousPartySize = partySize
|
||||
end
|
||||
|
@ -213,7 +213,7 @@ end
|
|||
function pokemon.isOpponent(...)
|
||||
local oid = memory.value("battle", "opponent_id")
|
||||
for i,name in ipairs(arg) do
|
||||
if (oid == pokeIDs[name]) then
|
||||
if oid == pokeIDs[name] then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
@ -222,7 +222,7 @@ end
|
|||
function pokemon.isDeployed(...)
|
||||
local deployedID = memory.value("battle", "our_id")
|
||||
for i,name in ipairs(arg) do
|
||||
if (deployedID == pokeIDs[name]) then
|
||||
if deployedID == pokeIDs[name] then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
@ -244,27 +244,27 @@ end
|
|||
function pokemon.use(move)
|
||||
local main = memory.value("menu", "main")
|
||||
local pokeName = pokemon.forMove(move)
|
||||
if (main == 141) then
|
||||
if main == 141 then
|
||||
input.press("A")
|
||||
elseif (main == 128) then
|
||||
elseif main == 128 then
|
||||
local column = menu.getCol()
|
||||
if (column == 11) then
|
||||
if column == 11 then
|
||||
menu.select(1, true)
|
||||
elseif (column == 10 or column == 12) then
|
||||
elseif column == 10 or column == 12 then
|
||||
local midx = 0
|
||||
local menuSize = memory.value("menu", "size")
|
||||
if (menuSize == 4) then
|
||||
if (move == "dig") then
|
||||
if menuSize == 4 then
|
||||
if move == "dig" then
|
||||
midx = 1
|
||||
elseif (move == "surf") then
|
||||
if (pokemon.inParty("paras")) then
|
||||
elseif move == "surf" then
|
||||
if pokemon.inParty("paras") then
|
||||
midx = 1
|
||||
end
|
||||
end
|
||||
elseif (menuSize == 5) then
|
||||
if (move == "dig") then
|
||||
elseif menuSize == 5 then
|
||||
if move == "dig" then
|
||||
midx = 2
|
||||
elseif (move == "surf") then
|
||||
elseif move == "surf" then
|
||||
midx = 1
|
||||
end
|
||||
end
|
||||
|
@ -272,9 +272,9 @@ function pokemon.use(move)
|
|||
else
|
||||
input.press("B")
|
||||
end
|
||||
elseif (main == 103) then
|
||||
elseif main == 103 then
|
||||
menu.select(pokeName, true)
|
||||
elseif (main == 228) then
|
||||
elseif main == 228 then
|
||||
input.press("B")
|
||||
else
|
||||
return false
|
||||
|
|
|
@ -11,9 +11,9 @@ local client = nil
|
|||
local timeStopped = true
|
||||
|
||||
local function send(prefix, body)
|
||||
if (client) then
|
||||
if client then
|
||||
local message = prefix
|
||||
if (body) then
|
||||
if body then
|
||||
message = message..","..body
|
||||
end
|
||||
client:send(message.."\n")
|
||||
|
@ -22,7 +22,7 @@ local function send(prefix, body)
|
|||
end
|
||||
|
||||
local function readln()
|
||||
if (client) then
|
||||
if client then
|
||||
local s, status, partial = client:receive("*l")
|
||||
if status == "closed" then
|
||||
client = nil
|
||||
|
@ -40,7 +40,7 @@ function bridge.init()
|
|||
if socket then
|
||||
-- io.popen("java -jar Main.jar")
|
||||
client = socket.connect("127.0.0.1", 13378)
|
||||
if (client) then
|
||||
if client then
|
||||
client:settimeout(0.005)
|
||||
client:setoption("keepalive", true)
|
||||
print("Connected to Java!");
|
||||
|
@ -62,7 +62,7 @@ function bridge.pollForName()
|
|||
end
|
||||
|
||||
function bridge.chat(message, extra)
|
||||
if (extra) then
|
||||
if extra then
|
||||
print(message.." || "..extra)
|
||||
else
|
||||
print(message)
|
||||
|
@ -71,7 +71,7 @@ function bridge.chat(message, extra)
|
|||
end
|
||||
|
||||
function bridge.time(message)
|
||||
if (not timeStopped) then
|
||||
if not timeStopped then
|
||||
return send("time", message)
|
||||
end
|
||||
end
|
||||
|
@ -90,9 +90,9 @@ end
|
|||
|
||||
function bridge.process()
|
||||
local response = readln()
|
||||
if (response) then
|
||||
if response then
|
||||
-- print(">"..response)
|
||||
if (response:find("name:")) then
|
||||
if response:find("name:") then
|
||||
return response:gsub("name:", "")
|
||||
else
|
||||
|
||||
|
@ -105,7 +105,7 @@ function bridge.input(key)
|
|||
end
|
||||
|
||||
function bridge.caught(name)
|
||||
if (name) then
|
||||
if name then
|
||||
send("caught", name)
|
||||
end
|
||||
end
|
||||
|
@ -120,7 +120,7 @@ function bridge.liveSplit()
|
|||
end
|
||||
|
||||
function bridge.split(finished)
|
||||
if (finished) then
|
||||
if finished then
|
||||
timeStopped = true
|
||||
end
|
||||
send("split")
|
||||
|
|
|
@ -9,7 +9,7 @@ local debug
|
|||
local bCancel = true
|
||||
|
||||
local function bridgeButton(btn)
|
||||
if (btn ~= lastSend) then
|
||||
if btn ~= lastSend then
|
||||
lastSend = btn
|
||||
bridge.input(btn)
|
||||
end
|
||||
|
@ -18,10 +18,10 @@ end
|
|||
local function sendButton(button, ab)
|
||||
local inputTable = {[button] = true}
|
||||
joypad.set(inputTable)
|
||||
if (debug) then
|
||||
if debug then
|
||||
gui.text(0, 7, button.." "..remainingFrames)
|
||||
end
|
||||
if (ab) then
|
||||
if ab then
|
||||
buttonbutton = "A,B"
|
||||
end
|
||||
bridgeButton(button)
|
||||
|
@ -29,15 +29,15 @@ local function sendButton(button, ab)
|
|||
end
|
||||
|
||||
function input.press(button, frames)
|
||||
if (setForFrame) then
|
||||
if setForFrame then
|
||||
print("ERR: Reassigning "..setForFrame.." to "..button)
|
||||
return
|
||||
end
|
||||
if (frames == nil or frames > 0) then
|
||||
if (button == currentButton) then
|
||||
if frames == nil or frames > 0 then
|
||||
if button == currentButton then
|
||||
return
|
||||
end
|
||||
if (not frames) then
|
||||
if not frames then
|
||||
frames = 1
|
||||
end
|
||||
currentButton = button
|
||||
|
@ -50,11 +50,11 @@ function input.press(button, frames)
|
|||
end
|
||||
|
||||
function input.cancel(accept)
|
||||
if (accept and memory.value("menu", "shop_current") == 20) then
|
||||
if accept and memory.value("menu", "shop_current") == 20 then
|
||||
input.press(accept)
|
||||
else
|
||||
local button
|
||||
if (bCancel) then
|
||||
if bCancel then
|
||||
button = "B"
|
||||
else
|
||||
button = "A"
|
||||
|
@ -77,10 +77,10 @@ function input.clear()
|
|||
end
|
||||
|
||||
function input.update()
|
||||
if (currentButton) then
|
||||
if currentButton then
|
||||
remainingFrames = remainingFrames - 1
|
||||
if (remainingFrames >= 0) then
|
||||
if (remainingFrames > 0) then
|
||||
if remainingFrames >= 0 then
|
||||
if remainingFrames > 0 then
|
||||
sendButton(currentButton)
|
||||
return true
|
||||
end
|
||||
|
@ -92,7 +92,7 @@ function input.update()
|
|||
end
|
||||
|
||||
function input.advance()
|
||||
if (not setForFrame) then
|
||||
if not setForFrame then
|
||||
bridgeButton("e")
|
||||
end
|
||||
end
|
||||
|
@ -102,15 +102,15 @@ function input.setDebug(enabled)
|
|||
end
|
||||
|
||||
function input.test(fn, completes)
|
||||
while (true) do
|
||||
if (not input.update()) then
|
||||
if (fn() and completes) then
|
||||
while true do
|
||||
if not input.update() then
|
||||
if fn() and completes then
|
||||
break
|
||||
end
|
||||
end
|
||||
emu.frameadvance()
|
||||
end
|
||||
if (completes) then
|
||||
if completes then
|
||||
print(completes.." complete!")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -133,7 +133,7 @@ end
|
|||
|
||||
function Memory.value(section, key)
|
||||
local memoryAddress = memoryNames[section]
|
||||
if (key) then
|
||||
if key then
|
||||
memoryAddress = memoryAddress[key]
|
||||
end
|
||||
return raw(memoryAddress)
|
||||
|
|
|
@ -10,13 +10,13 @@ local sliding = false
|
|||
-- Private functions
|
||||
|
||||
local function getRow(menuType, scrolls)
|
||||
if (menuType and menuType == "settings") then
|
||||
if menuType and menuType == "settings" then
|
||||
menuType = menuType.."_row"
|
||||
else
|
||||
menuType = "row"
|
||||
end
|
||||
local row = memory.value("menu", menuType)
|
||||
if (scrolls) then
|
||||
if scrolls then
|
||||
row = row + memory.value("menu", "scroll_offset")
|
||||
end
|
||||
return row
|
||||
|
@ -24,12 +24,12 @@ end
|
|||
|
||||
local function setRow(desired, throttle, scrolls, menuType, loop)
|
||||
local currentRow = getRow(menuType, scrolls)
|
||||
if (throttle == "accelerate") then
|
||||
if (sliding) then
|
||||
if throttle == "accelerate" then
|
||||
if sliding then
|
||||
throttle = false
|
||||
else
|
||||
local dist = math.abs(desired - currentRow)
|
||||
if (dist < 15) then
|
||||
if dist < 15 then
|
||||
throttle = true
|
||||
else
|
||||
throttle = false
|
||||
|
@ -43,7 +43,7 @@ local function setRow(desired, throttle, scrolls, menuType, loop)
|
|||
end
|
||||
|
||||
local function isCurrently(desired, menuType)
|
||||
if (menuType) then
|
||||
if menuType then
|
||||
menuType = menuType.."_current"
|
||||
else
|
||||
menuType = "current"
|
||||
|
@ -59,7 +59,7 @@ function menu.getCol()
|
|||
end
|
||||
|
||||
function menu.open(desired, atIndex, menuType)
|
||||
if (isCurrently(desired, menuType)) then
|
||||
if isCurrently(desired, menuType) then
|
||||
return true
|
||||
end
|
||||
menu.select(atIndex, false, false, menuType)
|
||||
|
@ -67,12 +67,12 @@ function menu.open(desired, atIndex, menuType)
|
|||
end
|
||||
|
||||
function menu.select(option, throttle, scrolls, menuType, dontPress, loop)
|
||||
if (setRow(option, throttle, scrolls, menuType, loop)) then
|
||||
if setRow(option, throttle, scrolls, menuType, loop) then
|
||||
local delay = 1
|
||||
if (throttle) then
|
||||
if throttle then
|
||||
delay = 2
|
||||
end
|
||||
if (not dontPress) then
|
||||
if not dontPress then
|
||||
input.press("A", delay)
|
||||
end
|
||||
return true
|
||||
|
@ -80,7 +80,7 @@ function menu.select(option, throttle, scrolls, menuType, dontPress, loop)
|
|||
end
|
||||
|
||||
function menu.cancel(desired, menuType)
|
||||
if (not isCurrently(desired, menuType)) then
|
||||
if not isCurrently(desired, menuType) then
|
||||
return true
|
||||
end
|
||||
input.press("B")
|
||||
|
@ -90,20 +90,20 @@ end
|
|||
-- Selections
|
||||
|
||||
function menu.balance(current, desired, inverted, looping, throttle)
|
||||
if (current == desired) then
|
||||
if current == desired then
|
||||
sliding = false
|
||||
return true
|
||||
end
|
||||
if (not throttle) then
|
||||
if not throttle then
|
||||
throttle = 0
|
||||
else
|
||||
throttle = 1
|
||||
end
|
||||
local goUp = current > desired == inverted
|
||||
if (looping and math.abs(current - desired) > math.floor(looping / 2)) then
|
||||
if looping and math.abs(current - desired) > math.floor(looping / 2) then
|
||||
goUp = not goUp
|
||||
end
|
||||
if (goUp) then
|
||||
if goUp then
|
||||
input.press("Up", throttle)
|
||||
else
|
||||
input.press("Down", throttle)
|
||||
|
@ -112,19 +112,19 @@ function menu.balance(current, desired, inverted, looping, throttle)
|
|||
end
|
||||
|
||||
function menu.sidle(current, desired, looping, throttle)
|
||||
if (current == desired) then
|
||||
if current == desired then
|
||||
return true
|
||||
end
|
||||
if (not throttle) then
|
||||
if not throttle then
|
||||
throttle = 0
|
||||
else
|
||||
throttle = 1
|
||||
end
|
||||
local goLeft = current > desired
|
||||
if (looping and math.abs(current - desired) > math.floor(looping / 2)) then
|
||||
if looping and math.abs(current - desired) > math.floor(looping / 2) then
|
||||
goLeft = not goLeft
|
||||
end
|
||||
if (goLeft) then
|
||||
if goLeft then
|
||||
input.press("Left", throttle)
|
||||
else
|
||||
input.press("Right", throttle)
|
||||
|
@ -139,14 +139,14 @@ end
|
|||
-- Options
|
||||
|
||||
function menu.setOption(name, desired)
|
||||
if (YELLOW) then
|
||||
if YELLOW then
|
||||
local rowFor = {
|
||||
text_speed = 0,
|
||||
battle_animation = 1,
|
||||
battle_style = 2
|
||||
}
|
||||
local currentRow = memory.raw(0x0D3D)
|
||||
if (menu.balance(currentRow, rowFor[name], true, false, true)) then
|
||||
if menu.balance(currentRow, rowFor[name], true, false, true) then
|
||||
input.press("Left")
|
||||
end
|
||||
else
|
||||
|
@ -155,10 +155,10 @@ function menu.setOption(name, desired)
|
|||
battle_animation = 8,
|
||||
battle_style = 13
|
||||
}
|
||||
if (memory.value("setting", name) == desired) then
|
||||
if memory.value("setting", name) == desired then
|
||||
return true
|
||||
end
|
||||
if (setRow(rowFor[name], true, false, "settings")) then
|
||||
if setRow(rowFor[name], true, false, "settings") then
|
||||
menu.setCol(desired)
|
||||
end
|
||||
end
|
||||
|
@ -172,16 +172,16 @@ function menu.isOpen()
|
|||
end
|
||||
|
||||
function menu.close()
|
||||
if (memory.value("game", "textbox") == 0 and memory.value("menu", "main") < 8) then
|
||||
if memory.value("game", "textbox") == 0 and memory.value("menu", "main") < 8 then
|
||||
return true
|
||||
end
|
||||
input.press("B")
|
||||
end
|
||||
|
||||
function menu.pause()
|
||||
if (memory.value("game", "textbox") == 1) then
|
||||
if memory.value("game", "textbox") == 1 then
|
||||
local main = memory.value("menu", "main")
|
||||
if (main > 2 and main ~= 64) then
|
||||
if main > 2 and main ~= 64 then
|
||||
return true
|
||||
end
|
||||
input.press("B")
|
||||
|
|
|
@ -15,21 +15,21 @@ function paint.draw(currentMap)
|
|||
gui.text(0, 14, currentMap..": "..px.." "..py)
|
||||
gui.text(0, 0, elapsedTime())
|
||||
|
||||
if (memory.value("battle", "our_id") > 0) then
|
||||
if memory.value("battle", "our_id") > 0 then
|
||||
local hp = pokemon.index(0, "hp")
|
||||
local hpStatus
|
||||
if (hp == 0) then
|
||||
if hp == 0 then
|
||||
hpStatus = "DEAD"
|
||||
elseif (hp <= math.ceil(pokemon.index(0, "max_hp") * 0.2)) then
|
||||
elseif hp <= math.ceil(pokemon.index(0, "max_hp") * 0.2) then
|
||||
hpStatus = "RED"
|
||||
end
|
||||
if (hpStatus) then
|
||||
if hpStatus then
|
||||
gui.text(120, 7, hpStatus)
|
||||
end
|
||||
end
|
||||
|
||||
local nidx = pokemon.indexOf("nidoran", "nidorino", "nidoking")
|
||||
if (nidx ~= -1) then
|
||||
if nidx ~= -1 then
|
||||
local att = pokemon.index(nidx, "attack")
|
||||
local def = pokemon.index(nidx, "defense")
|
||||
local spd = pokemon.index(nidx, "speed")
|
||||
|
@ -37,7 +37,7 @@ function paint.draw(currentMap)
|
|||
gui.text(100, 0, att.." "..def.." "..spd.." "..scl)
|
||||
end
|
||||
local enc = " encounter"
|
||||
if (encounters ~= 1) then
|
||||
if encounters ~= 1 then
|
||||
enc = enc.."s"
|
||||
end
|
||||
gui.text(0, 116, memory.value("battle", "critical"))
|
||||
|
|
|
@ -12,16 +12,16 @@ function player.isFacing(direction)
|
|||
end
|
||||
|
||||
function player.face(direction)
|
||||
if (player.isFacing(direction)) then
|
||||
if player.isFacing(direction) then
|
||||
return true
|
||||
end
|
||||
if (textbox.handle()) then
|
||||
if textbox.handle() then
|
||||
input.press(direction, 0)
|
||||
end
|
||||
end
|
||||
|
||||
function player.interact(direction)
|
||||
if (player.face(direction)) then
|
||||
if player.face(direction) then
|
||||
input.press("A", 2)
|
||||
return true
|
||||
end
|
||||
|
|
|
@ -6,14 +6,14 @@ local menu = require "util.menu"
|
|||
local YELLOW = GAME_NAME == "yellow"
|
||||
|
||||
local settings_menu
|
||||
if (YELLOW) then
|
||||
if YELLOW then
|
||||
settings_menu = 93
|
||||
else
|
||||
settings_menu = 94
|
||||
end
|
||||
|
||||
local desired = {}
|
||||
if (YELLOW) then
|
||||
if YELLOW then
|
||||
desired.text_speed = 1
|
||||
desired.battle_animation = 128
|
||||
desired.battle_style = 64
|
||||
|
@ -24,7 +24,7 @@ else
|
|||
end
|
||||
|
||||
local function isEnabled(name)
|
||||
if (YELLOW) then
|
||||
if YELLOW then
|
||||
local matching = {
|
||||
text_speed = 0xF,
|
||||
battle_animation = 128,
|
||||
|
@ -39,8 +39,8 @@ end
|
|||
|
||||
function settings.set(...)
|
||||
for i,name in ipairs(arg) do
|
||||
if (not isEnabled(name)) then
|
||||
if (menu.open(settings_menu, 1)) then
|
||||
if not isEnabled(name) then
|
||||
if menu.open(settings_menu, 1) then
|
||||
menu.setOption(name, desired[name])
|
||||
end
|
||||
return false
|
||||
|
|
|
@ -18,7 +18,7 @@ end
|
|||
|
||||
function utils.eachi(table, func)
|
||||
for idx,val in ipairs(table) do
|
||||
if (val) then
|
||||
if val then
|
||||
func(idx.." "..val)
|
||||
else
|
||||
func(idx)
|
||||
|
@ -28,7 +28,7 @@ end
|
|||
|
||||
function utils.match(needle, haystack)
|
||||
for i,val in ipairs(haystack) do
|
||||
if (needle == val) then
|
||||
if needle == val then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -37,7 +37,7 @@ end
|
|||
|
||||
function utils.key(needle, haystack)
|
||||
for key,val in pairs(haystack) do
|
||||
if (needle == val) then
|
||||
if needle == val then
|
||||
return key
|
||||
end
|
||||
end
|
||||
|
@ -58,7 +58,7 @@ end
|
|||
-- TIME
|
||||
|
||||
local function clockSegment(unit)
|
||||
if (unit < 10) then
|
||||
if unit < 10 then
|
||||
unit = "0"..unit
|
||||
end
|
||||
return unit
|
||||
|
@ -68,7 +68,7 @@ function utils.timeSince(prevTime)
|
|||
local currTime = utils.igt()
|
||||
local diff = currTime - prevTime
|
||||
local timeString
|
||||
if (diff > 0) then
|
||||
if diff > 0 then
|
||||
local mins = math.floor(diff / 60)
|
||||
local secs = mins % 60
|
||||
timeString = clockSegment(mins)..":"..clockSegment(secs)
|
||||
|
@ -78,11 +78,11 @@ end
|
|||
|
||||
function utils.elapsedTime()
|
||||
local secs = memory.raw(0xDA44)
|
||||
if (secs < 10) then
|
||||
if secs < 10 then
|
||||
secs = "0"..secs
|
||||
end
|
||||
local mins = memory.raw(0xDA43)
|
||||
if (mins < 10) then
|
||||
if mins < 10 then
|
||||
mins = "0"..mins
|
||||
end
|
||||
return memory.raw(0xDA41)..":"..mins..":"..secs
|
||||
|
|
Loading…
Reference in New Issue