From 04477507bb97df02f01a294ca831d4aa8e2a3e58 Mon Sep 17 00:00:00 2001 From: Buurazu Date: Fri, 10 Jun 2022 20:00:27 -0400 Subject: [PATCH] Track recently touched items --- eid_api.lua | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index c48facca..f2c076b7 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -1624,7 +1624,9 @@ function EID:evaluateTransformationProgress(transformation) end -- Watch for a player's queued item (holding an item over their head) to track active item touches +-- Used for Transformation Progress and for tracking Recently Touched Items EID.PlayerItemInteractions = {} +EID.RecentlyTouchedItems = {} local hadQueuedItem = {} function EID:evaluateQueuedItems() --initialize the interactions table for all players if it isn't already @@ -1633,6 +1635,7 @@ function EID:evaluateQueuedItems() if not EID.PlayerItemInteractions[i] then EID.PlayerItemInteractions[i] = {LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}} end + EID.RecentlyTouchedItems[i] = EID.RecentlyTouchedItems[i] or {} end for i = 0, game:GetNumPlayers() - 1 do local player = Isaac.GetPlayer(i) @@ -1647,25 +1650,31 @@ function EID:evaluateQueuedItems() else EID.PlayerItemInteractions[i].LastTouch = 0 end - - if not player.QueuedItem.Touched and player.QueuedItem.Item and player.QueuedItem.Item.Type == ItemType.ITEM_ACTIVE then - local itemID = tostring(player.QueuedItem.Item.ID) - -- A new active item was touched; initiate its touch count to 0 for all players - -- (Fixes co-op bugs, compared to only initiating it for the toucher) - for j = 0, game:GetNumPlayers() - 1 do - local player = Isaac.GetPlayer(j) - EID.PlayerItemInteractions[j].actives[itemID] = EID.PlayerItemInteractions[j].actives[itemID] or 0 - EID.PlayerItemInteractions[j].altActives[itemID] = EID.PlayerItemInteractions[j].altActives[itemID] or 0 - end - - -- Dead Tainted Lazarus exceptions - local activesTable = EID.PlayerItemInteractions[i].actives - if player:GetPlayerType() == 38 then - activesTable = EID.PlayerItemInteractions[i].altActives or activesTable - end - EID.ForceRefreshCache = true - activesTable[itemID] = activesTable[itemID] + 1 + + if not player.QueuedItem.Touched and player.QueuedItem.Item then EID.PlayerItemInteractions[i].LastTouch = game:GetFrameCount() + + if player.QueuedItem.Item.Type == ItemType.ITEM_ACTIVE then + local itemID = tostring(player.QueuedItem.Item.ID) + -- A new active item was touched; initiate its touch count to 0 for all players + -- (Fixes co-op bugs, compared to only initiating it for the toucher) + for j = 0, game:GetNumPlayers() - 1 do + local player = Isaac.GetPlayer(j) + EID.PlayerItemInteractions[j].actives[itemID] = EID.PlayerItemInteractions[j].actives[itemID] or 0 + EID.PlayerItemInteractions[j].altActives[itemID] = EID.PlayerItemInteractions[j].altActives[itemID] or 0 + end + + -- Dead Tainted Lazarus exceptions + local activesTable = EID.PlayerItemInteractions[i].actives + if player:GetPlayerType() == 38 then + activesTable = EID.PlayerItemInteractions[i].altActives or activesTable + end + EID.ForceRefreshCache = true + activesTable[itemID] = activesTable[itemID] + 1 + elseif player.QueuedItem.Item.Type ~= ItemType.ITEM_TRINKET then + -- 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) + end end end end