Skip to content

Commit

Permalink
Merge pull request #126 from Brian0255/dev
Browse files Browse the repository at this point in the history
6.3.0 update
  • Loading branch information
Brian0255 authored Sep 26, 2024
2 parents 987777a + 0aa45c4 commit 4da6c1a
Show file tree
Hide file tree
Showing 28 changed files with 5,284 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Settings.ini
NetworkSettings.ini
Requests.json
*.trackerdata
*.nds
*.log
Expand All @@ -8,6 +10,7 @@ Settings.ini
*.colortheme
*.qlp
!death_quotes.txt
!StreamerbotCodeImport.txt
*.pt
*.faves
*.tdata
11 changes: 8 additions & 3 deletions ironmon_tracker/BattleHandlerBase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ function BattleHandlerBase:_playerSlotHasFainted(slotIndex)
end
end

function BattleHandlerBase:_onPlayerSlotFainted()
self._program.onRunEnded()
end

function BattleHandlerBase:checkIfRunHasEnded()
if not self:inBattleAndFetched() then
if not self:inBattleAndFetched() or self._program.hasRunEnded() then
return
end
if
Expand All @@ -238,7 +242,7 @@ function BattleHandlerBase:checkIfRunHasEnded()
end
end
if self:_playerSlotHasFainted(self._faintMonIndex) then
self._program.onRunEnded()
self:_onPlayerSlotFainted()
end
end

Expand Down Expand Up @@ -427,7 +431,8 @@ function BattleHandlerBase:getActivePokemonInBattle(selected)
end

function BattleHandlerBase:runEvents()
for _, frameCounter in pairs(self._frameCounters) do
--shallow copy in the rare instance a frame counter is added when one is removed
for _, frameCounter in pairs(MiscUtils.shallowCopy(self._frameCounters)) do
frameCounter.decrement()
end
for _, listener in pairs(self._joypadEvents) do
Expand Down
27 changes: 27 additions & 0 deletions ironmon_tracker/BattleHandlerGen5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ function BattleHandlerGen5:_setUpBattleVariables()
self:_baseSetUpBattleVariables()
local battleData = self:getBattleData()
self._battlerAmount = 0
self._waitedForUIHP = false
self._framesWaitedForUI = 0
end

function BattleHandlerGen5:new(o, gameInfo, memoryAddresses, pokemonDataReader, tracker, program, settings)
Expand All @@ -27,9 +29,34 @@ function BattleHandlerGen5:new(o, gameInfo, memoryAddresses, pokemonDataReader,
}
self._battlerAmount = 0
self._playerPartyPointers = {}
self._framesWaitedForUI = 0
return self
end

function BattleHandlerGen5._checkUIHPZero(self)
self._framesWaitedForUI = self._framesWaitedForUI + 1
local addressStart = Memory.read_pointer(self.memoryAddresses.someBattleUIPtr)
local UIHPAddress = addressStart + self._gameInfo.UI_HP_OFFSET
local HPValue = Memory.read_u8(UIHPAddress)
if HPValue == 0 or self._framesWaitedForUI >= 480 then
self._program.onRunEnded()
self:removeFrameCounter("checkUIHPZero")
end
end

function BattleHandlerGen5._onBattleUIHPTick(self)
self:removeFrameCounter("battleUIHPTickStart")
self:addFrameCounter("checkUIHPZero", FrameCounter(1, self._checkUIHPZero, self))
end

function BattleHandlerGen5:_onPlayerSlotFainted()
--here is how it works:
--internal pokemon HP is set to 0, then the UI slowly updates to match it
--it takes a few frames for the UI to initially start ticking (it is 0 otherwise)
--so we wait a few frames then start checking the UI every frame until it's 0 (or too many frames have passed)
self:addFrameCounter("battleUIHPTickStart",FrameCounter(3, self._onBattleUIHPTick, self))
end

