Simplify Battle fight function

This commit is contained in:
Kyle Coburn 2015-04-09 16:53:56 -07:00
parent d42b289aff
commit 50c8f2bf13
2 changed files with 11 additions and 6 deletions

View File

@ -184,15 +184,16 @@ function Battle.handleWild()
Battle.handle() Battle.handle()
end end
function Battle.fight(move, isNumber, skipBuffs) function Battle.fight(move, skipBuffs)
if move then if move then
if not isNumber then if type(move) ~= "number" then
move = Pokemon.battleMove(move) move = Pokemon.battleMove(move)
end end
attack(move) attack(move)
else else
move = Combat.bestMove() move = Combat.bestMove()
if move then if move then
Battle.accurateAttack = move.accuracy == 100
attack(move.midx) attack(move.midx)
elseif Memory.value("menu", "text_length") == 127 then elseif Memory.value("menu", "text_length") == 127 then
Input.press("B") Input.press("B")
@ -235,12 +236,12 @@ function Battle.automate(moveName, skipBuffs)
end end
if state == 1 then if state == 1 then
if Control.shouldFight() then if Control.shouldFight() then
Battle.fight(moveName, false, skipBuffs) Battle.fight(moveName, skipBuffs)
else else
Battle.run() Battle.run()
end end
elseif state == 2 then elseif state == 2 then
Battle.fight(moveName, false, skipBuffs) Battle.fight(moveName, skipBuffs)
end end
end end
end end
@ -269,7 +270,11 @@ function Battle.redeployNidoking()
else else
local __, turns = Combat.bestMove() local __, turns = Combat.bestMove()
if turns == 1 then if turns == 1 then
forced = "sand_attack" if Pokemon.isDeployed("spearow") then
forced = "growl"
else
forced = "sand_attack"
end
end end
Battle.automate(forced) Battle.automate(forced)
end end

View File

@ -241,7 +241,7 @@ function Control.shouldCatch(partySize)
penultimate = Combat.nonKill() penultimate = Combat.nonKill()
end end
if penultimate then if penultimate then
require("action.battle").fight(penultimate.midx, true) require("action.battle").fight(penultimate.midx)
else else
Inventory.use("pokeball", nil, true) Inventory.use("pokeball", nil, true)
end end