From 94186a6591293741bb6fff9fe6f192483957e004 Mon Sep 17 00:00:00 2001 From: kittenchilly Date: Tue, 19 Oct 2021 09:37:17 -0500 Subject: [PATCH 1/2] Better Spindown Dice Method Part 2: Unlockables --- eid_api.lua | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- main.lua | 1 + 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/eid_api.lua b/eid_api.lua index d44e499f..168403b0 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -755,10 +755,57 @@ function EID:getSpindownResult(collectibleID) local newID = collectibleID repeat newID = newID - 1 - until config:GetCollectible(newID) and not config:GetCollectible(newID).Hidden + until (config:GetCollectible(newID) and EID:isCollectibleUnlockedAnyPool(newID) and not config:GetCollectible(newID).Hidden) or newID == CollectibleType.COLLECTIBLE_NULL return newID end +function EID:isCollectibleUnlocked(collectibleID, itemPoolOfItem) + local itemPool = Game():GetItemPool() + local itemConfig = Isaac.GetItemConfig() + for i= 1, GetMaxCollectibleID() do + if ItemConfig.Config.IsValidCollectible(i) and i ~= collectibleID then + itemPool:AddRoomBlacklist(i) + end + end + local room = Game():GetRoom() + local isUnlocked = false + for i = 0,1 do -- some samples to make sure + local collID = itemPool:GetCollectible(itemPoolOfItem, false) + if collID == collectibleID then + isUnlocked = true + break + end + end + itemPool:ResetRoomBlacklist() + return isUnlocked +end + +function EID:isCollectibleUnlockedAnyPool(collectibleID) + local itemConfig = Isaac.GetItemConfig() + if EID.itemUnlockStates[collectibleID] == nil then + local itemPoolNum = 0 + while EID:isCollectibleUnlocked(collectibleID, itemPoolNum) == false do + if itemPoolNum == ItemPoolType.NUM_ITEMPOOLS - 1 then + if itemConfig:GetCollectible(collectibleID).Tags & ItemConfig.TAG_QUEST == ItemConfig.TAG_QUEST then + --print("item " .. tostring(collectibleID) .. " is tagged as quest!") + EID.itemUnlockStates[collectibleID] = true + return true + end + --print("couldn't find item " .. tostring(collectibleID) .. " in any item pools") + EID.itemUnlockStates[collectibleID] = false + return false + end + itemPoolNum = itemPoolNum + 1 + end + --print("found item " .. tostring(collectibleID) .. " unlocked in pool " .. tostring(itemPoolNum)) + EID.itemUnlockStates[collectibleID] = true + return true + else + --print("item " .. tostring(collectibleID) .. " was already cached: " .. tostring(EID.itemUnlockStates[collectibleID])) + return EID.itemUnlockStates[collectibleID] + end +end + -- Converts a given table into a string containing the crafting icons of the table -- Example input: {1,2,3,4,5,6,7,8} -- Result: "{{Crafting8}}{{Crafting7}}{{Crafting6}}{{Crafting5}}{{Crafting4}}{{Crafting3}}{{Crafting2}}{{Crafting1}}" diff --git a/main.lua b/main.lua index af73e117..f97b4bd1 100644 --- a/main.lua +++ b/main.lua @@ -26,6 +26,7 @@ EID.lineHeight = 11 EID.sacrificeCounter = {} EID.itemConfig = Isaac.GetItemConfig() EID.effectList = {["76"] = true} +EID.itemUnlockStates = {} -- Sprite inits EID.IconSprite = Sprite() From 1394de7c77e0eccd9d40478c6a41c596c00704b6 Mon Sep 17 00:00:00 2001 From: kittenchilly Date: Tue, 19 Oct 2021 09:41:51 -0500 Subject: [PATCH 2/2] Formatting --- eid_api.lua | 72 ++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index 168403b0..9ae40089 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -760,50 +760,50 @@ function EID:getSpindownResult(collectibleID) end function EID:isCollectibleUnlocked(collectibleID, itemPoolOfItem) - local itemPool = Game():GetItemPool() - local itemConfig = Isaac.GetItemConfig() - for i= 1, GetMaxCollectibleID() do - if ItemConfig.Config.IsValidCollectible(i) and i ~= collectibleID then - itemPool:AddRoomBlacklist(i) - end - end - local room = Game():GetRoom() - local isUnlocked = false - for i = 0,1 do -- some samples to make sure - local collID = itemPool:GetCollectible(itemPoolOfItem, false) - if collID == collectibleID then - isUnlocked = true - break - end - end - itemPool:ResetRoomBlacklist() - return isUnlocked + local itemPool = Game():GetItemPool() + local itemConfig = Isaac.GetItemConfig() + for i= 1, GetMaxCollectibleID() do + if ItemConfig.Config.IsValidCollectible(i) and i ~= collectibleID then + itemPool:AddRoomBlacklist(i) + end + end + local room = Game():GetRoom() + local isUnlocked = false + for i = 0,1 do -- some samples to make sure + local collID = itemPool:GetCollectible(itemPoolOfItem, false) + if collID == collectibleID then + isUnlocked = true + break + end + end + itemPool:ResetRoomBlacklist() + return isUnlocked end function EID:isCollectibleUnlockedAnyPool(collectibleID) - local itemConfig = Isaac.GetItemConfig() - if EID.itemUnlockStates[collectibleID] == nil then - local itemPoolNum = 0 - while EID:isCollectibleUnlocked(collectibleID, itemPoolNum) == false do - if itemPoolNum == ItemPoolType.NUM_ITEMPOOLS - 1 then + local itemConfig = Isaac.GetItemConfig() + if EID.itemUnlockStates[collectibleID] == nil then + local itemPoolNum = 0 + while EID:isCollectibleUnlocked(collectibleID, itemPoolNum) == false do + if itemPoolNum == ItemPoolType.NUM_ITEMPOOLS - 1 then if itemConfig:GetCollectible(collectibleID).Tags & ItemConfig.TAG_QUEST == ItemConfig.TAG_QUEST then --print("item " .. tostring(collectibleID) .. " is tagged as quest!") EID.itemUnlockStates[collectibleID] = true return true end - --print("couldn't find item " .. tostring(collectibleID) .. " in any item pools") - EID.itemUnlockStates[collectibleID] = false - return false - end - itemPoolNum = itemPoolNum + 1 - end - --print("found item " .. tostring(collectibleID) .. " unlocked in pool " .. tostring(itemPoolNum)) - EID.itemUnlockStates[collectibleID] = true - return true - else - --print("item " .. tostring(collectibleID) .. " was already cached: " .. tostring(EID.itemUnlockStates[collectibleID])) - return EID.itemUnlockStates[collectibleID] - end + --print("couldn't find item " .. tostring(collectibleID) .. " in any item pools") + EID.itemUnlockStates[collectibleID] = false + return false + end + itemPoolNum = itemPoolNum + 1 + end + --print("found item " .. tostring(collectibleID) .. " unlocked in pool " .. tostring(itemPoolNum)) + EID.itemUnlockStates[collectibleID] = true + return true + else + --print("item " .. tostring(collectibleID) .. " was already cached: " .. tostring(EID.itemUnlockStates[collectibleID])) + return EID.itemUnlockStates[collectibleID] + end end -- Converts a given table into a string containing the crafting icons of the table