Standardize potion amount checking
This commit is contained in:
parent
17d8f9810b
commit
728371a10c
|
@ -13,28 +13,15 @@ local utils = require "util.utils"
|
||||||
local inventory = require "storage.inventory"
|
local inventory = require "storage.inventory"
|
||||||
local pokemon = require "storage.pokemon"
|
local pokemon = require "storage.pokemon"
|
||||||
|
|
||||||
local function potionsForHit(potion, currHP, maxHP)
|
local function potionsForHit(potion, curr_hp, max_hp)
|
||||||
if not potion then
|
if not potion then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local ours, killAmount = combat.inKillRange()
|
local ours, killAmount = combat.inKillRange()
|
||||||
if ours then
|
if ours then
|
||||||
local potionHP
|
return utils.canPotionWith(potion, killAmount, curr_hp, max_hp)
|
||||||
if potion == "full_restore" then
|
|
||||||
potionHP = 999
|
|
||||||
elseif potion == "super_potion" then
|
|
||||||
potionHP = 50
|
|
||||||
else
|
|
||||||
potionHP = 20
|
|
||||||
end
|
|
||||||
if not currHP then
|
|
||||||
currHP = pokemon.index(0, "hp")
|
|
||||||
maxHP = pokemon.index(0, "max_hp")
|
|
||||||
end
|
|
||||||
return math.min(currHP + potionHP, maxHP) >= killAmount - 2
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
battle.potionsForHit = potionsForHit
|
|
||||||
|
|
||||||
local function recover()
|
local function recover()
|
||||||
if control.canRecover() then
|
if control.canRecover() then
|
||||||
|
|
|
@ -163,7 +163,7 @@ local function modPlayerStats(user, enemy, move)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function calcBestHit(attacker, defender, ours, rng)
|
local function calcBestHit(attacker, defender, ours, rng)
|
||||||
local bestTurns, bestMinTurns = 9999, 9999
|
local bestTurns, bestMinTurns = 9001, 9001
|
||||||
local bestDmg = -1
|
local bestDmg = -1
|
||||||
local ourMaxHit
|
local ourMaxHit
|
||||||
local ret = nil
|
local ret = nil
|
||||||
|
@ -173,7 +173,7 @@ local function calcBestHit(attacker, defender, ours, rng)
|
||||||
if maxDmg then
|
if maxDmg then
|
||||||
local minTurns, maxTurns
|
local minTurns, maxTurns
|
||||||
if maxDmg <= 0 then
|
if maxDmg <= 0 then
|
||||||
minTurns, maxTurns = 9999, 9999
|
minTurns, maxTurns = 9001, 9001
|
||||||
else
|
else
|
||||||
minTurns = math.ceil(defender.hp / maxDmg)
|
minTurns = math.ceil(defender.hp / maxDmg)
|
||||||
maxTurns = math.ceil(defender.hp / minDmg)
|
maxTurns = math.ceil(defender.hp / minDmg)
|
||||||
|
|
|
@ -215,19 +215,12 @@ end
|
||||||
local function canHealFor(damage)
|
local function canHealFor(damage)
|
||||||
local curr_hp = pokemon.index(0, "hp")
|
local curr_hp = pokemon.index(0, "hp")
|
||||||
local max_hp = pokemon.index(0, "max_hp")
|
local max_hp = pokemon.index(0, "max_hp")
|
||||||
if max_hp - curr_hp < 5 then
|
if max_hp - curr_hp > 3 then
|
||||||
return nil
|
local healChecks = {"full_restore", "super_potion", "potion"}
|
||||||
end
|
|
||||||
local healChecks = {
|
|
||||||
{"full_restore", 9001},
|
|
||||||
{"super_potion", 50},
|
|
||||||
{"potion", 20},
|
|
||||||
}
|
|
||||||
for idx,potion in ipairs(healChecks) do
|
for idx,potion in ipairs(healChecks) do
|
||||||
local name = potion[1]
|
if inventory.contains(potion) and utils.canPotionWith(potion, damage, curr_hp, max_hp) then
|
||||||
local result_hp = math.min(curr_hp + potion[2], max_hp)
|
return potion
|
||||||
if result_hp >= damage and inventory.contains(name) then
|
end
|
||||||
return name
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,14 +2,12 @@ local utils = {}
|
||||||
|
|
||||||
local memory = require "util.memory"
|
local memory = require "util.memory"
|
||||||
|
|
||||||
|
-- GENERAL
|
||||||
|
|
||||||
function utils.dist(x1, y1, x2, y2)
|
function utils.dist(x1, y1, x2, y2)
|
||||||
return math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2))
|
return math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2))
|
||||||
end
|
end
|
||||||
|
|
||||||
function utils.ingame()
|
|
||||||
return memory.raw(0x020E) > 0
|
|
||||||
end
|
|
||||||
|
|
||||||
function utils.each(table, func)
|
function utils.each(table, func)
|
||||||
for key,val in pairs(table) do
|
for key,val in pairs(table) do
|
||||||
func(key.." = "..tostring(val)..",")
|
func(key.." = "..tostring(val)..",")
|
||||||
|
@ -44,11 +42,22 @@ function utils.key(needle, haystack)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function utils.igt()
|
-- GAME
|
||||||
local secs = memory.raw(0xDA44)
|
|
||||||
local mins = memory.raw(0xDA43)
|
function utils.canPotionWith(potion, forDamage, curr_hp, max_hp)
|
||||||
local hours = memory.raw(0xDA41)
|
local potion_hp
|
||||||
return secs + mins * 60 + hours * 3600
|
if potion == "full_restore" then
|
||||||
|
potion_hp = 9001
|
||||||
|
elseif potion == "super_potion" then
|
||||||
|
potion_hp = 50
|
||||||
|
else
|
||||||
|
potion_hp = 20
|
||||||
|
end
|
||||||
|
return math.min(curr_hp + potion_hp, max_hp) >= forDamage - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function utils.ingame()
|
||||||
|
return memory.raw(0x020E) > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function utils.onPokemonSelect(battleMenu)
|
function utils.onPokemonSelect(battleMenu)
|
||||||
|
@ -57,6 +66,13 @@ end
|
||||||
|
|
||||||
-- TIME
|
-- TIME
|
||||||
|
|
||||||
|
function utils.igt()
|
||||||
|
local secs = memory.raw(0xDA44)
|
||||||
|
local mins = memory.raw(0xDA43)
|
||||||
|
local hours = memory.raw(0xDA41)
|
||||||
|
return secs + mins * 60 + hours * 3600
|
||||||
|
end
|
||||||
|
|
||||||
local function clockSegment(unit)
|
local function clockSegment(unit)
|
||||||
if unit < 10 then
|
if unit < 10 then
|
||||||
unit = "0"..unit
|
unit = "0"..unit
|
||||||
|
|
Loading…
Reference in New Issue