function BattleHandlerGen5:_readAmountOfBattlers()
--more than 2 mean multi-player double/triple
local currentPointer = self.memoryAddresses.mainBattleDataPtr + 0x18
Expand Down
3 changes: 2 additions & 1 deletion ironmon_tracker/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ local function Main()
Chars.accentedE = "\233"
end

dofile("ironmon_tracker/constants/Paths.lua")
dofile("ironmon_tracker/utils/FormsUtils.lua")
dofile("ironmon_tracker/utils/MiscUtils.lua")
dofile("ironmon_tracker/constants/PlaythroughConstants.lua")
dofile("ironmon_tracker/constants/MiscConstants.lua")

dofile("ironmon_tracker/constants/Paths.lua")
dofile(Paths.FOLDERS.DATA_FOLDER .. "/Pickle.lua")
dofile(Paths.FOLDERS.DATA_FOLDER .. "/QuickLoader.lua")
dofile(Paths.FOLDERS.CONSTANTS_FOLDER .. "/MiscData.lua")
Expand All @@ -44,6 +44,7 @@ local function Main()
dofile(Paths.FOLDERS.UTILS_FOLDER .. "/ThemeFactory.lua")
dofile(Paths.FOLDERS.UTILS_FOLDER .. "/HoverFrameFactory.lua")
dofile(Paths.FOLDERS.UTILS_FOLDER .. "/FrameFactory.lua")
dofile(Paths.FOLDERS.UTILS_FOLDER .. "/NetworkUtils.lua")
dofile(Paths.FOLDERS.DATA_FOLDER .. "/GameConfigurator.lua")
dofile(Paths.FOLDERS.UTILS_FOLDER .. "/UIUtils.lua")
dofile(Paths.FOLDERS.DATA_FOLDER .. "/RepelDrawer.lua")
Expand Down
66 changes: 53 additions & 13 deletions ironmon_tracker/Program.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
local ExtrasScreen = dofile(Paths.FOLDERS.UI_FOLDER .. "/ExtrasScreen.lua")
local EvoDataScreen = dofile(Paths.FOLDERS.UI_FOLDER .. "/EvoDataScreen.lua")
local CoverageCalcScreen = dofile(Paths.FOLDERS.UI_FOLDER .. "/CoverageCalcScreen.lua")
local TimerScreen = dofile(Paths.FOLDERS.UI_FOLDER .. "/TimerScreen.lua")
local TimerScreen = dofile(Paths.FOLDERS.UI_FOLDER .. "/TimerScreen.lua")
local StreamerbotConfigScreen = dofile(Paths.FOLDERS.UI_FOLDER .. "/StreamerbotConfigScreen.lua")

local INI = dofile(Paths.FOLDERS.DATA_FOLDER .. "/Inifile.lua")
local PokemonDataReader = dofile(Paths.FOLDERS.DATA_FOLDER .. "/PokemonDataReader.lua")
Expand All @@ -38,6 +39,7 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
dofile(Paths.FOLDERS.DATA_FOLDER .. "/BattleHandlerGen5.lua")
local PokemonThemeManager = dofile(Paths.FOLDERS.DATA_FOLDER .. "/PokemonThemeManager.lua")
local TourneyTracker = dofile(Paths.FOLDERS.DATA_FOLDER .. "/TourneyTracker.lua")
dofile(Paths.FOLDERS.NETWORK_FOLDER .. "/Network.lua")

