From 27862c5e6a9c13cdc25501178ebd02a79dd10197 Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Fri, 30 Jun 2023 23:44:11 +0200 Subject: [PATCH] Bag of Crafting: Curse of Maze room switch is now properly handled in pickup tracker --- eid_bagofcrafting.lua | 40 +++++++++++++++++++++++++++++++++------- main.lua | 1 + 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/eid_bagofcrafting.lua b/eid_bagofcrafting.lua index e4fc6b3f..0e9b3d74 100644 --- a/eid_bagofcrafting.lua +++ b/eid_bagofcrafting.lua @@ -503,8 +503,8 @@ local function calcHeldItems() end local function calcFloorItems() EID.BoC.FloorQuery = {} - for _,v in pairs(EID.BoC.RoomQueries) do - for _,v1 in ipairs(v) do + for _,roomQuery in pairs(EID.BoC.RoomQueries) do + for _,v1 in ipairs(roomQuery[1]) do table.insert(EID.BoC.FloorQuery, v1) end end @@ -696,9 +696,9 @@ local function combinations(arr, length, startPos, tempResult, randResults, newR coroutine.yield() coTimer = Isaac.GetTime() end - local length = length or 8 - local startPos = startPos or 1 - local tempResult = tempResult or {} + length = length or 8 + startPos = startPos or 1 + tempResult = tempResult or {} if (length == 0) then local resultString = table.concat(tempResult,",") if (randResults[resultString] == nil) then @@ -880,6 +880,32 @@ local function RecipeCrunchCoroutine() EID.RefreshBagTextbox = true end +function EID:BOCHandleCurseOfMaze() + -- switches tracked room contents when rooms are switched by curse of maze + if game:GetLevel():GetCurses() & LevelCurse.CURSE_OF_MAZE ~= LevelCurse.CURSE_OF_MAZE then + return + end + local rooms = game:GetLevel():GetRooms() + local changedRooms = {} + for i = 0, rooms.Size - 1 do + local roomDesc = rooms:Get(i) + if roomDesc and roomDesc.Data then + local savedRoomContent = EID.BoC.RoomQueries[roomDesc.ListIndex .. ""] + if not savedRoomContent then + EID.BoC.RoomQueries[roomDesc.ListIndex .. ""] = { {}, roomDesc.Data.Variant } + end + if savedRoomContent and savedRoomContent[2] ~= roomDesc.Data.Variant then + table.insert(changedRooms, roomDesc.ListIndex) + end + end + end + if #changedRooms >= 2 then + local temp = EID.BoC.RoomQueries[changedRooms[2] .. ""] + EID.BoC.RoomQueries[changedRooms[2] .. ""] = EID.BoC.RoomQueries[changedRooms[1] .. ""] + EID.BoC.RoomQueries[changedRooms[1] .. ""] = temp + end +end + local prevOffset = 0 -- Called 60 times a second so we can read input properly function EID:handleBagOfCraftingUpdating() @@ -1015,13 +1041,13 @@ function EID:handleBagOfCraftingRendering(ignoreRefreshRate) end end end - EID.BoC.RoomQueries[curRoomIndex..""] = roomItems + EID.BoC.RoomQueries[curRoomIndex .. ""] = { roomItems, game:GetLevel():GetCurrentRoomDesc().Data.Variant } EID.BoC.CurrentPickupCount = #pickups calcHeldItems() calcFloorItems() EID.RefreshBagTextbox = true else - roomItems = EID.BoC.RoomQueries[curRoomIndex..""] or {} + roomItems = EID.BoC.RoomQueries[curRoomIndex .. ""] and EID.BoC.RoomQueries[curRoomIndex .. ""][1] or {} end itemQuery = {} diff --git a/main.lua b/main.lua index 9d24fc0a..4c19ec2f 100644 --- a/main.lua +++ b/main.lua @@ -764,6 +764,7 @@ if EID.isRepentance then local level = game:GetLevel() EID.isMirrorRoom = level:GetCurrentRoom():IsMirrorWorld() EID.isDeathCertRoom = EID:GetDimension(level) == 2 + EID:BOCHandleCurseOfMaze() -- Handle Flip Item initialItemNext = false