Global change, absorbed check improved

This commit is contained in:
Buurazu authored and GitHub committed 2022-02-13 05:09:54 -05:00
1 parent f7f90a16aa
commit 5d73a07bbf
1 file changed
+44 -35
+44 -35
View File
@@ -2,46 +2,54 @@ local game = Game()
EID.TabPreviewID = 0 EID.TabPreviewID = 0
-- Modifiers switching the previewed description can cause infinite loops or undesired text, use this to help prevent it -- Modifiers switching the previewed description can cause infinite loops or undesired text, use this to help prevent it
local inPreview = false EID.inModifierPreview = false
-- Afterbirth+ modifiers -- List of collectible IDs for us to check if a player owns them; feel free to add to this in mods that add description modifiers!
local collectiblesToCheck = { CollectibleType.COLLECTIBLE_VOID, } EID.collectiblesToCheck = { CollectibleType.COLLECTIBLE_VOID, }
local maxSlot = 1 local maxSlot = 1
-- Repentance modifiers -- Repentance modifiers
if REPENTANCE then if REPENTANCE then
maxSlot = 3 maxSlot = 3
--include the AB+ collectiblesToCheck in this table! --include the AB+ collectiblesToCheck in this table! (wish there was an easy way to merge two tables)
collectiblesToCheck = { CollectibleType.COLLECTIBLE_VOID, EID.collectiblesToCheck = { CollectibleType.COLLECTIBLE_VOID,
CollectibleType.COLLECTIBLE_BINGE_EATER, CollectibleType.COLLECTIBLE_BOOK_OF_VIRTUES, CollectibleType.COLLECTIBLE_SPINDOWN_DICE, CollectibleType.COLLECTIBLE_BINGE_EATER, CollectibleType.COLLECTIBLE_BOOK_OF_VIRTUES, CollectibleType.COLLECTIBLE_SPINDOWN_DICE,
CollectibleType.COLLECTIBLE_TAROT_CLOTH, CollectibleType.COLLECTIBLE_MOMS_BOX, 59, --Birthright Belial CollectibleType.COLLECTIBLE_TAROT_CLOTH, CollectibleType.COLLECTIBLE_MOMS_BOX, 59, --Birthright Belial
CollectibleType.COLLECTIBLE_BLANK_CARD, CollectibleType.COLLECTIBLE_CLEAR_RUNE, CollectibleType.COLLECTIBLE_PLACEBO, CollectibleType.COLLECTIBLE_BLANK_CARD, CollectibleType.COLLECTIBLE_CLEAR_RUNE, CollectibleType.COLLECTIBLE_PLACEBO,
CollectibleType.COLLECTIBLE_FALSE_PHD, CollectibleType.COLLECTIBLE_ABYSS, CollectibleType.COLLECTIBLE_FLIP, CollectibleType.COLLECTIBLE_FALSE_PHD, CollectibleType.COLLECTIBLE_ABYSS, CollectibleType.COLLECTIBLE_FLIP,
} }
end end
local collectiblesOwned = {} EID.collectiblesOwned = {}
local blackRuneOwned = false EID.collectiblesAbsorbed = {}
EID.blackRuneOwned = false
local lastCheck = 0 local lastCheck = 0
local function CheckPlayersCollectibles() function EID:CheckPlayersCollectibles()
-- recheck the players' owned collectibles periodically, not every frame -- recheck the players' owned collectibles periodically, not every frame
-- (has to be checked regularly due to mechanics like D4 / Tainted Eden)
if EID.GameUpdateCount >= lastCheck + 15 then if EID.GameUpdateCount >= lastCheck + 15 then
lastCheck = EID.GameUpdateCount lastCheck = EID.GameUpdateCount
local numPlayers = game:GetNumPlayers() local numPlayers = game:GetNumPlayers()
local players = {}; for i = 0, numPlayers - 1 do players[i] = Isaac.GetPlayer(i) end local players = {}; for i = 0, numPlayers - 1 do players[i] = Isaac.GetPlayer(i) end
for _,v in ipairs(collectiblesToCheck) do for _,v in ipairs(EID.collectiblesToCheck) do
collectiblesOwned[v] = false EID.collectiblesOwned[v] = false
EID.collectiblesAbsorbed[v] = false
for i = 0, numPlayers - 1 do for i = 0, numPlayers - 1 do
if players[i]:HasCollectible(v) then if players[i]:HasCollectible(v) then
collectiblesOwned[v] = i EID.collectiblesOwned[v] = i
break break
-- Check for the item being inside this player's Void
-- note: currently Absorb checks are only done as a backup, will always be false if it's owned legitimately
elseif EID.absorbedItems[tostring(i)] and EID.absorbedItems[tostring(i)][tostring(v)] and players[i]:HasCollectible(477) then
EID.collectiblesAbsorbed[v] = i
end end
end end
end end
blackRuneOwned = false -- other Card in inventory checks could be done in this loop here if ever desired
EID.blackRuneOwned = false
for i = 0, numPlayers - 1 do for i = 0, numPlayers - 1 do
for j = 0, maxSlot do for j = 0, maxSlot do
if players[i]:GetCard(j) == Card.RUNE_BLACK then if players[i]:GetCard(j) == Card.RUNE_BLACK then
blackRuneOwned = i EID.blackRuneOwned = i
break break
end end
end end
@@ -51,9 +59,9 @@ end
local function TabCallback(descObj) local function TabCallback(descObj)
if EID.TabPreviewID == 0 then return descObj end if EID.TabPreviewID == 0 then return descObj end
inPreview = true EID.inModifierPreview = true
local descEntry = EID:getDescriptionObj(5, 100, EID.TabPreviewID) local descEntry = EID:getDescriptionObj(5, 100, EID.TabPreviewID)
inPreview = false EID.inModifierPreview = false
return descEntry return descEntry
end end
@@ -70,8 +78,8 @@ local function VoidCallback(descObj, isRune)
-- Do both Void and Rune here since they could both be requested in the same frame -- Do both Void and Rune here since they could both be requested in the same frame
if EID.GameUpdateCount >= lastVoidCheck + 30 or EID.RecheckVoid then if EID.GameUpdateCount >= lastVoidCheck + 30 or EID.RecheckVoid then
EID:VoidRoomCheck() EID:VoidRoomCheck()
if collectiblesOwned[477] then EID:VoidRNGCheck(Isaac.GetPlayer(collectiblesOwned[477]), false) end if EID.collectiblesOwned[477] then EID:VoidRNGCheck(Isaac.GetPlayer(EID.collectiblesOwned[477]), false) end
if blackRuneOwned then EID:VoidRNGCheck(Isaac.GetPlayer(blackRuneOwned), true) end if EID.blackRuneOwned then EID:VoidRNGCheck(Isaac.GetPlayer(EID.blackRuneOwned), true) end
lastVoidCheck = EID.GameUpdateCount lastVoidCheck = EID.GameUpdateCount
EID.RecheckVoid = false EID.RecheckVoid = false
end end
@@ -183,7 +191,7 @@ if REPENTANCE then
-- Handle Spindown Dice description addition -- Handle Spindown Dice description addition
local function SpindownDiceCallback(descObj) local function SpindownDiceCallback(descObj)
-- get the ID of the player that owns the Spindown Dice -- get the ID of the player that owns the Spindown Dice
local playerID = (collectiblesOwned[723] or (EID.absorbedItems[723] and collectiblesOwned[477])) local playerID = (EID.collectiblesOwned[723] or EID.collectiblesAbsorbed[723])
EID:appendToDescription(descObj, "#{{Collectible723}} :") EID:appendToDescription(descObj, "#{{Collectible723}} :")
local refID = descObj.ObjSubType local refID = descObj.ObjSubType
local hasCarBattery = Isaac.GetPlayer(playerID):HasCollectible(CollectibleType.COLLECTIBLE_CAR_BATTERY) local hasCarBattery = Isaac.GetPlayer(playerID):HasCollectible(CollectibleType.COLLECTIBLE_CAR_BATTERY)
@@ -423,7 +431,7 @@ if REPENTANCE then
-- currently, only pickup descriptions have modifiers -- currently, only pickup descriptions have modifiers
if descObj.ObjType ~= 5 then return false end if descObj.ObjType ~= 5 then return false end
CheckPlayersCollectibles() EID:CheckPlayersCollectibles()
local callbacks = {} local callbacks = {}
@@ -433,30 +441,30 @@ if REPENTANCE then
-- Check Birthright first because it overwrites the description instead of appending to it -- Check Birthright first because it overwrites the description instead of appending to it
if descObj.ObjSubType == 619 then table.insert(callbacks, BirthrightCallback) end if descObj.ObjSubType == 619 then table.insert(callbacks, BirthrightCallback) end
if collectiblesOwned[664] then table.insert(callbacks, BingeEaterCallback) end if EID.collectiblesOwned[664] then table.insert(callbacks, BingeEaterCallback) end
if collectiblesOwned[59] then table.insert(callbacks, BookOfBelialCallback) end if EID.collectiblesOwned[59] then table.insert(callbacks, BookOfBelialCallback) end
if collectiblesOwned[584] then table.insert(callbacks, BookOfVirtuesCallback) end if EID.collectiblesOwned[584] then table.insert(callbacks, BookOfVirtuesCallback) end
if collectiblesOwned[706] or (EID.absorbedItems[706] and collectiblesOwned[477]) then table.insert(callbacks, AbyssCallback) end if EID.collectiblesOwned[706] or EID.collectiblesAbsorbed[706] then table.insert(callbacks, AbyssCallback) end
if collectiblesOwned[711] and EID:getEntityData(descObj.Entity, "EID_FlipItemID") then table.insert(callbacks, FlipCallback) end if EID.collectiblesOwned[711] and EID:getEntityData(descObj.Entity, "EID_FlipItemID") then table.insert(callbacks, FlipCallback) end
if EID.Config["SpindownDiceResults"] > 0 and (collectiblesOwned[723] or (EID.absorbedItems[723] and collectiblesOwned[477])) and descObj.ObjSubType ~= 668 then table.insert(callbacks, SpindownDiceCallback) end if EID.Config["SpindownDiceResults"] > 0 and (EID.collectiblesOwned[723] or EID.collectiblesAbsorbed[723]) and descObj.ObjSubType ~= 668 then table.insert(callbacks, SpindownDiceCallback) end
-- Card / Rune Callbacks -- Card / Rune Callbacks
elseif descObj.ObjVariant == PickupVariant.PICKUP_TAROTCARD then elseif descObj.ObjVariant == PickupVariant.PICKUP_TAROTCARD then
if collectiblesOwned[451] then table.insert(callbacks, TarotClothCallback) end if EID.collectiblesOwned[451] then table.insert(callbacks, TarotClothCallback) end
if collectiblesOwned[286] and not blankCardHidden[descObj.ObjSubType] and descObj.ObjSubType <= 80 then table.insert(callbacks, BlankCardCallback) end if EID.collectiblesOwned[286] and not blankCardHidden[descObj.ObjSubType] and descObj.ObjSubType <= 80 then table.insert(callbacks, BlankCardCallback) end
if collectiblesOwned[263] and runeIDs[descObj.ObjSubType] then table.insert(callbacks, ClearRuneCallback) end if EID.collectiblesOwned[263] and runeIDs[descObj.ObjSubType] then table.insert(callbacks, ClearRuneCallback) end
-- Pill Callbacks -- Pill Callbacks
elseif descObj.ObjVariant == PickupVariant.PICKUP_PILL then elseif descObj.ObjVariant == PickupVariant.PICKUP_PILL then
if collectiblesOwned[654] then table.insert(callbacks, FalsePHDCallback) end if EID.collectiblesOwned[654] then table.insert(callbacks, FalsePHDCallback) end
if collectiblesOwned[348] then table.insert(callbacks, PlaceboCallback) end if EID.collectiblesOwned[348] then table.insert(callbacks, PlaceboCallback) end
-- Trinket Callbacks -- Trinket Callbacks
elseif descObj.ObjVariant == PickupVariant.PICKUP_TRINKET then elseif descObj.ObjVariant == PickupVariant.PICKUP_TRINKET then
-- Golden Trinket / Mom's Box -- Golden Trinket / Mom's Box
isGolden = (descObj.ObjSubType > TrinketType.TRINKET_GOLDEN_FLAG) isGolden = (descObj.ObjSubType > TrinketType.TRINKET_GOLDEN_FLAG)
hasBox = collectiblesOwned[439] hasBox = EID.collectiblesOwned[439]
if isGolden or hasBox then table.insert(callbacks, GoldenTrinketCallback) end if isGolden or hasBox then table.insert(callbacks, GoldenTrinketCallback) end
end end
@@ -471,7 +479,7 @@ local function EIDConditionsAB(descObj)
-- currently, only pickup descriptions have modifiers -- currently, only pickup descriptions have modifiers
if descObj.ObjType ~= 5 then return false end if descObj.ObjType ~= 5 then return false end
CheckPlayersCollectibles() EID:CheckPlayersCollectibles()
local callbacks = {} local callbacks = {}
@@ -480,8 +488,8 @@ local function EIDConditionsAB(descObj)
if EID:requiredForCollectionPage(descObj.ObjSubType) then table.insert(callbacks, ItemCollectionPageCallback) end if EID:requiredForCollectionPage(descObj.ObjSubType) then table.insert(callbacks, ItemCollectionPageCallback) end
if EID.Config["DisplayVoidStatInfo"] then if EID.Config["DisplayVoidStatInfo"] then
if collectiblesOwned[477] then table.insert(callbacks, VoidCallback) end if EID.collectiblesOwned[477] then table.insert(callbacks, VoidCallback) end
if blackRuneOwned then table.insert(callbacks, BlackRuneCallback) end if EID.blackRuneOwned then table.insert(callbacks, BlackRuneCallback) end
end end
end end
@@ -489,8 +497,9 @@ local function EIDConditionsAB(descObj)
end end
EID:addDescriptionModifier("EID Afterbirth+", EIDConditionsAB, nil) EID:addDescriptionModifier("EID Afterbirth+", EIDConditionsAB, nil)
-- should this be done differently so that mods can add tab previews?
local function TabConditions(descObj) local function TabConditions(descObj)
if EID.player and Input.IsActionPressed(ButtonAction.ACTION_MAP, EID.player.ControllerIndex) and not inPreview then return true end if EID.player and Input.IsActionPressed(ButtonAction.ACTION_MAP, EID.player.ControllerIndex) and not EID.inModifierPreview then return true end
return false return false
end end