Ensure wild battles are not automatically ran from unintentionally, standardize HP retrieval
This commit is contained in:
parent
042f707ec6
commit
dc3a87c67d
|
@ -125,7 +125,7 @@ function Battle.isTrainer()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if battleType == 1 then
|
if battleType == 1 then
|
||||||
Battle.run()
|
Battle.handle()
|
||||||
else
|
else
|
||||||
Textbox.handle()
|
Textbox.handle()
|
||||||
end
|
end
|
||||||
|
@ -154,11 +154,21 @@ function Battle.run()
|
||||||
end
|
end
|
||||||
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()
|
function Battle.handleWild()
|
||||||
if Memory.value("game", "battle") ~= 1 then
|
if Memory.value("game", "battle") ~= 1 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
Battle.run()
|
Battle.handle()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Battle.fight(move, isNumber, skipBuffs)
|
function Battle.fight(move, isNumber, skipBuffs)
|
||||||
|
|
|
@ -4,6 +4,7 @@ local Movelist = require "data.movelist"
|
||||||
local Opponents = require "data.opponents"
|
local Opponents = require "data.opponents"
|
||||||
|
|
||||||
local Memory = require "util.memory"
|
local Memory = require "util.memory"
|
||||||
|
local Pokemon = require "storage.pokemon"
|
||||||
|
|
||||||
local damageMultiplier = { -- http://bulbapedia.bulbagarden.net/wiki/Type_chart#Generation_I
|
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, },
|
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
|
end
|
||||||
Combat.isConfused = isConfused
|
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
|
-- Combat AI
|
||||||
|
|
||||||
function Combat.factorPP(enabled)
|
function Combat.factorPP(enabled)
|
||||||
|
|
|
@ -24,6 +24,10 @@ Control.areaName = "Unknown"
|
||||||
Control.moonEncounters = nil
|
Control.moonEncounters = nil
|
||||||
Control.yolo = false
|
Control.yolo = false
|
||||||
|
|
||||||
|
local function withinOneKill(forExp)
|
||||||
|
return Pokemon.getExp() + 80 > forExp
|
||||||
|
end
|
||||||
|
|
||||||
local controlFunctions = {
|
local controlFunctions = {
|
||||||
|
|
||||||
a = function(data)
|
a = function(data)
|
||||||
|
@ -84,11 +88,17 @@ local controlFunctions = {
|
||||||
moon2Exp = function()
|
moon2Exp = function()
|
||||||
minExp = 3011
|
minExp = 3011
|
||||||
shouldFight = {{name="zubat"}, {name="paras"}}
|
shouldFight = {{name="zubat"}, {name="paras"}}
|
||||||
|
oneHits = not withinOneKill(minExp)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
moon3Exp = function()
|
moon3Exp = function()
|
||||||
|
local expTotal = Pokemon.getExp()
|
||||||
minExp = 3798
|
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,
|
end,
|
||||||
|
|
||||||
catchNidoran = function()
|
catchNidoran = function()
|
||||||
|
|
|
@ -277,12 +277,8 @@ strategyFunctions.catchNidoran = function()
|
||||||
else
|
else
|
||||||
Input.cancel()
|
Input.cancel()
|
||||||
end
|
end
|
||||||
elseif not Control.shouldCatch() then
|
else
|
||||||
if Control.shouldFight() then
|
Battle.handle()
|
||||||
Battle.fight()
|
|
||||||
else
|
|
||||||
Battle.run()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local noDSum
|
local noDSum
|
||||||
|
@ -368,11 +364,11 @@ strategyFunctions.grabForestPotion = function()
|
||||||
if Battle.handleWild() then
|
if Battle.handleWild() then
|
||||||
local potionCount = Inventory.count("potion")
|
local potionCount = Inventory.count("potion")
|
||||||
if Strategies.initialize() then
|
if Strategies.initialize() then
|
||||||
status.tempDir = potionCount
|
status.tries = potionCount
|
||||||
end
|
end
|
||||||
if potionCount > 0 then
|
if potionCount > 0 then
|
||||||
if status.tempDir and potionCount > status.tempDir then
|
if status.tries and potionCount > status.tries then
|
||||||
status.tempDir = nil
|
status.tries = nil
|
||||||
end
|
end
|
||||||
local healthNeeded = (Pokemon.info("spearow", "level") == 3) and 8 or 15
|
local healthNeeded = (Pokemon.info("spearow", "level") == 3) and 8 or 15
|
||||||
if Pokemon.info("squirtle", "hp") <= healthNeeded then
|
if Pokemon.info("squirtle", "hp") <= healthNeeded then
|
||||||
|
@ -382,7 +378,7 @@ strategyFunctions.grabForestPotion = function()
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
elseif not status.tempDir then
|
elseif not status.tries then
|
||||||
return true
|
return true
|
||||||
elseif Menu.close() then
|
elseif Menu.close() then
|
||||||
Player.interact("Up")
|
Player.interact("Up")
|
||||||
|
@ -743,8 +739,8 @@ strategyFunctions.catchFlierBackup = function()
|
||||||
else
|
else
|
||||||
Input.press("A")
|
Input.press("A")
|
||||||
end
|
end
|
||||||
elseif not Control.shouldCatch() then
|
else
|
||||||
Battle.run()
|
Battle.handle()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local birdPath
|
local birdPath
|
||||||
|
@ -941,7 +937,7 @@ strategyFunctions.redbarMankey = function()
|
||||||
if not Strategies.setYolo("mankey") then
|
if not Strategies.setYolo("mankey") then
|
||||||
return true
|
return true
|
||||||
end
|
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
|
if curr_hp <= red_hp then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -1092,9 +1088,7 @@ strategyFunctions.catchOddish = function()
|
||||||
if status.tries == 0 and py == 31 then
|
if status.tries == 0 and py == 31 then
|
||||||
status.tries = 1
|
status.tries = 1
|
||||||
end
|
end
|
||||||
if not Control.shouldCatch() then
|
Battle.handle()
|
||||||
Battle.run()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
elseif status.tries == 1 and py == 31 then
|
elseif status.tries == 1 and py == 31 then
|
||||||
Player.interact("Left")
|
Player.interact("Left")
|
||||||
|
@ -1266,7 +1260,7 @@ strategyFunctions.fightSurge = function()
|
||||||
if not enemyTurns or enemyTurns > 2 then
|
if not enemyTurns or enemyTurns > 2 then
|
||||||
forced = "bubblebeam"
|
forced = "bubblebeam"
|
||||||
elseif enemyTurns == 2 and not Strategies.opponentDamaged() then
|
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
|
local afterHit = curr_hp - 20
|
||||||
if afterHit > 5 and afterHit <= red_hp then
|
if afterHit > 5 and afterHit <= red_hp then
|
||||||
forced = "bubblebeam"
|
forced = "bubblebeam"
|
||||||
|
@ -1329,7 +1323,7 @@ strategyFunctions.redbarCubone = function()
|
||||||
if Pokemon.isOpponent("cubone") then
|
if Pokemon.isOpponent("cubone") then
|
||||||
local enemyMove, enemyTurns = Combat.enemyAttack()
|
local enemyMove, enemyTurns = Combat.enemyAttack()
|
||||||
if enemyTurns then
|
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 clubDmg = enemyMove.damage
|
||||||
local afterHit = curr_hp - clubDmg
|
local afterHit = curr_hp - clubDmg
|
||||||
red_hp = red_hp - 2
|
red_hp = red_hp - 2
|
||||||
|
@ -1654,7 +1648,7 @@ strategyFunctions.silphRival = function()
|
||||||
local opponentName = Battle.opponent()
|
local opponentName = Battle.opponent()
|
||||||
if opponentName == "gyarados" then
|
if opponentName == "gyarados" then
|
||||||
readyToAttack = true
|
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 hp > gyaradosDamage * 0.98 and hp - gyaradosDamage * 0.975 < red_hp then --TODO
|
||||||
if Strategies.prepare("x_special") then
|
if Strategies.prepare("x_special") then
|
||||||
forced = "ice_beam"
|
forced = "ice_beam"
|
||||||
|
@ -1735,7 +1729,7 @@ end
|
||||||
-- 9: SILPH CO.
|
-- 9: SILPH CO.
|
||||||
|
|
||||||
strategyFunctions.potionBeforeHypno = function()
|
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 healthUnderRedBar = red_hp - curr_hp
|
||||||
local yoloHP = Combat.healthFor("HypnoHeadbutt") * 0.9
|
local yoloHP = Combat.healthFor("HypnoHeadbutt") * 0.9
|
||||||
local useRareCandy = Inventory.count("rare_candy") > 2
|
local useRareCandy = Inventory.count("rare_candy") > 2
|
||||||
|
@ -1858,7 +1852,7 @@ strategyFunctions.fightErika = function()
|
||||||
if Battle.isActive() then
|
if Battle.isActive() then
|
||||||
status.canProgress = true
|
status.canProgress = true
|
||||||
local forced
|
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
|
local razorDamage = 34
|
||||||
if curr_hp > razorDamage and curr_hp - razorDamage < red_hp then
|
if curr_hp > razorDamage and curr_hp - razorDamage < red_hp then
|
||||||
if Strategies.opponentDamaged() then
|
if Strategies.opponentDamaged() then
|
||||||
|
@ -2176,7 +2170,7 @@ strategyFunctions.bruno = function()
|
||||||
local forced
|
local forced
|
||||||
if Pokemon.isOpponent("onix") then
|
if Pokemon.isOpponent("onix") then
|
||||||
forced = "ice_beam"
|
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
|
-- if curr_hp > red_hp then
|
||||||
-- local enemyMove, enemyTurns = Combat.enemyAttack()
|
-- local enemyMove, enemyTurns = Combat.enemyAttack()
|
||||||
-- if enemyTurns and enemyTurns > 1 then
|
-- if enemyTurns and enemyTurns > 1 then
|
||||||
|
|
|
@ -159,10 +159,6 @@ function Strategies.opponentDamaged(factor)
|
||||||
return Memory.double("battle", "opponent_hp") * factor < Memory.double("battle", "opponent_max_hp")
|
return Memory.double("battle", "opponent_hp") * factor < Memory.double("battle", "opponent_max_hp")
|
||||||
end
|
end
|
||||||
|
|
||||||
function Strategies.redHP()
|
|
||||||
return math.ceil(Pokemon.index(0, "max_hp") * 0.2)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Strategies.buffTo(buff, defLevel)
|
function Strategies.buffTo(buff, defLevel)
|
||||||
if Battle.isActive() then
|
if Battle.isActive() then
|
||||||
status.canProgress = true
|
status.canProgress = true
|
||||||
|
@ -710,6 +706,7 @@ function Strategies.softReset()
|
||||||
Strategies.status = status
|
Strategies.status = status
|
||||||
splitNumber, splitTime = 0, 0
|
splitNumber, splitTime = 0, 0
|
||||||
resetting = nil
|
resetting = nil
|
||||||
|
Strategies.deepRun = false
|
||||||
Strategies.resetGame()
|
Strategies.resetGame()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -51,9 +51,11 @@ function Bridge.init()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Bridge.tweet(message) -- Two of the same tweet in a row will only send one
|
function Bridge.tweet(message)
|
||||||
print("tweet::"..message)
|
if INTERNAL and STREAMING_MODE then
|
||||||
return send("tweet", message)
|
print("tweet::"..message)
|
||||||
|
return send("tweet", message)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Bridge.pollForName()
|
function Bridge.pollForName()
|
||||||
|
|
Loading…
Reference in New Issue