Skip to content

Commit

Permalink
New Catch Rates screen for all balls
Browse files Browse the repository at this point in the history
Resolves #466
  • Loading branch information
UTDZac committed Nov 16, 2024
1 parent b76134b commit b5ebd6b
Show file tree
Hide file tree
Showing 12 changed files with 473 additions and 30 deletions.
1 change: 1 addition & 0 deletions ironmon_tracker/Battle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ function Battle.trySwapScreenBackToMain()
[TrainersOnRouteScreen] = true,
[RandomEvosScreen] = true,
[MoveHistoryScreen] = true,
[CatchRatesScreen] = true,
[TypeDefensesScreen] = true,
[CoverageCalcScreen] = true,
[HealsInBagScreen] = true,
Expand Down
1 change: 1 addition & 0 deletions ironmon_tracker/FileManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ FileManager.LuaCode = {
{ name = "StatsScreen", filepath = FileManager.Folders.ScreensCode .. FileManager.slash .. "StatsScreen.lua", },
{ name = "RandomEvosScreen", filepath = FileManager.Folders.ScreensCode .. FileManager.slash .. "RandomEvosScreen.lua", },
{ name = "MoveHistoryScreen", filepath = FileManager.Folders.ScreensCode .. FileManager.slash .. "MoveHistoryScreen.lua", },
{ name = "CatchRatesScreen", filepath = FileManager.Folders.ScreensCode .. FileManager.slash .. "CatchRatesScreen.lua", },
{ name = "TypeDefensesScreen", filepath = FileManager.Folders.ScreensCode .. FileManager.slash .. "TypeDefensesScreen.lua", },
{ name = "HealsInBagScreen", filepath = FileManager.Folders.ScreensCode .. FileManager.slash .. "HealsInBagScreen.lua", },
{ name = "GameOverScreen", filepath = FileManager.Folders.ScreensCode .. FileManager.slash .. "GameOverScreen.lua", },
Expand Down
8 changes: 8 additions & 0 deletions ironmon_tracker/Languages/English.lua
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,14 @@ ScreenResources{
PromptPokemonTitle = "Pokédex Look up",
PromptPokemonDesc = "Choose a Pokémon to look up",
},
CatchRatesScreen = {
Title = "Ball Catch Rates",
PokemonsHPPercent = "Estimated HP",
PokemonsStatus = "Status",
HeaderBall = "Ball",
HeaderBag = "Bag",
HeaderRate = "Rate",
},
TypeDefensesScreen = {
Immunities = "Immunities",
Resistances = "Resistances",
Expand Down
8 changes: 8 additions & 0 deletions ironmon_tracker/Languages/French.lua
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,14 @@ ScreenResources{
PromptPokemonTitle = "Pokédex Look up", -- NEEDS TRANSLATION
PromptPokemonDesc = "Choose a Pokémon to look up", -- NEEDS TRANSLATION
},
CatchRatesScreen = {
Title = "Ball Catch Rates", -- NEEDS TRANSLATION
PokemonsHPPercent = "Estimated HP", -- NEEDS TRANSLATION
PokemonsStatus = "Status", -- NEEDS TRANSLATION
HeaderBall = "Ball", -- NEEDS TRANSLATION
HeaderBag = "Bag", -- NEEDS TRANSLATION
HeaderRate = "Rate", -- NEEDS TRANSLATION
},
TypeDefensesScreen = {
Immunities = "Immunities", -- NEEDS TRANSLATION
Resistances = "Resistances", -- NEEDS TRANSLATION
Expand Down
8 changes: 8 additions & 0 deletions ironmon_tracker/Languages/German.lua
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,14 @@ ScreenResources{
PromptPokemonTitle = "Pokédex Look up", -- NEEDS TRANSLATION
PromptPokemonDesc = "Choose a Pokémon to look up", -- NEEDS TRANSLATION
},
CatchRatesScreen = {
Title = "Ball Catch Rates", -- NEEDS TRANSLATION
PokemonsHPPercent = "Estimated HP", -- NEEDS TRANSLATION
PokemonsStatus = "Status", -- NEEDS TRANSLATION
HeaderBall = "Ball", -- NEEDS TRANSLATION
HeaderBag = "Bag", -- NEEDS TRANSLATION
HeaderRate = "Rate", -- NEEDS TRANSLATION
},
TypeDefensesScreen = {
Immunities = "Immunities", -- NEEDS TRANSLATION
Resistances = "Resistances", -- NEEDS TRANSLATION
Expand Down
8 changes: 8 additions & 0 deletions ironmon_tracker/Languages/Italian.lua
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,14 @@ ScreenResources{
PromptPokemonTitle = "Pokédex Look up", -- NEEDS TRANSLATION
PromptPokemonDesc = "Choose a Pokémon to look up", -- NEEDS TRANSLATION
},
CatchRatesScreen = {
Title = "Ball Catch Rates", -- NEEDS TRANSLATION
PokemonsHPPercent = "Estimated HP", -- NEEDS TRANSLATION
PokemonsStatus = "Status", -- NEEDS TRANSLATION
HeaderBall = "Ball", -- NEEDS TRANSLATION
HeaderBag = "Bag", -- NEEDS TRANSLATION
HeaderRate = "Rate", -- NEEDS TRANSLATION
},
TypeDefensesScreen = {
Immunities = "Immunities", -- NEEDS TRANSLATION
Resistances = "Resistances", -- NEEDS TRANSLATION
Expand Down
8 changes: 8 additions & 0 deletions ironmon_tracker/Languages/Japanese.lua
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ ScreenResources{
PromptPokemonTitle = "Pokédex Look up", -- NEEDS TRANSLATION
PromptPokemonDesc = "Choose a Pokémon to look up", -- NEEDS TRANSLATION
},
CatchRatesScreen = {
Title = "Ball Catch Rates", -- NEEDS TRANSLATION
PokemonsHPPercent = "Estimated HP", -- NEEDS TRANSLATION
PokemonsStatus = "Status", -- NEEDS TRANSLATION
HeaderBall = "Ball", -- NEEDS TRANSLATION
HeaderBag = "Bag", -- NEEDS TRANSLATION
HeaderRate = "Rate", -- NEEDS TRANSLATION
},
TypeDefensesScreen = {
Immunities = "Immunities", -- NEEDS TRANSLATION
Resistances = "Resistances", -- NEEDS TRANSLATION
Expand Down
8 changes: 8 additions & 0 deletions ironmon_tracker/Languages/Spanish.lua
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,14 @@ ScreenResources{
PromptPokemonTitle = "Pokédex Look up", -- NEEDS TRANSLATION
PromptPokemonDesc = "Choose a Pokémon to look up", -- NEEDS TRANSLATION
},
CatchRatesScreen = {
Title = "Ball Catch Rates", -- NEEDS TRANSLATION
PokemonsHPPercent = "Estimated HP", -- NEEDS TRANSLATION
PokemonsStatus = "Status", -- NEEDS TRANSLATION
HeaderBall = "Ball", -- NEEDS TRANSLATION
HeaderBag = "Bag", -- NEEDS TRANSLATION
HeaderRate = "Rate", -- NEEDS TRANSLATION
},
TypeDefensesScreen = {
Immunities = "Immunities", -- NEEDS TRANSLATION
Resistances = "Resistances", -- NEEDS TRANSLATION
Expand Down
12 changes: 10 additions & 2 deletions ironmon_tracker/Program.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Program = {
offsetPokemonStatsSpaSpd = 0x60,
offsetRivalName = 0x3A4C, -- SaveBlock1
offsetOptionsButtonMode = 0x13, -- SaveBlock2
offsetPokedex = 0x18, -- SaveBlock2
offsetPokedexOwned = 0x10, -- SaveBlock2's Pokedex struct
offsetPokedexSeen = 0x44, -- SaveBlock2's Pokedex struct

sizeofBaseStatsPokemon = 0x1C,
sizeofExpTablePokemon = 0x194,
Expand Down Expand Up @@ -90,6 +93,7 @@ Program.GameData = {
healingTotal = 0, -- A calculation of total HP heals
healingPercentage = 0, -- A calculation of percentage heals
-- Each of the below: map of [itemId] -> quanity of item
PokeBalls = {},
HPHeals = {},
PPHeals = {},
StatusHeals = {},
Expand Down Expand Up @@ -1434,6 +1438,7 @@ function Program.updateBagItems()
Program.GameData.Items = {
healingTotal = 0,
healingPercentage = 0,
PokeBalls = {},
HPHeals = {},
PPHeals = {},
StatusHeals = {},
Expand All @@ -1447,8 +1452,8 @@ function Program.updateBagItems()
local addressesToScan = {
[saveBlock1Addr + GameSettings.bagPocket_Items_offset] = GameSettings.bagPocket_Items_Size,
[saveBlock1Addr + GameSettings.bagPocket_Berries_offset] = GameSettings.bagPocket_Berries_Size,
[saveBlock1Addr + GameSettings.bagPocket_Balls_offset] = GameSettings.bagPocket_Balls_Size,
-- Don't have a use for these yet, so not reading them from memory
-- [saveBlock1Addr + GameSettings.bagPocket_Balls_offset] = GameSettings.bagPocket_Balls_Size,
-- [saveBlock1Addr + GameSettings.bagPocket_TmHm_offset] = GameSettings.bagPocket_TmHm_Size,
}
for address, size in pairs(addressesToScan) do
Expand All @@ -1462,6 +1467,9 @@ function Program.updateBagItems()
quantity = Utils.bit_xor(quantity, key)
end
if quantity > 0 then
if MiscData.PokeBalls[itemID] then
items.PokeBalls[itemID] = quantity
end
if MiscData.HealingItems[itemID] then
items.HPHeals[itemID] = quantity
end
Expand All @@ -1475,7 +1483,7 @@ function Program.updateBagItems()
items.EvoStones[itemID] = quantity
end
-- If the item wasn't categorized anywhere, mark as "Other"
if not (items.HPHeals[itemID] or items.PPHeals[itemID] or items.StatusHeals[itemID] or items.EvoStones[itemID]) then
if not (items.PokeBalls[itemID] or items.HPHeals[itemID] or items.PPHeals[itemID] or items.StatusHeals[itemID] or items.EvoStones[itemID]) then
items.Other[itemID] = quantity
end
end
Expand Down
53 changes: 29 additions & 24 deletions ironmon_tracker/data/PokemonData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ end
---@param hpCurrent number
---@param level number? Optional, the Pokémon level, used only for Nest Ball; defaults to 5
---@param status number? Optional, defaults to "None"
---@param ball number? Optional, defaults to Poké Ball (item id = 3)
---@param ball number? Optional, defaults to Poké Ball (item id = 4)
---@param terrain number? Optional, defaults to 0 (no terrain); use 3 for UNDERWATER
---@param battleTurn number? Optional, defaults to 0; first turn of a battle
---@return number
Expand All @@ -449,7 +449,7 @@ function PokemonData.calcCatchRate(pokemonID, hpMax, hpCurrent, level, status, b
end
level = level or 5
status = status or MiscData.StatusType.None
ball = ball or 3
ball = ball or 4
terrain = terrain or 0
battleTurn = battleTurn or 0

Expand All @@ -467,35 +467,40 @@ function PokemonData.calcCatchRate(pokemonID, hpMax, hpCurrent, level, status, b

-- Determine ball type bonus multiplier
local ballBonusMap = {
[0] = 255, --Master Ball
[1] = 20, --Ultra Ball
[2] = 15, --Great Ball
[3] = 10, --Poke Ball
[4] = 15, --Safari Ball
[5] = 30, --Net Ball; only for WATER or BUG types
[6] = 35, --Dive Ball; only when map type is UNDERWATER
[7] = 40, --Nest Ball; subtract level of enemy, floor is 10
[8] = 30, --Repeat Ball; only if pokemon is flagged as caught already
[9] = 10, --Timer Ball; add turn counter, caps at 40
[10] = 10, --Luxury Ball
[11] = 10, --Premier Ball
[1] = 255, -- Master Ball
[2] = 20, -- Ultra Ball
[3] = 15, -- Great Ball
[4] = 10, -- Poke Ball
[5] = 15, -- Safari Ball
[6] = 30, -- Net Ball; only for WATER or BUG types
[7] = 35, -- Dive Ball; only when map type is UNDERWATER
[8] = 40, -- Nest Ball; subtract level of enemy, floor is 10
[9] = 30, -- Repeat Ball; only if pokemon is flagged as caught already
[10] = 10, -- Timer Ball; add turn counter, caps at 40
[11] = 10, -- Luxury Ball
[12] = 10, -- Premier Ball
}
local ballBonus
if ball <= 4 or ball >= 10 then
if ball <= 5 or ball >= 11 then
ballBonus = ballBonusMap[ball] or 10 -- default: poké ball
elseif ball == 5 and (pokemon.types[1] == PokemonData.Types.WATER or pokemon.types[2] == PokemonData.Types.WATER or pokemon.types[1] == PokemonData.Types.BUG or pokemon.types[2] == PokemonData.Types.BUG) then
ballBonus = ballBonusMap[5]
elseif ball == 6 and terrain == 3 then -- terrain 3: UNDERWATER
ballBonus = ballBonusMap[6]
elseif ball == 7 then
ballBonus = math.max(10, 40 - level)
elseif ball == 6 and (pokemon.types[1] == PokemonData.Types.WATER or pokemon.types[2] == PokemonData.Types.WATER or pokemon.types[1] == PokemonData.Types.BUG or pokemon.types[2] == PokemonData.Types.BUG) then
ballBonus = ballBonusMap[ball]
elseif ball == 7 and terrain == 3 then -- terrain 3: UNDERWATER
ballBonus = ballBonusMap[ball]
elseif ball == 8 then
-- Data not available yet for calculation, default to poké ball
ballBonus = 10
ballBonus = math.max(10, 40 - level)
elseif ball == 9 then
local dexAddr = Utils.getSaveBlock2Addr() + Program.Addresses.offsetPokedex + Program.Addresses.offsetPokedexOwned
local bitIndex = math.floor((pokemonID - 1) / 8)
local bitRemainder = (pokemonID - 1) % 8
local dexValue = Memory.readbyte(dexAddr + bitIndex)
if Utils.getbits(dexValue, bitRemainder, 1) == 1 then -- if 1, has caught the mon previously
ballBonus = ballBonusMap[ball]
end
elseif ball == 10 then
ballBonus = math.min(10 + battleTurn, 40)
end
ballBonus = ballBonus / 10
ballBonus = (ballBonus or 10) / 10

-- Determine status bonus multiplier
local statusBonusMap = {
Expand Down
Loading

0 comments on commit b5ebd6b

Please sign in to comment.