From 73b10108c3f92989e40e787b7a270b1a3aa42169 Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Mon, 7 Nov 2022 01:18:57 +0100 Subject: [PATCH] Fixed Pill usage not being tracked correctly anymore --- eid_api.lua | 33 +++++++++++++++++++++++++++++---- main.lua | 4 ++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index c0bb3f86..267991a2 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -1681,12 +1681,27 @@ 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 pickupHistory = EID.PlayerItemInteractions[i].pickupHistory + local pillsTable = {} + -- Dead Tainted Lazarus exception + if player:GetPlayerType() == 38 then + pickupHistory = EID.PlayerItemInteractions[i].altPickupHistory or pickupHistory + end + if pickupHistory then + for j = 1, #pickupHistory do + if pickupHistory[j][1] == "pill" then + local pillSubType = tostring(pickupHistory[j][3]) + if not pillsTable[pillSubType] then + pillsTable[pillSubType] = 0 + end + pillsTable[pillSubType] = pillsTable[pillSubType] + 1 -- collect pill SubType + end + end + end + 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("([^.]+).([^.]+).([^.]+)") @@ -1716,6 +1731,16 @@ function EID:evaluateTransformationProgress(transformation) end end +-- Workaround function to get the currently held pill of the players. Used to map Pill ID to pill color and vise versa +EID.PlayerHeldPill = {} +function EID:evaluateHeldPill() + EID.PlayerHeldPill = {} + for i = 0, game:GetNumPlayers() - 1 do + local player = Isaac.GetPlayer(i) + EID.PlayerHeldPill[i] = player:GetPill(0) + end +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 = {} @@ -1768,7 +1793,7 @@ end -- if the player ItemInteraction table doesnt exist, create it with its init values function EID:InitItemInteractionIfAbsent(playerID) if not EID.PlayerItemInteractions[playerID] then - EID.PlayerItemInteractions[playerID] = { LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}, + EID.PlayerItemInteractions[playerID] = { LastTouch = 0, actives = {}, altActives = {}, pickupHistory = {}, altPickupHistory = {}, rerollItems = {} } end EID.RecentlyTouchedItems[playerID] = EID.RecentlyTouchedItems[playerID] or {} diff --git a/main.lua b/main.lua index 8253bc15..85cd1553 100644 --- a/main.lua +++ b/main.lua @@ -991,6 +991,7 @@ function EID:onGameUpdate() EID.GameUpdateCount = EID.GameUpdateCount + 1 EID:checkPlayersForMissingItems() EID:evaluateQueuedItems() + EID:evaluateHeldPill() -- Fix some outdated mods erroneously setting the REPENTANCE constant to false if EID.GameVersion == "rep" and REPENTANCE == false then @@ -1577,10 +1578,9 @@ end function EID:OnUsePill(pillEffectID, player, useFlags) player = player or EID.player --AB+ doesn't receive player in callback arguments! -- get the pill color by checking the player's pocket (not accurate for Temperance? and such, but useFlags will help us ignore those) - local pillColor = player:GetPill(0) + local pillColor = EID.PlayerHeldPill[EID:getPlayerID(player)] if pillColor == 0 then return end -- ignore if no pill found in pocket EID:AddPickupToHistory("pill", pillEffectID+1, player, useFlags, pillColor) -- Echo Chamber tracking - -- for tracking used pills, ignore gold pills and noannouncer flag pills -- (not using a bitmask, because Placebo is mimic+noannouncer, and we want to count those) if REPENTANCE and (pillColor % PillColor.PILL_GIANT_FLAG == PillColor.PILL_GOLD or useFlags == UseFlag.USE_NOANNOUNCER) then return end