From 9d05ee343efa2a96eb7bf98e1eee7361bf4bb55d Mon Sep 17 00:00:00 2001 From: Kyle Coburn Date: Fri, 17 Apr 2015 17:30:00 -0700 Subject: [PATCH] Differentiate status changes by bit mask --- action/battle.lua | 2 +- ai/combat.lua | 12 ++++++++++++ ai/red/strategies.lua | 3 +-- ai/strategies.lua | 2 +- storage/pokemon.lua | 3 ++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/action/battle.lua b/action/battle.lua index 074d9dd..9a3e4c0 100644 --- a/action/battle.lua +++ b/action/battle.lua @@ -58,7 +58,7 @@ local function recover() end end end - if Memory.value("battle", "paralyzed") == 64 then + if Combat.isParalyzed() then local heals = Inventory.contains("paralyze_heal", "full_restore") if heals then Inventory.use(heals, nil, true) diff --git a/ai/combat.lua b/ai/combat.lua index b824183..5d242ce 100644 --- a/ai/combat.lua +++ b/ai/combat.lua @@ -289,6 +289,18 @@ Combat.activePokemon = activePokemon -- STATUS +local function checkStatus(target, value) + return bit.band(Pokemon.info(target, "status"), value) == value +end + +function Combat.isPoisoned(target) + return checkStatus(target, 0x8) +end + +function Combat.isParalyzed(target) + return checkStatus(target, 0x40) +end + local function isSleeping() return Memory.raw(0x116F) > 1 end diff --git a/ai/red/strategies.lua b/ai/red/strategies.lua index 265fd35..26518ca 100644 --- a/ai/red/strategies.lua +++ b/ai/red/strategies.lua @@ -484,8 +484,7 @@ strategyFunctions.equipForBrock = function(data) return Strategies.reset("level8", "Did not reach level 8 before Brock", Pokemon.getExp(), true) end if data.anti then - local poisoned = Pokemon.info("squirtle", "status") > 0 - if not poisoned then + if not Combat.isPoisoned("squirtle") then return true end if not Inventory.contains("antidote") then diff --git a/ai/strategies.lua b/ai/strategies.lua index 53174f6..b052f19 100644 --- a/ai/strategies.lua +++ b/ai/strategies.lua @@ -906,7 +906,7 @@ Strategies.functions = { return false end else - if Pokemon.info("squirtle", "status") > 0 then + if Combat.isPoisoned("squirtle")then Inventory.use("antidote", "squirtle") return false end diff --git a/storage/pokemon.lua b/storage/pokemon.lua index 0ed67f1..8652f25 100644 --- a/storage/pokemon.lua +++ b/storage/pokemon.lua @@ -198,7 +198,8 @@ function Pokemon.moveIndex(move, pokemon) end function Pokemon.info(name, offset) - return index(indexOf(name), offset) + local targetIndex = name and indexOf(name) or 0 + return index(targetIndex, offset) end function Pokemon.getID(name)