From 50c8f2bf1316c3c5af0cf492eb66f19b05aeee21 Mon Sep 17 00:00:00 2001 From: Kyle Coburn Date: Thu, 9 Apr 2015 16:53:56 -0700 Subject: [PATCH] Simplify Battle fight function --- action/battle.lua | 15 ++++++++++----- ai/control.lua | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/action/battle.lua b/action/battle.lua index 20b41a1..2c272bb 100644 --- a/action/battle.lua +++ b/action/battle.lua @@ -184,15 +184,16 @@ function Battle.handleWild() Battle.handle() end -function Battle.fight(move, isNumber, skipBuffs) +function Battle.fight(move, skipBuffs) if move then - if not isNumber then + if type(move) ~= "number" then move = Pokemon.battleMove(move) end attack(move) else move = Combat.bestMove() if move then + Battle.accurateAttack = move.accuracy == 100 attack(move.midx) elseif Memory.value("menu", "text_length") == 127 then Input.press("B") @@ -235,12 +236,12 @@ function Battle.automate(moveName, skipBuffs) end if state == 1 then if Control.shouldFight() then - Battle.fight(moveName, false, skipBuffs) + Battle.fight(moveName, skipBuffs) else Battle.run() end elseif state == 2 then - Battle.fight(moveName, false, skipBuffs) + Battle.fight(moveName, skipBuffs) end end end @@ -269,7 +270,11 @@ function Battle.redeployNidoking() else local __, turns = Combat.bestMove() if turns == 1 then - forced = "sand_attack" + if Pokemon.isDeployed("spearow") then + forced = "growl" + else + forced = "sand_attack" + end end Battle.automate(forced) end diff --git a/ai/control.lua b/ai/control.lua index c87cf03..b2e55fb 100644 --- a/ai/control.lua +++ b/ai/control.lua @@ -241,7 +241,7 @@ function Control.shouldCatch(partySize) penultimate = Combat.nonKill() end if penultimate then - require("action.battle").fight(penultimate.midx, true) + require("action.battle").fight(penultimate.midx) else Inventory.use("pokeball", nil, true) end