self.SELECTED_PLAYERS = {
PLAYER = 0,
Expand All @@ -64,6 +66,7 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
local lockedPokemonCopy = nil
local selectedPlayer = self.SELECTED_PLAYERS.PLAYER
local healingItems = nil
local ppItems = nil
local inTrackedPokemonView = false
local doneWithTitleScreen = false
local inPastRunView = false
Expand Down Expand Up @@ -130,7 +133,8 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
local blankInitialization = {
[self.UI_SCREENS.QUICK_LOAD_SCREEN] = true,
[self.UI_SCREENS.UPDATE_NOTES_SCREEN] = true,
[self.UI_SCREENS.RESTORE_POINTS_SCREEN] = true
[self.UI_SCREENS.RESTORE_POINTS_SCREEN] = true,
[self.UI_SCREENS.STREAMERBOT_CONFIG_SCREEN] = true
}
local seedLoggerInitialization = {
[self.UI_SCREENS.STATISTICS_SCREEN] = true,
Expand Down Expand Up @@ -258,7 +262,8 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
EXTRAS_SCREEN = 21,
EVO_DATA_SCREEN = 22,
COVERAGE_CALC_SCREEN = 23,
TIMER_SCREEN = 24
TIMER_SCREEN = 24,
STREAMERBOT_CONFIG_SCREEN = 25
}

self.UI_SCREEN_OBJECTS = {
Expand Down Expand Up @@ -286,7 +291,8 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
[self.UI_SCREENS.EXTRAS_SCREEN] = ExtrasScreen(settings, tracker, self),
[self.UI_SCREENS.EVO_DATA_SCREEN] = EvoDataScreen(settings, tracker, self),
[self.UI_SCREENS.COVERAGE_CALC_SCREEN] = CoverageCalcScreen(settings, tracker, self),
[self.UI_SCREENS.TIMER_SCREEN] = TimerScreen(settings, tracker, self)
[self.UI_SCREENS.TIMER_SCREEN] = TimerScreen(settings, tracker, self),
[self.UI_SCREENS.STREAMERBOT_CONFIG_SCREEN] = StreamerbotConfigScreen(settings,tracker,self)
}

tourneyTracker =
Expand Down Expand Up @@ -325,6 +331,7 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,

local function scanForHealingItems()
healingItems = {}
ppItems = {}
statusItems = {}
local itemStart, berryStart = memoryAddresses.itemStartNoBattle, memoryAddresses.berryBagStart
if battleHandler:inBattleAndFetched() then
Expand Down Expand Up @@ -352,6 +359,9 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
if ItemData.HEALING_ITEMS[id] ~= nil then
healingItems[id] = quantity
end
if ItemData.PP_ITEMS[id] ~= nil then
ppItems[id] = quantity
end
if ItemData.STATUS_ITEMS[id] ~= nil then
statusItems[id] = quantity
end
Expand Down Expand Up @@ -399,9 +409,13 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
return totals
end

local function displayRunOver()
self.openScreen(self.UI_SCREENS.RUN_OVER_SCREEN)
frameCounters["displayRunOver"] = nil
local function displayRunOver()
self.openScreen(self.UI_SCREENS.RUN_OVER_SCREEN)
frameCounters["displayRunOver"] = nil
end

function self.hasRunEnded()
return tracker.hasRunEnded()
end

function self.onRunEnded()
Expand All @@ -425,11 +439,7 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
tracker.updatePlaytime(gameInfo.NAME)
local runOverMessage = seedLogger.getRandomRunOverMessage(pastRun)
self.UI_SCREEN_OBJECTS[self.UI_SCREENS.RUN_OVER_SCREEN].initialize(runOverMessage)
if gameInfo.GEN == 5 then
frameCounters["displayRunOver"] = FrameCounter(60, displayRunOver)
else
self.openScreen(self.UI_SCREENS.RUN_OVER_SCREEN)
end
self.openScreen(self.UI_SCREENS.RUN_OVER_SCREEN)
tracker.setRunOver()
end

Expand Down Expand Up @@ -480,6 +490,10 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
return selectedPlayer
end

function self.getPlayerPokemon()
return playerPokemon
end

local function getPokemonData(selected)
if battleHandler:inBattleAndFetched() then
local data = battleHandler:getActivePokemonInBattle(selected)
Expand Down Expand Up @@ -612,6 +626,10 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
currentLocation = areaName
end

function self.getCurrentMapID()
return currentMapID
end

function self.getCurrentLocation()
return currentLocation
end
Expand Down Expand Up @@ -688,6 +706,7 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,

function self.tryToInstallUpdate(callbackFunc)
tracker.save(gameInfo.NAME)
Network.closeConnections()
local success = trackerUpdater.downloadUpdate()
if type(callbackFunc) == "function" then
callbackFunc(success)
Expand Down Expand Up @@ -720,6 +739,10 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
return healingItems
end

function self.getPPItems()
return ppItems
end

function self.getStatusTotals()
local total = 0
if statusItems ~= nil then
Expand Down Expand Up @@ -931,6 +954,10 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
end
end

function self.getBadges()
return badges
end

local function updateRestorePoints()
self.UI_SCREEN_OBJECTS[self.UI_SCREENS.RESTORE_POINTS_SCREEN].update()
if currentScreens[self.UI_SCREENS.RESTORE_POINTS_SCREEN] then
Expand Down Expand Up @@ -959,6 +986,12 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
AnimatedSpriteManager.advanceFrame()
end

local function delayedNetworkStartup()
Network.delayedStartupActions()
-- Remove the delayed start frame counter; only need to run startup once
frameCounters.networkStartup = nil
end

frameCounters = {
restorePointUpdate = FrameCounter(30, updateRestorePoints),
memoryReading = FrameCounter(30, readMemory, nil, true),
Expand All @@ -971,7 +1004,9 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
nil,
true
),
animatedSprites = FrameCounter(8, advanceAnimationFrame, nil, true)
animatedSprites = FrameCounter(8, advanceAnimationFrame, nil, true),
networkStartup = FrameCounter(30, delayedNetworkStartup, nil, true),
networkUpdate = FrameCounter(10, Network.update, nil, true),
}

