Pickup collision overhaul

This commit is contained in:
Buurazu authored and GitHub committed 2022-01-28 16:48:22 -05:00
1 parent 4eb48c24d2
commit a24ac7877d
1 file changed
+32 -58
+32 -58
View File
@@ -191,16 +191,18 @@ local sortedIDs = {}
local function sortAllItems() local function sortAllItems()
sortedIDs = {} sortedIDs = {}
local objectNames = {}
for i = 1, CraftingMaxItemID do for i = 1, CraftingMaxItemID do
if CraftingItemQualities[i] ~= nil then if CraftingItemQualities[i] ~= nil then
table.insert(sortedIDs, i) table.insert(sortedIDs, i)
objectNames[i] = EID:getObjectName(5, 100, i)
end end
end end
table.sort(sortedIDs, function(a, b) table.sort(sortedIDs, function(a, b)
if CraftingItemQualities[a] == CraftingItemQualities[b] then if CraftingItemQualities[a] == CraftingItemQualities[b] then
return (EID:getObjectName(5, 100, a) < EID:getObjectName(5, 100, b)) return (objectNames[a] < objectNames[b])
else else
return (CraftingItemQualities[a] > CraftingItemQualities[b]) return (CraftingItemQualities[a] > CraftingItemQualities[b])
end end
@@ -226,8 +228,9 @@ local function nextFloat()
return RNGNext() * multi; return RNGNext() * multi;
end end
-- Convert a pickup's ID into what ingredient it counts as
function EID:getBagOfCraftingID(Variant, SubType) function EID:getBagOfCraftingID(Variant, SubType)
local entry = pickupIDLookup[""..Variant.."."..SubType] local entry = pickupIDLookup[Variant.."."..SubType]
if entry ~= nil then if entry ~= nil then
return entry return entry
elseif Variant == 300 then elseif Variant == 300 then
@@ -242,6 +245,7 @@ function EID:getBagOfCraftingID(Variant, SubType)
return nil return nil
end end
-- NO RECIPES MODE: Get percentages of what quality / item pool a given set of 8 ingredients can yield
function EID:simulateBagOfCrafting(componentsTable) function EID:simulateBagOfCrafting(componentsTable)
local components = componentsTable local components = componentsTable
local compTotalWeight = 0 local compTotalWeight = 0
@@ -533,64 +537,37 @@ EID:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, GameStartCrafting)
------------------------------------------ ------------------------------------------
------------------------------------------ ------------------------------------------
local pickupsCollected = {} -- table of collected pickup indexes, reset each room
local pickupsOnInit = {} local pickupsJustTouched = {} -- one-frame flags of pickups a player/pickup-collector has touched, so the bag doesn't think it collected it
EID:AddCallback(ModCallbacks.MC_PRE_PICKUP_COLLISION, function(_, pickup,collider,_) EID:AddCallback(ModCallbacks.MC_PRE_PICKUP_COLLISION, function(_, pickup,collider,_)
if collider.Type ~= EntityType.ENTITY_PLAYER then if collider.Type == EntityType.ENTITY_PLAYER or collider.Type == EntityType.ENTITY_FAMILIAR or
return collider.Type == EntityType.ENTITY_BUMBINO or collider.Type == EntityType.ENTITY_ULTRA_GREED then
pickupsJustTouched[pickup.Index] = true
end end
-- Remove pickups picked up normally
local pickupsOnInitCorrected = {}
for _,e in ipairs (pickupsOnInit) do
if GetPtrHash(pickup) ~= GetPtrHash(e) then
table.insert(pickupsOnInitCorrected, e)
end
end
pickupsOnInit = pickupsOnInitCorrected
end) end)
EID:AddCallback(ModCallbacks.MC_POST_KNIFE_INIT, function(_, entity) EID:AddCallback(ModCallbacks.MC_POST_PICKUP_UPDATE, function(_, pickup)
if entity.Variant ~= 4 then if pickup:GetSprite():GetAnimation() == "Collect" and not pickupsCollected[pickup.Index] then
return pickupsCollected[pickup.Index] = true
end if not pickupsJustTouched[pickup.Index] then
pickupsOnInit = {} print(pickup.Index .. "," .. pickup:GetSprite():GetFrame() .. "," .. Isaac.GetTime())
for _,e in ipairs (Isaac.FindByType(EntityType.ENTITY_PICKUP, -1, -1, false, false)) do local craftingIDs = EID:getBagOfCraftingID(pickup.Variant, pickup.SubType)
if e:GetSprite():GetAnimation() ~= "Collect" then
table.insert(pickupsOnInit, e)
end
end
end, 4)
EID:AddCallback(ModCallbacks.MC_POST_ENTITY_REMOVE, function(_, bag)
if bag.Variant ~= 4 or bag.SubType ~= 4 then
return
end
table.sort(pickupsOnInit, function (a,b)
return
a:GetSprite():GetFrame() > b:GetSprite():GetFrame() or
(a:GetSprite():GetFrame() == b:GetSprite():GetFrame() and a.Index < b.Index)
end)
for _,e in ipairs (pickupsOnInit) do
if e:GetSprite():GetAnimation() == "Collect" then
local craftingIDs = EID:getBagOfCraftingID(e.Variant, e.SubType)
if craftingIDs ~= nil then if craftingIDs ~= nil then
for _,v in ipairs(craftingIDs) do for _,v in ipairs(craftingIDs) do
if #EID.BagItems >= 8 then if #EID.BagItems >= 8 then table.remove(EID.BagItems, 1) end
local newContent = {}
for i=2,#EID.BagItems do
table.insert(newContent, EID.BagItems[i])
end
EID.BagItems = newContent
end
table.insert(EID.BagItems, v) table.insert(EID.BagItems, v)
end end
end end
end end
end end
end, EntityType.ENTITY_KNIFE) pickupsJustTouched[pickup.Index] = nil
end)
EID:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, function(_)
-- We're using the pickup indexes for quick checking, which reset on each new room
pickupsCollected = {}
end)
--Tainted Cain "hold to craft" check --Tainted Cain "hold to craft" check
local holdCounter = 0 local holdCounter = 0
@@ -612,14 +589,11 @@ local function trackBagHolding()
end end
end end
local function trackBagActivated() --Active slot "press to craft" check
if IsTaintedCain() then return end EID:AddCallback(ModCallbacks.MC_PRE_USE_ITEM, function(_, _, _, _, _, slot)
if Input.IsActionTriggered(ButtonAction.ACTION_ITEM, EID.player.ControllerIndex) and #EID.BagItems >= 8 then if slot ~= 0 or #EID.BagItems < 8 then return end
EID.BagItems = {} EID.BagItems = {}
-- SCHOOLBAG BREAKS THIS!!! but it's better than nothing end, CollectibleType.COLLECTIBLE_BAG_OF_CRAFTING)
-- and, technically, if the active item bag has 8 items, it's impossible to fill it without first emptying it, and then we're synced again
end
end
local function shiftBagContent() local function shiftBagContent()
local newContent = {} local newContent = {}
@@ -629,7 +603,6 @@ local function shiftBagContent()
table.insert(newContent, EID.BagItems[1]) table.insert(newContent, EID.BagItems[1])
EID.BagItems = newContent EID.BagItems = newContent
end end
-- only Tainted Cain's consumable slot bag can have its ingredients shifted -- only Tainted Cain's consumable slot bag can have its ingredients shifted
local function detectBagContentShift() local function detectBagContentShift()
if Input.IsActionTriggered(ButtonAction.ACTION_DROP, EID.player.ControllerIndex) and IsTaintedCain() then if Input.IsActionTriggered(ButtonAction.ACTION_DROP, EID.player.ControllerIndex) and IsTaintedCain() then
@@ -791,7 +764,6 @@ function EID:handleBagOfCraftingRendering()
lastSeedUsed = curSeed lastSeedUsed = curSeed
trackBagHolding() trackBagHolding()
trackBagActivated()
detectBagContentShift() detectBagContentShift()
local tableToCraftingIconsFunc = EID.tableToCraftingIconsMerged local tableToCraftingIconsFunc = EID.tableToCraftingIconsMerged
@@ -847,6 +819,7 @@ function EID:handleBagOfCraftingRendering()
--if we're in Preview Only mode, then we have nothing more to do --if we're in Preview Only mode, then we have nothing more to do
if (EID.Config["BagOfCraftingDisplayMode"] == "Preview Only") then return false end if (EID.Config["BagOfCraftingDisplayMode"] == "Preview Only") then return false end
-- check what pickups are available in this room
local curRoomIndex = game:GetLevel():GetCurrentRoomDesc().SafeGridIndex local curRoomIndex = game:GetLevel():GetCurrentRoomDesc().SafeGridIndex
local results = {} local results = {}
@@ -872,6 +845,7 @@ function EID:handleBagOfCraftingRendering()
local itemQuery = {} local itemQuery = {}
local itemCount = {} local itemCount = {}
-- Merge our list of the floor's pickups and our bag's pickups
--max 8 copies of a single item in our list, to avoid repeat recipes --max 8 copies of a single item in our list, to avoid repeat recipes
for _, v in ipairs(EID.bagOfCraftingFloorQuery) do for _, v in ipairs(EID.bagOfCraftingFloorQuery) do
if (not itemCount[v] or itemCount[v] < 8) then if (not itemCount[v] or itemCount[v] < 8) then