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

View File

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