ItemReminder: Added better passive item tracking

This commit is contained in:
Wofsauge committed 2024-04-29 20:38:33 +02:00
1 parent b864e5538b
commit 01f5f599ba
3 files changed
+82 -8

No files matched your search

+69 -6
View File
@@ -1191,7 +1191,12 @@ function EID:getSpindownResult(collectibleID)
return newID return newID
end 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() function EID:GetMaxCollectibleID()
if maxCollectibleID then
return maxCollectibleID
end
local id = CollectibleType.NUM_COLLECTIBLES-1 local id = CollectibleType.NUM_COLLECTIBLES-1
local step = 16 local step = 16
while step > 0 do while step > 0 do
@@ -1201,16 +1206,12 @@ function EID:GetMaxCollectibleID()
step = step // 2 step = step // 2
end end
end end
maxCollectibleID = id
return id return id
end end
local maxCollectibleID = nil
function EID:DetectModdedItems() function EID:DetectModdedItems()
if maxCollectibleID == nil then if EID:GetMaxCollectibleID() > EID.XMLMaxItemID then
maxCollectibleID = EID:GetMaxCollectibleID()
end
if maxCollectibleID > EID.XMLMaxItemID then
return true return true
end end
if EID.itemConfig:GetCollectible(EID.XMLMaxItemID) == nil then if EID.itemConfig:GetCollectible(EID.XMLMaxItemID) == nil then
@@ -1808,6 +1809,7 @@ function EID:evaluateQueuedItems()
end end
-- Put non-active item pickups into the recent item list, for printing in the Item Reminder -- 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) table.insert(EID.RecentlyTouchedItems[i], player.QueuedItem.Item.ID)
EID.ItemReminderSelectedItem = 0
end end
end end
end end
@@ -1978,3 +1980,64 @@ function EID:GetPlayerIcon(playerID, altFallback)
return EID:getIcon("Player" .. playerID) ~= EID.InlineIcons["ERROR"] and "{{Player" .. playerID .. "}}" or fallback return EID:getIcon("Player" .. playerID) ~= EID.InlineIcons["ERROR"] and "{{Player" .. playerID .. "}}" or fallback
end 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
+11 -1
View File
@@ -444,6 +444,16 @@ function EID:IsCategorySelected(categoryID)
return EID.ItemReminderCategories[EID.ItemReminderSelectedCategory + 1].id == categoryID return EID.ItemReminderCategories[EID.ItemReminderSelectedCategory + 1].id == categoryID
end 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() function EID:ItemReminderGetTitle()
local category = EID.ItemReminderCategories[EID.ItemReminderSelectedCategory + 1] local category = EID.ItemReminderCategories[EID.ItemReminderSelectedCategory + 1]
@@ -477,7 +487,7 @@ function EID:ItemReminderGetDescription()
currentBlacklist = {} currentBlacklist = {}
for key, _ in pairs(EID.ItemReminderBlacklist) do currentBlacklist[key] = true end 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 if EID.Config["ItemReminderShowOverview"] and EID.ItemReminderSelectedCategory == 0 then
-- execute all functions defined per category -- execute all functions defined per category
+2 -1
View File
@@ -1284,7 +1284,7 @@ function EID:OnRender()
if tabHeld then if tabHeld then
EID.holdTabPlayer = EID.coopMainPlayers[playerNumHoldingTab] EID.holdTabPlayer = EID.coopMainPlayers[playerNumHoldingTab]
if EID.holdTabCounter == 0 then -- update item reminder player selection if EID.holdTabCounter == 0 then -- update item reminder player selection
EID.ItemReminderSelectedPlayer = playerNumHoldingTab - 1 EID:ItemReminderHandleInitHoldTab(playerNumHoldingTab)
end end
EID.holdTabCounter = EID.holdTabCounter + 1 EID.holdTabCounter = EID.holdTabCounter + 1
else else
@@ -1622,6 +1622,7 @@ local function CheckAllActiveItemProgress()
end end
local function OnGameStartGeneral(_,isSave) local function OnGameStartGeneral(_,isSave)
EID:GetAllPassiveItems()
EID:GetTransformationsOfModdedItems() EID:GetTransformationsOfModdedItems()
EID:buildTransformationTables() EID:buildTransformationTables()
EID.RecentlyTouchedItems = {} EID.RecentlyTouchedItems = {}