# Duality (COLLECTIBLE_DUALITY = 498 / 0x1f2): both deal doors Only one code test of 0x1f2 matters for the rooms: `Room::TrySpawnDevilRoomDoor 0x7f83b0` (`PlayerManager::FirstCollectibleOwner(0x1f2)`); the other is the stat HUD (`FUN_0084c170`, StatHUD, see notes/systems/rep_screen_3.md: devil = angel row = the whole chance, merged icon). ## TrySpawnDevilRoomDoor 0x7f83b0 (isAnimate, isForce) Called from `Room::TriggerClear 0x8068f0` and `Level::load_room 0x73e0a0` (a cleared room with descriptor flag 1, not on Greed difficulties 2/3, with `isAnimate = 0, isForce = 0`), so it runs again on every revisit of the boss room. 1. Unforced: `Level::CanSpawnDevilRoom` and the current room is `_lastBossRoomListIdx`, else 0. 2. Unforced: a draw of `_devilAngelRoomRNG` (shifts 2, 21, 9; seed NOT advanced) >= `GetDevilRoomChance` (and the chance < 1) sets `_devilRoomDisabled` (Game+9) and returns 0. 3. **Duality**: an owner of 0x1f2 and the deal room not made (`roomList[0x1fb].Data == null`, roomList index 507 = GRIDINDEX -1, only in dimensions 0..2): - an RNG on the boss room descriptor's seed (+0x58), shifts (2, 5, 0x15); `RandomInt(8)` gives a start slot; slots `(start + i) & 7` for i in 0..7 that the room's shape allows (Data+0x38 door mask) with no door yet are collected; with **more than one**, `RNG::Shuffle` them and take the first two: - `MakeDoor` if needed; door 0 gets `SetRoomTypes(door, 1, 14)` (devil), door 1 `SetRoomTypes(door, 1, 15)` (angel); with Rosary Bead (TRINKET 7, `AnyoneHasTrinket`) door 0 is the angel one and door 1 the devil one (`isAngelDoorPlaced`). Both get `_targetRoomIdx` (+0x394) = -1 and `GridEntity_Door::Open`. - isAnimate: 5..8 dust clouds (1000.59) per door, then sounds 320 (`satan room appear`) and 23 (`choir`) both. - `_lastDevilRoomStage = clamp(stage (+1 on stage types 4/5), 0, 13)`; returns 1. - It does NOT call InitializeDevilAngelRoom, does NOT set game flags 1/0x20, does NOT advance `_devilAngelRoomRNG`: the deal room stays unmade. - fewer than two free slots: falls through to the normal path. 4. Normal path: `Level::InitializeDevilAngelRoom(anyone has Rosary Bead, 0)` (returns at once if the room is made), one door of the made room's type (Data+8: 14 sets game flag 0x20, 15 sets flag 1), at the door Isaac came back by from the deal room or a seeded slot whose opposite the deal room has; advances `_devilAngelRoomRNG`. ## Room::update_door_transitions 0x7f01c0: the door taken decides Walking through a door with `_targetRoomIdx == -1` while `roomList[0x1fb].Data == null` (after `Game::save_rewind_state`): `Level::InitializeDevilAngelRoom(door._targetRoomType (+0x160) == 15, door._targetRoomType != 15)`, then game flag 1 (angel) or 0x20 (devil). So Duality's deal room is made only as Isaac takes one of the two doors, of that door's kind; the room is made, so on the next load of the boss room step 3 is skipped and step 4 gives the single door of the made room's kind (the other door is gone). ## Level::InitializeDevilAngelRoom 0x7499a0 (ForceAngel, ForceDevil) Returns if Data is set. Draws `_devilAngelRoomRNG` against `get_angel_room_chance` always (forced or not); angel = roll or ForceAngel; ForceDevil makes it a devil room whatever the roll (subtype 1 with trinket 0xae). Other callers: `Level::QueryRoomTypeIndex 0x7484c0` (types 14/15: InitializeDevilAngelRoom(0, 0), returns -1: a teleport into the deal room makes it by the plain roll), `Entity_Pickup::TryOpenChest`, `GridEntity::hurt_func`, `Entity_Player::Update`. ## isaac-classic port (items/duality) - One deal room slot suffices, as in Rep+: `DevilDealState::pairDoors` holds the two door slots while the room is unmade; `RoomDoors::deal_pair_place` places them (shuffled free slots, the hidden deal door's slot counted free); `Game::deal_room_init` = InitializeDevilAngelRoom (draw, forced kinds, flags), called by the door spawn (no Duality / one free slot), by the door transit (Game::is_room_moved, forced by the door's kind), by teleports (QueryRoomTypeIndex) and on re-entering the boss room with Duality gone. - Not ported: the dust clouds and sound 320 (the port's single deal door plays neither; the pair plays the angel door's reveal as an angel door does).