Track recently touched items

This commit is contained in:
Buurazu authored and GitHub committed 2022-06-10 20:00:27 -04:00
1 parent 02c32bd2a9
commit 04477507bb
1 file changed
+27 -18
+27 -18
View File
@@ -1624,7 +1624,9 @@ function EID:evaluateTransformationProgress(transformation)
end end
-- Watch for a player's queued item (holding an item over their head) to track active item touches -- 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.PlayerItemInteractions = {}
EID.RecentlyTouchedItems = {}
local hadQueuedItem = {} local hadQueuedItem = {}
function EID:evaluateQueuedItems() function EID:evaluateQueuedItems()
--initialize the interactions table for all players if it isn't already --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 if not EID.PlayerItemInteractions[i] then
EID.PlayerItemInteractions[i] = {LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}} EID.PlayerItemInteractions[i] = {LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}}
end end
EID.RecentlyTouchedItems[i] = EID.RecentlyTouchedItems[i] or {}
end end
for i = 0, game:GetNumPlayers() - 1 do for i = 0, game:GetNumPlayers() - 1 do
local player = Isaac.GetPlayer(i) local player = Isaac.GetPlayer(i)
@@ -1647,25 +1650,31 @@ function EID:evaluateQueuedItems()
else else
EID.PlayerItemInteractions[i].LastTouch = 0 EID.PlayerItemInteractions[i].LastTouch = 0
end end
if not player.QueuedItem.Touched and player.QueuedItem.Item and player.QueuedItem.Item.Type == ItemType.ITEM_ACTIVE then if not player.QueuedItem.Touched and player.QueuedItem.Item 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
EID.PlayerItemInteractions[i].LastTouch = game:GetFrameCount() 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 end
end end