diff --git a/action/battle.lua b/action/battle.lua index 39f0b1a..6c28eda 100644 --- a/action/battle.lua +++ b/action/battle.lua @@ -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) diff --git a/action/shop.lua b/action/shop.lua index 4f58ed7..7911ac4 100644 --- a/action/shop.lua +++ b/action/shop.lua @@ -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") diff --git a/action/textbox.lua b/action/textbox.lua index 865ee72..ee99f8b 100644 --- a/action/textbox.lua +++ b/action/textbox.lua @@ -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() diff --git a/action/walk.lua b/action/walk.lua index 7e5ff60..53d2cb6 100644 --- a/action/walk.lua +++ b/action/walk.lua @@ -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 diff --git a/ai/combat.lua b/ai/combat.lua index ebdb0ce..5eb0300 100644 --- a/ai/combat.lua +++ b/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) diff --git a/ai/control.lua b/ai/control.lua index 3051fa3..b04c6d6 100644 --- a/ai/control.lua +++ b/ai/control.lua @@ -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) diff --git a/ai/strategies.lua b/ai/strategies.lua index bf3bff2..c8e5884 100644 --- a/ai/strategies.lua +++ b/ai/strategies.lua @@ -33,7 +33,7 @@ local timeRequirements = { nidoran = function() local timeLimit = 6.25 - if (pokemon.inParty("spearow")) then + if pokemon.inParty("spearow") then timeLimit = timeLimit + 0.67 end return timeLimit @@ -41,10 +41,10 @@ local timeRequirements = { mt_moon = function() local timeLimit = 27 - if (nidoAttack > 15 and nidoSpeed > 14) then + if nidoAttack > 15 and nidoSpeed > 14 then timeLimit = timeLimit + 0.25 end - if (pokemon.inParty("paras")) then + if pokemon.inParty("paras") then timeLimit = timeLimit + 0.75 end return timeLimit @@ -52,7 +52,7 @@ local timeRequirements = { mankey = function() local timeLimit = 33 - if (pokemon.inParty("paras")) then + if pokemon.inParty("paras") then timeLimit = timeLimit + 0.75 end return timeLimit @@ -60,7 +60,7 @@ local timeRequirements = { goldeen = function() local timeLimit = 38 - if (pokemon.inParty("paras")) then + if pokemon.inParty("paras") then timeLimit = timeLimit + 0.75 end return timeLimit @@ -68,7 +68,7 @@ local timeRequirements = { misty = function() local timeLimit = 40 - if (pokemon.inParty("paras")) then + if pokemon.inParty("paras") then timeLimit = timeLimit + 0.75 end return timeLimit @@ -80,13 +80,13 @@ local timeRequirements = { trash = function() local timeLimit = 47 - if (nidoSpecial > 44) then + if nidoSpecial > 44 then timeLimit = timeLimit + 0.25 end - if (nidoAttack > 53) then + if nidoAttack > 53 then timeLimit = timeLimit + 0.25 end - if (nidoAttack >= 54 and nidoSpecial >= 45) then + if nidoAttack >= 54 and nidoSpecial >= 45 then timeLimit = timeLimit + 0.25 end return timeLimit @@ -109,10 +109,10 @@ local timeRequirements = { local function hardReset(message, extra) resetting = true - if (extra) then + if extra then message = message.." | "..extra end - if (strategies.seed) then + if strategies.seed then message = message.." | "..strategies.seed end bridge.chat(message) @@ -123,14 +123,14 @@ end local function reset(reason, extra) local time = utils.elapsedTime() local resetString = "Reset" - if (time) then + if time then resetString = resetString.." after "..time end - if (areaName) then + if areaName then resetString = " "..resetString.." at "..areaName end local separator - if (deepRun and not yolo) then + if deepRun and not yolo then separator = " BibleThump" else separator = ":" @@ -142,9 +142,9 @@ strategies.reset = reset local function resetDeath(extra) local reason - if (strategies.criticaled) then + if strategies.criticaled then reason = "Critical'd" - elseif (yolo) then + elseif yolo then reason = "Yolo strats" else reason = "Died" @@ -158,12 +158,12 @@ local function overMinute(min) end local function resetTime(timeLimit, reason, once) - if (overMinute(timeLimit)) then + if overMinute(timeLimit) then reason = "Took too long to "..reason - if (RESET_FOR_TIME) then + if RESET_FOR_TIME then return reset(reason) end - if (once) then + if once then print(reason.." "..utils.elapsedTime()) end end @@ -176,16 +176,16 @@ end local function setYolo(name) local minimumTime = getTimeRequirement(name) local shouldYolo = overMinute(minimumTime) - if (yolo ~= shouldYolo) then + if yolo ~= shouldYolo then yolo = shouldYolo control.setYolo(shouldYolo) local prefix - if (yolo) then + if yolo then prefix = "en" else prefix = "dis" end - if (areaName) then + if areaName then print("YOLO "..prefix.."abled at "..areaName) else print("YOLO "..prefix.."abled") @@ -197,7 +197,7 @@ end -- PRIVATE local function initialize() - if (not initialized) then + if not initialized then initialized = true return true end @@ -214,28 +214,28 @@ local function canHealFor(damage) for idx,potion in ipairs(healChecks) do local name = potion[1] local result_hp = math.min(curr_hp + potion[2], max_hp) - if (result_hp >= damage and inventory.contains(name)) then + if result_hp >= damage and inventory.contains(name) then return name end end end local function hasHealthFor(opponent, extra) - if (not extra) then + if not extra then extra = 0 end return pokemon.index(0, "hp") + extra > combat.healthFor(opponent) end local function damaged(factor) - if (not factor) then + if not factor then factor = 1 end return pokemon.index(0, "hp") * factor < pokemon.index(0, "max_hp") end local function opponentDamaged(factor) - if (not factor) then + if not factor then factor = 1 end return memory.double("battle", "opponent_hp") * factor < memory.double("battle", "opponent_max_hp") @@ -246,14 +246,14 @@ local function redHP() end local function buffTo(buff, defLevel) - if (battle.isActive()) then + if battle.isActive() then canProgress = true local forced - if (defLevel and memory.double("battle", "opponent_defense") > defLevel) then + if defLevel and memory.double("battle", "opponent_defense") > defLevel then forced = buff end battle.automate(forced, true) - elseif (canProgress) then + elseif canProgress then return true else battle.automate() @@ -261,19 +261,19 @@ local function buffTo(buff, defLevel) end local function dodgeUp(npc, sx, sy, dodge, offset) - if (not battle.handleWild()) then + if not battle.handleWild() then return false end local px, py = player.position() - if (py < sy - 1) then + if py < sy - 1 then return true end local wx, wy = px, py - if (py < sy) then + if py < sy then wy = py - 1 - elseif (px == sx or px == dodge) then - if (px - memory.raw(npc) == offset) then - if (px == sx) then + elseif px == sx or px == dodge then + if px - memory.raw(npc) == offset then + if px == sx then wx = dodge else wx = sx @@ -287,19 +287,19 @@ end local function dodgeH(options) local left = 1 - if (options.left) then + if options.left then left = -1 end local px, py = player.position() - if (px * left > options.sx * left + (options.dist or 1) * left) then + if px * left > options.sx * left + (options.dist or 1) * left then return true end local wx, wy = px, py - if (px * left > options.sx * left) then + if px * left > options.sx * left then wx = px + 1 * left - elseif (py == options.sy or py == options.dodge) then - if (py - memory.raw(options.npc) == options.offset) then - if (py == options.sy) then + elseif py == options.sy or py == options.dodge then + if py - memory.raw(options.npc) == options.offset then + if py == options.sy then wy = options.dodge else wy = options.sy @@ -313,35 +313,35 @@ end local function completedMenuFor(data) local count = inventory.count(data.item) - if (count == 0 or count + (data.amount or 1) <= tries) then + if count == 0 or count + (data.amount or 1) <= tries then return true end return false end local function closeMenuFor(data) - if ((not tempDir and not data.close) or data.chain or menu.close()) then + if (not tempDir and not data.close) or data.chain or menu.close() then return true end end local function useItem(data) local main = memory.value("menu", "main") - if (tries == 0) then + if tries == 0 then tries = inventory.count(data.item) - if (tries == 0) then - if (closeMenuFor(data)) then + if tries == 0 then + if closeMenuFor(data) then return true end return false end end - if (completedMenuFor(data)) then - if (closeMenuFor(data)) then + if completedMenuFor(data) then + if closeMenuFor(data) then return true end else - if (inventory.use(data.item, data.poke)) then + if inventory.use(data.item, data.poke) then tempDir = true else menu.pause() @@ -350,34 +350,34 @@ local function useItem(data) end local function completedSkillFor(data) - if (data.map) then - if (data.map ~= memory.value("game", "map")) then + if data.map then + if data.map ~= memory.value("game", "map") then return true end - elseif (data.x or data.y) then + elseif data.x or data.y then local px, py = player.position() - if (data.x == px or data.y == py) then + if data.x == px or data.y == py then return true end - elseif (data.done) then - if (memory.raw(data.done) > (data.val or 0)) then + elseif data.done then + if memory.raw(data.done) > (data.val or 0) then return true end - elseif (tries > 0 and not menu.isOpen()) then + elseif tries > 0 and not menu.isOpen() then return true end return false end local function isPrepared(...) - if (tries == 0) then + if tries == 0 then tries = {} end for i,name in ipairs(arg) do local currentCount = inventory.count(name) - if (currentCount > 0) then + if currentCount > 0 then local previousCount = tries[name] - if (previousCount == nil or currentCount == previousCount) then + if previousCount == nil or currentCount == previousCount then return false end end @@ -386,7 +386,7 @@ local function isPrepared(...) end local function prepare(...) - if (tries == 0) then + if tries == 0 then tries = {} end local item @@ -394,20 +394,20 @@ local function prepare(...) local currentCount = inventory.count(name) local needsItem = currentCount > 0 local previousCount = tries[name] - if (previousCount == nil) then + if previousCount == nil then tries[name] = currentCount - elseif (needsItem) then + elseif needsItem then needsItem = currentCount == previousCount end - if (needsItem) then + if needsItem then item = name break end end - if (not item) then + if not item then return true end - if (battle.isActive()) then + if battle.isActive() then inventory.use(item, nil, true) else input.cancel() @@ -418,50 +418,50 @@ end local function nidoranDSum(disabled) local sx, sy = player.position() - if (not disabled and tries == nil) then + if not disabled and tries == nil then local opName = battle.opponent() local opLevel = memory.value("battle", "opponent_level") - if (opName == "rattata") then - if (opLevel == 2) then + if opName == "rattata" then + if opLevel == 2 then tries = {0, 4, 12} - elseif (opLevel == 3) then + elseif opLevel == 3 then tries = {0, 14, 11} else -- tries = {0, 0, 10} -- TODO can't escape end - elseif (opName == "spearow") then - if (opLevel == 5) then + elseif opName == "spearow" then + if opLevel == 5 then -- can't escape end - elseif (opName == "nidoran") then + elseif opName == "nidoran" then tries = {0, 6, 12} - elseif (opName == "nidoranf") then - if (opLevel == 3) then + elseif opName == "nidoranf" then + if opLevel == 3 then tries = {4, 6, 12} else tries = {5, 6, 12} end end - if (tries) then + if tries then tries.idx = 1 tries.x, tries.y = sx, sy else tries = 0 end end - if (not disabled and tries ~= 0) then - if (tries[tries.idx] == 0) then + if not disabled and tries ~= 0 then + if tries[tries.idx] == 0 then tries.idx = tries.idx + 1 - if (tries.idx > 3) then + if tries.idx > 3 then tries = 0 end return nidoranDSum() end - if (tries.x ~= sx or tries.y ~= sy) then + if tries.x ~= sx or tries.y ~= sy then tries[tries.idx] = tries[tries.idx] - 1 tries.x, tries.y = sx, sy end - if (tries.idx == 2) then + if tries.idx == 2 then sy = 11 else sy = 12 @@ -469,7 +469,7 @@ local function nidoranDSum(disabled) else sy = 11 end - if (sx == 33) then + if sx == 33 then sx = 32 else sx = 33 @@ -495,7 +495,7 @@ strategyFunctions = { reportFrames = function() print("FR "..strategies.frames) local repels = memory.value("player", "repel") - if (repels > 0) then + if repels > 0 then print("S "..repels) end strategies.frames = nil @@ -504,12 +504,12 @@ strategyFunctions = { tweetMisty = function() local elt = utils.elapsedTime() - if (setYolo("misty")) then + if setYolo("misty") then print("Misty: "..elt) else local pbn = "" local pbTime = getTimeRequirement("misty") - 1.75 - if (not overMinute(pbTime)) then + if not overMinute(pbTime) then pbn = " (PB pace)" end bridge.tweet("Got a run going, just beat Misty "..elt.." in"..pbn.." http://www.twitch.tv/thepokebot") @@ -520,7 +520,7 @@ strategyFunctions = { tweetVictoryRoad = function() local elt = utils.elapsedTime() local pbn = "" - if (not overMinute(98)) then -- TODO verify + if not overMinute(98) then -- TODO verify pbn = " (PB pace)" end local elt = utils.elapsedTime() @@ -534,7 +534,7 @@ strategyFunctions = { local timeDiff splitTime, timeDiff = utils.timeSince(splitTime) - if (timeDiff) then + if timeDiff then print(splitNumber..". "..areaName..": "..utils.elapsedTime().." ("..timeDiff..")") end return true @@ -553,29 +553,29 @@ strategyFunctions = { -- Global interact = function(data) - if (battle.handleWild()) then - if (battle.isActive()) then + if battle.handleWild() then + if battle.isActive() then return true end - if (textbox.isActive()) then - if (tries > 0) then + if textbox.isActive() then + if tries > 0 then return true end tries = tries - 1 input.cancel() - elseif (player.interact(data.dir)) then + elseif player.interact(data.dir) then tries = tries + 1 end end end, confirm = function(data) - if (battle.handleWild()) then - if (textbox.isActive()) then + if battle.handleWild() then + if textbox.isActive() then tries = tries + 1 input.cancel(data.type or "A") else - if (tries > 0) then + if tries > 0 then return true end player.interact(data.dir) @@ -584,9 +584,9 @@ strategyFunctions = { end, item = function(data) - if (battle.handleWild()) then - if (data.full and not inventory.isFull()) then - if (closeMenuFor(data)) then + if battle.handleWild() then + if data.full and not inventory.isFull() then + if closeMenuFor(data) then return true end return false @@ -597,85 +597,85 @@ strategyFunctions = { potion = function(data) local curr_hp = pokemon.index(0, "hp") - if (curr_hp == 0) then + if curr_hp == 0 then return false end local toHP - if (yolo and data.yolo ~= nil) then + if yolo and data.yolo ~= nil then toHP = data.yolo else toHP = data.hp end - if (type(toHP) == "string") then + if type(toHP) == "string" then toHP = combat.healthFor(toHP) end local toHeal = toHP - curr_hp - if (toHeal > 0) then + if toHeal > 0 then local toPotion - if (data.forced) then + if data.forced then toPotion = inventory.contains(data.forced) else local p_first, p_second, p_third - if (toHeal > 50) then - if (data.full) then + if toHeal > 50 then + if data.full then p_first = "full_restore" else p_first = "super_potion" end p_second, p_third = "super_potion", "potion" else - if (toHeal > 20) then + if toHeal > 20 then p_first, p_second = "super_potion", "potion" else p_first, p_second = "potion", "super_potion" end - if (data.full) then + if data.full then p_third = "full_restore" end end toPotion = inventory.contains(p_first, p_second, p_third) end - if (toPotion) then - if (menu.pause()) then + if toPotion then + if menu.pause() then inventory.use(toPotion) tempDir = true end return false end end - if (closeMenuFor(data)) then + if closeMenuFor(data) then return true end end, teach = function(data) - if (data.full and not inventory.isFull()) then + if data.full and not inventory.isFull() then return true end local itemName - if (data.item) then + if data.item then itemName = data.item else itemName = data.move end - if (pokemon.hasMove(data.move)) then + if pokemon.hasMove(data.move) then local main = memory.value("menu", "main") - if (main == 128) then - if (data.chain) then + if main == 128 then + if data.chain then return true end - elseif (main < 3) then + elseif main < 3 then return true end input.press("B") else local replacement - if (data.replace) then + if data.replace then replacement = pokemon.moveIndex(data.replace, data.poke) - 1 else replacement = 0 end - if (inventory.teach(itemName, data.poke, replacement, data.alt)) then + if inventory.teach(itemName, data.poke, replacement, data.alt) then tempDir = true else menu.pause() @@ -684,13 +684,13 @@ strategyFunctions = { end, skill = function(data) - if (completedSkillFor(data)) then - if (not textbox.isActive()) then + if completedSkillFor(data) then + if not textbox.isActive() then return true end input.press("B") - elseif (not data.dir or player.face(data.dir)) then - if (pokemon.use(data.move)) then + elseif not data.dir or player.face(data.dir) then + if pokemon.use(data.move) then tries = tries + 1 else menu.pause() @@ -699,7 +699,7 @@ strategyFunctions = { end, fly = function(data) - if (memory.value("game", "map") == data.map) then + if memory.value("game", "map") == data.map then return true end local cities = { @@ -712,24 +712,24 @@ strategyFunctions = { } local main = memory.value("menu", "main") - if (main == 228) then + if main == 228 then local currentFly = memory.raw(0x1FEF) local destination = cities[data.dest] local press - if (destination[1] - currentFly == 0) then + if destination[1] - currentFly == 0 then press = "A" else press = destination[2] end input.press(press) - elseif (not pokemon.use("fly")) then + elseif not pokemon.use("fly") then menu.pause() end end, bicycle = function() - if (memory.raw(0x1700) == 1) then - if (textbox.handle()) then + if memory.raw(0x1700) == 1 then + if textbox.handle() then return true end else @@ -742,42 +742,42 @@ strategyFunctions = { end, waitToTalk = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = false battle.automate() - elseif (textbox.isActive()) then + elseif textbox.isActive() then canProgress = true input.cancel() - elseif (canProgress) then + elseif canProgress then return true end end, waitToPause = function() local main = memory.value("menu", "main") - if (main == 128) then - if (canProgress) then + if main == 128 then + if canProgress then return true end - elseif (battle.isActive()) then + elseif battle.isActive() then canProgress = false battle.automate() - elseif (main == 123) then + elseif main == 123 then canProgress = true input.press("B") - elseif (textbox.handle()) then + elseif textbox.handle() then input.press("Start", 2) end end, waitToFight = function(data) - if (battle.isActive()) then + if battle.isActive() then canProgress = true battle.automate() - elseif (canProgress) then + elseif canProgress then return true - elseif (textbox.handle()) then - if (data.dir) then + elseif textbox.handle() then + if data.dir then player.interact(data.dir) else input.cancel() @@ -793,23 +793,23 @@ strategyFunctions = { -- Route squirtleIChooseYou = function() - if (pokemon.inParty("squirtle")) then + if pokemon.inParty("squirtle") then bridge.caught("squirtle") return true end - if (player.face("Up")) then + if player.face("Up") then textbox.name("A") end end, fightBulbasaur = function() - if (tries < 9000 and pokemon.index(0, "level") == 6) then - if (tries > 200) then + if tries < 9000 and pokemon.index(0, "level") == 6 then + if tries > 200 then squirtleAtt = pokemon.index(0, "attack") squirtleDef = pokemon.index(0, "defense") squirtleSpd = pokemon.index(0, "speed") squirtleScl = pokemon.index(0, "special") - if (squirtleAtt < 11 and squirtleScl < 12) then + if squirtleAtt < 11 and squirtleScl < 12 then return reset("Bad Squirtle - "..squirtleAtt.." attack, "..squirtleScl.." special") end tries = 9001 @@ -817,7 +817,7 @@ strategyFunctions = { tries = tries + 1 end end - if (battle.isActive() and memory.double("battle", "opponent_hp") > 0 and resetTime(2.15, "kill Bulbasaur")) then + if battle.isActive() and memory.double("battle", "opponent_hp") > 0 and resetTime(2.15, "kill Bulbasaur") then return true end return buffTo("tail_whip", 6) @@ -834,32 +834,32 @@ strategyFunctions = { end, catchNidoran = function() - if (not control.canCatch()) then + if not control.canCatch() then return true end local pokeballs = inventory.count("pokeball") local caught = memory.value("player", "party_size") - 1 - if (pokeballs < 5 - caught * 2) then + if pokeballs < 5 - caught * 2 then return reset("Ran too low on PokeBalls", pokeballs) end - if (battle.isActive()) then + if battle.isActive() then local isNidoran = pokemon.isOpponent("nidoran") - if (isNidoran and memory.value("battle", "opponent_level") > 2) then - if (initialize()) then + if isNidoran and memory.value("battle", "opponent_level") > 2 then + if initialize() then bridge.pollForName() end end tries = nil - if (memory.value("menu", "text_input") == 240) then + if memory.value("menu", "text_input") == 240 then textbox.name() - elseif (memory.value("battle", "menu") == 95) then - if (isNidoran) then + elseif memory.value("battle", "menu") == 95 then + if isNidoran then input.press("A") else input.cancel() end - elseif (not control.shouldCatch()) then - if (control.shouldFight()) then + elseif not control.shouldCatch() then + if control.shouldFight() then battle.fight() else battle.run() @@ -869,12 +869,12 @@ strategyFunctions = { local noDSum pokemon.updateParty() local hasNidoran = pokemon.inParty("nidoran") - if (hasNidoran) then - if (not tempDir) then + if hasNidoran then + if not tempDir then bridge.caught("nidoran") tempDir = true end - if (pokemon.getExp() > 205) then + if pokemon.getExp() > 205 then local nidoranLevel = pokemon.info("nidoran", "level") level4Nidoran = nidoranLevel == 4 print("Level "..nidoranLevel.." Nidoran") @@ -885,15 +885,15 @@ strategyFunctions = { local timeLimit = getTimeRequirement("nidoran") local resetMessage - if (hasNidoran) then + if hasNidoran then resetMessage = "get an experience kill before Brock" else resetMessage = "find a Nidoran" end - if (resetTime(timeLimit, resetMessage)) then + if resetTime(timeLimit, resetMessage) then return true end - if (not noDSum and overMinute(timeLimit - 0.25)) then + if not noDSum and overMinute(timeLimit - 0.25) then noDSum = true end nidoranDSum(noDSum) @@ -908,16 +908,16 @@ strategyFunctions = { grabAntidote = function() local px, py = player.position() - if (py < 11) then + if py < 11 then return true end - if (pokemon.info("spearow", "level") == 3) then - if (px < 26) then + if pokemon.info("spearow", "level") == 3 then + if px < 26 then px = 26 else py = 10 end - elseif (inventory.contains("antidote")) then + elseif inventory.contains("antidote") then py = 10 else player.interact("Up") @@ -926,101 +926,101 @@ strategyFunctions = { end, grabForestPotion = function() - if (inventory.contains("potion")) then + if inventory.contains("potion") then local healthNeeded = (pokemon.info("spearow", "level") == 3) and 6 or 10 - if (pokemon.info("squirtle", "hp") <= healthNeeded) then - if (menu.pause()) then + if pokemon.info("squirtle", "hp") <= healthNeeded then + if menu.pause() then inventory.use("potion", "squirtle") end else return true end - elseif (menu.close()) then + elseif menu.close() then player.interact("Up") end end, fightWeedle = function() - if (battle.isTrainer()) then + if battle.isTrainer() then canProgress = true local squirtleOut = pokemon.isDeployed("squirtle") - if (squirtleOut and memory.value("battle", "our_status") > 0 and not inventory.contains("antidote")) then + if squirtleOut and memory.value("battle", "our_status") > 0 and not inventory.contains("antidote") then return reset("Poisoned, but we skipped the antidote") end local sidx = pokemon.indexOf("spearow") - if (sidx ~= -1 and pokemon.index(sidx, "level") > 3) then + if sidx ~= -1 and pokemon.index(sidx, "level") > 3 then sidx = -1 end - if (sidx == -1) then + if sidx == -1 then return buffTo("tail_whip", 5) end - if (pokemon.index(sidx, "hp") < 1) then + if pokemon.index(sidx, "hp") < 1 then local battleMenu = memory.value("battle", "menu") - if (utils.onPokemonSelect(battleMenu)) then + if utils.onPokemonSelect(battleMenu) then menu.select(pokemon.indexOf("squirtle"), true) - elseif (battleMenu == 95) then + elseif battleMenu == 95 then input.press("A") - elseif (squirtleOut) then + elseif squirtleOut then battle.automate() else input.cancel() end - elseif (squirtleOut) then + elseif squirtleOut then battle.swap("spearow") else local peck = combat.bestMove() local forced - if (peck and peck.damage and peck.damage + 1 >= memory.double("battle", "opponent_hp")) then + if peck and peck.damage and peck.damage + 1 >= memory.double("battle", "opponent_hp") then forced = "growl" end battle.fight(forced) end - elseif (canProgress) then + elseif canProgress then return true end end, equipForBrock = function(data) - if (initialize()) then - if (pokemon.info("squirtle", "level") < 8) then + if initialize() then + if pokemon.info("squirtle", "level") < 8 then return reset("Not level 8 before Brock", pokemon.getExp()) end - if (data.anti) then + if data.anti then local poisoned = pokemon.info("squirtle", "status") > 0 - if (not poisoned) then + if not poisoned then return true end - if (not inventory.contains("antidote")) then + if not inventory.contains("antidote") then return reset("Poisoned, but we skipped the antidote") end - if (inventory.contains("potion") and pokemon.info("squirtle", "hp") > 8) then + if inventory.contains("potion") and pokemon.info("squirtle", "hp") > 8 then return true end end end local main = memory.value("menu", "main") local nidoranIndex = pokemon.indexOf("nidoran") - if (nidoranIndex == 0) then - if (menu.close()) then + if nidoranIndex == 0 then + if menu.close() then return true end - elseif (menu.pause()) then + elseif menu.pause() then local column = menu.getCol() - if (pokemon.info("squirtle", "status") > 0) then + if pokemon.info("squirtle", "status") > 0 then inventory.use("antidote", "squirtle") - elseif (inventory.contains("potion") and pokemon.info("squirtle", "hp") < 15) then + elseif inventory.contains("potion") and pokemon.info("squirtle", "hp") < 15 then inventory.use("potion", "squirtle") else - if (main == 128) then - if (column == 11) then + if main == 128 then + if column == 11 then menu.select(1, true) - elseif (column == 12) then + elseif column == 12 then menu.select(1, true) else input.press("B") end - elseif (main == 103) then - if (memory.value("menu", "selection_mode") == 1) then + elseif main == 103 then + if memory.value("menu", "selection_mode") == 1 then menu.select(nidoranIndex, true) else menu.select(0, true) @@ -1034,49 +1034,49 @@ strategyFunctions = { fightBrock = function() local squirtleHP = pokemon.info("squirtle", "hp") - if (squirtleHP == 0) then + if squirtleHP == 0 then return resetDeath() end - if (battle.isActive()) then - if (tries < 1) then + if battle.isActive() then + if tries < 1 then tries = 1 end local bubble, turnsToKill, turnsToDie = combat.bestMove() - if (not pokemon.isDeployed("squirtle")) then + if not pokemon.isDeployed("squirtle") then battle.swap("squirtle") - elseif (turnsToDie and turnsToDie < 2 and inventory.contains("potion")) then + elseif turnsToDie and turnsToDie < 2 and inventory.contains("potion") then inventory.use("potion", "squirtle", true) else local battleMenu = memory.value("battle", "menu") local bideTurns = memory.value("battle", "opponent_bide") - if (battleMenu == 95 and menu.getCol() == 1) then + if battleMenu == 95 and menu.getCol() == 1 then input.press("A") - elseif (bideTurns > 0) then + elseif bideTurns > 0 then local onixHP = memory.double("battle", "opponent_hp") - if (not canProgress) then + if not canProgress then canProgress = onixHP tempDir = bideTurns end - if (turnsToKill) then + if turnsToKill then local forced - if (turnsToDie < 2 or turnsToKill < 2 or tempDir - bideTurns > 1) then - -- elseif (turnsToKill < 3 and tempDir == bideTurns) then - elseif (onixHP == canProgress) then + if turnsToDie < 2 or turnsToKill < 2 or tempDir - bideTurns > 1 then + -- elseif turnsToKill < 3 and tempDir == bideTurns then + elseif onixHP == canProgress then forced = "tail_whip" end battle.fight(forced) else input.cancel() end - elseif (utils.onPokemonSelect(battleMenu)) then + elseif utils.onPokemonSelect(battleMenu) then menu.select(pokemon.indexOf("nidoran"), true) else canProgress = false battle.fight() end - if (tries < 9000) then + if tries < 9000 then local nidx = pokemon.indexOf("nidoran") - if (pokemon.index(nidx, "level") == 8) then + if pokemon.index(nidx, "level") == 8 then local att = pokemon.index(nidx, "attack") local def = pokemon.index(nidx, "defense") local spd = pokemon.index(nidx, "speed") @@ -1085,43 +1085,43 @@ strategyFunctions = { nidoAttack = att nidoSpeed = spd nidoSpecial = scl - if (tries > 300) then + if tries > 300 then local statDiff = (16 - att) + (15 - spd) + (13 - scl) - if (def < 12) then + if def < 12 then statDiff = statDiff + 1 end - if (level4Nidoran) then + if level4Nidoran then statDiff = statDiff - 1 end local resets = att < 15 or spd < 14 or scl < 12 or statDiff > 3 - if (not resets and att == 15 and spd == 14) then + if not resets and att == 15 and spd == 14 then resets = true end local nStatus = "Att: "..att..", Def: "..def..", Speed: "..spd..", Special: "..scl - if (resets) then + if resets then return reset("Bad Nidoran - "..nStatus) end tries = 9001 local superlative local exclaim = "!" - if (statDiff == 0) then - if (def == 14) then + if statDiff == 0 then + if def == 14 then superlative = " god" exclaim = "! Kreygasm" else superlative = " perfect" end - elseif (att == 16 and spd == 15) then - if (statDiff == 1) then + elseif att == 16 and spd == 15 then + if statDiff == 1 then superlative = " great" - elseif (statDiff == 2) then + elseif statDiff == 2 then superlative = " good" else superlative = " okay" end - elseif (statDiff == 1) then + elseif statDiff == 1 then superlative = " good" - elseif (statDiff == 2) then + elseif statDiff == 2 then superlative = "n okay" exclaim = "." else @@ -1136,9 +1136,9 @@ strategyFunctions = { end end end - elseif (tries > 0) then + elseif tries > 0 then return true - elseif (textbox.handle()) then + elseif textbox.handle() then player.interact("Up") end end, @@ -1152,19 +1152,19 @@ strategyFunctions = { end, battleModeSet = function() - if (memory.value("setting", "battle_style") == 10) then - if (menu.close()) then + if memory.value("setting", "battle_style") == 10 then + if menu.close() then return true end - elseif (menu.pause()) then + elseif menu.pause() then local main = memory.value("menu", "main") - if (main == 128) then - if (menu.getCol() ~= 11) then + if main == 128 then + if menu.getCol() ~= 11 then input.press("B") else menu.select(5, true) end - elseif (main == 228) then + elseif main == 228 then menu.setOption("battle_style", 8, 10) else input.press("B") @@ -1174,10 +1174,10 @@ strategyFunctions = { leer = function(data) local bm = combat.bestMove() - if (not bm or bm.minTurns < 3) then - if (battle.isActive()) then + if not bm or bm.minTurns < 3 then + if battle.isActive() then canProgress = true - elseif (canProgress) then + elseif canProgress then return true end battle.automate() @@ -1186,9 +1186,9 @@ strategyFunctions = { local opp = battle.opponent() local defLimit = 9001 for i,poke in ipairs(data) do - if (opp == poke[1]) then + if opp == poke[1] then local minimumAttack = poke[3] - if (not minimumAttack or nidoAttack > minimumAttack) then + if not minimumAttack or nidoAttack > minimumAttack then defLimit = poke[2] end break @@ -1198,22 +1198,22 @@ strategyFunctions = { end, bugCatcher = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true local isWeedle = pokemon.isOpponent("weedle") - if (isWeedle and not tempDir) then + if isWeedle and not tempDir then tempDir = true end secondCaterpie = tempDir - if (not isWeedle and secondCaterpie) then - if (level4Nidoran and nidoSpeed >= 14 and pokemon.index(0, "attack") >= 19) then + if not isWeedle and secondCaterpie then + if level4Nidoran and nidoSpeed >= 14 and pokemon.index(0, "attack") >= 19 then -- print("IA "..pokemon.index(0, "attack")) battle.automate() return end end strategyFunctions.leer({{"caterpie",8}, {"weedle",7}}) - elseif (canProgress) then + elseif canProgress then return true else battle.automate() @@ -1222,18 +1222,18 @@ strategyFunctions = { shortsKid = function() local fightingEkans = pokemon.isOpponent("ekans") - if (fightingEkans) then + if fightingEkans then local wrapping = memory.value("battle", "turns") > 0 - if (wrapping) then + if wrapping then local curr_hp = memory.double("battle", "our_hp") - if (not tempDir) then + if not tempDir then tempDir = curr_hp end - if (tempDir - curr_hp < 4 and curr_hp < 14 and not opponentDamaged()) then + if tempDir - curr_hp < 4 and curr_hp < 14 and not opponentDamaged() then inventory.use("potion", nil, true) return false end - elseif (tempDir) then + elseif tempDir then tempDir = nil end end @@ -1242,27 +1242,27 @@ strategyFunctions = { end, potionBeforeCocoons = function() - if (nidoSpeed >= 15) then + if nidoSpeed >= 15 then return true end return strategyFunctions.potion({hp=6, yolo=3}) end, swapHornAttack = function() - if (pokemon.battleMove("horn_attack") == 1) then + if pokemon.battleMove("horn_attack") == 1 then return true end battle.swapMove(1, 3) end, fightMetapod = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true - if (memory.double("battle", "opponent_hp") > 0 and pokemon.isOpponent("metapod")) then + if memory.double("battle", "opponent_hp") > 0 and pokemon.isOpponent("metapod") then return true end battle.automate() - elseif (canProgress) then + elseif canProgress then return true else battle.automate() @@ -1270,39 +1270,39 @@ strategyFunctions = { end, catchFlierBackup = function() - if (initialize()) then + if initialize() then control.canDie(true) end - if (not control.canCatch()) then + if not control.canCatch() then return true end local caught = pokemon.inParty("pidgey", "spearow") - if (battle.isActive()) then - if (memory.double("battle", "our_hp") == 0) then - if (pokemon.info("squirtle", "hp") == 0) then + if battle.isActive() then + if memory.double("battle", "our_hp") == 0 then + if pokemon.info("squirtle", "hp") == 0 then control.canDie(false) - elseif (utils.onPokemonSelect(memory.value("battle", "menu"))) then + elseif utils.onPokemonSelect(memory.value("battle", "menu")) then menu.select(pokemon.indexOf("squirtle"), true) else input.press("A") end - elseif (not control.shouldCatch()) then + elseif not control.shouldCatch() then battle.run() end else local birdPath local px, py = player.position() - if (caught) then - if (px > 33) then + if caught then + if px > 33 then return true end local startY = 9 - if (px > 28) then + if px > 28 then startY = py end birdPath = {{32,startY}, {32,11}, {34,11}} - elseif (px == 37) then - if (py == 10) then + elseif px == 37 then + if py == 10 then py = 11 else py = 10 @@ -1311,7 +1311,7 @@ strategyFunctions = { else birdPath = {{32,10}, {32,11}, {34,11}, {34,10}, {37,10}} end - if (birdPath) then + if birdPath then walk.custom(birdPath) end end @@ -1326,23 +1326,23 @@ strategyFunctions = { end, evolveNidorino = function() - if (pokemon.inParty("nidorino")) then + if pokemon.inParty("nidorino") then bridge.caught("nidorino") return true end - if (battle.isActive()) then + if battle.isActive() then tries = 0 canProgress = true - if (memory.double("battle", "opponent_hp") == 0) then + if memory.double("battle", "opponent_hp") == 0 then input.press("A") else battle.automate() end - elseif (tries > 3600) then + elseif tries > 3600 then print("Broke from Nidorino on tries") return true else - if (canProgress) then + if canProgress then tries = tries + 1 end input.press("A") @@ -1350,23 +1350,23 @@ strategyFunctions = { end, evolveNidoking = function() - if (battle.handleWild()) then - if (not inventory.contains("moon_stone")) then - if (initialize()) then + if battle.handleWild() then + if not inventory.contains("moon_stone") then + if initialize() then bridge.caught("nidoking") end - if (menu.close()) then + if menu.close() then return true end - elseif (not inventory.use("moon_stone")) then + elseif not inventory.use("moon_stone") then menu.pause() end end end, helix = function() - if (battle.handleWild()) then - if (inventory.contains("helix_fossil")) then + if battle.handleWild() then + if inventory.contains("helix_fossil") then return true end player.interact("Up") @@ -1374,23 +1374,23 @@ strategyFunctions = { end, reportMtMoon = function() - if (battle.pp("horn_attack") == 0) then + if battle.pp("horn_attack") == 0 then print("ERR: Ran out of Horn Attacks") end - if (strategies.moonEncounters) then + if strategies.moonEncounters then local parasStatus local conjunction = "but" local goodEncounters = strategies.moonEncounters < 10 local parasCatch - if (pokemon.inParty("paras")) then + if pokemon.inParty("paras") then parasCatch = "paras" - if (goodEncounters) then + if goodEncounters then conjunction = "and" end parasStatus = "we found a Paras!" else parasCatch = "no_paras" - if (not goodEncounters) then + if not goodEncounters then conjunction = "and" end parasStatus = "we didn't find a Paras :(" @@ -1429,25 +1429,25 @@ strategyFunctions = { end, rivalSandAttack = function(data) - if (battle.isActive()) then - if (battle.redeployNidoking()) then + if battle.isActive() then + if battle.redeployNidoking() then return false end local opponent = battle.opponent() - if (opponent == "pidgeotto") then + if opponent == "pidgeotto" then canProgress = true combat.disableThrash = true - if (memory.value("battle", "accuracy") < 7) then + if memory.value("battle", "accuracy") < 7 then local __, turns = combat.bestMove() - if (turns == 1 and battle.sacrifice("pidgey", "spearow", "paras", "oddish", "squirtle")) then + if turns == 1 and battle.sacrifice("pidgey", "spearow", "paras", "oddish", "squirtle") then return false end end - elseif (opponent == "raticate") then + elseif opponent == "raticate" then combat.disableThrash = opponentDamaged() or (not yolo and pokemon.index(0, "hp") < 32) -- RISK - elseif (opponent == "ivysaur") then - if (not yolo and damaged(5) and inventory.contains("super_potion")) then + elseif opponent == "ivysaur" then + if not yolo and damaged(5) and inventory.contains("super_potion") then inventory.use("super_potion", nil, true) return false end @@ -1457,7 +1457,7 @@ strategyFunctions = { end battle.automate() canProgress = true - elseif (canProgress) then + elseif canProgress then combat.disableThrash = false return true else @@ -1466,13 +1466,13 @@ strategyFunctions = { end, teachThrash = function() - if (initialize()) then - if (pokemon.hasMove("thrash") or pokemon.info("nidoking", "level") < 21) then + if initialize() then + if pokemon.hasMove("thrash") or pokemon.info("nidoking", "level") < 21 then return true end end - if (strategyFunctions.teach({move="thrash",item="rare_candy",replace="leer"})) then - if (menu.close()) then + if strategyFunctions.teach({move="thrash",item="rare_candy",replace="leer"}) then + if menu.close() then local att = pokemon.index(0, "attack") local def = pokemon.index(0, "defense") local spd = pokemon.index(0, "speed") @@ -1489,33 +1489,33 @@ strategyFunctions = { end, redbarMankey = function() - if (not setYolo("mankey")) then + if not setYolo("mankey") then return true end local curr_hp, red_hp = pokemon.index(0, "hp"), redHP() - if (curr_hp <= red_hp) then + if curr_hp <= red_hp then return true end - if (initialize()) then - if (pokemon.info("nidoking", "level") < 23 or inventory.count("potion") < 3) then -- RISK + if initialize() then + if pokemon.info("nidoking", "level") < 23 or inventory.count("potion") < 3 then -- RISK return true end bridge.chat("Using Poison Sting to attempt to redbar off Mankey") end - if (battle.isActive()) then + if battle.isActive() then canProgress = true local enemyMove, enemyTurns = combat.enemyAttack() - if (enemyTurns) then - if (enemyTurns < 2) then + if enemyTurns then + if enemyTurns < 2 then return true end local scratchDmg = enemyMove.damage - if (curr_hp - red_hp > scratchDmg) then + if curr_hp - red_hp > scratchDmg then return true end end battle.automate("poison_sting") - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -1523,15 +1523,15 @@ strategyFunctions = { end, thrashGeodude = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true - if (pokemon.isOpponent("geodude") and pokemon.isDeployed("nidoking")) then - if (battle.sacrifice("squirtle")) then + if pokemon.isOpponent("geodude") and pokemon.isDeployed("nidoking") then + if battle.sacrifice("squirtle") then return false end end battle.automate() - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -1539,11 +1539,11 @@ strategyFunctions = { end, potionBeforeGoldeen = function() - if (not STREAMING_MODE and nidoSpeed == 51) then + if not STREAMING_MODE and nidoSpeed == 51 then return false --TEST end - if (initialize()) then - if (setYolo("goldeen") or pokemon.index(0, "hp") > 7) then + if initialize() then + if setYolo("goldeen") or pokemon.index(0, "hp") > 7 then return true end end @@ -1552,21 +1552,21 @@ strategyFunctions = { potionBeforeMisty = function() local healAmount = 70 - if (yolo) then - if (nidoAttack > 53 and nidoSpeed > 50) then + if yolo then + if nidoAttack > 53 and nidoSpeed > 50 then healAmount = 45 - elseif (nidoAttack > 53) then + elseif nidoAttack > 53 then healAmount = 65 end else - if (nidoAttack > 54 and nidoSpeed > 51) then -- RISK + if nidoAttack > 54 and nidoSpeed > 51 then -- RISK healAmount = 45 - elseif (nidoAttack > 53 and nidoSpeed > 50) then + elseif nidoAttack > 53 and nidoSpeed > 50 then healAmount = 65 end end - if (initialize()) then - if (healAmount < 60) then + if initialize() then + if healAmount < 60 then bridge.chat("Limiting heals to attempt to get closer to red-bar off Misty", inventory.count("potion")) end end @@ -1574,23 +1574,23 @@ strategyFunctions = { end, fightMisty = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true - if (battle.redeployNidoking()) then - if (tempDir == false) then + if battle.redeployNidoking() then + if tempDir == false then tempDir = true end return false end local swappedOut = tempDir - if (not swappedOut and combat.isConfused()) then + if not swappedOut and combat.isConfused() then tempDir = false - if (battle.sacrifice("pidgey", "spearow", "paras")) then + if battle.sacrifice("pidgey", "spearow", "paras") then return false end end battle.automate() - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -1601,19 +1601,19 @@ strategyFunctions = { potionBeforeRocket = function() local minAttack = 55 -- RISK - if (yolo) then + if yolo then minAttack = minAttack - 1 end - if (nidoAttack >= minAttack) then + if nidoAttack >= minAttack then return true end return strategyFunctions.potion({hp=10}) end, jingleSkip = function() - if (canProgress) then + if canProgress then local px, py = player.position() - if (px < 4) then + if px < 4 then return true end input.press("Left", 0) @@ -1624,60 +1624,60 @@ strategyFunctions = { end, catchOddish = function() - if (not control.canCatch()) then + if not control.canCatch() then return true end local caught = pokemon.inParty("oddish", "paras") local battleValue = memory.value("game", "battle") local px, py = player.position() - if (battleValue > 0) then - if (battleValue == 2) then + if battleValue > 0 then + if battleValue == 2 then tries = 2 battle.automate() else - if (tries == 0 and py == 31) then + if tries == 0 and py == 31 then tries = 1 end - if (not control.shouldCatch()) then + if not control.shouldCatch() then battle.run() end end - elseif (tries == 1 and py == 31) then + elseif tries == 1 and py == 31 then player.interact("Left") else local path - if (caught) then - if (not tempDir) then + if caught then + if not tempDir then bridge.caught(pokemon.inParty("oddish")) tempDir = true end - if (py < 21) then + if py < 21 then py = 21 - elseif (py < 24) then - if (px < 16) then + elseif py < 24 then + if px < 16 then px = 17 else py = 24 end - elseif (py < 25) then + elseif py < 25 then py = 25 - elseif (px > 15) then + elseif px > 15 then px = 15 - elseif (py < 28) then + elseif py < 28 then py = 28 - elseif (py > 29) then + elseif py > 29 then py = 29 - elseif (px ~= 11) then + elseif px ~= 11 then px = 11 - elseif (py ~= 29) then + elseif py ~= 29 then py = 29 else return true end walk.step(px, py) - elseif (px == 12) then + elseif px == 12 then local dy - if (py == 30) then + if py == 30 then dy = 31 else dy = 30 @@ -1691,11 +1691,11 @@ strategyFunctions = { end, shopVermilionMart = function() - if (initialize()) then + if initialize() then setYolo("vermilion") end local buyArray, sellArray - if (not inventory.contains("pokeball") or (not yolo and nidoAttack < 53)) then + if not inventory.contains("pokeball") or (not yolo and nidoAttack < 53) then sellArray = {{name="pokeball"}, {name="antidote"}, {name="tm34"}, {name="nugget"}} buyArray = {{name="super_potion",index=1,amount=3}, {name="paralyze_heal",index=4,amount=2}, {name="repel",index=5,amount=3}} else @@ -1712,36 +1712,36 @@ strategyFunctions = { trashcans = function() local progress = memory.value("progress", "trashcans") - if (textbox.isActive()) then - if (not canProgress) then - if (progress < 2) then + if textbox.isActive() then + if not canProgress then + if progress < 2 then tries = tries + 1 end canProgress = true end input.cancel() else - if (progress == 3) then + if progress == 3 then local px, py = player.position() - if (px == 4 and py == 6) then + if px == 4 and py == 6 then tries = tries + 1 local timeLimit = getTimeRequirement("trash") + 1 - if (resetTime(timeLimit, "complete Trashcans ("..tries.." tries)")) then + if resetTime(timeLimit, "complete Trashcans ("..tries.." tries)") then return true end setYolo("trash") local prefix local suffix = "!" - if (tries < 2) then + if tries < 2 then prefix = "PERFECT" - elseif (tries < 4) then + elseif tries < 4 then prefix = "Amazing" - elseif (tries < 7) then + elseif tries < 7 then prefix = "Great" - elseif (tries < 10) then + elseif tries < 10 then prefix = "Good" - elseif (tries < 24) then + elseif tries < 24 then prefix = "Ugh" suffix = "." else -- TODO trashcans WR @@ -1759,15 +1759,15 @@ strategyFunctions = { local walkIn = "Up" for dir,tileset in pairs(completePath) do for i,tile in ipairs(tileset) do - if (px == tile[1] and py == tile[2]) then + if px == tile[1] and py == tile[2] then walkIn = dir break end end end input.press(walkIn, 0) - elseif (progress == 2) then - if (canProgress) then + elseif progress == 2 then + if canProgress then canProgress = false walk.invertCustom() end @@ -1780,17 +1780,17 @@ strategyFunctions = { player.interact(inverse[tempDir]) else local trashPath = {{2,11},{"Left"},{2,11}, {2,12},{4,12},{4,11},{"Right"},{4,11}, {4,9},{"Left"},{4,9}, {4,7},{"Right"},{4,7}, {4,6},{2,6},{2,7},{"Left"},{2,7}, {2,6},{4,6},{4,8},{7,8},{"Down"},{7,8}, {9,8},{"Up"},{9,8}, {8,8},{8,11},{"Right"},{8,11}} - if (tempDir and type(tempDir) == "number") then + if tempDir and type(tempDir) == "number" then local px, py = player.position() local dx, dy = px, py - if (py < 12) then + if py < 12 then dy = 12 - elseif (tempDir == 1) then + elseif tempDir == 1 then dx = 2 else dx = 8 end - if (px ~= dx or py ~= dy) then + if px ~= dx or py ~= dy then walk.step(dx, dy) return end @@ -1803,18 +1803,18 @@ strategyFunctions = { end, fightSurge = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true local forced - if (pokemon.isOpponent("voltorb")) then + if pokemon.isOpponent("voltorb") then combat.disableThrash = true local __, enemyTurns = combat.enemyAttack() - if (not enemyTurns or enemyTurns > 2) then + if not enemyTurns or enemyTurns > 2 then forced = "bubblebeam" - elseif (enemyTurns == 2 and not opponentDamaged()) then + elseif enemyTurns == 2 and not opponentDamaged() then local curr_hp, red_hp = pokemon.index(0, "hp"), redHP() local afterHit = curr_hp - 20 - if (afterHit > 5 and afterHit <= red_hp) then + if afterHit > 5 and afterHit <= red_hp then forced = "bubblebeam" end end @@ -1822,7 +1822,7 @@ strategyFunctions = { combat.disableThrash = false end battle.automate(forced) - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -1832,33 +1832,33 @@ strategyFunctions = { -- 7: SURGE procureBicycle = function() - if (inventory.contains("bicycle")) then - if (not textbox.isActive()) then + if inventory.contains("bicycle") then + if not textbox.isActive() then return true end input.cancel() - elseif (textbox.handle()) then + elseif textbox.handle() then player.interact("Right") end end, swapBicycle = function() local bicycleIdx = inventory.indexOf("bicycle") - if (bicycleIdx < 3) then + if bicycleIdx < 3 then return true end local main = memory.value("menu", "main") - if (main == 128) then - if (menu.getCol() ~= 5) then + if main == 128 then + if menu.getCol() ~= 5 then menu.select(2, true) else local selection = memory.value("menu", "selection_mode") - if (selection == 0) then - if (menu.select(0, "accelerate", true, nil, true)) then + if selection == 0 then + if menu.select(0, "accelerate", true, nil, true) then input.press("Select") end else - if (menu.select(bicycleIdx, "accelerate", true, nil, true)) then + if menu.select(bicycleIdx, "accelerate", true, nil, true) then input.press("Select") end end @@ -1869,31 +1869,31 @@ strategyFunctions = { end, redbarCubone = function() - if (battle.isActive()) then + if battle.isActive() then local forced canProgress = true - if (pokemon.isOpponent("cubone")) then + if pokemon.isOpponent("cubone") then local enemyMove, enemyTurns = combat.enemyAttack() - if (enemyTurns) then + if enemyTurns then local curr_hp, red_hp = pokemon.index(0, "hp"), redHP() local clubDmg = enemyMove.damage local afterHit = curr_hp - clubDmg red_hp = red_hp - 2 - if (afterHit > -2 and afterHit < red_hp) then + if afterHit > -2 and afterHit < red_hp then forced = "thunderbolt" else afterHit = afterHit - clubDmg - if (afterHit > -4 and afterHit < red_hp) then + if afterHit > -4 and afterHit < red_hp then forced = "thunderbolt" end end - if (forced and initialize()) then + if forced and initialize() then bridge.chat("Using Thunderbolt to attempt to redbar off Cubone") end end end battle.automate(forced) - elseif (canProgress) then + elseif canProgress then return true else battle.automate() @@ -1929,15 +1929,15 @@ strategyFunctions = { end, giveWater = function() - if (not inventory.contains("fresh_water", "soda_pop")) then + if not inventory.contains("fresh_water", "soda_pop") then return true end - if (textbox.isActive()) then + if textbox.isActive() then input.cancel("A") else local cx, cy = memory.raw(0x0223) - 3, memory.raw(0x0222) - 3 local px, py = player.position() - if (utils.dist(cx, cy, px, py) == 1) then + if utils.dist(cx, cy, px, py) == 1 then player.interact(walk.dir(px, py, cx, cy)) else walk.step(cx, cy) @@ -1953,21 +1953,21 @@ strategyFunctions = { end, shopBuffs = function() - if (initialize()) then + if initialize() then local minSpecial = 45 - if (yolo) then + if yolo then minSpecial = minSpecial - 1 end - if (nidoAttack >= 54 and nidoSpecial >= minSpecial) then + if nidoAttack >= 54 and nidoSpecial >= minSpecial then riskGiovanni = true print("Giovanni skip strats!") end end local xspecAmt = 4 - if (riskGiovanni) then + if riskGiovanni then xspecAmt = xspecAmt + 1 - elseif (nidoSpecial < 46) then + elseif nidoSpecial < 46 then -- xspecAmt = xspecAmt - 1 end return shop.transaction{ @@ -1977,11 +1977,11 @@ strategyFunctions = { end, deptElevator = function() - if (textbox.isActive()) then + if textbox.isActive() then canProgress = true menu.select(0, false) else - if (canProgress) then + if canProgress then return true end player.interact("Up") @@ -1990,21 +1990,21 @@ strategyFunctions = { swapRepels = function() local repelIdx = inventory.indexOf("super_repel") - if (repelIdx < 3) then + if repelIdx < 3 then return true end local main = memory.value("menu", "main") - if (main == 128) then - if (menu.getCol() ~= 5) then + if main == 128 then + if menu.getCol() ~= 5 then menu.select(2, true) else local selection = memory.value("menu", "selection_mode") - if (selection == 0) then - if (menu.select(1, "accelerate", true, nil, true)) then + if selection == 0 then + if menu.select(1, "accelerate", true, nil, true) then input.press("Select") end else - if (menu.select(repelIdx, "accelerate", true, nil, true)) then + if menu.select(repelIdx, "accelerate", true, nil, true) then input.press("Select") end end @@ -2017,20 +2017,20 @@ strategyFunctions = { -- 8: FLY lavenderRival = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true local forced - if (nidoSpecial > 44) then -- RISK + if nidoSpecial > 44 then -- RISK local __, enemyTurns = combat.enemyAttack() - if (enemyTurns and enemyTurns < 2 and pokemon.isOpponent("pidgeotto", "gyarados")) then + if enemyTurns and enemyTurns < 2 and pokemon.isOpponent("pidgeotto", "gyarados") then battle.automate() return false end end - if (pokemon.isOpponent("gyarados") or prepare("x_accuracy")) then + if pokemon.isOpponent("gyarados") or prepare("x_accuracy") then battle.automate() end - elseif (canProgress) then + elseif canProgress then return true else input.cancel() @@ -2038,10 +2038,10 @@ strategyFunctions = { end, pokeDoll = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true inventory.use("pokedoll", nil, true) - elseif (canProgress) then + elseif canProgress then return true else input.cancel() @@ -2049,12 +2049,12 @@ strategyFunctions = { end, digFight = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true local backupIndex = pokemon.indexOf("paras", "squirtle") - if (pokemon.isDeployed("nidoking")) then - if (pokemon.info("nidoking", "hp") == 0) then - if (utils.onPokemonSelect(memory.value("battle", "menu"))) then + if pokemon.isDeployed("nidoking") then + if pokemon.info("nidoking", "hp") == 0 then + if utils.onPokemonSelect(memory.value("battle", "menu")) then menu.select(backupIndex, true) else input.press("A") @@ -2062,12 +2062,12 @@ strategyFunctions = { else battle.automate() end - elseif (pokemon.info("nidoking", "hp") == 0 and pokemon.index(backupIndex, "hp") == 0 and pokemon.isDeployed("paras", "squirtle")) then + elseif pokemon.info("nidoking", "hp") == 0 and pokemon.index(backupIndex, "hp") == 0 and pokemon.isDeployed("paras", "squirtle") then return resetDeath() else battle.fight("dig") end - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2076,10 +2076,10 @@ strategyFunctions = { thunderboltFirst = function() local forced - if (pokemon.isOpponent("zubat")) then + if pokemon.isOpponent("zubat") then canProgress = true forced = "thunderbolt" - elseif (canProgress) then + elseif canProgress then return true end battle.automate(forced) @@ -2088,29 +2088,29 @@ strategyFunctions = { -- 8: POKÉFLUTE playPokeflute = function() - if (battle.isActive()) then + if battle.isActive() then return true end - if (memory.value("battle", "menu") == 95) then + if memory.value("battle", "menu") == 95 then input.press("A") - elseif (menu.pause()) then + elseif menu.pause() then inventory.use("pokeflute") end end, drivebyRareCandy = function() - if (textbox.isActive()) then + if textbox.isActive() then canProgress = true input.cancel() - elseif (canProgress) then + elseif canProgress then return true else local px, py = player.position() - if (py < 13) then + if py < 13 then tries = 0 return end - if (py == 13 and tries % 2 == 0) then + if py == 13 and tries % 2 == 0 then input.press("A", 2) else input.press("Up") @@ -2121,25 +2121,25 @@ strategyFunctions = { end, safariCarbos = function() - if (initialize()) then + if initialize() then setYolo("safari_carbos") end local minSpeed = 50 - if (yolo) then + if yolo then minSpeed = minSpeed - 1 end - if (nidoSpeed >= minSpeed) then + if nidoSpeed >= minSpeed then return true end - if (inventory.contains("carbos")) then - if (walk.step(20, 20)) then + if inventory.contains("carbos") then + if walk.step(20, 20) then return true end else local px, py = player.position() - if (px < 21) then + if px < 21 then walk.step(21, py) - elseif (px == 21 and py == 13) then + elseif px == 21 and py == 13 then player.interact("Left") else walk.step(21, 13) @@ -2148,16 +2148,16 @@ strategyFunctions = { end, centerSkipFullRestore = function() - if (initialize()) then - if (yolo or inventory.contains("full_restore")) then + if initialize() then + if yolo or inventory.contains("full_restore") then return true end bridge.chat("We need to grab the backup Full Restore here.") end local px, py = player.position() - if (px < 21) then + if px < 21 then px = 21 - elseif (py < 9) then + elseif py < 9 then py = 9 else return strategyFunctions.interact({dir="Down"}) @@ -2166,11 +2166,11 @@ strategyFunctions = { end, silphElevator = function() - if (textbox.isActive()) then + if textbox.isActive() then canProgress = true menu.select(9, false, true) else - if (canProgress) then + if canProgress then return true end player.interact("Up") @@ -2178,13 +2178,13 @@ strategyFunctions = { end, fightSilphMachoke = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true - if (nidoSpecial > 44) then + if nidoSpecial > 44 then return prepare("x_accuracy") end battle.automate("thrash") - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2192,15 +2192,15 @@ strategyFunctions = { end, silphCarbos = function() - if (nidoSpeed > 50) then + if nidoSpeed > 50 then return true end return strategyFunctions.interact({dir="Left"}) end, silphRival = function() - if (battle.isActive()) then - if (initialize()) then + if battle.isActive() then + if initialize() then tempDir = combat.healthFor("RivalGyarados") print("Gyarados "..tempDir) canProgress = true @@ -2213,38 +2213,38 @@ strategyFunctions = { if opName == "gyarados" then readyToAttack = true local hp, red_hp = pokemon.index(0, "hp"), redHP() - if (hp > gyaradosDamage * 0.98 and hp - gyaradosDamage * 0.975 < red_hp) then --TODO - if (prepare("x_special")) then + if hp > gyaradosDamage * 0.98 and hp - gyaradosDamage * 0.975 < red_hp then --TODO + if prepare("x_special") then forced = "ice_beam" else readyToAttack = false end - elseif (isPrepared("x_special")) then + elseif isPrepared("x_special") then local canPotion - if (inventory.contains("potion") and hp + 20 > gyaradosDamage and hp + 20 - gyaradosDamage < red_hp) then + if inventory.contains("potion") and hp + 20 > gyaradosDamage and hp + 20 - gyaradosDamage < red_hp then canPotion = "potion" - elseif (inventory.contains("super_potion") and hp + 50 > gyaradosDamage and hp + 50 - gyaradosDamage < red_hp) then + elseif inventory.contains("super_potion") and hp + 50 > gyaradosDamage and hp + 50 - gyaradosDamage < red_hp then canPotion = "super_potion" end - if (canPotion) then + if canPotion then inventory.use(canPotion, nil, true) readyToAttack = false end end - elseif (prepare("x_accuracy", "x_speed")) then - if (opName == "pidgeot") then - if (riskGiovanni or nidoSpecial < 45 or pokemon.info("nidoking", "hp") > 85) then + elseif prepare("x_accuracy", "x_speed") then + if opName == "pidgeot" then + if riskGiovanni or nidoSpecial < 45 or pokemon.info("nidoking", "hp") > 85 then forced = "thunderbolt" end - elseif (opName == "alakazam" or opName == "growlithe") then + elseif opName == "alakazam" or opName == "growlithe" then forced = "earthquake" end readyToAttack = true end - if (readyToAttack) then + if readyToAttack then battle.automate(forced) end - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2252,22 +2252,22 @@ strategyFunctions = { end, fightSilphGiovanni = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true local forced - if (pokemon.isOpponent("nidorino")) then - if (battle.pp("horn_drill") > 2) then + if pokemon.isOpponent("nidorino") then + if battle.pp("horn_drill") > 2 then forced = "horn_drill" else forced = "earthquake" end - elseif (pokemon.isOpponent("rhyhorn")) then + elseif pokemon.isOpponent("rhyhorn") then forced = "ice_beam" - elseif (pokemon.isOpponent("kangaskhan")) then + elseif pokemon.isOpponent("kangaskhan") then forced = "horn_drill" end battle.automate(forced) - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2283,10 +2283,10 @@ strategyFunctions = { local healTarget local rareCandyCount = inventory.count("rare_candy") local useRareCandy - if (healthUnderRedBar >= 0) then + if healthUnderRedBar >= 0 then healTarget = "HypnoHeadbutt" - if (healthUnderRedBar > 2) then - if (rareCandyCount > 2) then + if healthUnderRedBar > 2 then + if rareCandyCount > 2 then useRareCandy = true end end @@ -2295,7 +2295,7 @@ strategyFunctions = { useRareCandy = rareCandyCount > 2 end if useRareCandy then - if (menu.pause()) then + if menu.pause() then inventory.use("rare_candy", nil, false) end return false @@ -2305,11 +2305,11 @@ strategyFunctions = { end, fightHypno = function() - if (battle.isActive()) then + if battle.isActive() then local forced - if (pokemon.isOpponent("hypno")) then - if (pokemon.info("nidoking", "hp") > combat.healthFor("KogaWeezing") * 0.9) then - if (combat.isDisabled(85)) then + if pokemon.isOpponent("hypno") then + if pokemon.info("nidoking", "hp") > combat.healthFor("KogaWeezing") * 0.9 then + if combat.isDisabled(85) then forced = "ice_beam" else forced = "thunderbolt" @@ -2318,7 +2318,7 @@ strategyFunctions = { end battle.automate(forced) canProgress = true - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2326,10 +2326,10 @@ strategyFunctions = { end, fightKoga = function() --TODO x-accuracy? - if (battle.isActive()) then + if battle.isActive() then local forced - if (pokemon.isOpponent("weezing")) then - if (opponentDamaged(2)) then + if pokemon.isOpponent("weezing") then + if opponentDamaged(2) then inventory.use("pokeflute", nil, true) return false end @@ -2338,7 +2338,7 @@ strategyFunctions = { end battle.fight(forced) canProgress = true - elseif (canProgress) then + elseif canProgress then deepRun = true return true else @@ -2351,15 +2351,15 @@ strategyFunctions = { dodgeGirl = function() local gx, gy = memory.raw(0x0223) - 5, memory.raw(0x0222) local px, py = player.position() - if (py > gy) then - if (px > 3) then + if py > gy then + if px > 3 then px = 3 else return true end - elseif (gy - py ~= 1 or px ~= gx) then + elseif gy - py ~= 1 or px ~= gx then py = py + 1 - elseif (px == 3) then + elseif px == 3 then px = 2 else px = 3 @@ -2369,19 +2369,19 @@ strategyFunctions = { cinnabarCarbos = function() local px, py = player.position() - if (px == 21) then + if px == 21 then return true end local minSpeed = 51 - if (yolo) then + if yolo then minSpeed = minSpeed - 1 end - if (nidoSpeed > minSpeed) then -- TODO >= + if nidoSpeed > minSpeed then -- TODO >= walk.step(21, 20) else - if (py == 20) then + if py == 20 then py = 21 - elseif (px == 17 and not inventory.contains("carbos")) then + elseif px == 17 and not inventory.contains("carbos") then player.interact("Right") return false else @@ -2392,24 +2392,24 @@ strategyFunctions = { end, fightErika = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true local forced local curr_hp, red_hp = pokemon.index(0, "hp"), redHP() local razorDamage = 34 - if (curr_hp > razorDamage and curr_hp - razorDamage < red_hp) then - if (opponentDamaged()) then + if curr_hp > razorDamage and curr_hp - razorDamage < red_hp then + if opponentDamaged() then forced = "thunderbolt" - elseif (nidoSpecial < 45) then + elseif nidoSpecial < 45 then forced = "ice_beam" else forced = "thunderbolt" end - elseif (riskGiovanni) then + elseif riskGiovanni then forced = "ice_beam" end battle.automate(forced) - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2420,11 +2420,11 @@ strategyFunctions = { waitToReceive = function() local main = memory.value("menu", "main") - if (main == 128) then - if (canProgress) then + if main == 128 then + if canProgress then return true end - elseif (main == 32 or main == 123) then + elseif main == 32 or main == 123 then canProgress = true input.cancel() else @@ -2435,14 +2435,14 @@ strategyFunctions = { -- 14: SABRINA earthquakeElixer = function(data) - if (battle.pp("earthquake") >= data.min) then - if (closeMenuFor(data)) then + if battle.pp("earthquake") >= data.min then + if closeMenuFor(data) then return true end return false end - if (initialize()) then - if (areaName) then + if initialize() then + if areaName then print("EQ Elixer: "..areaName) end end @@ -2450,10 +2450,10 @@ strategyFunctions = { end, fightGiovanniMachoke = function() - if (initialize()) then - if (nidoAttack >= 55) then + if initialize() then + if nidoAttack >= 55 then local eqRequired = nidoSpecial >= 47 and 7 or 8 - if (battle.pp("earthquake") >= eqRequired) then + if battle.pp("earthquake") >= eqRequired then bridge.chat("Using Earthquake strats on the Machokes") return true end @@ -2464,13 +2464,13 @@ strategyFunctions = { checkGiovanni = function() local ryhornDamage = math.floor(combat.healthFor("GiovanniRhyhorn") * 0.9) - if (initialize()) then + if initialize() then local earthquakePP = battle.pp("earthquake") - if (earthquakePP >= 2) then - if (riskGiovanni) then - if (earthquakePP >= 5) then + if earthquakePP >= 2 then + if riskGiovanni then + if earthquakePP >= 5 then bridge.chat("Saved enough Earthquake PP for safe strats on Giovanni!") - elseif (earthquakePP >= 3 and battle.pp("horn_drill") >= 5 and (yolo or pokemon.info("nidoking", "hp") >= ryhornDamage)) then -- RISK + elseif earthquakePP >= 3 and battle.pp("horn_drill") >= 5 and (yolo or pokemon.info("nidoking", "hp") >= ryhornDamage) then -- RISK bridge.chat("Using risky strats on Giovanni to skip the extra Max Ether...") else riskGiovanni = false @@ -2479,7 +2479,7 @@ strategyFunctions = { return true end local message = "Ran out of Earthquake PP :( " - if (yolo) then + if yolo then message = message.."Risking on Giovanni." else message = message.."Time for standard strats." @@ -2491,31 +2491,31 @@ strategyFunctions = { end, fightGiovanni = function() - if (battle.isActive()) then - if (initialize()) then + if battle.isActive() then + if initialize() then tempDir = battle.pp("earthquake") canProgress = true end local forced, needsXSpecial local startEqPP = tempDir - if (riskGiovanni) then - if (startEqPP < 5) then + if riskGiovanni then + if startEqPP < 5 then needsXSpecial = true end - if (needsXSpecial or battle.pp("earthquake") < 4) then + if needsXSpecial or battle.pp("earthquake") < 4 then forced = "ice_beam" end else needsXSpecial = startEqPP < 2 - if (pokemon.isOpponent("rhydon")) then + if pokemon.isOpponent("rhydon") then forced = "ice_beam" end end - if (needsXSpecial and not prepare("x_special")) then + if needsXSpecial and not prepare("x_special") then return false end battle.automate(forced) - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2525,31 +2525,31 @@ strategyFunctions = { -- 15: GIOVANNI viridianRival = function() - if (battle.isActive()) then - if (not canProgress) then - if (riskGiovanni or nidoSpecial < 45 or pokemon.index(0, "speed") < 134) then + if battle.isActive() then + if not canProgress then + if riskGiovanni or nidoSpecial < 45 or pokemon.index(0, "speed") < 134 then tempDir = "x_special" else print("Skip X Special strats!") end canProgress = true end - if (prepare("x_accuracy", tempDir)) then + if prepare("x_accuracy", tempDir) then local forced - if (pokemon.isOpponent("pidgeot")) then + if pokemon.isOpponent("pidgeot") then forced = "thunderbolt" - elseif (riskGiovanni) then - if (pokemon.isOpponent("rhyhorn") or opponentDamaged()) then + elseif riskGiovanni then + if pokemon.isOpponent("rhyhorn") or opponentDamaged() then forced = "ice_beam" - elseif (pokemon.isOpponent("gyarados")) then + elseif pokemon.isOpponent("gyarados") then forced = "thunderbolt" - elseif (pokemon.isOpponent("growlithe", "alakazam")) then + elseif pokemon.isOpponent("growlithe", "alakazam") then forced = "earthquake" end end battle.automate(forced) end - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2559,55 +2559,55 @@ strategyFunctions = { ether = function(data) local main = memory.value("menu", "main") data.item = tempDir - if (tempDir and completedMenuFor(data)) then - if (closeMenuFor(data)) then + if tempDir and completedMenuFor(data) then + if closeMenuFor(data) then return true end else - if (not tempDir) then - if (data.max) then + if not tempDir then + if data.max then -- TODO don't skip center if not in redbar maxEtherSkip = nidoAttack > 53 and battle.pp("earthquake") > 0 and battle.pp("horn_drill") > 3 - if (maxEtherSkip) then + if maxEtherSkip then return true end bridge.chat("Grabbing the Max Ether to skip the Elite 4 Center") end tempDir = inventory.contains("ether", "max_ether") - if (not tempDir) then + if not tempDir then return true end tries = inventory.count(tempDir) --TODO remove? end - if (memory.value("menu", "main") == 144 and menu.getCol() == 5) then - if (memory.value("battle", "menu") ~= 95) then + if memory.value("menu", "main") == 144 and menu.getCol() == 5 then + if memory.value("battle", "menu") ~= 95 then menu.select(pokemon.battleMove("horn_drill"), true) else input.cancel() end - elseif (menu.pause()) then + elseif menu.pause() then inventory.use(tempDir, "nidoking") end end end, pickMaxEther = function() - if (not canProgress) then - if (maxEtherSkip) then + if not canProgress then + if maxEtherSkip then return true end - if (memory.value("player", "moving") == 0) then - if (player.isFacing("Right")) then + if memory.value("player", "moving") == 0 then + if player.isFacing("Right") then canProgress = true end tries = not tries - if (tries) then + if tries then input.press("Right", 1) end end return false end - if (inventory.contains("max_ether")) then + if inventory.contains("max_ether") then return true end player.interact("Right") @@ -2615,29 +2615,29 @@ strategyFunctions = { push = function(data) local pos - if (data.dir == "Up" or data.dir == "Down") then + if data.dir == "Up" or data.dir == "Down" then pos = data.y else pos = data.x end local newP = memory.raw(pos) - if (tries == 0) then + if tries == 0 then tries = {start=newP} - elseif (tries.start ~= newP) then + elseif tries.start ~= newP then return true end input.press(data.dir, 0) end, healBeforeLorelei = function() - if (initialize()) then + if initialize() then local canPotion - if (inventory.contains("potion") and hasHealthFor("LoreleiDewgong", 20)) then + if inventory.contains("potion") and hasHealthFor("LoreleiDewgong", 20) then canPotion = true - elseif (inventory.contains("super_potion") and hasHealthFor("LoreleiDewgong", 50)) then + elseif inventory.contains("super_potion") and hasHealthFor("LoreleiDewgong", 50) then canPotion = true end - if (not canPotion) then + if not canPotion then return true end bridge.chat("Healing before Lorelei to skip the Elite 4 Center...") @@ -2647,22 +2647,22 @@ strategyFunctions = { depositPokemon = function() local toSize - if (hasHealthFor("LoreleiDewgong")) then + if hasHealthFor("LoreleiDewgong") then toSize = 1 else toSize = 2 end - if (memory.value("player", "party_size") == toSize) then - if (menu.close()) then + if memory.value("player", "party_size") == toSize then + if menu.close() then return true end else - if (not textbox.isActive()) then + if not textbox.isActive() then player.interact("Up") else local pc = memory.value("menu", "size") - if (memory.value("battle", "menu") ~= 95 and (pc == 2 or pc == 4)) then - if (menu.getCol() == 10) then + if memory.value("battle", "menu") ~= 95 and (pc == 2 or pc == 4) then + if menu.getCol() == 10 then input.press("A") else menu.select(1) @@ -2677,7 +2677,7 @@ strategyFunctions = { centerSkip = function() setYolo("e4center") local message = "Skipping the Center and attempting to redbar " - if (hasHealthFor("LoreleiDewgong")) then + if hasHealthFor("LoreleiDewgong") then message = message.."off Lorelei..." else message = message.."the Elite 4!" @@ -2687,20 +2687,20 @@ strategyFunctions = { end, lorelei = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true - if (battle.redeployNidoking()) then + if battle.redeployNidoking() then return false end - if (pokemon.isOpponent("dewgong")) then - if (battle.sacrifice("pidgey", "spearow", "squirtle", "paras", "oddish")) then + if pokemon.isOpponent("dewgong") then + if battle.sacrifice("pidgey", "spearow", "squirtle", "paras", "oddish") then return false end end - if (prepare("x_accuracy")) then + if prepare("x_accuracy") then battle.automate() end - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2710,26 +2710,26 @@ strategyFunctions = { -- 16: LORELEI bruno = function() - if (battle.isActive()) then + if battle.isActive() then canProgress = true local forced - if (pokemon.isOpponent("onix")) then + if pokemon.isOpponent("onix") then forced = "ice_beam" -- local curr_hp, red_hp = pokemon.info("nidoking", "hp"), redHP() - -- if (curr_hp > red_hp) then + -- if curr_hp > red_hp then -- local enemyMove, enemyTurns = combat.enemyAttack() - -- if (enemyTurns and enemyTurns > 1) then + -- if enemyTurns and enemyTurns > 1 then -- local rockDmg = enemyMove.damage - -- if (curr_hp - rockDmg <= red_hp) then + -- if curr_hp - rockDmg <= red_hp then -- forced = "thunderbolt" -- end -- end -- end end - if (prepare("x_accuracy")) then + if prepare("x_accuracy") then battle.automate(forced) end - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2737,29 +2737,29 @@ strategyFunctions = { end, agatha = function() --TODO test without x acc - if (battle.isActive()) then + if battle.isActive() then canProgress = true - if (combat.isSleeping()) then + if combat.isSleeping() then inventory.use("pokeflute", nil, true) return false end - if (pokemon.isOpponent("gengar")) then + if pokemon.isOpponent("gengar") then local currentHP = pokemon.info("nidoking", "hp") - -- if (not yolo and currentHP <= 56 and not isPrepared("x_speed")) then - if (not yolo and currentHP <= 56 and not isPrepared("x_accuracy", "x_speed")) then + -- if not yolo and currentHP <= 56 and not isPrepared("x_speed") then + if not yolo and currentHP <= 56 and not isPrepared("x_accuracy", "x_speed") then local toPotion = inventory.contains("full_restore", "super_potion") - if (toPotion) then + if toPotion then inventory.use(toPotion, nil, true) return false end end - -- if (not prepare("x_speed")) then - if (not prepare("x_accuracy", "x_speed")) then + -- if not prepare("x_speed") then + if not prepare("x_accuracy", "x_speed") then return false end end battle.automate() - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2768,9 +2768,9 @@ strategyFunctions = { prepareForLance = function() local enableFull - if (hasHealthFor("LanceGyarados", 100)) then + if hasHealthFor("LanceGyarados", 100) then enableFull = inventory.count("super_potion") < 2 - elseif (hasHealthFor("LanceGyarados", 50)) then + elseif hasHealthFor("LanceGyarados", 50) then enableFull = not inventory.contains("super_potion") else enableFull = true @@ -2781,7 +2781,7 @@ strategyFunctions = { lance = function() local xItem - if (pokemon.isOpponent("dragonair")) then + if pokemon.isOpponent("dragonair") then xItem = "x_speed" else xItem = "x_special" @@ -2790,7 +2790,7 @@ strategyFunctions = { end, prepareForBlue = function() - if (initialize()) then + if initialize() then setYolo("blue") end local skyDmg = combat.healthFor("BlueSky") * 0.9 @@ -2799,22 +2799,22 @@ strategyFunctions = { end, blue = function() - if (battle.isActive()) then - if (not canProgress) then + if battle.isActive() then + if not canProgress then canProgress = true - if (nidoSpecial >= 45 and pokemon.index(0, "speed") >= 52 and inventory.contains("x_special")) then + if nidoSpecial >= 45 and pokemon.index(0, "speed") >= 52 and inventory.contains("x_special") then tempDir = "x_special" else tempDir = "x_speed" end - if (not STREAMING_MODE) then + if not STREAMING_MODE then tempDir = "x_speed" end end local boostFirst = pokemon.index(0, "hp") < 55 local firstItem, secondItem - if (boostFirst) then + if boostFirst then firstItem = tempDir secondItem = "x_accuracy" else @@ -2824,17 +2824,17 @@ strategyFunctions = { local forced = "horn_drill" - if (memory.value("battle", "turns") > 0) then + if memory.value("battle", "turns") > 0 then local skyDamage = combat.healthFor("BlueSky") local healCutoff = skyDamage * 0.825 - if (initialize()) then - if (not isPrepared("x_accuracy", tempDir)) then + if initialize() then + if not isPrepared("x_accuracy", tempDir) then local msg = "Uh oh... First-turn Sky Attack could end the run here, " - if (pokemon.index(0, "hp") > skyDamage) then + if pokemon.index(0, "hp") > skyDamage then msg = msg.."no criticals pls D:" - elseif (canHealFor(healCutoff)) then + elseif canHealFor(healCutoff) then msg = msg.."attempting to heal for it" - if (not canHealFor(skyDamage)) then + if not canHealFor(skyDamage) then msg = msg.." (damage range)" end msg = msg.."." @@ -2845,33 +2845,33 @@ strategyFunctions = { end end - if (prepare(firstItem)) then - if (not isPrepared(secondItem)) then + if prepare(firstItem) then + if not isPrepared(secondItem) then local toPotion = canHealFor(healCutoff) - if (toPotion) then + if toPotion then inventory.use(toPotion, nil, true) return false end end - if (prepare("x_accuracy", tempDir)) then + if prepare("x_accuracy", tempDir) then battle.automate(forced) end end else - if (prepare(firstItem, secondItem)) then - if (pokemon.isOpponent("alakazam")) then - if (tempDir == "x_speed") then + if prepare(firstItem, secondItem) then + if pokemon.isOpponent("alakazam") then + if tempDir == "x_speed" then forced = "earthquake" end - elseif (pokemon.isOpponent("rhydon")) then - if (tempDir == "x_special") then + elseif pokemon.isOpponent("rhydon") then + if tempDir == "x_special" then forced = "ice_beam" end end battle.automate(forced) end end - elseif (canProgress) then + elseif canProgress then return true else textbox.handle() @@ -2879,20 +2879,20 @@ strategyFunctions = { end, champion = function() - if (canProgress) then - if (tries > 1500) then + if canProgress then + if tries > 1500 then return hardReset("Beat the game in "..canProgress.." !") end - if (tries == 0) then + if tries == 0 then bridge.tweet("Beat Pokemon Red in "..canProgress.."!") -- strategyFunctions.reportFrames() - if (strategies.seed) then + if strategies.seed then print(memory.value("game", "frames").." frames, with seed "..strategies.seed) print("Please save this seed number to share, if you would like proof of your run!") end end tries = tries + 1 - elseif (memory.value("menu", "shop_current") == 252) then + elseif memory.value("menu", "shop_current") == 252 then strategyFunctions.split({finished=true}) canProgress = utils.elapsedTime() else @@ -2902,12 +2902,12 @@ strategyFunctions = { } function strategies.execute(data) - if (strategyFunctions[data.s](data)) then + if strategyFunctions[data.s](data) then tries = 0 canProgress = false initialized = false tempDir = nil - if (resetting) then + if resetting then return nil end return true @@ -2916,7 +2916,7 @@ function strategies.execute(data) end function strategies.init(midGame) - if (not STREAMING_MODE) then + if not STREAMING_MODE then -- setYolo(0) nidoAttack = 55 nidoSpeed = 50 @@ -2925,7 +2925,7 @@ function strategies.init(midGame) splitTime = utils.timeSince(0) print(nidoAttack.." x "..nidoSpeed.." "..nidoSpecial) end - if (midGame) then + if midGame then combat.factorPP(true) end end diff --git a/main.lua b/main.lua index e81cd1f..f58714b 100644 --- a/main.lua +++ b/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 diff --git a/storage/inventory.lua b/storage/inventory.lua index dfa8d60..fda31d4 100644 --- a/storage/inventory.lua +++ b/storage/inventory.lua @@ -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 diff --git a/storage/pokemon.lua b/storage/pokemon.lua index 286b675..7c70904 100644 --- a/storage/pokemon.lua +++ b/storage/pokemon.lua @@ -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 diff --git a/util/bridge.lua b/util/bridge.lua index c76a9dd..5e47f37 100644 --- a/util/bridge.lua +++ b/util/bridge.lua @@ -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") diff --git a/util/input.lua b/util/input.lua index 33edce6..db32f9b 100644 --- a/util/input.lua +++ b/util/input.lua @@ -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 diff --git a/util/memory.lua b/util/memory.lua index 308b751..25fc5ff 100644 --- a/util/memory.lua +++ b/util/memory.lua @@ -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) diff --git a/util/menu.lua b/util/menu.lua index 42fd953..110ad21 100644 --- a/util/menu.lua +++ b/util/menu.lua @@ -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") diff --git a/util/paint.lua b/util/paint.lua index 1f2bcae..83f5cdd 100644 --- a/util/paint.lua +++ b/util/paint.lua @@ -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")) diff --git a/util/player.lua b/util/player.lua index a38fae9..3e499e4 100644 --- a/util/player.lua +++ b/util/player.lua @@ -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 diff --git a/util/settings.lua b/util/settings.lua index b949719..0fd5493 100644 --- a/util/settings.lua +++ b/util/settings.lua @@ -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 diff --git a/util/utils.lua b/util/utils.lua index fb9922a..62fd4e3 100644 --- a/util/utils.lua +++ b/util/utils.lua @@ -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