Reorganize a bit, reduce pedestal overlap checks

This commit is contained in:
Buurazu authored and GitHub committed 2022-01-22 20:18:39 -05:00
1 parent 14d8167d01
commit 82f1cc5238
1 file changed
+41 -41
+41 -41
View File
@@ -298,7 +298,7 @@ if REPENTANCE then
end end
EID:AddCallback(ModCallbacks.MC_PRE_ROOM_ENTITY_SPAWN, EID.preRoomEntitySpawn) EID:AddCallback(ModCallbacks.MC_PRE_ROOM_ENTITY_SPAWN, EID.preRoomEntitySpawn)
function EID:postPickupInit(entity) function EID:postPickupInitFlip(entity)
initialItemNext = false initialItemNext = false
flipItemNext = true flipItemNext = true
lastGetItemResult[4] = entity.InitSeed lastGetItemResult[4] = entity.InitSeed
@@ -324,7 +324,7 @@ if REPENTANCE then
entity:GetData()["EID_FlipItemID"] = flipEntry[1] entity:GetData()["EID_FlipItemID"] = flipEntry[1]
end end
end end
EID:AddCallback(ModCallbacks.MC_POST_PICKUP_INIT, EID.postPickupInit, PickupVariant.PICKUP_COLLECTIBLE) EID:AddCallback(ModCallbacks.MC_POST_PICKUP_INIT, EID.postPickupInitFlip, PickupVariant.PICKUP_COLLECTIBLE)
function EID:CheckPedestalIndex(entity) function EID:CheckPedestalIndex(entity)
-- Only pedestals with indexes that were present at room load can be flip pedestals -- Only pedestals with indexes that were present at room load can be flip pedestals
@@ -790,45 +790,33 @@ function EID:setPlayer()
end end
end end
-- is this needed if pathchecker uses a no reward seed? (and isn't even present for a render?)
if REPENTANCE then
function EID:removeWrongGuppyEyeInfo(effectEntity)
if EID.pathCheckerEntity ~= nil and effectEntity.Parent ~= nil then
if GetPtrHash(effectEntity.Parent) == GetPtrHash(EID.pathCheckerEntity) then
effectEntity:Remove()
end
end
end
EID:AddCallback(ModCallbacks.MC_POST_EFFECT_UPDATE, EID.removeWrongGuppyEyeInfo, EffectVariant.PICKUP_GHOST)
end
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
---------------------------On Update Function------------------------------ ---------------------------On Update Function------------------------------
-- Runs 30 times a second; doesn't update while paused
EID.lastDescriptionEntity = nil local collSpawned = false
EID.lastDist = 0
EID.pathCheckerEntity = nil
function EID:onGameUpdate() function EID:onGameUpdate()
-- Increases by 30 per second; doesn't update while paused
EID.GameUpdateCount = EID.GameUpdateCount + 1 EID.GameUpdateCount = EID.GameUpdateCount + 1
EID:setPlayer()
--Fix Overlapping Pedestals -- Fix Overlapping Pedestals if a collectible spawned this frame (needed for Mega Chest)
-- PERFORMANCENOTE move this to a post pickup init or something if collSpawned then
local curPositions = {} collSpawned = false
for _, entity in ipairs(Isaac.FindByType(5, 100, -1, true, false)) do local curPositions = {}
local pos = entity.Position for _, entity in ipairs(Isaac.FindByType(5, 100, -1, true, false)) do
for _, otherPos in ipairs(curPositions) do local pos = entity.Position
if pos:Distance(otherPos[2]) == 0 then for _, otherPos in ipairs(curPositions) do
entity:GetData()["EID_RenderOffset"] = Vector(10,0) if pos:Distance(otherPos[2]) == 0 then
otherPos[1]:GetData()["EID_RenderOffset"] = Vector(-10,0) print("yo " .. EID.GameUpdateCount .. " found overlap " .. entity.SubType .. "," .. otherPos[1].SubType)
entity:GetData()["EID_RenderOffset"] = Vector(10,0)
otherPos[1]:GetData()["EID_RenderOffset"] = Vector(-10,0)
end
end end
table.insert(curPositions, {entity, entity.Position})
end end
table.insert(curPositions, {entity, entity.Position})
end end
-- this could run less frequently, probably does have to be in update though -- Remove Crane Game item data if it's giving the prize out
if REPENTANCE then if REPENTANCE and EID.GameUpdateCount % 15 == 0 then
for _, crane in ipairs(Isaac.FindByType(6, 16, -1, true, false)) do for _, crane in ipairs(Isaac.FindByType(6, 16, -1, true, false)) do
if EID.CraneItemType[tostring(crane.InitSeed)] then if EID.CraneItemType[tostring(crane.InitSeed)] then
if crane:GetSprite():IsPlaying("Prize") then if crane:GetSprite():IsPlaying("Prize") then
@@ -840,6 +828,14 @@ function EID:onGameUpdate()
end end
EID:AddCallback(ModCallbacks.MC_POST_UPDATE, EID.onGameUpdate) EID:AddCallback(ModCallbacks.MC_POST_UPDATE, EID.onGameUpdate)
-- Wait until all collectibles spawning this frame have spawned before checking if there's an overlap
function EID:CollectibleSpawnedThisFrame(entity)
collSpawned = true
end
EID:AddCallback(ModCallbacks.MC_POST_PICKUP_INIT, EID.CollectibleSpawnedThisFrame, PickupVariant.PICKUP_COLLECTIBLE)
-- Pathchecking
local pathCheckerEntity = nil
local lastPathfindIndex = -1 local lastPathfindIndex = -1
local lastPathfindFrame = -1 local lastPathfindFrame = -1
local function attemptPathfind(entity) local function attemptPathfind(entity)
@@ -850,18 +846,18 @@ local function attemptPathfind(entity)
if entity.Index == lastPathfindIndex and EID.GameUpdateCount - lastPathfindFrame < 30 then return false end if entity.Index == lastPathfindIndex and EID.GameUpdateCount - lastPathfindFrame < 30 then return false end
-- Spawn a custom NPC entity to attempt a pathfind to the target pickup, then remove it afterwards -- Spawn a custom NPC entity to attempt a pathfind to the target pickup, then remove it afterwards
EID.pathCheckerEntity = game:Spawn(17, 3169, EID.player.Position, nullVector, EID.player, 0, 4354) pathCheckerEntity = game:Spawn(17, 3169, EID.player.Position, nullVector, EID.player, 0, 4354)
EID.pathCheckerEntity:ClearEntityFlags(EntityFlag.FLAG_APPEAR) pathCheckerEntity:ClearEntityFlags(EntityFlag.FLAG_APPEAR)
-- Not sure how much of this flagging is needed now that the entity is immediately removed afterwards -- Not sure how much of this flagging is needed now that the entity is immediately removed afterwards
EID.pathCheckerEntity:AddEntityFlags(EntityFlag.FLAG_PERSISTENT | EntityFlag.FLAG_NO_STATUS_EFFECTS | EntityFlag.FLAG_NO_SPRITE_UPDATE | EntityFlag.FLAG_HIDE_HP_BAR | EntityFlag.FLAG_NO_DEATH_TRIGGER | EntityFlag.FLAG_FRIENDLY) pathCheckerEntity:AddEntityFlags(EntityFlag.FLAG_PERSISTENT | EntityFlag.FLAG_NO_STATUS_EFFECTS | EntityFlag.FLAG_NO_SPRITE_UPDATE | EntityFlag.FLAG_HIDE_HP_BAR | EntityFlag.FLAG_NO_DEATH_TRIGGER | EntityFlag.FLAG_FRIENDLY)
if REPENTANCE then EID.pathCheckerEntity:AddEntityFlags(EntityFlag.FLAG_NO_QUERY) end if REPENTANCE then pathCheckerEntity:AddEntityFlags(EntityFlag.FLAG_NO_QUERY) end
EID.pathCheckerEntity.EntityCollisionClass = EntityCollisionClass.ENTCOLL_NONE pathCheckerEntity.EntityCollisionClass = EntityCollisionClass.ENTCOLL_NONE
EID.pathCheckerEntity.Visible = false -- it's invisible anyway? pathCheckerEntity.Visible = false -- it's invisible anyway?
EID.pathCheckerEntity.Position = EID.player.Position -- not needed, it spawned at our position? pathCheckerEntity.Position = EID.player.Position -- not needed, it spawned at our position?
local success = EID.pathCheckerEntity:ToNPC().Pathfinder:HasPathToPos(entity.Position, false) local success = pathCheckerEntity:ToNPC().Pathfinder:HasPathToPos(entity.Position, false)
entity:GetData()["EID_Pathfound"] = success entity:GetData()["EID_Pathfound"] = success
EID.pathCheckerEntity:Remove(); EID.pathCheckerEntity = nil pathCheckerEntity:Remove(); pathCheckerEntity = nil
lastPathfindIndex = entity.Index; lastPathfindFrame = EID.GameUpdateCount lastPathfindIndex = entity.Index; lastPathfindFrame = EID.GameUpdateCount
return success return success
end end
@@ -878,14 +874,15 @@ local function renderAchievementInfo()
demoDescObj.Description = EID:getDescriptionEntry("OldGameVersionWarningText") or "" demoDescObj.Description = EID:getDescriptionEntry("OldGameVersionWarningText") or ""
EID:displayPermanentText(demoDescObj) EID:displayPermanentText(demoDescObj)
hasShownAchievementWarning = true hasShownAchievementWarning = true
-- Bag of Crafting modded items check
elseif EID.player:HasCollectible(710) and EID:DetectModdedItems() and EID.Config.DisplayBagOfCrafting ~= "never" and (EID.Config.BagOfCraftingDisplayMode == "Recipe List" or EID.Config.BagOfCraftingDisplayMode == "Preview Only") then elseif EID.player:HasCollectible(710) and EID:DetectModdedItems() and EID.Config.DisplayBagOfCrafting ~= "never" and (EID.Config.BagOfCraftingDisplayMode == "Recipe List" or EID.Config.BagOfCraftingDisplayMode == "Preview Only") then
local demoDescObj = EID:getDescriptionObj(-999, -1, 1) local demoDescObj = EID:getDescriptionObj(-999, -1, 1)
demoDescObj.Name = EID:getDescriptionEntry("AchievementWarningTitle") or "" demoDescObj.Name = EID:getDescriptionEntry("AchievementWarningTitle") or ""
demoDescObj.Description = EID:getDescriptionEntry("ModdedRecipesWarningText") or "" demoDescObj.Description = EID:getDescriptionEntry("ModdedRecipesWarningText") or ""
EID:displayPermanentText(demoDescObj) EID:displayPermanentText(demoDescObj)
hasShownAchievementWarning = true hasShownAchievementWarning = true
-- Achievements Locked Check (do we have Cube of Meat or Book of Revelations unlocked?)
else else
-- Achievements Locked Check (do we have Cube of Meat or Book of Revelations unlocked?)
local characterID = EID.player:GetPlayerType() local characterID = EID.player:GetPlayerType()
--ID 21 = Tainted Isaac. Tainted characters have definitely beaten Mom! (Fixes Tainted Lost's item pools ruining this check) --ID 21 = Tainted Isaac. Tainted characters have definitely beaten Mom! (Fixes Tainted Lost's item pools ruining this check)
if characterID < 21 and game.Challenge == 0 and not EID:PlayersHaveCollectible(CollectibleType.COLLECTIBLE_TMTRAINER) then if characterID < 21 and game.Challenge == 0 and not EID:PlayersHaveCollectible(CollectibleType.COLLECTIBLE_TMTRAINER) then
@@ -912,6 +909,9 @@ end
---------------------------On Render Function------------------------------ ---------------------------On Render Function------------------------------
local searchPartitions = EntityPartition.FAMILIAR + EntityPartition.ENEMY + EntityPartition.PICKUP + EntityPartition.PLAYER local searchPartitions = EntityPartition.FAMILIAR + EntityPartition.ENEMY + EntityPartition.PICKUP + EntityPartition.PLAYER
EID.lastDescriptionEntity = nil
EID.lastDist = 0
local function onRender(t) local function onRender(t)
-- Increases by 60 per second, ignores pauses -- Increases by 60 per second, ignores pauses
EID.GameRenderCount = EID.GameRenderCount + 1 EID.GameRenderCount = EID.GameRenderCount + 1