#include "entity_player_trinkets.h" #include "active_items.h" #include "boss_ai.h" #include "entity_effect.h" #include "entity_familiar.h" #include "entity_pickup.h" #include "entity_player.h" #include "game.h" #include "grid_entity.h" #include "grid_entity_poop.h" #include "hud.h" #include "item_config.h" #include "item_pickup.h" #include "item_pool.h" #include "level.h" #include "log.h" #include "manager.h" #include "npc_ai.h" #include "npc_basement.h" #include "room.h" #include "room_config.h" #include "room_grid.h" #include "room_transition.h" #include "sfx_manager.h" #include #include #include // The trinkets' constants: Rosary Bead's Bible chance, the battery trinkets' achievement, Wooden Cross's mantles // counted in the high half of the mantle stacks, Mother's Kiss's hearts and Lil Clot's clots. constexpr int ROSARY_BIBLE_CHANCE = 5; constexpr int BATTERY_ITEMS_FOR_UNLOCK = 2; constexpr int ACHIEVEMENT_BATTERY_PACK = 367; constexpr int WOODEN_CROSS_MANTLES_MAX = 2; constexpr int MANTLE_STACK_LOW = 0xf; constexpr int MANTLE_STACK_HIGH_SHIFT = 4; constexpr int MOTHERS_KISS_HEARTS = 2; constexpr int MOMS_TOENAIL_STOMPS_MAX = 3; constexpr int CLOT_SUBTYPE = 7; constexpr float CLOT_LAUNCH_SPEED = 2; constexpr float CLOT_POOF_RISE = -6; constexpr float CLOT_POOF_DEPTH = 10; constexpr int PICKUP_COLLISION_COOLDOWN = 4; constexpr int ROOM_TRINKET_ODDS = 4; constexpr float GAIN_PICKUP_STEP = 40; constexpr int BRITTLE_BONES_HEARTS = 6; constexpr int BOOSTER_PACK_CARDS = 5; constexpr int BOOSTER_SPECIAL_FIRST = 15; constexpr int BOOSTER_SPECIAL = 25; constexpr int BOOSTER_SUIT_FIRST = 1; constexpr int BOOSTER_SUIT = 5; // Whether a trinket stays in its slot when a new one is picked up: the Tick, and Rainbow Worm in Pride Day (in a // versus match every trinket, when its rules keep them). static bool is_trinket_stuck(uint32_t trinket) { DeathmatchManager& versus = g_game->deathmatchManager; if (versus.is_active()) return !versus.type->is_trinket_swap_allowed(); return trinket == TRINKET_TICK || (trinket == TRINKET_RAINBOW_WORM && g_game->challenge == CHALLENGE_PRIDE_DAY); } // 007716c0 Whether a trinket burns the Tick away when picked up: Match Stick and Lighter. static bool is_tick_burner(int trinketId) { int id = trinketId & TRINKET_ID_MASK; return id == TRINKET_MATCH_STICK || id == TRINKET_LIGHTER; } // The Holy Mantles Wooden Cross lends a player: one per copy up to two, less those the player's own mantles cover. static int wooden_cross_mantles_kept(Entity_Player& player) { int crosses = std::min(player.GetTrinketMultiplier(TRINKET_WOODEN_CROSS), WOODEN_CROSS_MANTLES_MAX); return std::max(crosses - (player.holyMantleStacks & MANTLE_STACK_LOW), 0); } // 007db0a0 Wooden Cross lends a Holy Mantle effect, counted in the high half of the mantle stacks. void wooden_cross_mantle_add(Entity_Player& player) { if (wooden_cross_mantles_kept(player) == 0) return; if (ItemConfig_Item* mantle = g_manager->itemConfig.GetCollectible(COLLECTIBLE_HOLY_MANTLE)) player.temporaryEffects.AddEffect(TemporaryEffect(mantle), true, 1); uint8_t stacks = player.holyMantleStacks; player.holyMantleStacks = (uint8_t)(((stacks & ~MANTLE_STACK_LOW) + (1 << MANTLE_STACK_HIGH_SHIFT)) | (stacks & MANTLE_STACK_LOW)); } // 007db160 Takes back the Holy Mantle effects Wooden Cross lent beyond what the trinkets left still lend. The costume // goes with each one unless a mantle effect is still on. void Entity_Player::remove_wooden_cross_mantles() { ItemConfig_Item* mantle = g_manager->itemConfig.GetCollectible(COLLECTIBLE_HOLY_MANTLE); int kept = wooden_cross_mantles_kept(*this); int lent = holyMantleStacks >> MANTLE_STACK_HIGH_SHIFT; for (; lent > kept; lent--) { if (mantle) temporaryEffects.RemoveEffect(mantle, 1); if (!temporaryEffects.isDisabled && temporaryEffects.GetCollectibleEffectNum(COLLECTIBLE_HOLY_MANTLE) > 0) continue; RemoveCostume(mantle); } holyMantleStacks = (uint8_t)((holyMantleStacks & MANTLE_STACK_LOW) | (lent << MANTLE_STACK_HIGH_SHIFT)); } // 00771620 Whether the player holds the trinket golden, in a slot or smelted, or previews it golden. bool Entity_Player::HasGoldenTrinket(uint32_t trinketId) { for (int i = 0; i < GetMaxTrinkets(); i++) if ((trinkets[i] & TRINKET_ID_MASK) == trinketId && (trinkets[i] & TRINKET_GOLDEN_FLAG)) return true; if (trinketId < smeltedTrinkets.size() && smeltedTrinkets[trinketId].goldenCount > 0) return true; return (previewTrinket & TRINKET_ID_MASK) == trinketId && (previewTrinket & TRINKET_GOLDEN_FLAG); } // 007716f0 Whether the player can take a trinket: a free slot, or one holding a trinket that may be swapped out. The // Tick (and Rainbow Worm in Pride Day) stay unless the new trinket burns the Tick. bool Entity_Player::TryHoldTrinket(int trinketId) { for (int i = 0; i < GetMaxTrinkets(); i++) { uint32_t held = trinkets[i]; bool isBurningTick = (held & TRINKET_ID_MASK) == TRINKET_TICK && is_tick_burner(trinketId); if (held == 0 || !is_trinket_stuck(held) || isBurningTick) return true; } return false; } // Mom's Toenail dropped in a room still fighting: Mom stomps the cell it landed on (the top left corner when off the // grid), once per multiplier, a second apart. static void moms_toenail_stomp(Vector position, int stomps) { constexpr int STOMP_DELAY_STEP = 30; Room& room = *g_game->room; Vector cell = room.GetGridPosition(room.GetGridIndex(position)); for (int i = 0; i < stomps; i++) { uint32_t seed = Random(); auto* stomp = static_cast(g_game->Spawn({.position = cell, .subType = i * STOMP_DELAY_STEP, .type = ENTITY_EFFECT, .variant = EFFECT_MOM_FOOT_STOMP, .seed = seed})); stomp->targetPosition = cell; stomp->Update(); } } // 00771800 Drops the first trinket that may go (the Tick only to a trinket that burns it, with a sizzle), the next // slot moving up: it lands as a pickup at the position for a main player, its pickup effect undone and its costume // off unless its effect wears it. Butter plays its sound, and Mom's Toenail brings Mom's stomps in a fight. The stats // are evaluated. The dropped pickup, if any. Entity_Pickup* Entity_Player::DropTrinket(Vector position, bool isReplaceTick) { FlushQueueItem(); int slot = -1; for (int i = 0; i < TRINKET_SLOT_COUNT && trinkets[i] != 0; i++) { bool isKept = is_trinket_stuck(trinkets[i]) && !((trinkets[i] & TRINKET_ID_MASK) == TRINKET_TICK && isReplaceTick); if (!isKept) { slot = i; break; } } auto tick = std::ranges::find(trinkets, (uint32_t)TRINKET_TICK); if (isReplaceTick && tick != trinkets.end()) { sound_play(SOUND_TICK_BURN); slot = (int)(tick - trinkets.begin()); } if (slot < 0) { if (cacheFlags) EvaluateItems(); return nullptr; } uint32_t dropped = trinkets[slot]; uint32_t id = dropped & TRINKET_ID_MASK; int stomps = id == TRINKET_MOMS_TOENAIL ? std::min(GetTrinketMultiplier(TRINKET_MOMS_TOENAIL), MOMS_TOENAIL_STOMPS_MAX) : 0; if (slot == 0) trinkets[0] = trinkets[1]; trinkets[TRINKET_SLOT_COUNT - 1] = 0; ItemConfig_Item* trinket = g_manager->itemConfig.GetTrinket(id); if (trinket) cacheFlags |= trinket->cacheFlags; Entity_Pickup* pickup = nullptr; if (variant == PLAYER_VARIANT_PLAYER) { pickup = static_cast(g_game->Spawn({.position = position, .spawner = this, .subType = (int)dropped, .type = ENTITY_PICKUP, .variant = PICKUP_TRINKET, .seed = Random()})); pickup->collisionCooldown = PICKUP_COLLISION_COOLDOWN; pickup->isTouched = true; } TriggerTrinketRemoved(dropped); if (trinket) { bool isEffectWorn = !trinket->isAddCostumeOnPickup && !temporaryEffects.isDisabled && std::ranges::any_of(temporaryEffects.effects, [&](const TemporaryEffect& effect) { return effect.item->type == ITEM_TRINKET && (uint32_t)effect.item->id == dropped; }); if (!isEffectWorn) RemoveCostume(trinket); } if (id == TRINKET_BUTTER) sound_play(SOUND_BUTTER_DROP); else if (id == TRINKET_MOMS_TOENAIL && !(g_game->room->descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR) && pickup) moms_toenail_stomp(pickup->pos, stomps); if (cacheFlags) EvaluateItems(); return pickup; } // 00771d30 Puts a trinket in the first free slot (two with Mom's Purse or Belly Button), wearing its costume, then // sets off its pickup effect. Three battery items held unlock an achievement. A helper player drops it at once. void Entity_Player::AddTrinket(int type, bool isFirstTime) { ItemConfig_Item* trinket = g_manager->itemConfig.GetTrinket(type & TRINKET_ID_MASK); if (!trinket) return; if (trinket->isAddCostumeOnPickup) AddCostume(trinket, false); for (int i = 0; i < GetMaxTrinkets(); i++) { if (trinkets[i] != 0) continue; cacheFlags |= trinket->cacheFlags; trinkets[i] = (uint32_t)type; break; } log_printf(LOG_INFO, "Adding trinket %d (%s) to player %d (%s)\n", type, trinket->GetLocalizedName(LANGUAGE_CURRENT).c_str(), playerIndex, name.c_str()); TriggerTrinketAdded((uint32_t)type, isFirstTime); if (variant == PLAYER_VARIANT_PLAYER && !isCoopGhost) { if (ItemConfig::is_trinket_tagged((uint32_t)type, TAG_BATTERY) && tagged_item_count(TAG_BATTERY) > BATTERY_ITEMS_FOR_UNLOCK) g_manager->persistentGameData.TryUnlock(ACHIEVEMENT_BATTERY_PACK); InvalidateCoPlayerItems(); } HUD& hud = g_game->hud; if (hud.hudRefreshType != HUD_REFRESH_FULL) { hud.hudRefreshType = HUD_REFRESH_PLAYER; hud.hudRefreshCountdown = 2; } if (parent) DropTrinket(pos, true); } // The end of 007ad860 and 007adb30: the stats the trinket touches are evaluated with the next frame. static void trinket_cache_add(Entity_Player& player, uint32_t id) { ItemConfig_Item* trinket = g_manager->itemConfig.GetTrinket(id); if (!trinket || trinket->cacheFlags == 0) return; player.cacheFlags |= trinket->cacheFlags; player.temporaryEffects.isEvaluateCachePending = true; } // 007ad860 What picking a trinket up changes at once: the Bible's chance, the transformations it counts for, Duct // Tape's mode, Wooden Cross's mantles, Mother's Kiss's hearts, Gilded Key's key, Lil Clot's clots and the versus // trinkets. The trinket's stats are evaluated with the next frame. void Entity_Player::TriggerTrinketAdded(uint32_t trinketId, bool isFirstTime) { Game& game = *g_game; if (variant != PLAYER_VARIANT_PLAYER) return; bool isGolden = trinketId & TRINKET_GOLDEN_FLAG; uint32_t id = trinketId & TRINKET_ID_MASK; bool isVersus = game.deathmatchManager.is_active(); switch (id) { case TRINKET_ROSARY_BEAD: game.itemPool.pools[POOL_LIBRARY].bibleUpgrade += ROSARY_BIBLE_CHANCE; game.itemPool.pools[POOL_SHOP].bibleUpgrade += ROSARY_BIBLE_CHANCE; break; case TRINKET_MISSING_PAGE: IncrementPlayerFormCounter(PLAYER_FORM_NECROMANCER, 1); break; case TRINKET_BOBS_BLADDER: IncrementPlayerFormCounter(PLAYER_FORM_BOB, 1); break; case TRINKET_DUCT_TAPE: if (GetTrinketMultiplier(TRINKET_DUCT_TAPE) > 1 && ductTapeMode == 0) ductTapeMode = 1; break; case TRINKET_WOODEN_CROSS: wooden_cross_mantle_add(*this); if (isGolden || HasCollectible(COLLECTIBLE_MOMS_BOX)) wooden_cross_mantle_add(*this); break; case TRINKET_BROKEN_SYRINGE: if (isVersus) add_random_drug_item_effect(); break; case TRINKET_DEVILS_CROWN: Level::update_treasure_room_doors_for_trinket(); break; case TRINKET_MOMS_LOCK: if (isVersus) AddRandomMomItemEffect(); break; case TRINKET_MOTHERS_KISS: update_greeds_gullet(); if (isFirstTime) AddHearts(isGolden ? MOTHERS_KISS_HEARTS * 2 : MOTHERS_KISS_HEARTS, false, false); break; case TRINKET_MODELING_CLAY: if (isVersus) ModelingClay_roll(&trinketRNGs[TRINKET_MODELING_CLAY]); break; case TRINKET_KIDS_DRAWING: IncrementPlayerFormCounter(PLAYER_FORM_GUPPY, isGolden ? 2 : 1); break; case TRINKET_LIL_CLOT: spawn_lil_clot_familiars(); break; case TRINKET_THE_TWINS: if (isVersus) twins_duplicate_familiars(1); break; } if (isFirstTime && trinketId == TRINKET_GILDED_KEY) AddKeys(1); trinket_cache_add(*this, id); } // 007adb30 What losing a trinket changes at once, undoing its pickup: the Bible's chance, the transformations, Wooden // Cross's mantles, Modeling Clay's copied item and the versus trinkets' effects. The stats are evaluated with the next // frame. void Entity_Player::TriggerTrinketRemoved(uint32_t trinketId) { Game& game = *g_game; if (variant != PLAYER_VARIANT_PLAYER) return; uint32_t id = trinketId & TRINKET_ID_MASK; bool isVersusLost = game.deathmatchManager.is_active() && !HasTrinket(trinketId); switch (id) { case TRINKET_ROSARY_BEAD: game.itemPool.pools[POOL_LIBRARY].bibleUpgrade -= ROSARY_BIBLE_CHANCE; game.itemPool.pools[POOL_SHOP].bibleUpgrade -= ROSARY_BIBLE_CHANCE; break; case TRINKET_MISSING_PAGE: IncrementPlayerFormCounter(PLAYER_FORM_NECROMANCER, -1); break; case TRINKET_BOBS_BLADDER: IncrementPlayerFormCounter(PLAYER_FORM_BOB, -1); break; case TRINKET_WOODEN_CROSS: if (HasTrinket(TRINKET_WOODEN_CROSS)) break; remove_wooden_cross_mantles(); if (HasCollectible(COLLECTIBLE_MOMS_BOX)) remove_wooden_cross_mantles(); break; case TRINKET_BROKEN_SYRINGE: case TRINKET_MOMS_LOCK: { int& lent = id == TRINKET_BROKEN_SYRINGE ? versus.drugEffect : versus.momEffect; if (!isVersusLost || lent == 0) break; temporaryEffects.RemoveCollectibleEffect(lent, 1); lent = 0; break; } case TRINKET_THE_TWINS: if (!isVersusLost) break; for (int lent : versus.twinsEffects) if (g_manager->itemConfig.GetCollectible(lent)) temporaryEffects.RemoveCollectibleEffect(lent, 1); versus.twinsEffects.clear(); break; case TRINKET_DEVILS_CROWN: Level::update_treasure_room_doors_for_trinket(); break; case TRINKET_MOTHERS_KISS: update_greeds_gullet(); break; case TRINKET_MODELING_CLAY: { if (HasTrinket(trinketId)) break; int copied = modelingClayEffect; modelingClayEffect = 0; if (copied == 0) break; if (ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(copied)) { cacheFlags |= item->cacheFlags; temporaryEffects.isEvaluateCachePending = true; } TryRemoveCollectibleCostume(copied, false); break; } case TRINKET_KIDS_DRAWING: IncrementPlayerFormCounter(PLAYER_FORM_GUPPY, trinketId & TRINKET_GOLDEN_FLAG ? -2 : -1); break; } trinket_cache_add(*this, id); } // 007ad3a0 Takes a trinket's costume off, unless the trinket wears it only while its effect lasts and that is on. void Entity_Player::TryRemoveTrinketCostume(int trinketId) { ItemConfig_Item* trinket = g_manager->itemConfig.GetTrinket(trinketId & TRINKET_ID_MASK); if (!trinket) return; if (!trinket->isAddCostumeOnPickup && temporaryEffects.HasTrinketEffect(trinketId)) return; RemoveCostume(trinket); } // 00772260 Takes back one smelted copy of a trinket, a plain one first unless the id asks for a golden one, with its // history entry, and its costume once none is left. bool Entity_Player::TryRemoveSmeltedTrinket(uint32_t trinketId) { if (variant == PLAYER_VARIANT_PLAYER && !isCoopGhost) InvalidateCoPlayerItems(); uint32_t id = trinketId & TRINKET_ID_MASK; ItemConfig_Item* trinket = g_manager->itemConfig.GetTrinket(id); if (!trinket) { log_printf(LOG_WARN, "Tried to remove smelted trinket with invalid trinket type (%d) \n", trinketId); return false; } SmeltedTrinket& smelted = smeltedTrinkets[id]; bool isPlain = !(trinketId & TRINKET_GOLDEN_FLAG) && smelted.count > 0; if (!isPlain && smelted.goldenCount < 1) return false; uint32_t removed = isPlain ? id : id | TRINKET_GOLDEN_FLAG; log_printf(LOG_INFO, "Removing smelted trinket %d (%s) from player %d (%s)\n", removed, trinket->GetLocalizedName(LANGUAGE_CURRENT).c_str(), playerIndex, name.c_str()); if (isPlain) smelted.count--; else smelted.goldenCount--; TriggerTrinketRemoved(removed); history_item_remove(history, {.time = g_game->frameCount, .isTrinket = true, .id = (int)removed}); if (smelted.count < 1 && smelted.goldenCount < 1) TryRemoveTrinketCostume((int)id); return true; } // 00771f60 Takes a trinket away: the queued one, else from its slot (the next slot moving up) with its costume unless // its effect still wears it, else a smelted copy. A helper player gives back the glitched item standing for it. bool Entity_Player::TryRemoveTrinket(uint32_t trinketId) { uint32_t id = trinketId & TRINKET_ID_MASK; ItemConfig_Item* trinket = g_manager->itemConfig.GetTrinket(id); if (!trinket) return false; bool isMain = variant == PLAYER_VARIANT_PLAYER && !isCoopGhost; if (isMain) InvalidateCoPlayerItems(); if (queuedItem.item && queuedItem.item == trinket) { ClearQueueItem(); return true; } int slots = GetMaxTrinkets(); for (int i = 0; i < slots; i++) { if (trinkets[i] != trinketId && (trinkets[i] & TRINKET_ID_MASK) != trinketId) continue; std::shift_left(trinkets.begin() + i, trinkets.begin() + slots, 1); trinkets[slots - 1] = 0; log_printf(LOG_INFO, "Removing trinket %d (%s) from player %d (%s)\n", trinketId, trinket->GetLocalizedName(LANGUAGE_CURRENT).c_str(), playerIndex, name.c_str()); TriggerTrinketRemoved(trinketId); bool isEffectWorn = !trinket->isAddCostumeOnPickup && !temporaryEffects.isDisabled && std::ranges::any_of(temporaryEffects.effects, [&](const TemporaryEffect& effect) { return effect.item->type == ITEM_TRINKET && (uint32_t)effect.item->id == trinketId; }); if (!isEffectWorn) RemoveCostume(trinket); return true; } if (isMain) return TryRemoveSmeltedTrinket(trinketId); int glitched = glitched_item_copying(*this, ITEM_TRINKET, (int)trinketId); if (glitched == 0) return false; RemoveCollectible(glitched, false, 0, true); return true; } // 007d83f0 Lil Clot's clots: one per copy of the trinket, less those already following, each launched in a random // direction from a poof of blood with a squish. void Entity_Player::spawn_lil_clot_familiars() { if (!HasTrinket(TRINKET_LIL_CLOT)) return; int multiplier = GetTrinketMultiplier(TRINKET_LIL_CLOT); int clots = (int)std::ranges::count_if(g_game->room->entityList.updateEL, [this](Entity* entity) { return entity->type == ENTITY_FAMILIAR && entity->variant == Entity_Familiar::BLOOD_BABY && entity->subtype == CLOT_SUBTYPE && static_cast(entity)->player == this; }); for (int i = clots; i < multiplier; i++) { uint32_t seed = Random(); float angle = random_unit() * PI_ROUGH; angle += angle; Vector velocity = vector_make(std::cos(angle) * CLOT_LAUNCH_SPEED, std::sin(angle) * CLOT_LAUNCH_SPEED); Entity* clot = g_game->Spawn({.position = pos, .velocity = velocity, .spawner = this, .subType = CLOT_SUBTYPE, .type = ENTITY_FAMILIAR, .variant = Entity_Familiar::BLOOD_BABY, .seed = seed}); clot->ClearEntityFlags(FLAG_APPEAR); clot->Update(); sound_play(SOUND_MEAT_JUMPS); Entity* poof = g_game->Spawn({.position = pos, .subType = 2, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_EXPLOSION, .seed = Random()}); poof->SetColor(clot->splatColor, -1, 0xff, false, true); poof->sprite.offset = vector_make(0, CLOT_POOF_RISE); poof->renderDepthOffset = CLOT_POOF_DEPTH; poof->Update(); } } // The trinket part of 006e8ae0: a player not holding an item up who can take the trinket sees its name, drops the // trinket it swaps out (or the Tick a Match Stick or Lighter burns) as dropped, and holds the new one up, golden or not, // until it is added. Whether it was taken. bool trinket_collect(Entity_Pickup& pickup, Entity_Player& player, Entity_Pickup*& dropped) { int id = pickup.subtype; if (player.IsHoldingItem() || player.parent || !player.TryHoldTrinket(id)) return false; ItemConfig_Item* trinket = g_manager->itemConfig.GetTrinket(id); if (trinket) item_text_show(g_game->hud, &player, trinket); int slots = player.GetMaxTrinkets(); bool isTickHeld = std::ranges::any_of(player.trinkets.begin(), player.trinkets.begin() + slots, [](uint32_t held) { return (held & TRINKET_ID_MASK) == TRINKET_TICK; }); bool isTickBurnt = isTickHeld && is_tick_burner(id); bool isFull = player.trinkets[0] != 0 && (slots < 2 || player.trinkets[1] != 0); if (isFull || isTickBurnt) dropped = player.DropTrinket(player.pos, isTickBurnt); uint32_t flags = pickup.isTouched ? QUEUED_TOUCHED : 0; if (id & TRINKET_GOLDEN_FLAG) flags |= QUEUED_GOLDEN; player.SetQueuedItem({.item = g_manager->itemConfig.GetTrinket(id), .flags = flags, .itemPoolType = POOL_NONE}); return true; } // The free trinket's end of 006e8ae0: it sparkles over the player's head as they lift it, and the pickup goes. void trinket_lift(Entity_Pickup& pickup, Entity_Player& player) { pickup.sprite.Play("PlayerPickupSparkle"); player.AnimatePickup(&pickup.sprite, false, "Pickup"); pickup.Remove(); pickup.UpdateLootPreview(); } // Equality's part of 00782af0: a main player keeps the trinket's effect while bombs, coins and keys are equal, the // tears evaluated whenever it is checked. void equality_update(Entity_Player& player) { if (player.variant != PLAYER_VARIANT_PLAYER || player.isDead) return; TemporaryEffects& effects = player.temporaryEffects; bool isEqual = player.HasTrinket(TRINKET_EQUALITY) && player.numBombs == player.numCoins && player.numCoins == player.numKeys; if (isEqual == effects.HasTrinketEffect(TRINKET_EQUALITY)) return; if (isEqual) effects.AddTrinketEffect(TRINKET_EQUALITY, true, 1); else effects.RemoveTrinketEffect(TRINKET_EQUALITY, 1); player.cacheFlags |= CACHE_FIREDELAY; player.EvaluateItems(); } // Where a Cursed Penny teleport may lead: the room types it draws from, the special rooms it adds, and whether cleared // (visited) and uncleared (unvisited) rooms count. struct PennyTeleport { std::vector roomTypes; std::vector rooms; bool isClearedAllowed = false; bool isUnclearedAllowed = false; }; // The ordinary rooms most coins send to, with the Isaac's rooms and the extra ones some add after them. constexpr int PENNY_ROOMS[] = {ROOM_DEFAULT, ROOM_SHOP, ROOM_TREASURE, ROOM_BOSS, ROOM_MINIBOSS, ROOM_SECRET, ROOM_SUPERSECRET, ROOM_ARCADE, ROOM_CHALLENGE, ROOM_LIBRARY, ROOM_SACRIFICE}; // The rooms a coin's Cursed Penny teleport may lead to, rolled by the coin (a penny, a nickel, a dime, a double, a // lucky, a sticky or a golden one): better rooms the more Cursed Pennies (25 or 50 more in 100). A dime may open the // devil or the angel room, others the error room or the black market. static PennyTeleport penny_teleport_roll(int coin, int bonus, RNG& rng) { auto rooms = [](std::initializer_list extra) { std::vector types(std::begin(PENNY_ROOMS), std::end(PENNY_ROOMS)); types.insert(types.end(), extra); return types; }; PennyTeleport teleport; teleport.isClearedAllowed = coin >= 2 && coin <= 7; teleport.isUnclearedAllowed = coin >= 1 && coin <= 7; uint32_t roll = coin >= 1 && coin <= 7 ? rng.RandomInt(100) : 0; switch (coin) { case 1: if (roll < (uint32_t)bonus + 50) teleport.roomTypes = {ROOM_DEFAULT}; else { teleport.isClearedAllowed = true; teleport.roomTypes = rooms({ROOM_CHEST, ROOM_DICE, ROOM_BLACK_MARKET, ROOM_PLANETARIUM, ROOM_ISAACS}); } break; case 2: teleport.roomTypes = roll < (uint32_t)bonus + 50 ? std::vector{ROOM_SHOP, ROOM_TREASURE, ROOM_ARCADE, ROOM_CHALLENGE, ROOM_LIBRARY, ROOM_PLANETARIUM} : std::vector{ROOM_DEFAULT, ROOM_BOSS, ROOM_MINIBOSS, ROOM_SECRET, ROOM_SUPERSECRET, ROOM_SACRIFICE, ROOM_CHEST, ROOM_DICE, ROOM_BLACK_MARKET, ROOM_ISAACS}; break; case 3: if (roll < (uint32_t)bonus + 25) { bool isAngel = rng.RandomInt(100) < 50; g_game->InitializeDevilAngelRoom(isAngel, !isAngel); teleport.rooms = {ROOM_DEVIL_IDX}; break; } teleport.roomTypes = rooms({ROOM_CURSE, ROOM_CHEST, ROOM_DICE, ROOM_PLANETARIUM, ROOM_ISAACS}); teleport.rooms = {ROOM_ERROR_IDX, ROOM_BLACK_MARKET_IDX}; break; case 4: if (roll < (uint32_t)bonus + 50) teleport.roomTypes = {ROOM_CHEST, ROOM_DICE, ROOM_ISAACS}; else { teleport.roomTypes = rooms({ROOM_PLANETARIUM, ROOM_SECRET, ROOM_SUPERSECRET}); teleport.rooms = {ROOM_BLACK_MARKET_IDX}; } break; case 5: if (roll < (uint32_t)bonus + 50) teleport.roomTypes = {ROOM_SECRET, ROOM_SUPERSECRET}; else { teleport.roomTypes = rooms({ROOM_CHEST, ROOM_DICE, ROOM_PLANETARIUM, ROOM_ISAACS}); teleport.rooms = {ROOM_BLACK_MARKET_IDX}; } break; case 6: teleport.roomTypes = {roll < 50 ? ROOM_CURSE : ROOM_BOSS}; break; case 7: if (roll < (uint32_t)bonus + 10) teleport.rooms = {ROOM_ERROR_IDX}; else { teleport.roomTypes = rooms({ROOM_PLANETARIUM, ROOM_SECRET, ROOM_SUPERSECRET, ROOM_CHEST, ROOM_DICE, ROOM_ISAACS}); teleport.rooms = {ROOM_BLACK_MARKET_IDX}; } break; } return teleport; } // The floor's rooms in the current dimension of the rolled types, each cell once: a cleared one when cleared rooms // count, an uncleared one when those do, and only when a visited room's (or an unvisited room's) kind counts too. static void penny_rooms_add(PennyTeleport& teleport) { Game& game = *g_game; std::set seen; for (int index = 0; index < game.nbRooms; index++) { RoomDescriptor& room = game.roomList[index]; if (!room.data || room.dimension != game.currentDimensionIdx) continue; if (std::ranges::find(teleport.roomTypes, room.data->type) == teleport.roomTypes.end()) continue; if (!seen.insert(room.gridIndex).second) continue; bool isClear = room.flags & ROOM_DESCRIPTOR_FLAG_CLEAR; bool isAllowed = isClear ? teleport.isClearedAllowed : teleport.isUnclearedAllowed; bool isVisitAllowed = room.visitedCount != 0 ? teleport.isClearedAllowed : teleport.isUnclearedAllowed; if (isAllowed && isVisitAllowed) teleport.rooms.push_back(room.gridIndex); } } // Cursed Penny's teleport after a coin: to a random room of the coin's roll (a sticky coin's curse room falling back // on the boss room), else as Teleport! does. static void cursed_penny_teleport(Entity_Player& player) { RNG& rng = player.GetTrinketRNG(TRINKET_CURSED_PENNY); int copies = player.GetTrinketMultiplier(TRINKET_CURSED_PENNY); int bonus = copies == 2 ? 25 : copies == 3 ? 50 : 0; PennyTeleport teleport = penny_teleport_roll(player.cursedPennyPending, bonus, rng); penny_rooms_add(teleport); int target = teleport.rooms.empty() ? 0 : teleport.rooms[rng.RandomInt((uint32_t)teleport.rooms.size())]; if (player.cursedPennyPending == 6 && teleport.roomTypes.front() == ROOM_CURSE && target == 0) target = g_game->QueryRoomTypeIndex(ROOM_BOSS, false, rng, false); if (target == 0) { int item = player.GetTrinketMultiplier(TRINKET_BROKEN_REMOTE) <= 1 ? COLLECTIBLE_TELEPORT : COLLECTIBLE_TELEPORT_2; player.UseActiveItem({.item = item, .flags = USE_NOANIM}); return; } g_game->leaveDoor = -1; g_game->StartRoomTransition({.player = &player, .animation = TRANSITION_TELEPORT, .roomIndex = target}); } // Broken Remote's part of 00782af0: after an active used from the main slot the player teleports (Teleport 2.0's pick // with more than one copy). After a coin Cursed Penny teleports it. void trinket_teleports_update(Entity_Player& player) { Game& game = *g_game; if (player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) || game.roomTransition.is_active() || game.stageTransition.state != STAGE_TRANSITION_NONE) return; if (player.isBrokenRemotePending) { int item = player.GetTrinketMultiplier(TRINKET_BROKEN_REMOTE) <= 1 ? COLLECTIBLE_TELEPORT : COLLECTIBLE_TELEPORT_2; player.UseActiveItem({.item = item, .flags = USE_NOANIM}); } else if (player.cursedPennyPending != 0) cursed_penny_teleport(player); player.isBrokenRemotePending = false; player.cursedPennyPending = 0; } // The odds a room trinket rolls with: one in four over its multiplier, sure once that rounds to none. static bool is_room_trinket_rolled(Entity_Player& player, int trinket) { int odds = ROOM_TRINKET_ODDS / player.GetTrinketMultiplier(trinket); return odds == 0 || Random() % (uint32_t)odds == 0; } // 007dbba0 Broken Syringe lends one of eight drug collectibles' effects for the room. The versus mode remembers which. void Entity_Player::add_random_drug_item_effect() { constexpr int DRUG_ITEMS[] = {13, 14, 240, 70, 143, 345, 493, 496}; int id = DRUG_ITEMS[GetTrinketRNG(TRINKET_BROKEN_SYRINGE).Next() & 7]; temporaryEffects.AddEffect(TemporaryEffect(g_manager->itemConfig.GetCollectible(id)), true, 1); if (g_game->deathmatchManager.is_active()) versus.drugEffect = id; } // 007dbc80 Mom's Lock lends one of Mom's thirteen collectibles' effects for the room. The versus mode remembers which. void Entity_Player::AddRandomMomItemEffect() { constexpr int MOM_ITEMS[] = {29, 30, 31, 55, 110, 114, 199, 200, 217, 228, 355, 508, 732}; int id = MOM_ITEMS[GetTrinketRNG(TRINKET_MOMS_LOCK).Next() % std::size(MOM_ITEMS)]; temporaryEffects.AddEffect(TemporaryEffect(g_manager->itemConfig.GetCollectible(id)), true, 1); if (g_game->deathmatchManager.is_active()) versus.momEffect = id; } // 007dbe70 Modeling Clay copies only summonable collectibles. static bool is_clay_copyable(ItemConfig_Item& item) { bool isCollectible = item.type == ITEM_PASSIVE || item.type == ITEM_ACTIVE || item.type == ITEM_FAMILIAR; return !isCollectible || item.HasTags(TAG_SUMMONABLE); } // 007dbd70 Modeling Clay copies a summonable collectible the room's pool draws for the room, wearing its costume. void Entity_Player::ModelingClay_roll(RNG* rng) { ItemConfig& items = g_manager->itemConfig; items.availabilityFilters.push_back(is_clay_copyable); modelingClayEffect = g_game->itemPool.GetSeededCollectible(rng->Next(), 1, *g_game->room->descriptor); items.availabilityFilters.pop_back(); ItemConfig_Item* copied = items.GetCollectible(modelingClayEffect); if (!copied) return; cacheFlags |= copied->cacheFlags; temporaryEffects.isEvaluateCachePending = true; if (copied->isAddCostumeOnPickup) AddCostume(copied, false); g_game->hud.mark_all_slots_dirty(HISTORY_KEEP_ICONS, HISTORY_KEEP_ITEMS); } // The first trinket part of 007a8350: Liberty Cap lends a mushroom's effect, Broken Syringe a drug's and Mom's Lock one // of Mom's items, each one time in four over its multiplier. Redemption watches a devil room's first visit. Modeling // Clay's copy ends, and it copies anew one time in two over its multiplier on the room's seed. void trinkets_room_enter(Entity_Player& player) { constexpr int MUSHROOMS[] = {12, 71, 121, 120, 342, 398}; constexpr RNG CLAY_SHIFTS = {0, 7, 17, 21}; ItemConfig& items = g_manager->itemConfig; if (player.HasTrinket(TRINKET_LIBERTY_CAP) && is_room_trinket_rolled(player, TRINKET_LIBERTY_CAP)) { int id = MUSHROOMS[player.GetTrinketRNG(TRINKET_LIBERTY_CAP).Next() % std::size(MUSHROOMS)]; player.temporaryEffects.AddEffect(TemporaryEffect(items.GetCollectible(id)), true, 1); } if (player.HasTrinket(TRINKET_BROKEN_SYRINGE) && is_room_trinket_rolled(player, TRINKET_BROKEN_SYRINGE)) player.add_random_drug_item_effect(); if (player.HasTrinket(TRINKET_MOMS_LOCK) && is_room_trinket_rolled(player, TRINKET_MOMS_LOCK)) player.AddRandomMomItemEffect(); RoomDescriptor* descriptor = g_game->room->descriptor; bool isDevilRoom = g_game->room->roomType == ROOM_DEVIL || (descriptor && (descriptor->flags & ROOM_DESCRIPTOR_FLAG_DEVIL_TREASURE)); if (player.HasCollectible(COLLECTIBLE_REDEMPTION) && descriptor && descriptor->visitedCount == 1 && isDevilRoom && !player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_REDEMPTION)) player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_REDEMPTION, true, 1); int copied = player.modelingClayEffect; player.modelingClayEffect = 0; if (copied != 0) { if (ItemConfig_Item* item = items.GetCollectible(copied)) { player.cacheFlags |= item->cacheFlags; player.temporaryEffects.isEvaluateCachePending = true; } player.TryRemoveCollectibleCostume(copied, false); } RoomDescriptor* room = g_game->GetRoomByIdx(g_game->currentRoomIdx, -1); if (player.HasTrinket(TRINKET_MODELING_CLAY) && room->spawnSeed != 0) { RNG rng = CLAY_SHIFTS; rng._seed = room->spawnSeed; if (rng.RandomInt((uint32_t)(2 / player.GetTrinketMultiplier(TRINKET_MODELING_CLAY))) == 0) player.ModelingClay_roll(&rng); } } // Umbilical Cord's part of 007a8350: at one red heart or less (two or three with more copies) the player gets Little // Steven's effect for the room. void umbilical_cord_room_enter(Entity_Player& player) { TemporaryEffects& effects = player.temporaryEffects; if (!player.HasTrinket(TRINKET_UMBILICAL_CORD) || effects.HasCollectibleEffect(COLLECTIBLE_LITTLE_STEVEN)) return; int hearts = std::min(std::max(player.GetTrinketMultiplier(TRINKET_UMBILICAL_CORD), 1), 3); if (player.redHearts <= hearts) effects.AddCollectibleEffect(COLLECTIBLE_LITTLE_STEVEN, true, 1); } // Dice Bag's part of 007a8350: on a first visit, one time in two per copy, a single use die lands in the pocket. void dice_bag_room_enter(Entity_Player& player) { constexpr int DICE[] = {476, 284, 105, 609, 437, 406, 285, 386, 166, 283}; if (!player.HasTrinket(TRINKET_DICE_BAG) || g_game->room->descriptor->visitedCount != 1) return; if ((int)(player.GetTrinketRNG(TRINKET_DICE_BAG).Next() & 1) >= player.GetTrinketMultiplier(TRINKET_DICE_BAG)) return; // The original draws the die from The Twins' RNG. int die = DICE[player.GetTrinketRNG(TRINKET_THE_TWINS).Next() % std::size(DICE)]; player.SetPocketActiveItem(die, ACTIVE_SLOT_POCKET2, true); player.AnimateCollectible(die, "UseItem", "PlayerPickupSparkle"); sound_play(SOUND_SHELLGAME); } // Divorce Papers' first pickup: a bone heart, and Mysterious Paper from the trinket pool once it is unlocked (or in a // daily or debug run). static void divorce_papers_gain(Entity_Player& player, RNG& rng) { constexpr int ACHIEVEMENT_MYSTERIOUS_PAPER = 123; player.AddBoneHearts(1); Game& game = *g_game; bool isAllowed = g_manager->persistentGameData.achievements[ACHIEVEMENT_MYSTERIOUS_PAPER] || (g_manager->state == MANAGER_STATE_GAME && (game.dailyChallenge.id != 0 || game.isDebug)); if (!isAllowed || !game.itemPool.RemoveTrinket(TRINKET_MYSTERIOUS_PAPER)) return; Vector position = room_free_pickup_position_find({.position = player.pos, .step = GAIN_PICKUP_STEP}); game.Spawn({.position = position, .spawner = &player, .subType = TRINKET_MYSTERIOUS_PAPER, .type = ENTITY_PICKUP, .variant = PICKUP_TRINKET, .seed = rng.Next()}); } // Brittle Bones' first pickup: six bone hearts for the red hearts (and the Soul's) it takes, or a tears up (and the // bone hearts anyway) for a coin or no health player. static void brittle_bones_gain(Entity_Player& player) { HealthType health = player.GetHealthType(); if (health == HEALTH_COIN || health == HEALTH_NO_HEALTH) { player.brittleBonesUpgrades++; player.cacheFlags |= CACHE_FIREDELAY; } else { player.redHearts = 0; player.maxHearts = 0; if (Entity_Player* sub = player.subPlayer) { sub->redHearts = 0; sub->maxHearts = 0; } } player.AddBoneHearts(BRITTLE_BONES_HEARTS); } // The second Broken Shovel piece joins the first into Mom's Shovel, keeping the first piece's charge. static void broken_shovel_gain(Entity_Player& player) { int charge = 0; for (ActiveItemDesc& active : player.activeItems) if (active.item == COLLECTIBLE_BROKEN_SHOVEL_1) charge = active.batteryCharge + active.charge; if (!player.HasCollectible(COLLECTIBLE_BROKEN_SHOVEL_1)) return; player.RemoveCollectible(COLLECTIBLE_BROKEN_SHOVEL_1, false, 0, true); player.RemoveCollectible(COLLECTIBLE_BROKEN_SHOVEL_2, false, 0, true); player.AddCollectible(COLLECTIBLE_MOMS_SHOVEL, 0, false, 0, 0); int slot = player.GetActiveItemSlot(COLLECTIBLE_MOMS_SHOVEL); if (slot >= 0) player.SetActiveCharge(charge, slot); } // Booster Pack's first pickup: five cards, the first with a special card's chance, the others a suit's. static void booster_pack_gain(Entity_Player& player, RNG& rng) { for (int i = 0; i < BOOSTER_PACK_CARDS; i++) { bool isFirst = i == 0; int card = ItemPool::GetCardEx((int)rng.Next(), isFirst ? BOOSTER_SPECIAL_FIRST : BOOSTER_SPECIAL, 0, isFirst ? BOOSTER_SUIT_FIRST : BOOSTER_SUIT, false); Vector position = room_free_pickup_position_find({.position = player.pos, .step = GAIN_PICKUP_STEP}); auto* pickup = static_cast(g_game->Spawn({.position = position, .subType = card, .type = ENTITY_PICKUP, .variant = PICKUP_TAROTCARD, .seed = rng.Next()})); pickup->dropDelay = i; } } // TMTRAINER's first pickup: the music fades and every enemy (and versus player) still alive burns and freezes for a // hundred seconds. static void tmtrainer_gain(Entity_Player& player) { constexpr int TMTRAINER_FRAMES = 6000; constexpr float MUSIC_FADE = 0.01f; g_manager->musicManager.Fadeout(MUSIC_FADE); std::vector entities = g_game->room->entityList.updateEL; bool isVersus = g_game->deathmatchManager.is_active(); for (Entity* entity : entities) { bool isTarget = (isVersus && entity->type == ENTITY_PLAYER) || (entity->type >= ENTITY_FIRST_ENEMY && entity->type < ENTITY_EFFECT); if (!isTarget || entity->isDead || entity->type == ENTITY_FIREPLACE || entity->type == ENTITY_SHOPKEEPER) continue; entity->bossStatusEffectCooldown = 0; entity->CopyStatusEffects(); entity->AddBurn(EntityRef(&player), TMTRAINER_FRAMES, 0, false); entity->AddFreeze(EntityRef(&player), TMTRAINER_FRAMES, false); } } // Room::is_pre_ascent_mom_room: Mom's boss room on the floor before the Ascent. static bool is_pre_ascent_mom_room() { constexpr int BOSS_SUBTYPE_MOM = 89; Room& room = *g_game->room; return room.roomType == ROOM_BOSS && room.descriptor->data->subtype == BOSS_SUBTYPE_MOM && g_game->IsPreAscent(); } // The pickup effects of 0075f0e0 for Clear Rune's rune and the collectibles 367 on that do more than drop pickups: // Mom's Box's Wooden Cross and Duct Tape, Tarot Cloth's card, Divorce Papers, Brittle Bones, the Broken Shovel, Luna's secret room, // Saturnus' tears, the Booster Pack, Dad's Note's ascent and TMTRAINER. Camo Undies only acts in versus. void late_collectible_gain(Entity_Player& player, int type, bool isFirstTime) { RNG& rng = player.GetCollectibleRNG(type); switch (type) { case COLLECTIBLE_MOMS_BOX: if (player.HasTrinket(TRINKET_WOODEN_CROSS) && !player.HasGoldenTrinket(TRINKET_WOODEN_CROSS)) wooden_cross_mantle_add(player); if (player.GetTrinketMultiplier(TRINKET_DUCT_TAPE) > 1 && player.ductTapeMode == 0) player.ductTapeMode = 1; return; case COLLECTIBLE_CLEAR_RUNE: if (!isFirstTime) return; { int rune = ItemPool::GetCardEx((int)rng.Next(), 0, -1, 0, true); Vector position = room_free_pickup_position_find({.position = player.pos, .step = GAIN_PICKUP_STEP}); g_game->Spawn({.position = position, .subType = rune, .type = ENTITY_PICKUP, .variant = PICKUP_TAROTCARD, .seed = rng.Next()}); } return; case COLLECTIBLE_TAROT_CLOTH: if (!isFirstTime) return; { Vector position = room_free_pickup_position_find({.position = player.pos, .step = GAIN_PICKUP_STEP}); int card = ItemPool::GetCardEx((int)rng.Next(), 0, 0, 0, false); g_game->Spawn({.position = position, .subType = card, .type = ENTITY_PICKUP, .variant = PICKUP_TAROTCARD, .seed = rng.Next()}); } return; case COLLECTIBLE_CAMO_UNDIES: if (g_game->deathmatchManager.is_active()) camo_undies_confuse(player); return; case COLLECTIBLE_DIVORCE_PAPERS: if (isFirstTime) divorce_papers_gain(player, rng); return; case COLLECTIBLE_BRITTLE_BONES: if (isFirstTime) brittle_bones_gain(player); return; case COLLECTIBLE_BROKEN_SHOVEL_2: broken_shovel_gain(player); return; case COLLECTIBLE_LUNA: g_game->reveal_secret_room(); return; case COLLECTIBLE_SATURNUS: if (isFirstTime) player.fire_saturnus_tears(); return; case COLLECTIBLE_BOOSTER_PACK: if (isFirstTime) booster_pack_gain(player, rng); return; case COLLECTIBLE_DADS_NOTE: if (is_pre_ascent_mom_room() && !g_game->IsAscent() && g_game->ascentTimer < 1) g_game->ascentTimer = 1; return; case COLLECTIBLE_TMTRAINER: if (isFirstTime) tmtrainer_gain(player); return; } } // Purity's pickup in 0075f0e0: a colour is rolled, its aura and glow come on. void purity_gain(Entity_Player& player) { player.purityState = (int)player.GetCollectibleRNG(COLLECTIBLE_PURITY).RandomInt(PURITY_STATES); player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_PURITY, true, 1); player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_PURITY_GLOW), false); player.update_purity_glow(); player.versus.purityHits = 0; } // A crown's glow following its condition: the effect and the glowing float come on together, or go together. static void crown_glow_set(Entity_Player& player, int crown, ANM2& sprite, bool isLit) { TemporaryEffects& effects = player.temporaryEffects; if (isLit == effects.HasCollectibleEffect(crown)) return; if (isLit) effects.AddCollectibleEffect(crown, true, 1); else effects.RemoveCollectibleEffect(crown, 1); sprite.Play(isLit ? "FloatGlow" : "FloatNoGlow"); } // 007db360 Whether Dark Prince's Crown glows: at exactly one red heart, or in versus with a tenth to three tenths of // the red hearts. bool is_dark_prince_lit(Entity_Player& player) { constexpr float VERSUS_SHARE_MIN = 0.1f; constexpr float VERSUS_SHARE_MAX = 0.3f; constexpr int PRINCE_HEARTS = 2; if (!g_game->deathmatchManager.is_active()) return player.redHearts == PRINCE_HEARTS; float share = (float)player.redHearts / (float)player.maxHearts; return share >= VERSUS_SHARE_MIN && share <= VERSUS_SHARE_MAX; } // The crowns' part of 007c9ea0: Crown of Light glows while the player is at full red health and unhurt this room (in // versus at eight tenths of the red hearts), Dark Prince's Crown at one red heart. void crowns_update(Entity_Player& player) { constexpr float VERSUS_LIGHT_SHARE = 0.8f; if (player.HasCollectible(COLLECTIBLE_CROWN_OF_LIGHT)) { bool isLit = g_game->deathmatchManager.is_active() ? (float)player.redHearts / (float)player.maxHearts >= VERSUS_LIGHT_SHARE : !player.isHurtThisRoom && player.HasFullHearts(); crown_glow_set(player, COLLECTIBLE_CROWN_OF_LIGHT, player.crownOfLightSprite, isLit); } if (player.HasCollectible(COLLECTIBLE_DARK_PRINCES_CROWN)) crown_glow_set(player, COLLECTIBLE_DARK_PRINCES_CROWN, player.darkPrincesCrownSprite, is_dark_prince_lit(player)); } // The crowns' and Purity's part of 007a8350: Purity's aura comes back with its glow, and a crown not glowing is // lit again when its condition holds, its float showing which. void crowns_room_enter(Entity_Player& player) { TemporaryEffects& effects = player.temporaryEffects; if (player.HasCollectible(COLLECTIBLE_PURITY) && !effects.HasCollectibleEffect(COLLECTIBLE_PURITY)) { effects.AddEffect(TemporaryEffect(g_manager->itemConfig.GetCollectible(COLLECTIBLE_PURITY)), true, 1); player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_PURITY_GLOW), false); player.update_purity_glow(); } if (player.HasCollectible(COLLECTIBLE_CROWN_OF_LIGHT) && !effects.HasCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT)) { bool isLit = player.HasFullHearts(); if (isLit) effects.AddCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT, true, 1); player.crownOfLightSprite.Play(isLit ? "FloatGlow" : "FloatNoGlow"); } if (player.HasCollectible(COLLECTIBLE_DARK_PRINCES_CROWN) && !effects.HasCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN)) { bool isLit = is_dark_prince_lit(player); if (isLit) effects.AddCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN, true, 1); player.darkPrincesCrownSprite.Play(isLit ? "FloatGlow" : "FloatNoGlow"); } } // The Smelter's use in 005b39d0 (and Gulp!'s): a main player's held trinkets, the one held up first, are smelted into // it for good, each joining the history, plain or golden. void trinkets_smelt(Entity_Player& player) { if (player.variant != PLAYER_VARIANT_PLAYER) return; Game& game = *g_game; player.FlushQueueItem(); for (uint32_t& held : player.trinkets) { if (held == 0) continue; uint32_t id = held & TRINKET_ID_MASK; ItemConfig_Item* trinket = g_manager->itemConfig.GetTrinket(id); log_printf(LOG_INFO, "Adding smelted trinket %d (%s) to player %d (%s)\n", held, trinket ? trinket->GetLocalizedName(LANGUAGE_CURRENT).c_str() : "", player.playerIndex, player.name.c_str()); player.history.AddHistoryItem({game.frameCount, true, (int)held, (int)game.stage, (int)game.stageType, game.room->roomType, HISTORY_POOL_NONE}); SmeltedTrinket& smelted = player.smeltedTrinkets[id]; if (held & TRINKET_GOLDEN_FLAG) smelted.goldenCount++; else smelted.count++; held = 0; } player.InvalidateCoPlayerItems(); game.hud.mark_all_slots_dirty(HISTORY_KEEP_ICONS, HISTORY_KEEP_ITEMS); } // Hairpin's part of 00794e50: the frame after entering a boss room for the first time, the first active that takes a // charge is filled (overcharged when golden or with Mom's Box), with the battery sound and icon. static void hairpin_update(Entity_Player& player) { constexpr int BATTERY_ICON = 1; constexpr float BATTERY_ICON_RISE = -24; Room& room = *g_game->room; if (!room.isInitialized || g_game->frameCount - room.enterFrame != 1 || room.roomType != ROOM_BOSS || !room.isFirstVisit) return; bool isOvercharge = player.HasGoldenTrinket(TRINKET_HAIRPIN) || player.HasCollectible(COLLECTIBLE_MOMS_BOX); for (int slot = 0; slot < ACTIVE_SLOT_COUNT && !player.FullCharge(slot, false, isOvercharge); slot++) {} sound_play(SOUND_BATTERYCHARGE); Entity* icon = g_game->Spawn({.position = player.pos, .subType = BATTERY_ICON, .type = ENTITY_EFFECT, .variant = EFFECT_HEART, .seed = Random()}); icon->sprite.offset = vector_make(0, BATTERY_ICON_RISE); icon->renderDepthOffset = 1; } // Mysterious Candy's part of 00794e50: every 900 frames, one time in two, a poop (golden with a golden candy, black on // Meconium's roll) drops under a main player standing on an empty or decorated cell outside crawl spaces. Otherwise // every 1800 frames, one time in two, the player farts. static void mysterious_candy_update(Entity_Player& player) { constexpr int CANDY_POOP_FRAMES = 900; constexpr int CANDY_FART_FRAMES = 1800; constexpr float CANDY_FART_RADIUS = 120; constexpr int MECONIUM_CHANCES[] = {33, 66, 100}; Room& room = *g_game->room; int cell = room.GetGridIndex(player.pos); GridEntity* grid = room.GetGridEntity(cell); int frame = g_game->frameCount; bool isFree = !grid || grid->type == GRID_DECORATION || grid->type == GRID_SPIDERWEB; if (frame % CANDY_POOP_FRAMES == 0 && random_below(2) == 0 && isFree && room.roomType != ROOM_DUNGEON) { int variant = player.HasGoldenTrinket(TRINKET_MYSTERIOUS_CANDY) ? POOP_GOLDEN : POOP_NORMAL; if (player.HasTrinket(TRINKET_MECONIUM)) { int multiplier = player.GetTrinketMultiplier(TRINKET_MECONIUM); uint32_t chance = (uint32_t)MECONIUM_CHANCES[multiplier == 2 ? 1 : multiplier == 3 ? 2 : 0]; if (player.GetTrinketRNG(TRINKET_MECONIUM).RandomInt(100) < chance) variant = POOP_BLACK; } room.SpawnGridEntity(cell, GRID_POOP, variant, player.GetTrinketRNG(TRINKET_MYSTERIOUS_CANDY).Next(), 0); } else if (frame % CANDY_FART_FRAMES == 0 && random_below(2) == 0) game_butter_bean_fart({.position = player.pos, .source = &player, .radius = CANDY_FART_RADIUS}); } // Louse's part of 00794e50: in an uncleared room, every 900 frames one time in two (and surely every 1800), both // timed from the room's seed, the player throws a blue spider per copy. static void louse_update(Entity_Player& player) { constexpr int LOUSE_FRAMES = 900; constexpr int LOUSE_FRAMES_SURE = 1800; constexpr float LOUSE_VOLUME = 0.7f; int offset = (int)(g_game->room->GetSpawnSeed() % LOUSE_FRAMES_SURE); if (g_game->room->IsClear()) return; bool isTime = (player.IsFrame(LOUSE_FRAMES, offset) && random_below(2) == 0) || player.IsFrame(LOUSE_FRAMES_SURE, offset); if (!isTime) return; npc_sound_play(SOUND_BOIL_HATCH, LOUSE_VOLUME, 2, 1); for (int i = player.GetTrinketMultiplier(TRINKET_LOUSE); i > 0; i--) player.ThrowBlueSpider(player.pos, {}); } // The trinkets' part of the items' frame (00794e50), in their order there: Hairpin, Mysterious Candy, Louse and // Rainbow Worm, whose tear effect changes every 90 frames. void trinkets_frame_update(Entity_Player& player) { if (player.HasTrinket(TRINKET_HAIRPIN)) hairpin_update(player); if (player.HasTrinket(TRINKET_MYSTERIOUS_CANDY) && player.variant == PLAYER_VARIANT_PLAYER) mysterious_candy_update(player); if (player.HasTrinket(TRINKET_LOUSE)) louse_update(player); if (player.HasTrinket(TRINKET_RAINBOW_WORM) && g_game->frameCount % RAINBOW_WORM_FRAMES == 0) { player.cacheFlags |= CACHE_FIREDELAY | CACHE_SHOTSPEED | CACHE_RANGE | CACHE_TEARFLAG; player.EvaluateItems(); } } // The pennies' drop: once a penny trinket rolls at least its threshold, a pickup lands on a free spot near the player. static void penny_drop(Entity_Player& player, int variant, int subType) { uint32_t seed = Random(); Vector position = room_free_pickup_position_find({.position = player.pos, .step = GAIN_PICKUP_STEP}); g_game->Spawn({.position = position, .subType = subType, .type = ENTITY_PICKUP, .variant = variant, .seed = seed}); } // Whether a penny trinket's roll passes: a pickup worth more coins (and stronger copies, a quarter each) makes it likelier. static bool is_penny_rolled(Entity_Player& player, int trinket, float threshold) { float chance = threshold - (float)(player.GetTrinketMultiplier(trinket) - 1) * 0.25f; return chance <= player.GetTrinketRNG(trinket).RandomFloat(); } // Blessed Penny's chance of a half soul heart, by its strength and the coin's worth. static float blessed_penny_chance(int multiplier, int value) { constexpr float CHANCES[3][4] = {{0.17f, 0.3f, 0.6f, 0.83f}, {0.25f, 0.4f, 0.7f, 0.9f}, {0.3f, 0.5f, 0.75f, 1.0f}}; const float* chances = CHANCES[multiplier == 2 ? 1 : multiplier == 3 ? 2 : 0]; return value == 2 ? chances[1] : value == 5 ? chances[2] : value == 10 ? chances[3] : chances[0]; } // The penny trinkets' part of 006e8ae0 for a coin worth value: Burnt, Flat and Bloody Penny drop a bomb, key or half // heart (Bloody Penny one time in five with Daemon's Tail), Counterfeit Penny adds coins, Blessed Penny drops a half // soul heart, Charged Penny charges the first active that takes it, Cursed Penny teleports, Butt Penny farts (a dip with // Dirty Mind) and Rotten Penny brings blue flies. void coin_trinkets_collect(Entity_Pickup& pickup, Entity_Player& player, int value) { constexpr float BUTT_FART_RADIUS = 85; constexpr float BUTT_BEAN_RADIUS = 120; constexpr int BURNT_PENNY_BOMB = 1; float threshold = std::pow(0.75f, (float)value); float doubling = std::pow(0.5f, (float)value); if (player.HasTrinket(TRINKET_BURNT_PENNY) && is_penny_rolled(player, TRINKET_BURNT_PENNY, threshold)) penny_drop(player, PICKUP_BOMB, BURNT_PENNY_BOMB); if (player.HasTrinket(TRINKET_FLAT_PENNY) && is_penny_rolled(player, TRINKET_FLAT_PENNY, threshold)) penny_drop(player, PICKUP_KEY, KEY_NORMAL); if (player.HasTrinket(TRINKET_BLOODY_PENNY) && is_penny_rolled(player, TRINKET_BLOODY_PENNY, threshold) && (!player.HasTrinket(TRINKET_DAEMONS_TAIL) || player.GetTrinketRNG(TRINKET_DAEMONS_TAIL).RandomInt(DAEMONS_TAIL_ODDS) == 0)) penny_drop(player, PICKUP_HEART, HEART_HALF); if (player.HasTrinket(TRINKET_COUNTERFEIT_PENNY) && doubling <= player.GetTrinketRNG(TRINKET_COUNTERFEIT_PENNY).RandomFloat()) player.AddCoins(player.GetTrinketMultiplier(TRINKET_COUNTERFEIT_PENNY)); if (player.HasTrinket(TRINKET_BLESSED_PENNY)) { float chance = blessed_penny_chance(player.GetTrinketMultiplier(TRINKET_BLESSED_PENNY), value); if (player.GetTrinketRNG(TRINKET_BLESSED_PENNY).RandomFloat() <= chance) penny_drop(player, PICKUP_HEART, HEART_HALF_SOUL); } if (player.HasTrinket(TRINKET_CHARGED_PENNY) && threshold <= player.GetTrinketRNG(TRINKET_CHARGED_PENNY).RandomFloat()) { int charge = std::min(std::max(player.GetTrinketMultiplier(TRINKET_CHARGED_PENNY), 1), 3); for (int slot = 0; slot < ACTIVE_SLOT_COUNT && player.AddActiveCharge(charge, slot, false, false, false) == 0; slot++) {} } if (player.HasTrinket(TRINKET_CURSED_PENNY) && !player.HasCollectible(COLLECTIBLE_BLACK_CANDLE)) player.cursedPennyPending = pickup.subtype; if (player.HasTrinket(TRINKET_BUTT_PENNY)) { game_fart({.position = pickup.pos, .source = &player, .radius = BUTT_FART_RADIUS}); game_butter_bean_fart({.position = player.pos, .source = &player, .radius = BUTT_BEAN_RADIUS, .isShowEffect = false}); if (player.GetTrinketRNG(TRINKET_BUTT_PENNY).RandomInt(2) == 0 && player.HasCollectible(COLLECTIBLE_DIRTY_MIND)) { Vector target = room_free_pickup_position_find({.position = player.pos, .step = GAIN_PICKUP_STEP}); player.ThrowFriendlyDip(0, player.pos, target); } } if (player.HasTrinket(TRINKET_ROTTEN_PENNY)) player.AddBlueFlies(std::min(std::max(player.GetTrinketMultiplier(TRINKET_ROTTEN_PENNY), 1), 3), player.pos, nullptr); } constexpr int GLYPH_PICKUP_FEW = 1; constexpr int GLYPH_PICKUP_MANY = 5; constexpr int GLYPH_COINS_MANY = 15; constexpr int GLYPH_CHARGE_MANY = 12; constexpr int GLYPH_SOUL_HEARTS_FEW = 4; constexpr int GLYPH_HEARTS_ENOUGH = 12; // Glyph of Balance's drop as a pickup variant and subtype, kept as it is when it is already of the chosen variant (a // soul heart also keeps a black heart). struct GlyphDrop { int* variant = nullptr; int* subType = nullptr; void set(int newVariant, int newSubType) { if (*variant == newVariant) return; *variant = newVariant; *subType = newSubType; } void soul_heart_set() { if (*variant == PICKUP_HEART && (*subType == HEART_SOUL || *subType == HEART_BLACK)) return; *variant = PICKUP_HEART; *subType = HEART_SOUL; } }; // Whether the player keeps its bombs (Tainted ???'s poop) for Glyph of Balance, at least a count of them. static bool is_glyph_bombs_short(Entity_Player& player, int count) { return player.playerType == PLAYER_BLUEBABY_B ? player.poopMana < count : player.numBombs < count; } // The charge Bethany's or Tainted Bethany's heart drop needs: a soul heart or a red heart when short of it. static bool glyph_charge_drop(Entity_Player& player, GlyphDrop& drop, int count) { if (player.playerType == PLAYER_BETHANY && player.effectiveSoulCharge < count) drop.soul_heart_set(); else if (player.playerType == PLAYER_BETHANY_B && player.effectiveBloodCharge < count) drop.set(PICKUP_HEART, HEART_FULL); else return false; return true; } // 007d12c0 The pickup Glyph of Balance drops for the player, in order of need: a red heart when low on red health, a // soul heart without containers, a key, a bomb (poop for Tainted ???), Bethany's charge, red hearts to fill the // containers, coins, a trinket with enough of everything and none held or lying about, then more coins, keys, bombs // and charge, and soul hearts until twelve hearts are held. Else the drop is left as it is. void Entity_Player::GetGlyphOfBalanceDrop(int* variant, int* subType) { GlyphDrop drop = {variant, subType}; HealthType health = GetHealthType(); bool isRedHealth = (health == HEALTH_DEFAULT || health == HEALTH_BONE) && playerType != PLAYER_BETHANY; bool isBoneless = health == HEALTH_SOUL || health == HEALTH_NO_HEALTH; int containers = isBoneless ? maxHearts : maxHearts + boneHearts * 2; if (redHearts < 2 && containers >= 2 && (health == HEALTH_DEFAULT || health == HEALTH_BONE)) return drop.set(PICKUP_HEART, HEART_FULL); if (containers == 0 && soulHearts < GLYPH_SOUL_HEARTS_FEW && isRedHealth) return drop.soul_heart_set(); if (numKeys < GLYPH_PICKUP_FEW) return drop.set(PICKUP_KEY, 0); if (playerType == PLAYER_BLUEBABY_B && poopMana < GLYPH_PICKUP_FEW) return drop.set(PICKUP_POOP, POOP_BIG); if (playerType != PLAYER_BLUEBABY_B && numBombs < GLYPH_PICKUP_FEW) return drop.set(PICKUP_BOMB, 0); if (glyph_charge_drop(*this, drop, GLYPH_PICKUP_FEW)) return; if (redHearts < GetEffectiveMaxHearts() && GetEffectiveMaxHearts() >= 0 && GetHealthType() != HEALTH_COIN) return drop.set(PICKUP_HEART, HEART_FULL); if (numCoins < GLYPH_PICKUP_MANY) return drop.set(PICKUP_COIN, 0); bool isBombsKept = playerType == PLAYER_BLUEBABY_B ? poopMana != 0 : numBombs >= GLYPH_PICKUP_MANY; if (isBombsKept && numKeys >= GLYPH_PICKUP_MANY && trinkets[0] == 0 && entity_query(ENTITY_PICKUP, PICKUP_TRINKET).empty()) return drop.set(PICKUP_TRINKET, 0); if (numCoins < GLYPH_COINS_MANY) return drop.set(PICKUP_COIN, 0); if (numKeys < GLYPH_PICKUP_MANY) return drop.set(PICKUP_KEY, 0); if (is_glyph_bombs_short(*this, GLYPH_PICKUP_MANY)) return drop.set(playerType == PLAYER_BLUEBABY_B ? PICKUP_POOP : PICKUP_BOMB, playerType == PLAYER_BLUEBABY_B ? POOP_BIG : 0); if (glyph_charge_drop(*this, drop, GLYPH_CHARGE_MANY)) return; if (GetEffectiveMaxHearts() + soulHearts < std::min(GetHeartLimit(false), GLYPH_HEARTS_ENOUGH) && isRedHealth) drop.soul_heart_set(); } // 00772530 Turns a golden Store Credit back into a plain one: the one held over the head, else the first held (its // costume and effects swapped), else the first smelted one in the history. Whether one was changed. bool Entity_Player::replace_trinket() { bool isMainPlayer = variant == PLAYER_VARIANT_PLAYER && !isCoopGhost; ItemConfig_Item* storeCredit = g_manager->itemConfig.GetTrinket(TRINKET_STORE_CREDIT); uint32_t golden = TRINKET_STORE_CREDIT | TRINKET_GOLDEN_FLAG; if (isMainPlayer) InvalidateCoPlayerItems(); if (queuedItem.item && queuedItem.item == storeCredit && (queuedItem.flags & QUEUED_GOLDEN)) { queuedItem.flags &= ~QUEUED_GOLDEN; return true; } int slots = HasCollectible(COLLECTIBLE_MOMS_PURSE) || HasCollectible(COLLECTIBLE_BELLY_BUTTON) ? 2 : 1; for (int slot = 0; slot < slots; slot++) { if (trinkets[slot] != golden) continue; trinkets[slot] = TRINKET_STORE_CREDIT; log_printf(LOG_INFO, "Replacing trinket %d (%s) from player %d (%s) with trinket %d (%s)\n", golden, storeCredit->GetLocalizedName().c_str(), playerIndex, name.c_str(), TRINKET_STORE_CREDIT, storeCredit->GetLocalizedName().c_str()); TriggerTrinketRemoved(golden); if (storeCredit->isAddCostumeOnPickup || !temporaryEffects.HasTrinketEffect(golden)) RemoveCostume(storeCredit); TriggerTrinketAdded(TRINKET_STORE_CREDIT, false); if (storeCredit->isAddCostumeOnPickup) AddCostume(storeCredit, false); return true; } if (!isMainPlayer) return false; for (HistoryItem& item : history.historyItems) { if (!item.isTrinket || (uint32_t)item.id != golden) continue; item.id = TRINKET_STORE_CREDIT; SmeltedTrinket& smelted = smeltedTrinkets[storeCredit->id]; if (smelted.goldenCount > 0) { smelted.goldenCount--; TriggerTrinketRemoved(golden); if (smelted.count < 1 && smelted.goldenCount < 1) TryRemoveTrinketCostume(golden); smelted.count++; TriggerTrinketAdded(TRINKET_STORE_CREDIT, false); if (storeCredit->isAddCostumeOnPickup) AddCostume(storeCredit, false); } log_printf(LOG_INFO, "Replacing smelted trinket %d (%s) from player %d (%s) with trinket %d (%s)\n", golden, storeCredit->GetLocalizedName().c_str(), playerIndex, name.c_str(), TRINKET_STORE_CREDIT, storeCredit->GetLocalizedName().c_str()); g_game->hud.mark_all_slots_dirty(HISTORY_KEEP_ICONS, HISTORY_KEEP_ITEMS); return true; } return false; }