diff --git a/eid_api.lua b/eid_api.lua index cd2f03ac..3c81b3c6 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 @@ -1545,10 +1552,10 @@ 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)] + if pillsTable[tostring(eSubType)] then + EID.TransformationProgress[i][transformation] = EID.TransformationProgress[i][transformation] + pillsTable[tostring(eSubType)] end end end @@ -1557,15 +1564,21 @@ 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 = {} +local hadQueuedItem = {} function EID:evaluateQueuedItems() for i = 0, game:GetNumPlayers() - 1 do 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 + -- 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 @@ -1573,11 +1586,17 @@ function EID:evaluateQueuedItems() 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) - if not EID.PlayerItemInteractions[i].actives[itemID] then - EID.PlayerItemInteractions[i].actives[itemID] = 0 + -- Dead Tainted Lazarus exceptions + local activesTable = EID.PlayerItemInteractions[i].actives + if player:GetPlayerType() == 38 then + activesTable = EID.PlayerItemInteractions[i].altActives or activesTable end - EID.PlayerItemInteractions[i].actives[itemID] = EID.PlayerItemInteractions[i].actives[itemID] + 1 + EID.ForceRefreshCache = true + local itemID = tostring(player.QueuedItem.Item.ID) + if not activesTable[itemID] then + activesTable[itemID] = 0 + end + activesTable[itemID] = activesTable[itemID] + 1 EID.PlayerItemInteractions[i].LastTouch = game:GetFrameCount() end end diff --git a/main.lua b/main.lua index c43842ce..8362d62f 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 @@ -349,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 @@ -651,13 +654,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 @@ -1220,11 +1223,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 +1463,30 @@ 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 = {}, 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 + if isD4 then maxSlot = 1 end + for i = 0, maxSlot do + local itemID = tostring(player:GetActiveItem(i)) + if itemID ~= "0" then + if not activesTable[itemID] then + activesTable[itemID] = 0 + end + activesTable[itemID] = activesTable[itemID] + 1 + end + end +end local function OnGameStartGeneral(_,isSave) EID:buildTransformationTables() @@ -1467,26 +1498,22 @@ 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) 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) @@ -1529,6 +1556,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