function self.pauseEventListeners()
Expand Down Expand Up @@ -1049,6 +1084,7 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
tracker.updatePlaytime(gameInfo.NAME)
client.saveram()
forms.destroyall()
Network.closeConnections()
end

function self.getSeedLogger()
Expand Down Expand Up @@ -1099,6 +1135,7 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
client.SetSoundOn(false)
local logInfo = randomizerLogParser.parse(logPath)
if logInfo ~= nil then
Network.Data.logInfo = logInfo
local firstPokemonID = tracker.getFirstPokemonID()
logInfo.setStarterNumberFromPlayerPokemonID(firstPokemonID)
self.openScreen(self.UI_SCREENS.LOG_VIEWER_SCREEN)
Expand All @@ -1116,6 +1153,9 @@ local function Program(initialTracker, initialMemoryAddresses, initialGameInfo,
randomizerLogParser = RandomizerLogParser(self)
AnimatedSpriteManager.initialize(self.drawCurrentScreens, memoryAddresses, gameInfo, settings)

Network.initialize()
Network.linkData(self, tracker, battleHandler)

return self
end

Expand Down
5 changes: 4 additions & 1 deletion ironmon_tracker/RandomizerLogParser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ local function RandomizerLogParser(initialProgram)
end
currentLineIndex = currentLineIndex + 1
end
if pokemonList[647] ~= nil then
pokemonIDMappings["keldeo-r"] = 647
end
return true
end

Expand Down Expand Up @@ -514,7 +517,7 @@ local function RandomizerLogParser(initialProgram)
if self.LogParserConstants.SECTION_HEADER_TO_PARSE_FUNCTION[line] and not sectionHeaderStarts[line] then
sectionHeaderStarts[line] = index + 1
totalFound = totalFound + 1
if totalFound == #self.LogParserConstants.PREFERRED_PARSE_ORDER then
if totalFound == #self.LogParserConstants.PREFERRED_PARSE_ORDER - 1 then
break
end
end
Expand Down
Loading

0 comments on commit 4da6c1a

Please sign in to comment.