Standardize checking a live opponent, clarify some chat messages

This commit is contained in:
Kyle Coburn 2015-04-15 11:16:02 -07:00
parent 099c11291a
commit 60d79fb255
5 changed files with 25 additions and 13 deletions

View File

@ -93,7 +93,7 @@ local function openBattleMenu()
end
local function attack(attackIndex)
if Memory.double("battle", "opponent_hp") < 1 then
if not Battle.opponentAlive() then
Input.cancel()
elseif openBattleMenu() then
Menu.select(attackIndex, true, false, false, false, 3)
@ -146,10 +146,14 @@ function Battle.opponent()
return Pokemon.getName(Memory.value("battle", "opponent_id"))
end
function Battle.opponentAlive()
return Memory.double("battle", "opponent_hp") > 0
end
-- HANDLE
function Battle.run()
if Memory.double("battle", "opponent_hp") < 1 then
if not Battle.opponentAlive() then
Input.cancel()
elseif Memory.value("battle", "menu") ~= 94 then
if Memory.value("menu", "text_length") == 127 then
@ -161,6 +165,8 @@ function Battle.run()
local selected = Memory.value("menu", "selection")
if selected == 239 then
Input.press("A", 2)
elseif selected == 233 then
Input.press("Right")
else
Input.escape()
end

View File

@ -308,9 +308,9 @@ function Control.encounter(battleState)
Control.criticaled = isCritical
end
if wildBattle then
local opponentHP = Memory.double("battle", "opponent_hp")
local opponentAlive = Battle.opponentAlive()
if not Control.inBattle then
if opponentHP > 0 then
if opponentAlive then
Control.killedCatch = false
Control.inBattle = true
encounters = encounters + 1
@ -324,7 +324,7 @@ function Control.encounter(battleState)
end
end
else
if opponentHP == 0 and shouldCatch and not Control.killedCatch then
if not opponentAlive and shouldCatch and not Control.killedCatch then
local gottaCatchEm = {"pidgey", "spearow", "paras", "oddish"}
local opponent = Battle.opponent()
for i,catch in ipairs(gottaCatchEm) do

View File

@ -208,7 +208,6 @@ local function potionForRedBar(damage)
end
end
end
return canPotion
end
-- STATE
@ -306,7 +305,7 @@ strategyFunctions.fightBulbasaur = function()
status.tries = status.tries + 1
end
end
if Battle.isActive() and Memory.double("battle", "opponent_hp") > 0 and Strategies.resetTime("bulbasaur", "beat Bulbasaur") then
if Battle.isActive() and Battle.opponentAlive() and Strategies.resetTime("bulbasaur", "beat Bulbasaur") then
return true
end
return Strategies.buffTo("tail_whip", 6)
@ -691,7 +690,7 @@ end
strategyFunctions.fightMetapod = function()
if Battle.isActive() then
status.canProgress = true
if Memory.double("battle", "opponent_hp") > 0 and Pokemon.isOpponent("metapod") then
if Battle.opponentAlive() and Pokemon.isOpponent("metapod") then
return true
end
Battle.automate()
@ -820,7 +819,7 @@ end
strategyFunctions.thrashGeodude = function()
if Battle.isActive() then
status.canProgress = true
if Pokemon.isOpponent("geodude") and Pokemon.isDeployed("nidoking") then
if Pokemon.isOpponent("geodude") and Battle.opponentAlive() and Pokemon.isDeployed("nidoking") then
if Strategies.initialize() then
status.sacrificeSquirtle = not Control.yolo or Combat.inRedBar()
end
@ -931,7 +930,7 @@ strategyFunctions.fightMisty = function()
return false
end
local forced
if not status.swappedOut and Memory.double("battle", "opponent_hp") > 0 and Combat.isConfused() then
if not status.swappedOut and Battle.opponentAlive() and Combat.isConfused() then
if status.swappedOut == nil and Control.yolo then
status.swappedOut = true
return false
@ -1901,7 +1900,14 @@ strategyFunctions.prepareForBlue = function()
Strategies.setYolo("blue")
local curr_hp, red_hp = Combat.hp(), Combat.redHP()
if Control.yolo and curr_hp < red_hp + 30 then
Bridge.chat("is using limited potions to attempt to red-bar off Pidgeot")
local message
if curr_hp > wingDmg then
message = "is skipping potioning"
else
message = "is using limited potions"
end
message = message.." to attempt to red-bar off Pidgeot"
Bridge.chat(message)
end
end

View File

@ -921,7 +921,7 @@ Strategies.functions = {
if Battle.isActive() then
status.tries = 0
status.canProgress = true
if Memory.double("battle", "opponent_hp") == 0 then
if not Battle.opponentAlive() then
Input.press("A")
else
Battle.automate()

View File

@ -599,7 +599,7 @@ strategyFunctions.fightKoga = function()
local forced = "horn_drill"
local opponent = Battle.opponent()
if opponent == "venonat" then
if Memory.double("battle", "opponent_hp") == 0 then
if not Battle.opponentAlive() then
status.secondVenonat = true
end
if status.secondVenonat or Combat.isSleeping() then