From f29706558f7c55920e4eab840051f42d443c2034 Mon Sep 17 00:00:00 2001 From: Buurazu Date: Wed, 13 Apr 2022 01:32:43 -0400 Subject: [PATCH 1/6] check starting actives, fix D4 + pockets, improve desc caching with transformations --- main.lua | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/main.lua b/main.lua index c43842ce..ea80bd9c 100644 --- a/main.lua +++ b/main.lua @@ -39,6 +39,7 @@ EID.IgnoredEntities = {} local pathsChecked = {} local altPathItemChecked = {} local alwaysUseLocalMode = false -- set to true after drawing a non-local mode description this frame +EID.ForceRefreshCache = false -- set to true to force-refresh descriptions, currently used for potential transformation text changes EID.GameUpdateCount = 0 EID.GameRenderCount = 0 @@ -1220,11 +1221,15 @@ local function onRender(t) return end + if EID.ForceRefreshCache then + resetDescCache() + end -- This is not a frame we should check for new descriptions; just print our cached ones - if not EID:RefreshThisFrame() and not EID.MCM_OptionChanged then + if not EID:RefreshThisFrame() and not EID.MCM_OptionChanged and not EID.ForceRefreshCache then EID:printDescriptions(true) return end + EID.ForceRefreshCache = false -- We'll redraw the indicators in the process of determining what's in range, so wipe their cache EID.CachedIndicators = {} @@ -1456,6 +1461,25 @@ end EID:AddCallback(ModCallbacks.MC_POST_RENDER, onRender) +local function AddActiveItemProgress(player, isD4) + EID.ForceRefreshCache = true + local playerID = EID:getPlayerID(player) + if not EID.PlayerItemInteractions[playerID] then + EID.PlayerItemInteractions[playerID] = {LastTouch = 0, actives = {}, pills = {}} + end + -- don't check pocket items after D4, they don't reroll and would get counted twice + local maxSlot = 3 + if isD4 then maxSlot = 1 end + for i = 0, maxSlot do + local itemID = tostring(player:GetActiveItem(i)) + if itemID ~= "0" then + if not EID.PlayerItemInteractions[playerID].actives[itemID] then + EID.PlayerItemInteractions[playerID].actives[itemID] = 0 + end + EID.PlayerItemInteractions[playerID].actives[itemID] = EID.PlayerItemInteractions[playerID].actives[itemID] + 1 + end + end +end local function OnGameStartGeneral(_,isSave) EID:buildTransformationTables() @@ -1467,16 +1491,7 @@ EID:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, OnGameStartGeneral) -- Add currently held active items after D4 was used. Used for Transformation Progress local function OnUseD4(_, _, _, player) - local playerID = EID:getPlayerID(player) - for i = 0, 3 do - local itemID = tostring(player:GetActiveItem(i)) - if itemID ~= "0" then - if not EID.PlayerItemInteractions[playerID].actives[itemID] then - EID.PlayerItemInteractions[playerID].actives[itemID] = 0 - end - EID.PlayerItemInteractions[playerID].actives[itemID] = EID.PlayerItemInteractions[playerID].actives[itemID] + 1 - end - end + AddActiveItemProgress(player, true) end EID:AddCallback(ModCallbacks.MC_USE_ITEM, OnUseD4, CollectibleType.COLLECTIBLE_D4) @@ -1529,6 +1544,11 @@ if EID.MCMLoaded or REPENTANCE then end EID.PlayerItemInteractions[tonumber(playerID)] = convertedData end + else + -- check for the players' starting active items (thorough, for Eden and modded J&E chars' sake) + for i = 0, game:GetNumPlayers() - 1 do + AddActiveItemProgress(Isaac.GetPlayer(i)) + end end if REPENTANCE then From 44a6864b89a13180f5238ad90fbb6458a194fcf0 Mon Sep 17 00:00:00 2001 From: Buurazu Date: Wed, 13 Apr 2022 01:33:28 -0400 Subject: [PATCH 2/6] improve caching, Kid's Drawing --- eid_api.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index cd2f03ac..2b6553ae 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -1545,7 +1545,7 @@ function EID:evaluateTransformationProgress(transformation) end end elseif tonumber(eVariant) == PickupVariant.PICKUP_TRINKET and player:HasTrinket(eSubType) then - EID.TransformationProgress[i][transformation] = EID.TransformationProgress[i][transformation] + 1 + EID.TransformationProgress[i][transformation] = EID.TransformationProgress[i][transformation] + player:GetTrinketMultiplier(eSubType) elseif tonumber(eVariant) == PickupVariant.PICKUP_PILL then if EID.PlayerItemInteractions[i].pills[tostring(eSubType)] then EID.TransformationProgress[i][transformation] = EID.TransformationProgress[i][transformation] + EID.PlayerItemInteractions[i].pills[tostring(eSubType)] @@ -1557,7 +1557,7 @@ function EID:evaluateTransformationProgress(transformation) end end --- Given a transformation identifier, itterate over every player and count the number of items they have which count towards that transformation +-- Given a transformation identifier, iterate over every player and count the number of items they have which count towards that transformation EID.PlayerItemInteractions = {} function EID:evaluateQueuedItems() for i = 0, game:GetNumPlayers() - 1 do @@ -1573,6 +1573,7 @@ function EID:evaluateQueuedItems() end if not player.QueuedItem.Touched and player.QueuedItem.Item and player.QueuedItem.Item.Type == ItemType.ITEM_ACTIVE then + EID.ForceRefreshCache = true local itemID = tostring(player.QueuedItem.Item.ID) if not EID.PlayerItemInteractions[i].actives[itemID] then EID.PlayerItemInteractions[i].actives[itemID] = 0 From 98a7a0b8f0b16ecf6ff516520a5b248b0b99e23c Mon Sep 17 00:00:00 2001 From: Buurazu Date: Wed, 13 Apr 2022 02:39:26 -0400 Subject: [PATCH 3/6] Dead Tainted Lazarus exceptions --- eid_api.lua | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index 2b6553ae..9c49fdb9 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -1531,12 +1531,19 @@ function EID:evaluateTransformationProgress(transformation) if transformData and transformData.VanillaForm and player:HasPlayerForm(transformData.VanillaForm) then EID.TransformationProgress[i][transformation] = transformData.NumNeeded or 3 else + -- Dead Tainted Lazarus exceptions + local activesTable = EID.PlayerItemInteractions[i].actives + local pillsTable = EID.PlayerItemInteractions[i].pills + if player:GetPlayerType() == 38 then + activesTable = EID.PlayerItemInteractions[i].altActives or activesTable + pillsTable = EID.PlayerItemInteractions[i].altPills or pillsTable + end for entityString, _ in pairs(EID.TransformationLookup[transformation]) do local eType, eVariant, eSubType = entityString:match("([^.]+).([^.]+).([^.]+)") if tonumber(eType) == EntityType.ENTITY_PICKUP then if tonumber(eVariant) == PickupVariant.PICKUP_COLLECTIBLE then - if EID.PlayerItemInteractions[i].actives[tostring(eSubType)] then - EID.TransformationProgress[i][transformation] = EID.TransformationProgress[i][transformation] + EID.PlayerItemInteractions[i].actives[tostring(eSubType)] + if activesTable[tostring(eSubType)] then + EID.TransformationProgress[i][transformation] = EID.TransformationProgress[i][transformation] + activesTable[tostring(eSubType)] else EID.TransformationProgress[i][transformation] = EID.TransformationProgress[i][transformation] + player:GetCollectibleNum(eSubType, true) -- Undo the Book of Virtues active item getting counted here @@ -1547,8 +1554,8 @@ function EID:evaluateTransformationProgress(transformation) elseif tonumber(eVariant) == PickupVariant.PICKUP_TRINKET and player:HasTrinket(eSubType) then EID.TransformationProgress[i][transformation] = EID.TransformationProgress[i][transformation] + player:GetTrinketMultiplier(eSubType) elseif tonumber(eVariant) == PickupVariant.PICKUP_PILL then - if EID.PlayerItemInteractions[i].pills[tostring(eSubType)] then - EID.TransformationProgress[i][transformation] = EID.TransformationProgress[i][transformation] + EID.PlayerItemInteractions[i].pills[tostring(eSubType)] + if pillsTable[tostring(eSubType)] then + EID.TransformationProgress[i][transformation] = EID.TransformationProgress[i][transformation] + pillsTable[tostring(eSubType)] end end end @@ -1564,7 +1571,7 @@ function EID:evaluateQueuedItems() local player = Isaac.GetPlayer(i) if player.QueuedItem then if not EID.PlayerItemInteractions[i] then - EID.PlayerItemInteractions[i] = {LastTouch = 0, actives = {}, pills = {}} + EID.PlayerItemInteractions[i] = {LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}} end if EID.PlayerItemInteractions[i].LastTouch + 45 >= game:GetFrameCount() and player.QueuedItem.Item then return @@ -1573,12 +1580,17 @@ function EID:evaluateQueuedItems() end if not player.QueuedItem.Touched and player.QueuedItem.Item and player.QueuedItem.Item.Type == ItemType.ITEM_ACTIVE then + -- 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 local itemID = tostring(player.QueuedItem.Item.ID) - if not EID.PlayerItemInteractions[i].actives[itemID] then - EID.PlayerItemInteractions[i].actives[itemID] = 0 + if not activesTable[itemID] then + activesTable[itemID] = 0 end - EID.PlayerItemInteractions[i].actives[itemID] = EID.PlayerItemInteractions[i].actives[itemID] + 1 + activesTable[itemID] = activesTable[itemID] + 1 EID.PlayerItemInteractions[i].LastTouch = game:GetFrameCount() end end From 10fd31a923203c210e0e9e378f29b7f0143e84de Mon Sep 17 00:00:00 2001 From: Buurazu Date: Wed, 13 Apr 2022 02:39:54 -0400 Subject: [PATCH 4/6] Dead Tainted Lazarus + co-op fix --- main.lua | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/main.lua b/main.lua index ea80bd9c..53a76800 100644 --- a/main.lua +++ b/main.lua @@ -652,13 +652,13 @@ function EID:printDescription(desc, cachedID) if EID.Config["TransformationProgress"] then EID:evaluateTransformationProgress(transform) transformationName = transformationName .. " " - for _, player in ipairs(EID.players) do + for _, player in ipairs(EID.coopAllPlayers) do if player:GetPlayerType() ~= PlayerType.PLAYER_THESOUL_B then - if #EID.players > 1 then + if #EID.coopAllPlayers > 1 then local playerIcon = EID:getIcon("Player"..player.SubType) ~= EID.InlineIcons["ERROR"] and "{{Player"..player.SubType.."}}" or "{{CustomTransformation}}" transformationName = transformationName .. playerIcon end - local numCollected = EID.TransformationProgress[EID:getPlayerID(player)][transform] + local numCollected = EID.TransformationProgress[EID:getPlayerID(player)][transform] or 0 local numMax = EID.TransformationData[transform] and EID.TransformationData[transform].NumNeeded or 3 transformationName = transformationName.."("..numCollected.."/"..numMax..") " end @@ -1465,7 +1465,12 @@ local function AddActiveItemProgress(player, isD4) EID.ForceRefreshCache = true local playerID = EID:getPlayerID(player) if not EID.PlayerItemInteractions[playerID] then - EID.PlayerItemInteractions[playerID] = {LastTouch = 0, actives = {}, pills = {}} + EID.PlayerItemInteractions[playerID] = {LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}} + end + -- Dead Tainted Lazarus exceptions + local activesTable = EID.PlayerItemInteractions[playerID].actives + if player:GetPlayerType() == 38 then + activesTable = EID.PlayerItemInteractions[playerID].altActives or activesTable end -- don't check pocket items after D4, they don't reroll and would get counted twice local maxSlot = 3 @@ -1473,10 +1478,10 @@ local function AddActiveItemProgress(player, isD4) for i = 0, maxSlot do local itemID = tostring(player:GetActiveItem(i)) if itemID ~= "0" then - if not EID.PlayerItemInteractions[playerID].actives[itemID] then - EID.PlayerItemInteractions[playerID].actives[itemID] = 0 + if not activesTable[itemID] then + activesTable[itemID] = 0 end - EID.PlayerItemInteractions[playerID].actives[itemID] = EID.PlayerItemInteractions[playerID].actives[itemID] + 1 + activesTable[itemID] = activesTable[itemID] + 1 end end end @@ -1497,11 +1502,16 @@ EID:AddCallback(ModCallbacks.MC_USE_ITEM, OnUseD4, CollectibleType.COLLECTIBLE_D function EID:OnUsePill(pillEffectID, player) local playerID = EID:getPlayerID(player) - local effectID = tostring(pillEffectID+1) - if not EID.PlayerItemInteractions[playerID].pills[effectID] then - EID.PlayerItemInteractions[playerID].pills[effectID] = 0 + -- Dead Tainted Lazarus exceptions + local pillsTable = EID.PlayerItemInteractions[playerID].pills + if player:GetPlayerType() == 38 then + pillsTable = EID.PlayerItemInteractions[playerID].altPills or pillsTable end - EID.PlayerItemInteractions[playerID].pills[effectID] = EID.PlayerItemInteractions[playerID].pills[effectID] + 1 + local effectID = tostring(pillEffectID+1) + if not pillsTable[effectID] then + pillsTable[effectID] = 0 + end + pillsTable[effectID] = pillsTable[effectID] + 1 end EID:AddCallback(ModCallbacks.MC_USE_PILL, EID.OnUsePill) From 3fcf50d90608d50b3c855d88b8512e638b6e3828 Mon Sep 17 00:00:00 2001 From: Buurazu Date: Wed, 13 Apr 2022 03:28:59 -0400 Subject: [PATCH 5/6] fix Flip not refreshing progress --- main.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.lua b/main.lua index 53a76800..8362d62f 100644 --- a/main.lua +++ b/main.lua @@ -350,6 +350,8 @@ if REPENTANCE then -- Before using Flip, swap all flippable pedestal's current item with the flip one (also, fix grid index if needed) function EID:CheckFlipGridIndexes(collectibleType) + -- also, reload our descriptions due to transformation progress changing upon Flip + EID.ForceRefreshCache = true lastFrameGridChecked = Isaac.GetFrameCount() local curRoomIndex = game:GetLevel():GetCurrentRoomIndex() if EID.flipItemPositions[curRoomIndex] then From a19472c69ce598493363dc852d5d6916be414807 Mon Sep 17 00:00:00 2001 From: Buurazu Date: Wed, 13 Apr 2022 03:29:55 -0400 Subject: [PATCH 6/6] fix unqueued passives not refreshing cache --- eid_api.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eid_api.lua b/eid_api.lua index 9c49fdb9..3c81b3c6 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -1566,6 +1566,7 @@ end -- Given a transformation identifier, iterate over every player and count the number of items they have which count towards that transformation EID.PlayerItemInteractions = {} +local hadQueuedItem = {} function EID:evaluateQueuedItems() for i = 0, game:GetNumPlayers() - 1 do local player = Isaac.GetPlayer(i) @@ -1573,6 +1574,11 @@ function EID:evaluateQueuedItems() if not EID.PlayerItemInteractions[i] then EID.PlayerItemInteractions[i] = {LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}} end + -- Refresh our descriptions upon a queued passive item being added to a player + if not player.QueuedItem.Item and hadQueuedItem[i] then + EID.ForceRefreshCache = true + end + hadQueuedItem[i] = player.QueuedItem.Item ~= nil if EID.PlayerItemInteractions[i].LastTouch + 45 >= game:GetFrameCount() and player.QueuedItem.Item then return else