From 44e11223e135472a95fb6d3b06acf4b114186e3f Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Wed, 31 Aug 2022 21:06:53 +0200 Subject: [PATCH] Echo Chamber Reminder now supports Cards, Runes and pills --- eid_api.lua | 15 ++++++++++++++- eid_holdmapdesc.lua | 30 ++++++++++++++++-------------- eid_modifiers.lua | 25 +++++++++++-------------- main.lua | 22 +++++++++------------- 4 files changed, 50 insertions(+), 42 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index 3b3d22d4..5c2716c2 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -1575,7 +1575,7 @@ function EID:evaluateQueuedItems() for i = 0, game:GetNumPlayers() - 1 do local player = Isaac.GetPlayer(i) if not EID.PlayerItemInteractions[i] then - EID.PlayerItemInteractions[i] = {LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}, history = {pills = {},altPills = {}}} + EID.PlayerItemInteractions[i] = {LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}, pickupHistory = {}} end EID.RecentlyTouchedItems[i] = EID.RecentlyTouchedItems[i] or {} end @@ -1662,4 +1662,17 @@ end -- Set a pilleffect to be permanently unidentifyable by EID function EID:SetPillEffectUnidentifyable(pillEffectID, isUnidentifyable) EID.UnidentifyablePillEffects[pillEffectID + 1] = isUnidentifyable or nil +end + +-- Add pickup usage to history of pickups used by the player +function EID:AddPickupToHistory(pickupType, effectID, player, useFlags) + if REPENTANCE and useFlags & UseFlag.USE_MIMIC == UseFlag.USE_MIMIC then return end -- dont add mimic pills to history + local playerID = EID:getPlayerID(player) + if not EID.PlayerItemInteractions[playerID].pickupHistory then + EID.PlayerItemInteractions[playerID].pickupHistory = {} + end + local historyTable = EID.PlayerItemInteractions[playerID].pickupHistory + + -- pickupType = ["pill","card"], playerTypeID, effectID, hadEchoChamberWhenUsed + table.insert(historyTable, 1, {pickupType, player:GetPlayerType(), effectID, REPENTANCE and player:HasCollectible(700)}) end \ No newline at end of file diff --git a/eid_holdmapdesc.lua b/eid_holdmapdesc.lua index 32a4a7e6..3fc9c8f6 100644 --- a/eid_holdmapdesc.lua +++ b/eid_holdmapdesc.lua @@ -70,24 +70,26 @@ function EID:getHoldMapDescription(player, checkingTwin) -- Echo Chamber Description if REPENTANCE and player:HasCollectible(700) then local playerID = player:GetPlayerType() - if EID.PlayerItemInteractions[playerID].history then - local pillHistoryTable = EID.PlayerItemInteractions[playerID].history.pills - -- Dead Tainted Lazarus - if playerID == 38 then - pillHistoryTable = EID.PlayerItemInteractions[playerID].history.altPills or pillHistoryTable - end - local pillNames = "" - for i = 1, math.min(3,#pillHistoryTable) do - if pillHistoryTable[i][2] then -- Echo chamber is owned - local lastUsedPill = tonumber(pillHistoryTable[i][1]) - local name = EID:getPillName(lastUsedPill, false) - pillNames = pillNames..name.."#" + local pickupHistory = EID.PlayerItemInteractions[playerID].pickupHistory + if pickupHistory then + local pickupNames = "" + for i = 1, math.min(3, #pickupHistory) do + if pickupHistory[i][2] == playerID and pickupHistory[i][4] then -- Echo chamber is owned + if pickupHistory[i][1] == "pill" then + local name = EID:getPillName(pickupHistory[i][3], false) + pickupNames = pickupNames .. "{{Pill}} " .. name .. "#" + else + local name = EID:getObjectName(5, 300, pickupHistory[i][3]) + pickupNames = pickupNames .. "{{Card" .. pickupHistory[i][3] .. "}} " .. name .. "#" + end end end - append("{{Collectible700}}", EID:getObjectName(5,100,700), pillNames) + if pickupNames ~= "" then + append("{{Collectible700}}", EID:getObjectName(5, 100, 700), pickupNames) + end end end - + -- Recently Acquired Item Descriptions if EID.Config["ItemReminderShowRecentItem"] > 0 then local printedItems = 0 diff --git a/eid_modifiers.lua b/eid_modifiers.lua index 4323f944..cf30ae00 100644 --- a/eid_modifiers.lua +++ b/eid_modifiers.lua @@ -466,29 +466,26 @@ if REPENTANCE then local function VurpCallback(descObj) local adjustedID = EID:getAdjustedSubtype(descObj.ObjType, descObj.ObjVariant, descObj.ObjSubType) if adjustedID - 1 ~= PillEffect.PILLEFFECT_VURP then return descObj end - + local playerID = EID.player:GetPlayerType() - if EID.PlayerItemInteractions[playerID].history then - local pillHistoryTable = EID.PlayerItemInteractions[playerID].history.pills - -- Dead Tainted Lazarus - if playerID == 38 then - pillHistoryTable = EID.PlayerItemInteractions[playerID].history.altPills or pillHistoryTable - end - + local pickupHistory = EID.PlayerItemInteractions[playerID].pickupHistory + if pickupHistory then + local lastUsedPill = nil local i = 1 - while(i <= #pillHistoryTable) do - if tonumber(pillHistoryTable[i][1]) ~= PillEffect.PILLEFFECT_VURP + 1 then - lastUsedPill = tonumber(pillHistoryTable[i][1]) + while (i <= #pickupHistory) do + local entry = pickupHistory[i] + if entry[1] == "pill" and entry[2] == playerID and entry[3] ~= PillEffect.PILLEFFECT_VURP + 1 then + lastUsedPill = entry[3] break end - i = i +1 + i = i + 1 end - + if lastUsedPill then local tableName = EID:getTableName(descObj.ObjType, descObj.ObjVariant, descObj.ObjSubType) local name = EID:getPillName(lastUsedPill, tableName == "horsepills") - EID:appendToDescription(descObj, "#{{Pill}} {{ColorSilver}}"..name) + EID:appendToDescription(descObj, "#{{Pill}} {{ColorSilver}}" .. name) end end return descObj diff --git a/main.lua b/main.lua index 54607520..eb6d4088 100644 --- a/main.lua +++ b/main.lua @@ -1551,7 +1551,7 @@ 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 = {}, history = {pills = {},altPills = {}}} + EID.PlayerItemInteractions[playerID] = {LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}, pickupHistory = {}} end -- Dead Tainted Lazarus exceptions local activesTable = EID.PlayerItemInteractions[playerID].actives @@ -1609,29 +1609,25 @@ function EID:OnUsePill(pillEffectID, player, useFlags) local playerID = EID:getPlayerID(player) -- Dead Tainted Lazarus exceptions local pillsTable = EID.PlayerItemInteractions[playerID].pills - - if not EID.PlayerItemInteractions[playerID].history then - EID.PlayerItemInteractions[playerID].history = {pills = {},altPills = {}} - end - local pillHistoryTable = EID.PlayerItemInteractions[playerID].history.pills + if player:GetPlayerType() == 38 then pillsTable = EID.PlayerItemInteractions[playerID].altPills or pillsTable - pillHistoryTable = EID.PlayerItemInteractions[playerID].history.altPills or pillHistoryTable end local effectID = tostring(pillEffectID+1) if not pillsTable[effectID] then pillsTable[effectID] = 0 end pillsTable[effectID] = pillsTable[effectID] + 1 - - if REPENTANCE and useFlags & UseFlag.USE_MIMIC == UseFlag.USE_MIMIC then return end -- dont add mimic pills to history - table.insert(pillHistoryTable, 1, {effectID, REPENTANCE and player:HasCollectible(700)}) - for k,v in ipairs(pillHistoryTable) do - print(k,v[1]) - end + + EID:AddPickupToHistory("pill", pillEffectID+1, player, useFlags) end EID:AddCallback(ModCallbacks.MC_USE_PILL, EID.OnUsePill) +function EID:OnUseCard(cardID, player, useFlags) + player = player or EID.player --AB+ doesn't receive player in callback arguments! + EID:AddPickupToHistory("card", cardID, player, useFlags) +end +EID:AddCallback(ModCallbacks.MC_USE_CARD, EID.OnUseCard) -- only save and load configs when using MCM. Otherwise Config file changes arent valid if EID.MCMLoaded or REPENTANCE then