Standardize trainer fight Strategy framework

This commit is contained in:
Kyle Coburn 2015-04-22 19:20:51 -07:00
parent b73b3228ce
commit 8ca00b6a35
3 changed files with 103 additions and 216 deletions

View File

@ -498,13 +498,12 @@ strategyFunctions.grabForestPotion = function()
end
strategyFunctions.fightWeedle = function()
if Battle.isTrainer() then
status.canProgress = true
if Strategies.trainerBattle() then
if Memory.value("battle", "our_status") > 0 and not Inventory.contains("antidote") then
return Strategies.reset("antidote", "Poisoned, but we skipped the antidote")
end
return Strategies.buffTo("tail_whip", 5)
elseif status.canProgress then
elseif status.foughtTrainer then
return true
end
end
@ -571,6 +570,7 @@ strategyFunctions.fightBrock = function()
status.canProgress = false
Battle.fight()
end
if status.tries < 9000 then
local nidx = Pokemon.indexOf("nidoran")
if Pokemon.index(nidx, "level") == 8 then
@ -703,8 +703,7 @@ strategyFunctions.battleModeSet = function()
end
strategyFunctions.bugCatcher = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local isWeedle = Pokemon.isOpponent("weedle")
if isWeedle and not status.secondCaterpie then
status.secondCaterpie = true
@ -717,10 +716,8 @@ strategyFunctions.bugCatcher = function()
end
end
strategyFunctions.leer({{"caterpie",8}, {"weedle",7}})
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Battle.automate()
end
end
@ -776,16 +773,13 @@ end
-- swapHornAttack
strategyFunctions.fightMetapod = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Battle.opponentAlive() and Pokemon.isOpponent("metapod") then
return true
end
Battle.automate()
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Battle.automate()
end
end
@ -808,8 +802,7 @@ end
-- dodgeCerulean
strategyFunctions.rivalSandAttack = function(data)
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Battle.redeployNidoking() then
local sacrifice = Battle.deployed()
if sacrifice and Strategies.initialize("sacrificed") then
@ -866,11 +859,9 @@ strategyFunctions.rivalSandAttack = function(data)
Combat.setDisableThrash(disableThrash)
Battle.automate()
elseif status.canProgress then
elseif status.foughtTrainer then
Combat.setDisableThrash(false)
return true
else
Textbox.handle()
end
end
@ -880,16 +871,15 @@ strategyFunctions.hornAttackCaterpie = function()
return true
end
end
if Strategies.trainerBattle() then
local forced
if Battle.isActive() then
status.canProgress = true
if not Strategies.opponentDamaged() then
forced = "horn_attack"
end
elseif status.canProgress then
Battle.automate(forced)
elseif status.foughtTrainer then
return true
end
Battle.automate(forced)
end
-- rareCandyEarly
@ -915,8 +905,7 @@ strategyFunctions.redbarMankey = function()
if curr_hp <= red_hp then
return true
end
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local enemyMove, enemyTurns = Combat.enemyAttack()
if enemyTurns then
if enemyTurns < 2 then
@ -928,10 +917,8 @@ strategyFunctions.redbarMankey = function()
end
end
Battle.automate("poison_sting")
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
if Strategies.initialize() then
if Pokemon.info("nidoking", "level") < 23 or Inventory.count("potion") < 4 then -- RISK
@ -944,8 +931,7 @@ end
-- 6: NUGGET BRIDGE
strategyFunctions.thrashGeodude = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Pokemon.isDeployed("squirtle") then
if Strategies.initialize("sacrificed") then
Bridge.chat(" Thrash didn't finish the kill :( swapping to Squirtle for safety.")
@ -959,10 +945,8 @@ strategyFunctions.thrashGeodude = function()
end
end
Battle.automate()
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
@ -1037,8 +1021,7 @@ strategyFunctions.potionBeforeMisty = function(data)
end
strategyFunctions.fightMisty = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Battle.redeployNidoking() then
return false
end
@ -1065,10 +1048,8 @@ strategyFunctions.fightMisty = function()
end
end
Battle.automate(forced)
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
@ -1246,8 +1227,7 @@ strategyFunctions.potionBeforeSurge = function()
end
strategyFunctions.fightSurge = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local forced
local disableThrash = false
if Pokemon.isOpponent("voltorb") then
@ -1265,10 +1245,8 @@ strategyFunctions.fightSurge = function()
end
Combat.setDisableThrash(disableThrash)
Battle.automate(forced)
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
@ -1368,8 +1346,7 @@ end
-- 9: FLY
strategyFunctions.lavenderRival = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local forced
if stats.nidoran.special > 44 then -- RISK
local __, enemyTurns = Combat.enemyAttack()
@ -1381,10 +1358,8 @@ strategyFunctions.lavenderRival = function()
if Pokemon.isOpponent("gyarados") or Strategies.prepare("x_accuracy") then
Battle.automate()
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Input.cancel()
end
end
@ -1421,16 +1396,13 @@ end
-- silphElevator
strategyFunctions.fightSilphMachoke = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Control.yolo and stats.nidoran.special > 44 then
return Strategies.prepare("x_accuracy")
end
Battle.automate("thrash")
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
@ -1447,13 +1419,12 @@ strategyFunctions.swapXSpecials = function()
end
strategyFunctions.silphRival = function()
if Battle.isActive() then
if Strategies.trainerBattle() then
if Strategies.initialize() then
if Control.yolo then
status.gyaradosDamage = Combat.healthFor("RivalGyarados")
Bridge.chat("is attempting to red-bar off Silph Rival. Get ready to spaghetti!", status.gyaradosDamage.." "..Combat.redHP())
end
status.canProgress = true
end
if Strategies.prepare("x_accuracy", "x_speed") then
@ -1518,11 +1489,9 @@ strategyFunctions.silphRival = function()
end
Battle.automate(forced)
end
elseif status.canProgress then
elseif status.foughtTrainer then
Control.ignoreMiss = false
return true
else
Textbox.handle()
end
end
@ -1541,8 +1510,7 @@ strategyFunctions.rareCandyGiovanni = function()
end
strategyFunctions.fightSilphGiovanni = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local forced
local opponentName = Battle.opponent()
if opponentName == "nidorino" then
@ -1567,10 +1535,8 @@ strategyFunctions.fightSilphGiovanni = function()
end
end
Battle.automate(forced)
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
@ -1608,7 +1574,7 @@ strategyFunctions.potionBeforeHypno = function()
end
strategyFunctions.fightHypno = function()
if Battle.isActive() then
if Strategies.trainerBattle() then
local forced
if Pokemon.isOpponent("hypno") and not Strategies.damaged() then
if Pokemon.info("nidoking", "hp") > Combat.healthFor("KogaWeezing") * 0.9 then
@ -1620,16 +1586,13 @@ strategyFunctions.fightHypno = function()
end
end
Battle.automate(forced)
status.canProgress = true
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
strategyFunctions.fightKoga = function()
if Battle.isActive() then
if Strategies.trainerBattle() then
local forced
if Battle.opponentAlive() then
local opponent = Battle.opponent()
@ -1662,13 +1625,10 @@ strategyFunctions.fightKoga = function()
end
end
Battle.automate(forced)
status.canProgress = true
elseif status.canProgress then
elseif status.foughtTrainer then
Strategies.deepRun = true
Control.ignoreMiss = false
return true
else
Textbox.handle()
end
end
@ -1679,8 +1639,7 @@ end
-- cinnabarCarbos
strategyFunctions.fightErika = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local forced
if Control.yolo then
local curr_hp, red_hp = Combat.hp(), Combat.redHP()
@ -1696,10 +1655,8 @@ strategyFunctions.fightErika = function()
end
end
Battle.automate(forced)
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
@ -1730,8 +1687,7 @@ strategyFunctions.fightGiovanniMachoke = function()
status.skipSpecial = true
end
end
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Pokemon.isOpponent("machop") then
status.killedMachoke = true
elseif not status.killedMachoke then
@ -1744,10 +1700,8 @@ strategyFunctions.fightGiovanniMachoke = function()
end
end
Battle.automate()
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
@ -1776,10 +1730,9 @@ strategyFunctions.checkGiovanni = function()
end
strategyFunctions.fightGiovanni = function()
if Battle.isActive() then
if Strategies.trainerBattle() then
if Strategies.initialize() then
status.needsXSpecial = not Combat.inRedBar() or Battle.pp("earthquake") <= (riskGiovanni and 4 or 2)
status.canProgress = true
end
local forced
if riskGiovanni then
@ -1795,18 +1748,15 @@ strategyFunctions.fightGiovanni = function()
return false
end
Battle.automate(forced)
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
-- 16: GIOVANNI
strategyFunctions.viridianRival = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Strategies.prepare("x_accuracy", "x_special") then
local forced
if Pokemon.isOpponent("pidgeot") then
@ -1822,10 +1772,8 @@ strategyFunctions.viridianRival = function()
end
Battle.automate(forced)
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
@ -1913,8 +1861,7 @@ strategyFunctions.centerSkip = function()
end
strategyFunctions.lorelei = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Battle.redeployNidoking() then
return false
end
@ -1936,19 +1883,15 @@ strategyFunctions.lorelei = function()
if Strategies.prepare("x_accuracy") then
Battle.automate(forced)
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
-- 17: LORELEI
strategyFunctions.bruno = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Strategies.prepare("x_accuracy") then
local forced
if Pokemon.isOpponent("onix") then
@ -1956,16 +1899,13 @@ strategyFunctions.bruno = function()
end
Battle.automate(forced)
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
strategyFunctions.agatha = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Combat.isSleeping() then
Inventory.use("pokeflute", nil, true)
return false
@ -1990,18 +1930,15 @@ strategyFunctions.agatha = function()
end
end
Battle.automate()
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
-- prepareForLance
strategyFunctions.lance = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local xItem
if Pokemon.isOpponent("dragonair") then
xItem = "x_speed"
@ -2011,10 +1948,8 @@ strategyFunctions.lance = function()
if Strategies.prepare(xItem) then
Battle.automate()
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
@ -2040,9 +1975,8 @@ strategyFunctions.prepareForBlue = function()
end
strategyFunctions.blue = function()
if Battle.isActive() then
if not status.canProgress then
status.canProgress = true
if Strategies.trainerBattle() then
if Strategies.initialize() then
if stats.nidoran.specialDV >= 8 and stats.nidoran.speedDV >= 12 and Inventory.contains("x_special") then
status.xItem = "x_special"
else
@ -2109,10 +2043,8 @@ strategyFunctions.blue = function()
Battle.automate(forced)
end
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end

