diff --git a/action/battle.lua b/action/battle.lua index c7d209f..06b9a89 100644 --- a/action/battle.lua +++ b/action/battle.lua @@ -213,22 +213,38 @@ function Battle.handleWild(battleStatus) end function Battle.fight(move) + local moveIndex if move then - if type(move) ~= "number" then - move = Pokemon.battleMove(move) + local disableCheck + if type(move) == "string" then + disableCheck = move + moveIndex = Pokemon.battleMove(move) + else + disableCheck = move.id + Battle.accurateAttack = move.accuracy == 100 + moveIndex = move.midx end - attack(move) - else + if Combat.isDisabled(disableCheck) then + move = nil + end + end + if not move then 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") + moveIndex = move.midx else - Input.cancel() + moveIndex = nil end end + + if moveIndex then + attack(moveIndex) + elseif Memory.value("menu", "text_length") == 127 then + Input.press("B") + else + Input.cancel() + end end function Battle.swap(target) diff --git a/ai/combat.lua b/ai/combat.lua index a244402..585d58c 100644 --- a/ai/combat.lua +++ b/ai/combat.lua @@ -235,7 +235,7 @@ local function calcBestHit(attacker, defender, ours, rng) replaces = maxTurns < bestMinTurns end end - elseif maxTurns < 2 or maxTurns == bestTurns then + elseif maxTurns < 2 or maxTurns == bestMinTurns then if ret.name == "Earthquake" and (move.name == "Ice-Beam" or move.name == "Thunderbolt") then replaces = true elseif move.pp > ret.pp then diff --git a/ai/control.lua b/ai/control.lua index 58c50b6..9271728 100644 --- a/ai/control.lua +++ b/ai/control.lua @@ -286,7 +286,7 @@ function Control.shouldCatch(partySize) penultimate = Combat.nonKill() end if penultimate then - require("action.battle").fight(penultimate.midx) + require("action.battle").fight(penultimate) else if poke.requireHit and not Battle.opponentDamaged() then return false