This commit is contained in:
Kyle Coburn 2015-05-25 12:42:07 -07:00
parent 16f37b0330
commit 1461aa2877
15 changed files with 49 additions and 66 deletions

View File

@ -103,7 +103,7 @@ local function attack(attackIndex)
end
end
function movePP(name)
local function movePP(name)
local midx = Pokemon.battleMove(name)
if not midx then
return 0
@ -212,7 +212,7 @@ function Battle.handleWild(battleStatus)
Battle.handle()
end
function Battle.fight(move, skipBuffs)
function Battle.fight(move)
if move then
if type(move) ~= "number" then
move = Pokemon.battleMove(move)
@ -296,6 +296,7 @@ function Battle.redeployNidoking()
elseif Menu.hasTextbox() and Menu.getCol() == 1 then
Input.press("A")
else
local forced
local __, turns = Combat.bestMove()
if turns == 1 then
if Pokemon.isDeployed("spearow") then

View File

@ -1,7 +1,5 @@
local Shop = {}
local Textbox = require "action.textbox"
local Data = require "data.data"
local Input = require "util.input"
@ -17,7 +15,7 @@ function Shop.transaction(options)
menuIdx = 1
itemMenu = Data.yellow and 28 or 29
quantityMenu = 158
for i,sit in ipairs(options.sell) do
for __,sit in ipairs(options.sell) do
local idx = Inventory.indexOf(sit.name)
if idx ~= -1 then
item = sit
@ -31,7 +29,7 @@ function Shop.transaction(options)
menuIdx = 0
itemMenu = Data.yellow and 122 or 123
quantityMenu = 161
for i,bit in ipairs(options.buy) do
for __,bit in ipairs(options.buy) do
local needed = (bit.amount or 1) - Inventory.count(bit.name)
if needed > 0 then
item = bit
@ -78,8 +76,7 @@ end
function Shop.vend(options)
local item
menuIdx = 0
for i,bit in ipairs(options.buy) do
for __,bit in ipairs(options.buy) do
local needed = (bit.amount or 1) - Inventory.count(bit.name)
if needed > 0 then
item = bit

View File

@ -32,7 +32,7 @@ end
-- Helper functions
function dir(px, py, dx, dy)
local function dir(px, py, dx, dy)
local direction
if py > dy then
direction = "Up"
@ -47,7 +47,7 @@ function dir(px, py, dx, dy)
end
Walk.dir = dir
function step(dx, dy, through)
local function step(dx, dy, through)
local px, py = Player.position()
if px == dx and py == dy then
return true

View File

@ -44,7 +44,6 @@ types[24] = "psychic"
types[25] = "ice"
types[26] = "dragon"
local savedEncounters = {}
local conservePP = false
local allowDamageRange = false
local disableThrash = false
@ -133,7 +132,7 @@ local function getOpponentType(ty)
end
Combat.getOpponentType = getOpponentType
function getOurType(ty)
local function getOurType(ty)
local t1 = types[Memory.value("battle", "our_type1")]
if ty ~= 0 then
t1 = types[Memory.value("battle", "our_type2")]
@ -195,7 +194,7 @@ local function calcBestHit(attacker, defender, ours, rng)
local ourMaxHit
local targetHP = defender.hp
local ret = nil
for idx,move in ipairs(attacker.moves) do
for __,move in ipairs(attacker.moves) do
if not move.pp or move.pp > 0 then
local minDmg, maxDmg = calcDamage(move, attacker, defender, rng)
if maxDmg then
@ -236,7 +235,7 @@ local function calcBestHit(attacker, defender, ours, rng)
replaces = maxTurns < bestMinTurns
end
end
elseif maxTurns < 2 or maxTurns == bestMaxTurns then
elseif maxTurns < 2 or maxTurns == bestTurns then
if ret.name == "Earthquake" and (move.name == "Ice-Beam" or move.name == "Thunderbolt") then
replaces = true
elseif move.pp > ret.pp then
@ -278,7 +277,7 @@ local function getBestMove(ours, enemy, draw)
return
end
local bm, bestUs = calcBestHit(ours, enemy, true)
local jj, bestEnemy = calcBestHit(enemy, ours, false)
local __, bestEnemy = calcBestHit(enemy, ours, false)
if not bm then
return
end
@ -341,7 +340,7 @@ function Combat.isPoisoned(target)
return checkStatus(target, 0x8)
end
function Combat.hasParalyzeStatus(target)
function Combat.hasParalyzeStatus()
return Memory.value("battle", "paralyzed") > 0
end
@ -412,7 +411,7 @@ end
function Combat.inKillRange(draw)
local ours, enemy = activePokemon()
local enemyAttack, __ = calcBestHit(enemy, ours, false)
local enemyAttack, turnsToDie = calcBestHit(enemy, ours, false)
local __, turnsToKill = calcBestHit(ours, enemy, true)
if not turnsToKill or not enemyAttack then
return false
@ -434,7 +433,7 @@ function Combat.inKillRange(draw)
end
outsped = Memory.value("battle", "attack_turns") > 0
end
if outsped or isConfused or turnsToKill > 1 or ours.speed <= enemy.speed or Pokemon.info(target, "status") > 0 then
if outsped or isConfused or turnsToKill > 1 or ours.speed <= enemy.speed or Pokemon.info(0, "status") > 0 then
return ours, hpReq
end
end
@ -461,7 +460,7 @@ function Combat.nonKill()
end
local bestDmg = -1
local ret = nil
for idx,move in ipairs(ours.moves) do
for __,move in ipairs(ours.moves) do
if not move.pp or move.pp > 0 then
local __, maxDmg = calcDamage(move, ours, enemy, true)
if maxDmg > 0 then

