Improve fight method and add additional disable check

This commit is contained in:
Kyle Coburn 2015-05-28 02:23:28 -07:00
parent 2707444870
commit 9eab9701ce
3 changed files with 26 additions and 10 deletions

View File

@ -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)

View File

@ -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

View File

@ -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