From 01f5f599ba81e1f38b31d76494d8f7a984195d4f Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Mon, 29 Apr 2024 20:38:33 +0200 Subject: [PATCH] ItemReminder: Added better passive item tracking --- eid_api.lua | 75 +++++++++++++++++++++++++++++++++++++++++---- eid_holdmapdesc.lua | 12 +++++++- main.lua | 3 +- 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index ac762551..a2c13cee 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -1191,7 +1191,12 @@ function EID:getSpindownResult(collectibleID) return newID end +-- Returns the maximum collectible id, including modded items +local maxCollectibleID = nil -- cache after first use. this number will not change mid game function EID:GetMaxCollectibleID() + if maxCollectibleID then + return maxCollectibleID + end local id = CollectibleType.NUM_COLLECTIBLES-1 local step = 16 while step > 0 do @@ -1201,16 +1206,12 @@ function EID:GetMaxCollectibleID() step = step // 2 end end - + maxCollectibleID = id return id end -local maxCollectibleID = nil function EID:DetectModdedItems() - if maxCollectibleID == nil then - maxCollectibleID = EID:GetMaxCollectibleID() - end - if maxCollectibleID > EID.XMLMaxItemID then + if EID:GetMaxCollectibleID() > EID.XMLMaxItemID then return true end if EID.itemConfig:GetCollectible(EID.XMLMaxItemID) == nil then @@ -1808,6 +1809,7 @@ function EID:evaluateQueuedItems() end -- Put non-active item pickups into the recent item list, for printing in the Item Reminder table.insert(EID.RecentlyTouchedItems[i], player.QueuedItem.Item.ID) + EID.ItemReminderSelectedItem = 0 end end end @@ -1977,4 +1979,65 @@ function EID:GetPlayerIcon(playerID, altFallback) local fallback = altFallback or "{{CustomTransformation}}" return EID:getIcon("Player" .. playerID) ~= EID.InlineIcons["ERROR"] and "{{Player" .. playerID .. "}}" or fallback +end + +-- returns a list of all passive item ids +local passiveItems = nil -- cache of all passive item ids +function EID:GetAllPassiveItems() + if passiveItems then + return passiveItems + end + passiveItems = {} + + for i = 1, EID:GetMaxCollectibleID() do + local config = EID.itemConfig:GetCollectible(i) + if config ~= nil and (config.Type == ItemType.ITEM_PASSIVE or config.Type == ItemType.ITEM_FAMILIAR) then + table.insert(passiveItems, i) + end + end +end + +-- Updates the EID.RecentlyTouchedItems table to include the players currently held passive items +function EID:UpdateAllPlayerPassiveItems() + local passives = EID:GetAllPassiveItems() + local listUpdatedForPlayers = {} + for i = 1, #EID.coopAllPlayers do + local player = EID.coopAllPlayers[i] + local playerNum = EID:getPlayerID(player) + + if player == nil then + return listUpdatedForPlayers -- dont evaluate when bad data is present + end + + -- only update if collectible number changed + local currentCollectibleCount = player:GetCollectibleCount() + if #EID.RecentlyTouchedItems[playerNum] ~= currentCollectibleCount then + + -- remove items the player no longer has. reverse itteration to make deletion easier + for index = #EID.RecentlyTouchedItems[playerNum], 1, -1 do + if not player:HasCollectible(EID.RecentlyTouchedItems[playerNum][index]) then + table.remove(EID.RecentlyTouchedItems[playerNum], index) + listUpdatedForPlayers[i] = true + end + end + + -- add items the player did get with non-standard methods (console command, item effects, etc...) + for _, itemID in ipairs(passives) do + if player:HasCollectible(itemID) then + local alreadyInList = false + for _, heldItemID in ipairs(EID.RecentlyTouchedItems[playerNum]) do + if itemID == heldItemID then + alreadyInList = true + break + end + end + if not alreadyInList then + table.insert(EID.RecentlyTouchedItems[playerNum], itemID) + listUpdatedForPlayers[i] = true + end + end + end + end + end + return listUpdatedForPlayers end \ No newline at end of file diff --git a/eid_holdmapdesc.lua b/eid_holdmapdesc.lua index 52ba9650..929cb3e0 100644 --- a/eid_holdmapdesc.lua +++ b/eid_holdmapdesc.lua @@ -444,6 +444,16 @@ function EID:IsCategorySelected(categoryID) return EID.ItemReminderCategories[EID.ItemReminderSelectedCategory + 1].id == categoryID end +function EID:ItemReminderHandleInitHoldTab(playerNumHoldingTab) + local oldDisplayPlayer = EID.ItemReminderSelectedPlayer + EID.ItemReminderSelectedPlayer = playerNumHoldingTab - 1 + + local updatedPlayers = EID:UpdateAllPlayerPassiveItems() + if updatedPlayers[playerNumHoldingTab] or oldDisplayPlayer ~= EID.ItemReminderSelectedPlayer then + EID.ItemReminderSelectedItem = 0 + end +end + function EID:ItemReminderGetTitle() local category = EID.ItemReminderCategories[EID.ItemReminderSelectedCategory + 1] @@ -477,7 +487,7 @@ function EID:ItemReminderGetDescription() currentBlacklist = {} for key, _ in pairs(EID.ItemReminderBlacklist) do currentBlacklist[key] = true end - local player = EID.coopMainPlayers[EID.ItemReminderSelectedPlayer + 1] + local player = EID.coopAllPlayers[EID.ItemReminderSelectedPlayer + 1] if EID.Config["ItemReminderShowOverview"] and EID.ItemReminderSelectedCategory == 0 then -- execute all functions defined per category diff --git a/main.lua b/main.lua index cc36dd11..a1fdde63 100644 --- a/main.lua +++ b/main.lua @@ -1284,7 +1284,7 @@ function EID:OnRender() if tabHeld then EID.holdTabPlayer = EID.coopMainPlayers[playerNumHoldingTab] if EID.holdTabCounter == 0 then -- update item reminder player selection - EID.ItemReminderSelectedPlayer = playerNumHoldingTab - 1 + EID:ItemReminderHandleInitHoldTab(playerNumHoldingTab) end EID.holdTabCounter = EID.holdTabCounter + 1 else @@ -1622,6 +1622,7 @@ local function CheckAllActiveItemProgress() end local function OnGameStartGeneral(_,isSave) + EID:GetAllPassiveItems() EID:GetTransformationsOfModdedItems() EID:buildTransformationTables() EID.RecentlyTouchedItems = {}