Ensure wild battles are not automatically ran from unintentionally, standardize HP retrieval

This commit is contained in:
Kyle Coburn 2015-04-06 17:29:05 -07:00
parent 042f707ec6
commit dc3a87c67d
6 changed files with 60 additions and 32 deletions

View File

@ -125,7 +125,7 @@ function Battle.isTrainer()
return true
end
if battleType == 1 then
Battle.run()
Battle.handle()
else
Textbox.handle()
end
@ -154,11 +154,21 @@ function Battle.run()
end
end
function Battle.handle()
if not Control.shouldCatch() then
if Control.shouldFight() then
Battle.fight()
else
Battle.run()
end
end
end
function Battle.handleWild()
if Memory.value("game", "battle") ~= 1 then
return true
end
Battle.run()
Battle.handle()
end
function Battle.fight(move, isNumber, skipBuffs)

View File

@ -4,6 +4,7 @@ local Movelist = require "data.movelist"
local Opponents = require "data.opponents"
local Memory = require "util.memory"
local Pokemon = require "storage.pokemon"
local damageMultiplier = { -- http://bulbapedia.bulbagarden.net/wiki/Type_chart#Generation_I
normal = {normal=1.0, fighting=1.0, flying=1.0, poison=1.0, ground=1.0, rock=0.5, bug=1.0, ghost=0.0, fire=1.0, water=1.0, grass=1.0, electric=1.0, psychic=1.0, ice=1.0, dragon=1.0, },
@ -295,6 +296,20 @@ local function isConfused()
end
Combat.isConfused = isConfused
-- HP
function Combat.hp()
return Pokemon.index(0, "hp")
end
function Combat.redHP()
return math.ceil(Pokemon.index(0, "max_hp") * 0.2)
end
function Combat.inRedBar()
return Combat.hp() <= Combat.redHP()
end
-- Combat AI
function Combat.factorPP(enabled)

View File

@ -24,6 +24,10 @@ Control.areaName = "Unknown"
Control.moonEncounters = nil
Control.yolo = false
local function withinOneKill(forExp)
return Pokemon.getExp() + 80 > forExp
end
local controlFunctions = {
a = function(data)
@ -84,11 +88,17 @@ local controlFunctions = {
moon2Exp = function()
minExp = 3011
shouldFight = {{name="zubat"}, {name="paras"}}
oneHits = not withinOneKill(minExp)
end,
moon3Exp = function()
local expTotal = Pokemon.getExp()
minExp = 3798
shouldFight = {{name="zubat"}, {name="geodude",lvl={9}}, {name="paras"}} --TODO geodude?
if withinOneKill(minExp) then
shouldFight = {{name="zubat"}, {name="geodude",lvl={9}}, {name="paras"}} --TODO geodude?
else
shouldFight = nil
end
end,
catchNidoran = function()

View File

@ -277,12 +277,8 @@ strategyFunctions.catchNidoran = function()
else
Input.cancel()
end
elseif not Control.shouldCatch() then
if Control.shouldFight() then
Battle.fight()
else
Battle.run()
end
else
Battle.handle()
end
else
local noDSum
@ -368,11 +364,11 @@ strategyFunctions.grabForestPotion = function()
if Battle.handleWild() then
local potionCount = Inventory.count("potion")
if Strategies.initialize() then
status.tempDir = potionCount
status.tries = potionCount
end
if potionCount > 0 then
if status.tempDir and potionCount > status.tempDir then
status.tempDir = nil
if status.tries and potionCount > status.tries then
status.tries = nil
end
local healthNeeded = (Pokemon.info("spearow", "level") == 3) and 8 or 15
if Pokemon.info("squirtle", "hp") <= healthNeeded then
@ -382,7 +378,7 @@ strategyFunctions.grabForestPotion = function()
else
return true
end
elseif not status.tempDir then
elseif not status.tries then
return true
elseif Menu.close() then
Player.interact("Up")
@ -743,8 +739,8 @@ strategyFunctions.catchFlierBackup = function()
else
Input.press("A")
end
elseif not Control.shouldCatch() then
Battle.run()
else
Battle.handle()
end
else
local birdPath
@ -941,7 +937,7 @@ strategyFunctions.redbarMankey = function()
if not Strategies.setYolo("mankey") then
return true
end
local curr_hp, red_hp = Pokemon.index(0, "hp"), Strategies.redHP()
local curr_hp, red_hp = Pokemon.index(0, "hp"), Combat.redHP()
if curr_hp <= red_hp then
return true
end
@ -1092,9 +1088,7 @@ strategyFunctions.catchOddish = function()
if status.tries == 0 and py == 31 then
status.tries = 1
end
if not Control.shouldCatch() then
Battle.run()
end
Battle.handle()
end
elseif status.tries == 1 and py == 31 then
Player.interact("Left")
@ -1266,7 +1260,7 @@ strategyFunctions.fightSurge = function()
if not enemyTurns or enemyTurns > 2 then
forced = "bubblebeam"
elseif enemyTurns == 2 and not Strategies.opponentDamaged() then
local curr_hp, red_hp = Pokemon.index(0, "hp"), Strategies.redHP()
local curr_hp, red_hp = Pokemon.index(0, "hp"), Combat.redHP()
local afterHit = curr_hp - 20
if afterHit > 5 and afterHit <= red_hp then
forced = "bubblebeam"
@ -1329,7 +1323,7 @@ strategyFunctions.redbarCubone = function()
if Pokemon.isOpponent("cubone") then
local enemyMove, enemyTurns = Combat.enemyAttack()
if enemyTurns then
local curr_hp, red_hp = Pokemon.index(0, "hp"), Strategies.redHP()
local curr_hp, red_hp = Pokemon.index(0, "hp"), Combat.redHP()
local clubDmg = enemyMove.damage
local afterHit = curr_hp - clubDmg
red_hp = red_hp - 2
@ -1654,7 +1648,7 @@ strategyFunctions.silphRival = function()
local opponentName = Battle.opponent()
if opponentName == "gyarados" then
readyToAttack = true
local hp, red_hp = Pokemon.index(0, "hp"), Strategies.redHP()
local hp, red_hp = Pokemon.index(0, "hp"), Combat.redHP()
if hp > gyaradosDamage * 0.98 and hp - gyaradosDamage * 0.975 < red_hp then --TODO
if Strategies.prepare("x_special") then
forced = "ice_beam"
@ -1735,7 +1729,7 @@ end
-- 9: SILPH CO.
strategyFunctions.potionBeforeHypno = function()
local curr_hp, red_hp = Pokemon.index(0, "hp"), Strategies.redHP()
local curr_hp, red_hp = Pokemon.index(0, "hp"), Combat.redHP()
local healthUnderRedBar = red_hp - curr_hp
local yoloHP = Combat.healthFor("HypnoHeadbutt") * 0.9
local useRareCandy = Inventory.count("rare_candy") > 2
@ -1858,7 +1852,7 @@ strategyFunctions.fightErika = function()
if Battle.isActive() then
status.canProgress = true
local forced
local curr_hp, red_hp = Pokemon.index(0, "hp"), Strategies.redHP()
local curr_hp, red_hp = Pokemon.index(0, "hp"), Combat.redHP()
local razorDamage = 34
if curr_hp > razorDamage and curr_hp - razorDamage < red_hp then
if Strategies.opponentDamaged() then
@ -2176,7 +2170,7 @@ strategyFunctions.bruno = function()
local forced
if Pokemon.isOpponent("onix") then
forced = "ice_beam"
-- local curr_hp, red_hp = Pokemon.info("nidoking", "hp"), Strategies.redHP()
-- local curr_hp, red_hp = Pokemon.info("nidoking", "hp"), Combat.redHP()
-- if curr_hp > red_hp then
-- local enemyMove, enemyTurns = Combat.enemyAttack()
-- if enemyTurns and enemyTurns > 1 then

View File

@ -159,10 +159,6 @@ function Strategies.opponentDamaged(factor)
return Memory.double("battle", "opponent_hp") * factor < Memory.double("battle", "opponent_max_hp")
end
function Strategies.redHP()
return math.ceil(Pokemon.index(0, "max_hp") * 0.2)
end
function Strategies.buffTo(buff, defLevel)
if Battle.isActive() then
status.canProgress = true
@ -710,6 +706,7 @@ function Strategies.softReset()
Strategies.status = status
splitNumber, splitTime = 0, 0
resetting = nil
Strategies.deepRun = false
Strategies.resetGame()
end

View File

@ -51,9 +51,11 @@ function Bridge.init()
end
end
function Bridge.tweet(message) -- Two of the same tweet in a row will only send one
print("tweet::"..message)
return send("tweet", message)
function Bridge.tweet(message)
if INTERNAL and STREAMING_MODE then
print("tweet::"..message)
return send("tweet", message)
end
end
function Bridge.pollForName()