View File

@ -19,10 +19,11 @@ local potionInBattle = true
local encounters = 0
local canDie, shouldFight, minExp
local shouldCatch, attackIdx
local shouldCatch
local extraEncounter, maxEncounters
local battleYolo
local encountersSection
local oneHits
Control.areaName = "Unknown"
Control.getMoonExp = true
@ -204,7 +205,7 @@ function Control.shouldFight()
if expRemaining > 0 then
local oid = Memory.value("battle", "opponent_id")
local opponentLevel = Memory.value("battle", "opponent_level")
for i,encounter in ipairs(shouldFight) do
for __,encounter in ipairs(shouldFight) do
if oid == Pokemon.getID(encounter.name) and (not encounter.levels or Utils.match(opponentLevel, encounter.levels)) then
if oneHits then
local move = Combat.bestMove()
@ -222,7 +223,7 @@ function Control.shouldFight()
end
end
function Control.canCatch(partySize)
function Control.canCatch()
local minimumCount = 0
if not Pokemon.inParty("nidoran", "nidorino", "nidoking") then
minimumCount = minimumCount + (Data.yellow and 1 or 2)
@ -271,7 +272,7 @@ function Control.shouldCatch(partySize)
end
local oid = Memory.value("battle", "opponent_id")
local opponentLevel = Memory.value("battle", "opponent_level")
for i,poke in ipairs(shouldCatch) do
for __,poke in ipairs(shouldCatch) do
if oid == Pokemon.getID(poke.name) and not Pokemon.inParty(poke.name, poke.alt) then
if not poke.levels or Utils.match(opponentLevel, poke.levels) then
local overHP = poke.hp and Memory.double("battle", "opponent_hp") > poke.hp
@ -381,7 +382,7 @@ function Control.encounter(battleState)
if not opponentAlive and shouldCatch and not Control.killedCatch then
local gottaCatchEm = {"pidgey", "spearow", "paras", "oddish"}
local opponent = Battle.opponent()
for i,catch in ipairs(gottaCatchEm) do
for __,catch in ipairs(gottaCatchEm) do
if opponent == catch then
if not Pokemon.inParty(catch) then
local criticaled = Memory.value("battle", "critical") == 1

View File

@ -227,7 +227,7 @@ local function potionForRedBar(damage)
{"potion", 20},
{"super_potion", 50},
}
for i,potionTable in ipairs(potions) do
for __,potionTable in ipairs(potions) do
local potion = potionTable[1]
if Inventory.contains(potion) then
local healsFor = potionTable[2]
@ -700,7 +700,7 @@ end
-- dodgeCerulean
strategyFunctions.rivalSandAttack = function(data)
strategyFunctions.rivalSandAttack = function()
if Strategies.trainerBattle() then
if Battle.redeployNidoking() then
local sacrifice = Battle.deployed()
@ -930,7 +930,6 @@ strategyFunctions.catchOddish = function()
Player.interact("Left")
Strategies.foughtRaticateEarly = true
else
local path
if caught then
if Strategies.initialize("caught") then
Bridge.caught(Pokemon.inParty("oddish"))
@ -1212,7 +1211,6 @@ end
strategyFunctions.lavenderRival = function()
if Strategies.trainerBattle() then
local forced
if stats.nidoran.special > 44 then -- RISK
local __, enemyTurns = Combat.enemyAttack()
if enemyTurns and enemyTurns < 2 and Pokemon.isOpponent("pidgeotto", "gyarados") then
@ -1293,7 +1291,7 @@ strategyFunctions.silphRival = function()
if Strategies.prepare("x_accuracy", "x_speed") then
local forced
local opponentName = Battle.opponent()
local curr_hp, red_hp = Combat.hp(), Combat.redHP()
local curr_hp = Combat.hp()
if opponentName == "gyarados" then
if status.gyaradosDamage then
if willRedBar(status.gyaradosDamage) then

