Isolate HP updating

This commit is contained in:
Kyle Coburn 2015-05-01 11:10:37 -07:00
parent 7d4b9ddfc0
commit 10b64df3d4
3 changed files with 21 additions and 14 deletions

View File

@ -3,6 +3,7 @@ local Combat = {}
local Movelist = require "data.movelist"
local Opponents = require "data.opponents"
local Bridge = require "util.bridge"
local Memory = require "util.memory"
local Utils = require "util.utils"
@ -46,6 +47,7 @@ types[26] = "dragon"
local savedEncounters = {}
local conservePP = false
local disableThrash = false
local lastHP, lastExp
local floor = math.floor
@ -53,7 +55,7 @@ local function isDisabled(move)
if type(move) == "string" then
move = Pokemon.moveID(move)
end
return mid == Memory.value("battle", "disabled")
return move == Memory.value("battle", "disabled")
end
Combat.isDisabled = isDisabled
@ -437,4 +439,19 @@ function Combat.enemyAttack()
return calcBestHit(enemy, ours, false)
end
function Combat.updateHP(curr_hp)
local expChange = Memory.raw(0x117B)
if curr_hp ~= lastHP or expChange ~= lastExp then
local max_hp = Combat.maxHP()
if max_hp < curr_hp then
max_hp = curr_hp
end
lastExp = expChange
lastHP = curr_hp
local expForCurrentLevel = Pokemon.getExp() - Pokemon.getExpForLevelFromCurrent(0)
local nextLevelExp = Pokemon.getExpForLevelFromCurrent(1)
Bridge.hp(curr_hp, max_hp, expForCurrentLevel, nextLevelExp, Pokemon.index(0, "level"))
end
end
return Combat

View File

@ -36,7 +36,6 @@ local Pokemon = require "storage.pokemon"
local hasAlreadyStartedPlaying = false
local oldSeconds
local running = true
local lastHP, lastExp
local previousMap
-- HELPERS
@ -122,18 +121,8 @@ local function generateNextInput(currentMap)
Control.encounter(battleState)
local curr_hp = Combat.hp()
local expChange = Memory.raw(0x117B)
if curr_hp ~= lastHP or expChange ~= lastExp then
local max_hp = Combat.maxHP()
if max_hp < curr_hp then
max_hp = curr_hp
end
lastExp = expChange
lastHP = curr_hp
local expForCurrentLevel = Pokemon.getExp() - Pokemon.getExpForLevelFromCurrent(0)
local nextLevelExp = Pokemon.getExpForLevelFromCurrent(1)
Bridge.hp(curr_hp, max_hp, expForCurrentLevel, nextLevelExp, Pokemon.index(0, "level"))
end
Combat.updateHP(curr_hp)
if curr_hp == 0 and not Control.canDie() and Pokemon.index(0) > 0 then
Strategies.death(currentMap)
elseif Walk.strategy then

View File

@ -150,6 +150,7 @@ function Bridge.report(report)
end
-- GUESSING
function Bridge.moonGuesses(enabled)
send("moon,"..(enabled and "on" or "off"))
end