Standardize curr/max hp lookup
This commit is contained in:
parent
6f0f99f1d3
commit
efc63e2e19
|
@ -30,14 +30,14 @@ end
|
|||
|
||||
local function recover()
|
||||
if Control.canRecover() then
|
||||
local currentHP = Pokemon.index(0, "hp")
|
||||
if currentHP > 0 then
|
||||
local maxHP = Pokemon.index(0, "max_hp")
|
||||
if currentHP < maxHP then
|
||||
local curr_hp = Combat.hp()
|
||||
if curr_hp > 0 then
|
||||
local max_hp = Combat.maxHP()
|
||||
if curr_hp < max_hp then
|
||||
local first, second
|
||||
if Control.preferredPotion == "full" then
|
||||
first, second = "full_restore", "super_potion"
|
||||
if maxHP - currentHP > 54 then
|
||||
if max_hp - curr_hp > 54 then
|
||||
first = "full_restore"
|
||||
second = "super_potion"
|
||||
else
|
||||
|
@ -45,7 +45,7 @@ local function recover()
|
|||
second = "full_restore"
|
||||
end
|
||||
else
|
||||
if Control.preferredPotion == "super" and maxHP - currentHP > 22 then
|
||||
if Control.preferredPotion == "super" and max_hp - curr_hp > 22 then
|
||||
first = "super_potion"
|
||||
second = "potion"
|
||||
else
|
||||
|
@ -54,7 +54,7 @@ local function recover()
|
|||
end
|
||||
end
|
||||
local potion = Inventory.contains(first, second)
|
||||
if potionsForHit(potion, currentHP, maxHP) then
|
||||
if potionsForHit(potion, curr_hp, max_hp) then
|
||||
Inventory.use(potion, nil, true)
|
||||
return true
|
||||
end
|
||||
|
|
|
@ -326,8 +326,12 @@ function Combat.hp()
|
|||
return Pokemon.index(0, "hp")
|
||||
end
|
||||
|
||||
function Combat.maxHP()
|
||||
return Pokemon.index(0, "max_hp")
|
||||
end
|
||||
|
||||
function Combat.redHP()
|
||||
return math.ceil(Pokemon.index(0, "max_hp") * 0.2)
|
||||
return math.ceil(Combat.maxHP() * 0.2)
|
||||
end
|
||||
|
||||
function Combat.inRedBar()
|
||||
|
|
|
@ -202,8 +202,7 @@ local function willRedBar(forDamage)
|
|||
end
|
||||
|
||||
local function potionForRedBar(damage)
|
||||
local curr_hp, red_hp = Combat.hp(), Combat.redHP()
|
||||
local max_hp = Pokemon.index(0, "max_hp")
|
||||
local curr_hp, max_hp, red_hp = Combat.hp(), Combat.maxHP(), Combat.redHP()
|
||||
|
||||
local potions = {
|
||||
{"potion", 20},
|
||||
|
@ -963,7 +962,7 @@ strategyFunctions.potionBeforeMisty = function(data)
|
|||
if not data.goldeen and Strategies.initialize("healed") then
|
||||
local message
|
||||
local potionCount = Inventory.count("potion")
|
||||
local needsToHeal = healAmount - Pokemon.index(0, "hp")
|
||||
local needsToHeal = healAmount - Combat.hp()
|
||||
if potionCount * 20 < needsToHeal then
|
||||
message = "ran too low on potions to adequately heal before Misty D:"
|
||||
elseif healAmount < 60 then
|
||||
|
@ -1381,7 +1380,7 @@ strategyFunctions.silphRival = function()
|
|||
if Strategies.initialize() then
|
||||
if Control.yolo then
|
||||
local gyaradosDamage = Combat.healthFor("RivalGyarados")
|
||||
if gyaradosDamage < Pokemon.index(0, "max_hp") then
|
||||
if gyaradosDamage < Combat.maxHP() then
|
||||
Bridge.chat("is attempting to red-bar off Silph Rival. Get ready to spaghetti!")
|
||||
status.gyaradosDamage = gyaradosDamage
|
||||
end
|
||||
|
@ -1428,7 +1427,7 @@ strategyFunctions.silphRival = function()
|
|||
end
|
||||
forced = "ice_beam"
|
||||
else
|
||||
if Inventory.count("super_potion") > 2 and curr_hp + 50 > status.gyaradosDamage and curr_hp + 25 < Pokemon.index(0, "max_hp") then
|
||||
if Inventory.count("super_potion") > 2 and curr_hp + 50 > status.gyaradosDamage and curr_hp + 25 < Combat.maxHP() then
|
||||
Inventory.use("super_potion", nil, true)
|
||||
return false
|
||||
end
|
||||
|
@ -1878,14 +1877,14 @@ strategyFunctions.agatha = function()
|
|||
return false
|
||||
end
|
||||
if Pokemon.isOpponent("gengar") then
|
||||
local currentHP = Pokemon.info("nidoking", "hp")
|
||||
local curr_hp = Pokemon.info("nidoking", "hp")
|
||||
local xItem1, xItem2
|
||||
if not Control.yolo then
|
||||
xItem1, xItem2 = "x_accuracy", "x_speed"
|
||||
else
|
||||
xItem1 = "x_speed"
|
||||
end
|
||||
if not Control.yolo and currentHP <= 56 and not Strategies.isPrepared(xItem1, xItem2) then
|
||||
if not Control.yolo and curr_hp <= 56 and not Strategies.isPrepared(xItem1, xItem2) then
|
||||
local toPotion = Inventory.contains("full_restore", "super_potion")
|
||||
if toPotion then
|
||||
Inventory.use(toPotion, nil, true)
|
||||
|
@ -1951,7 +1950,7 @@ strategyFunctions.blue = function()
|
|||
end
|
||||
end
|
||||
|
||||
local boostFirst = Pokemon.index(0, "hp") < 55
|
||||
local boostFirst = Combat.hp() < 55
|
||||
local firstItem, secondItem
|
||||
if boostFirst then
|
||||
firstItem = status.xItem
|
||||
|
@ -1969,7 +1968,7 @@ strategyFunctions.blue = function()
|
|||
if Strategies.initialize("skyAttacked") then
|
||||
if not Strategies.isPrepared("x_accuracy", status.xItem) then
|
||||
local msg = " Uh oh... First-turn Sky Attack could end the run here, "
|
||||
if Pokemon.index(0, "hp") > skyDamage then
|
||||
if Combat.hp() > skyDamage then
|
||||
msg = msg.."no criticals pls D:"
|
||||
elseif Strategies.canHealFor(healCutoff) then
|
||||
msg = msg.."attempting to heal for it"
|
||||
|
|
|
@ -163,8 +163,7 @@ function Strategies.initialize(var)
|
|||
end
|
||||
|
||||
function Strategies.canHealFor(damage)
|
||||
local curr_hp = Pokemon.index(0, "hp")
|
||||
local max_hp = Pokemon.index(0, "max_hp")
|
||||
local curr_hp, max_hp = Combat.hp(), Combat.maxHP()
|
||||
if max_hp - curr_hp > 3 then
|
||||
local healChecks = {"full_restore", "super_potion", "potion"}
|
||||
for idx,potion in ipairs(healChecks) do
|
||||
|
@ -179,7 +178,7 @@ function Strategies.hasHealthFor(opponent, extra)
|
|||
if not extra then
|
||||
extra = 0
|
||||
end
|
||||
local afterHealth = math.min(Pokemon.index(0, "hp") + extra, Pokemon.index(0, "max_hp"))
|
||||
local afterHealth = math.min(Combat.hp() + extra, Combat.maxHP())
|
||||
return afterHealth > Combat.healthFor(opponent)
|
||||
end
|
||||
|
||||
|
@ -187,7 +186,7 @@ function Strategies.damaged(factor)
|
|||
if not factor then
|
||||
factor = 1
|
||||
end
|
||||
return Pokemon.index(0, "hp") * factor < Pokemon.index(0, "max_hp")
|
||||
return Combat.hp() * factor < Combat.maxHP()
|
||||
end
|
||||
|
||||
function Strategies.trainerBattle()
|
||||
|
@ -590,7 +589,7 @@ Strategies.functions = {
|
|||
end,
|
||||
|
||||
potion = function(data)
|
||||
local curr_hp = Pokemon.index(0, "hp")
|
||||
local curr_hp = Combat.hp()
|
||||
if curr_hp == 0 then
|
||||
return false
|
||||
end
|
||||
|
@ -603,7 +602,7 @@ Strategies.functions = {
|
|||
if type(toHP) == "string" then
|
||||
toHP = Combat.healthFor(toHP)
|
||||
end
|
||||
toHP = math.min(toHP, Pokemon.index(0, "max_hp"))
|
||||
toHP = math.min(toHP, Combat.maxHP())
|
||||
local toHeal = toHP - curr_hp
|
||||
if toHeal > 0 then
|
||||
local toPotion
|
||||
|
|
|
@ -304,11 +304,6 @@ function Pokemon.getMaxExp()
|
|||
return math.floor((6 / 5 * level^3) - (15 * level^2) + (100 * level) - 140)
|
||||
end
|
||||
|
||||
function Pokemon.inRedBar()
|
||||
local curr_hp, max_hp = index(0, "hp"), index(0, "max_hp")
|
||||
return curr_hp / max_hp <= 0.2
|
||||
end
|
||||
|
||||
function Pokemon.use(move)
|
||||
local main = Memory.value("menu", "main")
|
||||
local pokeName = Pokemon.forMove(move)
|
||||
|
|
|
@ -116,8 +116,8 @@ function Bridge.caught(name)
|
|||
end
|
||||
end
|
||||
|
||||
function Bridge.hp(curr, max)
|
||||
send("hp", curr..","..max)
|
||||
function Bridge.hp(curr_hp, max_hp, curr_xp, max_xp, level)
|
||||
send("hpxp", curr_hp..","..max_hp..","..curr_xp..","..max_xp..","..level)
|
||||
end
|
||||
|
||||
function Bridge.liveSplit()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
local Paint = {}
|
||||
|
||||
local Combat = require "ai.combat"
|
||||
|
||||
local Memory = require "util.memory"
|
||||
local Player = require "util.player"
|
||||
local Utils = require "util.utils"
|
||||
|
@ -18,11 +20,11 @@ function Paint.draw(currentMap)
|
|||
drawText(0, 7, currentMap..": "..px.." "..py)
|
||||
|
||||
if Memory.value("battle", "our_id") > 0 then
|
||||
local curr_hp = Pokemon.index(0, "hp")
|
||||
local curr_hp = Combat.hp()
|
||||
local hpStatus
|
||||
if curr_hp == 0 then
|
||||
hpStatus = "DEAD"
|
||||
elseif curr_hp <= math.ceil(Pokemon.index(0, "max_hp") * 0.2) then
|
||||
elseif curr_hp <= math.ceil(Combat.maxHP() * 0.2) then
|
||||
hpStatus = "RED"
|
||||
end
|
||||
if hpStatus then
|
||||
|
|
Loading…
Reference in New Issue