View File

@ -184,6 +184,18 @@ function Strategies.damaged(factor)
return Pokemon.index(0, "hp") * factor < Pokemon.index(0, "max_hp")
end
function Strategies.trainerBattle()
if Battle.isActive() then
if not status.foughtTrainer then
if Battle.handleWild() then
status.foughtTrainer = true
end
end
return true
end
Textbox.handle()
end
function Strategies.opponentDamaged(factor)
if not factor then
factor = 1
@ -210,17 +222,14 @@ local function interact(direction, extended)
end
function Strategies.buffTo(buff, defLevel)
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local forced
if defLevel and Memory.double("battle", "opponent_defense") > defLevel then
forced = buff
end
Battle.automate(forced, true)
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Battle.automate()
end
end
@ -866,12 +875,11 @@ Strategies.functions = {
leer = function(data)
local bm = Combat.bestMove()
if not bm or bm.minTurns < 3 then
if Battle.isActive() then
status.canProgress = true
elseif status.canProgress then
if Strategies.trainerBattle() then
Battle.automate(data.forced)
elseif status.foughtTrainer then
return true
end
Battle.automate(data.forced)
return false
end
local opp = Battle.opponent()
@ -1039,9 +1047,8 @@ Strategies.functions = {
end
end
if usedMoonStone then
if not status.canProgress then
if Strategies.initialize("evolved") then
Bridge.caught("nidoking")
status.canProgress = true
end
if Menu.close() then
return true
@ -1147,8 +1154,7 @@ Strategies.functions = {
return true
end
end
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Pokemon.moveIndex("thrash", "nidoking") then
nidokingStats()
return true
@ -1171,10 +1177,10 @@ Strategies.functions = {
return false
end
end
elseif status.canProgress then
Battle.automate()
elseif status.foughtTrainer then
return true
end
Battle.automate()
end,
swapThrash = function()
@ -1240,9 +1246,8 @@ Strategies.functions = {
end,
redbarCubone = function()
if Battle.isActive() then
if Strategies.trainerBattle() then
local forced
status.canProgress = true
if Pokemon.isOpponent("cubone") then
local enemyMove, enemyTurns = Combat.enemyAttack()
if enemyTurns then
@ -1265,16 +1270,13 @@ Strategies.functions = {
Control.ignoreMiss = forced ~= nil
end
Battle.automate(forced)
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Battle.automate()
end
end,
announceOddish = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Pokemon.isOpponent("oddish") then
local __, turnsToKill = Combat.bestMove()
if turnsToKill and turnsToKill > 1 and Strategies.initialize() then
@ -1282,12 +1284,9 @@ Strategies.functions = {
end
end
Battle.automate()
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Battle.automate()
end
return true
end,
shopTM07 = function()
@ -1349,8 +1348,7 @@ Strategies.functions = {
Bridge.chat("is using Rock Slide to one-hit these Ghastlies in red-bar (each is 1 in 10 to miss).")
end
end
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local currentlyDead = Memory.double("battle", "our_hp") == 0
if currentlyDead then
local backupPokemon = Pokemon.getSacrifice("paras", "squirtle", "sandshrew", "charmander")
@ -1368,10 +1366,8 @@ Strategies.functions = {
else
Battle.automate()
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end,

View File

@ -388,8 +388,7 @@ strategyFunctions.fightBrock = function()
if curr_hp == 0 then
return Strategies.death()
end
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local __, turnsToKill, turnsToDie = Combat.bestMove()
if turnsToDie and turnsToDie < 2 and Inventory.contains("potion") then
Inventory.use("potion", "nidoran", true)
@ -417,10 +416,8 @@ strategyFunctions.fightBrock = function()
strategyFunctions.leer({{"onix", 13}})
end
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
elseif Textbox.handle() then
Player.interact("Up")
end
end
@ -638,15 +635,12 @@ end
-- shopRepels
strategyFunctions.lavenderRival = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Strategies.prepare("x_accuracy") then
Battle.automate()
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Input.cancel()
end
end
@ -671,11 +665,7 @@ strategyFunctions.silphCarbos = function(data)
end
strategyFunctions.silphRival = function()
if Battle.isActive() then
if Strategies.initialize() then
status.canProgress = true
end
if Strategies.trainerBattle() then
if Strategies.prepare("x_accuracy") then
-- Strategies.prepare("x_speed")
local forced, prepare
@ -696,11 +686,9 @@ strategyFunctions.silphRival = function()
Battle.automate(forced)
end
end
elseif status.canProgress then
elseif status.foughtTrainer then
Control.ignoreMiss = false
return true
else
Textbox.handle()
end
end
@ -716,9 +704,8 @@ strategyFunctions.tossTM34 = function()
end
strategyFunctions.fightKoga = function()
if Battle.isActive() then
if Strategies.trainerBattle() then
if Strategies.prepare("x_accuracy") then
status.canProgress = true
local forced = "horn_drill"
local opponent = Battle.opponent()
if opponent == "venonat" then
@ -733,18 +720,15 @@ strategyFunctions.fightKoga = function()
end
Battle.automate(forced)
end
elseif status.canProgress then
elseif status.foughtTrainer then
Strategies.deepRun = true
Control.ignoreMiss = false
return true
else
Textbox.handle()
end
end
strategyFunctions.fightSabrina = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Strategies.prepare("x_accuracy", "x_speed") then
-- local forced = "horn_drill"
-- local opponent = Battle.opponent()
@ -752,12 +736,10 @@ strategyFunctions.fightSabrina = function()
-- end
Battle.automate(forced)
end
elseif status.canProgress then
elseif status.foughtTrainer then
Strategies.deepRun = true
Control.ignoreMiss = false
return true
else
Textbox.handle()
end
end
@ -768,9 +750,8 @@ end
-- waitToReceive
strategyFunctions.fightGiovanni = function()
if Battle.isActive() then
if Strategies.trainerBattle() then
if Strategies.initialize() then
status.canProgress = true
Bridge.chat(" Giovanni can end the run here with Dugtrio's high chance to critical...")
end
if Strategies.prepare("x_speed") then
@ -794,12 +775,10 @@ strategyFunctions.fightGiovanni = function()
Battle.automate(forced)
end
end
elseif status.canProgress then
elseif status.foughtTrainer then
Strategies.deepRun = true
Control.ignoreMiss = false
return true
else
Textbox.handle()
end
end
@ -813,8 +792,7 @@ strategyFunctions.useViridianEther = function()
end
strategyFunctions.fightViridianRival = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local xItem1, xItem2
if Strategies.vaporeon then
xItem1 = "x_accuracy"
@ -827,10 +805,8 @@ strategyFunctions.fightViridianRival = function()
if Strategies.prepare(xItem1, xItem2) then
Battle.automate()
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
@ -883,9 +859,7 @@ strategyFunctions.shopE4 = function()
end
strategyFunctions.lorelei = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local opponentName = Battle.opponent()
if opponentName == "dewgong" then
if Memory.double("battle", "our_speed") < 121 then
@ -900,17 +874,13 @@ strategyFunctions.lorelei = function()
if Strategies.prepare("x_accuracy") then
Battle.automate()
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
strategyFunctions.bruno = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local forced
local opponentName = Battle.opponent()
if opponentName == "onix" then
@ -921,16 +891,13 @@ strategyFunctions.bruno = function()
end
end
Battle.automate(forced)
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
strategyFunctions.agatha = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
if Combat.isSleeping() then
Inventory.use("pokeflute", nil, true)
return false
@ -946,16 +913,13 @@ strategyFunctions.agatha = function()
end
end
Battle.automate()
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
strategyFunctions.lance = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local xItem
if Pokemon.isOpponent("dragonair") then
xItem = "x_speed"
@ -975,16 +939,13 @@ strategyFunctions.lance = function()
if Strategies.prepare(xItem) then
Battle.automate()
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end
strategyFunctions.blue = function()
if Battle.isActive() then
status.canProgress = true
if Strategies.trainerBattle() then
local xItem
if Pokemon.isOpponent("exeggutor") then
if Combat.isSleeping() then
@ -1004,10 +965,8 @@ strategyFunctions.blue = function()
if Strategies.prepare(xItem) then
Battle.automate()
end
elseif status.canProgress then
elseif status.foughtTrainer then
return true
else
Textbox.handle()
end
end