View File

@ -209,7 +209,7 @@ function Strategies.canHealFor(damage, allowAlreadyHealed, allowFullRestore)
if allowFullRestore then
table.insert(healChecks, 1, "full_restore")
end
for idx,potion in ipairs(healChecks) do
for __,potion in ipairs(healChecks) do
if Inventory.contains(potion) and Utils.canPotionWith(potion, damage, curr_hp, max_hp) then
return potion
end
@ -410,7 +410,7 @@ function Strategies.isPrepared(...)
if not status.preparing then
return false
end
for i,name in ipairs(arg) do
for __,name in ipairs(arg) do
local currentCount = Inventory.count(name)
if currentCount > 0 then
local previousCount = status.preparing[name]
@ -427,7 +427,7 @@ function Strategies.prepare(...)
status.preparing = {}
end
local item
for idx,name in ipairs(arg) do
for __,name in ipairs(arg) do
local currentCount = Inventory.count(name)
local needsItem = currentCount > 0
local previousCount = status.preparing[name]
@ -550,7 +550,7 @@ function Strategies.completeCans()
}
local walkIn = "Up"
for dir,tileset in pairs(completePath) do
for i,tile in ipairs(tileset) do
for __,tile in ipairs(tileset) do
if px == tile[1] and py == tile[2] then
walkIn = dir
break
@ -923,7 +923,7 @@ Strategies.functions = {
elseif status.firstIndex < 0 or status.lastIndex < 0 then
swapComplete = true
if Strategies.initialize("swapUnavailable") then
p("Not available to swap", data.item, data.dest, itemIndex, destIndex)
p("Not available to swap", data.item, data.dest, status.firstIndex, status.lastIndex)
end
elseif status.startedAt ~= Inventory.indexOf(status.checkItem) then
swapComplete = true
@ -1011,7 +1011,7 @@ Strategies.functions = {
local opp = Battle.opponent()
local defLimit = 9001
local forced
for i,poke in ipairs(data) do
for __,poke in ipairs(data) do
if opp == poke[1] then
local minimumAttack = poke[3]
if not minimumAttack or stats.nidoran.attack > minimumAttack then
@ -1203,7 +1203,7 @@ Strategies.functions = {
end
if resetsForStats then
local nidoranStatus
local nidoranStatus = nil
if att < 15 and spd < 14 and scl < 12 then
nidoranStatus = Utils.random {
"let's just forget this ever happened",
@ -1630,7 +1630,6 @@ Strategies.functions = {
if Battle.redeployNidoking() then
return false
end
local forced
if Pokemon.isOpponent("staryu") then
local __, turnsToKill = Combat.bestMove()
if turnsToKill and turnsToKill > 1 then
@ -1660,7 +1659,7 @@ Strategies.functions = {
return false
end
end
Battle.automate(forced)
Battle.automate()
elseif status.foughtTrainer then
return true
end
@ -2035,7 +2034,6 @@ Strategies.functions = {
end,
cinnabarCarbos = function()
local minDV = Data.yellow and 11 or 10
local skipsCarbos = not Strategies.needsCarbosAtLeast(Data.yellow and 2 or 1)
if Strategies.initialize() then
status.startCount = Inventory.count("carbos")
@ -2064,7 +2062,6 @@ Strategies.functions = {
end,
ether = function(data)
local main = Memory.value("menu", "main")
data.item = status.item
if status.item and Strategies.completedMenuFor(data) then
if Strategies.closeMenuFor(data) then

View File

@ -11,8 +11,6 @@ local PAINT_ON = true -- Display contextual information while the bot runs
VERSION = "2.0.2"
local START_WAIT = 99
local Data = require "data.data"
Data.init()
@ -30,7 +28,6 @@ local Pokemon = require "storage.pokemon"
local Bridge = require "util.bridge"
local Input = require "util.input"
local Memory = require "util.memory"
local Menu = require "util.menu"
local Paint = require "util.paint"
local Utils = require "util.utils"
local Settings = require "util.settings"
@ -109,7 +106,7 @@ local function generateNextInput(currentMap)
resetAll()
end
else
Settings.startNewAdventure(START_WAIT)
Settings.startNewAdventure()
end
else
if not running then
@ -134,7 +131,7 @@ local function generateNextInput(currentMap)
end
end
elseif battleState > 0 then
if not Control.shouldCatch(partySize) then
if not Control.shouldCatch() then
Battle.automate()
end
elseif Textbox.handle() then

View File

@ -3,7 +3,6 @@ local Inventory = {}
local Input = require "util.input"
local Memory = require "util.memory"
local Menu = require "util.menu"
local Utils = require "util.utils"
local Pokemon = require "storage.pokemon"
@ -82,7 +81,7 @@ function Inventory.count(name)
end
function Inventory.contains(...)
for i,name in ipairs(arg) do
for __,name in ipairs(arg) do
if Inventory.count(name) > 0 then
return name
end
@ -90,7 +89,7 @@ function Inventory.contains(...)
end
function Inventory.containsAll(...)
for i,name in ipairs(arg) do
for __,name in ipairs(arg) do
if not Inventory.contains(name) then
return false
end

View File

@ -126,7 +126,7 @@ end
Pokemon.index = index
local function indexOf(...)
for ni,name in ipairs(arg) do
for __,name in ipairs(arg) do
local pid = pokeIDs[name]
for i=0,5 do
local atIdx = index(i)
@ -223,7 +223,7 @@ function Pokemon.getName(id)
end
function Pokemon.getSacrifice(...)
for i,name in ipairs(arg) do
for __,name in ipairs(arg) do
local pokemonIndex = indexOf(name)
if pokemonIndex ~= -1 and index(pokemonIndex, "hp") > 0 then
return name
@ -232,7 +232,7 @@ function Pokemon.getSacrifice(...)
end
function Pokemon.inParty(...)
for i,name in ipairs(arg) do
for __,name in ipairs(arg) do
if indexOf(name) ~= -1 then
return name
end
@ -276,7 +276,7 @@ end
function Pokemon.isOpponent(...)
local oid = Memory.value("battle", "opponent_id")
for i,name in ipairs(arg) do
for __,name in ipairs(arg) do
if oid == pokeIDs[name] then
return name
end
@ -285,7 +285,7 @@ end
function Pokemon.isDeployed(...)
local deployedID = Memory.value("battle", "our_id")
for i,name in ipairs(arg) do
for __,name in ipairs(arg) do
if deployedID == pokeIDs[name] then
return name
end

View File

@ -9,8 +9,6 @@ if INTERNAL then
socket = require "socket"
end
local utils = require "util.utils"
local client = nil
local timeStopped = true
@ -107,8 +105,6 @@ function Bridge.process()
-- print(">"..response)
if response:find("name:") then
return response:gsub("name:", "")
else
end
end
end

View File

@ -39,7 +39,7 @@ function Paint.draw(currentMap)
{"paras", "oddish", "charmander", "sandshrew"},
}
local partyY = BOTTOM_EDGE
for i,pokemonCategory in ipairs(caughtPokemon) do
for __,pokemonCategory in ipairs(caughtPokemon) do
local pokemon = Pokemon.inParty(unpack(pokemonCategory))
if pokemon then
drawText(RIGHT_EDGE, partyY, Utils.capitalize(pokemon), true)

View File

@ -2,8 +2,6 @@ local Player = {}
local Textbox = require "action.textbox"
local Data = require "data.data"
local Input = require "util.input"
local Memory = require "util.memory"

View File

@ -47,7 +47,7 @@ end
-- PUBLIC
function Settings.set(...)
for i,name in ipairs(arg) do
for __,name in ipairs(arg) do
if not isEnabled(name) then
if Menu.open(settings_menu, 1) then
Menu.setOption(name, desired[name])
@ -58,7 +58,7 @@ function Settings.set(...)
return Menu.cancel(settings_menu)
end
function Settings.startNewAdventure(startWait)
function Settings.startNewAdventure()
local startMenu, withBattleStyle
if Data.gameName ~= "red" then
withBattleStyle = "battle_style"
@ -72,7 +72,7 @@ function Settings.startNewAdventure(startWait)
if Settings.set("text_speed", "battle_animation", withBattleStyle) then
Menu.select(0)
end
elseif math.random(0, startWait) == 0 then
elseif math.random(0, START_WAIT) == 0 then
Input.press("Start", 2)
end
end

View File

@ -12,7 +12,7 @@ function p(...)
string = arg[0]
else
string = ""
for i,str in ipairs(arg) do
for __,str in ipairs(arg) do
if str == true then
string = string.."\n"
else
@ -46,7 +46,7 @@ function Utils.eachi(table, func)
end
function Utils.match(needle, haystack)
for i,val in ipairs(haystack) do
for __,val in ipairs(haystack) do
if needle == val then
return true
end
@ -86,7 +86,7 @@ end
function Utils.multiplyString(string, times)
local result = string
for i=1, times-1 do
for __=1, times-1 do
result = result.." "..string
end
return result