#include "entity_player_effects.h" #include "boss_ai.h" #include "entity_bomb.h" #include "entity_effect.h" #include "entity_pickup.h" #include "entity_npc.h" #include "entity_player.h" #include "entity_player_characters.h" #include "entity_projectile.h" #include "entity_slot.h" #include "game.h" #include "manager.h" #include "grid_entity_pit.h" #include "npc_ai.h" #include "room.h" #include "room_grid.h" #include "temporary_effects.h" #include "sfx_manager.h" #include #include // The Ladder's reach: how near a player must stand to a laid ladder to keep it, and the turn of a ladder laid across. constexpr float LADDER_KEEP_DISTANCE_SQUARED = 3249; constexpr float LADDER_ACROSS_ROTATION = 90; // The pit at a cell, or null off the grid or on any other grid entity. static GridEntity_Pit* pit_at(Room& room, int gridIndex) { if (gridIndex < 0 || gridIndex >= ROOM_GRID_CELLS) return nullptr; GridEntity* grid = room.gridEntities[gridIndex]; return grid && grid->type == GRID_PIT ? static_cast(grid) : nullptr; } // Whether a cell is one a ladder may lean on: inside the room's first width squared cells and not a pit. The // original bounds the cells by the width twice, not by the width and the height. static bool is_ladder_side(Room& room, int gridIndex) { return gridIndex >= 0 && gridIndex < room.gridWidth * room.gridWidth && !pit_at(room, gridIndex); } // A laid ladder taken up: its pit is a pit again and it hides. static void ladder_lift(Room& room, Entity_Effect& ladder) { if (GridEntity_Pit* pit = pit_at(room, ladder.state)) { pit->hasLadder = false; pit->UpdateCollision(); } ladder.state = -1; ladder.isVisible = false; } // 0079f3c0 The Ladder: its hidden ladder effect is spawned once. A laid ladder stays while a player (or a flying // one) stands near it, else it is taken up. Walking from solid ground towards an open pit lays it over that pit, // across when the walk is sideways with no pits beside, along when it is upright with no pits above and below. // Without the item the ladder goes once it is taken up. void Entity_Player::update_ladder() { Room& room = *g_game->room; bool isOwner = HasCollectible(COLLECTIBLE_LADDER) && variant == PLAYER_VARIANT_PLAYER; if (!isOwner && !ladder) return; if (!ladder) { Entity* spawned = g_game->Spawn({.type = ENTITY_EFFECT, .variant = EFFECT_LADDER, .seed = Random()}); spawned->isVisible = false; static_cast(spawned)->state = -1; ladder = spawned; } auto& effect = *static_cast(ladder.get()); Vector start = pos; Vector walk = velocity; if (effect.isVisible) { Vector center = room.GetGridPosition(effect.state); bool isStoodOn = std::ranges::any_of(g_game->playerManager.playerList, [&](Entity_Player* player) { bool isCounted = player == this || player->entityGridCollisionClass == GRIDCOLL_NOPITS; return isCounted && vector_length_squared(vector_sub(player->pos, center)) <= LADDER_KEEP_DISTANCE_SQUARED; }); if (!isStoodOn) ladder_lift(room, effect); } if (!isOwner) { if (effect.isVisible) return; effect.Remove(); ladder = nullptr; return; } int here = room.GetGridIndex(start); if (here < 0) return; Vector step = vector_length(walk) > 0 ? vector_normalized(walk) : walk; int ahead = room.GetGridIndex(vector_add(start, vector_scale(step, GRID_CELL_SIZE))); if (effect.state == ahead) return; GridEntity_Pit* standing = pit_at(room, here); GridEntity_Pit* pit = pit_at(room, ahead); if ((standing && standing->state <= 1) || !pit || pit->state != 0) return; bool isSideways = std::fabs(walk.x) > std::fabs(walk.y); bool isUpright = std::fabs(walk.y) > std::fabs(walk.x); bool isAcross = isSideways && is_ladder_side(room, ahead - 1) && is_ladder_side(room, ahead + 1); if (!isAcross && !(isUpright && is_ladder_side(room, ahead - room.gridWidth) && is_ladder_side(room, ahead + room.gridWidth))) return; ladder_lift(room, effect); pit->hasLadder = true; pit->UpdateCollision(); effect.state = ahead; effect.pos = room.GetGridPosition(ahead); effect.isVisible = true; effect.sprite.rotation = isAcross ? LADDER_ACROSS_ROTATION : 0; npc_sound_play(SOUND_LADDER, 1, 2, 1); } // The items' frame pieces' reach, timings and strengths, with the exe's values. constexpr float DADS_RING_RADIUS = 40; constexpr int DADS_RING_FREEZE = -4; constexpr int DADS_RING_BOSS_FREEZE = -50; constexpr float SPOOKY_RADIUS = 80; constexpr float VENUS_RADIUS = 120; constexpr int VENUS_CHARM_FRAMES = 60; constexpr float SPOOKY_FEAR_REACH = 80; constexpr int SPOOKY_FEAR_FRAMES = -20; constexpr int SPOOKY_BOSS_FEAR_FRAMES = -60; constexpr float MONSTRANCE_RADIUS = 90; constexpr float MONSTRANCE_PERIOD = 4; constexpr LerpRange MONSTRANCE_FALLOFF = {.inMin = 30, .inMax = 90, .outMin = 0, .outMax = 0.4f}; constexpr float MONSTRANCE_STAGE_DAMAGE = 0.32f; constexpr float MONSTRANCE_BASE_DAMAGE = 3.6f; constexpr int MONSTRANCE_HIT_COUNTDOWN = 30; constexpr int HALO_DADS_RING = 0; constexpr int HALO_MONSTRANCE = 2; constexpr int MARS_READY_PONY_STEP = 2; constexpr int MARS_READY_DAMAGE_COOLDOWN = 30; constexpr float MARS_READY_PITCH = 0.8f; constexpr int MARS_READY_FLASH_FRAMES = 3; constexpr int TOOTH_AND_NAIL_WARNINGS[] = {105, 120, 135}; constexpr int TOOTH_AND_NAIL_STATUE_FRAME = 150; constexpr int TOOTH_AND_NAIL_END_FRAME = 180; constexpr int TOOTH_AND_NAIL_WARNING_STEP = 15; constexpr int TOOTH_AND_NAIL_WARNING_LAST = 9; constexpr int FLASH_FRAMES = 2; constexpr int FLASH_PRIORITY = 255; constexpr int IBS_DRAIN_FRAMES = 60; constexpr float IBS_CHARGE_PER_DAMAGE = 1.5f; constexpr float KEEPER_COIN_PULL_RADIUS = 80; constexpr float KEEPER_COIN_PULL_MIN_SQUARED = 16; constexpr float KEEPER_COIN_PULL_SPEED = 10; constexpr int PURGATORY_PERIOD = 30; constexpr int LINGER_BEAN_PERIOD = 240; constexpr float GIGANTE_CLOUD_SCALE = 2; constexpr int SPLAT_PERIOD = 3; constexpr float PLAYER_SPLAT_SIZE_RANGE = 0.5f; constexpr float PLAYER_SPLAT_SIZE_MIN = 0.2f; constexpr int SPIN_TO_WIN_DRAIN = -1; constexpr int FADED_POLAROID_FADE_FRAMES = 30; constexpr float FADED_POLAROID_PULSE = 0.1f; constexpr float CAMO_SETTLE = 0.1f; constexpr float CAMO_TINT = 0.01f; constexpr float SIZE_SCALE_MIN = 0.3f; constexpr float MINI_MUSH_SIZE = 0.75f; constexpr float SMALL_SIZE = 0.5f; constexpr int SMALL_COLLISION_POINTS = 12; constexpr float MEGA_MUSH_SIZE_MAX = 2; constexpr float MEGA_MUSH_SHADOW = 3; constexpr float GHOST_SHADOW = 0.5f; constexpr float HEART_PUSH_MARGIN = 8; constexpr float HEART_BLOCK_MARGIN = 20; constexpr float HEART_BLOCK_HEIGHT = -90; constexpr float WARNING_VOLUME = 0.8f; constexpr float WARNING_VOLUME_STEP = 0.2f; constexpr float WARNING_FADE_STEP = 0.3f; constexpr float WARNING_OFFSET = 0.3f; constexpr float WARNING_OFFSET_STEP = 0.06f; constexpr uint32_t FRAME_STAT_CACHE = CACHE_DAMAGE | CACHE_FIREDELAY | CACHE_TEARFLAG | CACHE_TEARCOLOR; // The flashes the frame lays on the player: Tooth and Nail's statue turning, and Mars' dash being ready. constexpr ColorMod GREY_FLASH = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {0.8f, 0.8f, 0.8f}}; constexpr ColorMod MARS_READY_COLOR = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {1, 0.2f, 0.2f}}; // The splats some items leave every third frame: Dirty Mind's brown, Rotten Tomato's red and Neptunus' faint black. constexpr ColorMod DIRTY_MIND_SPLAT = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.255f, 0.161f, 0.137f}}; constexpr ColorMod ROTTEN_TOMATO_SPLAT = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.45f, 0.1f, 0.09f}}; constexpr ColorMod NEPTUNUS_SPLAT = {{0, 0, 0, 0.08f}, {0, 0, 0, 0}, {0, 0, 0}}; // The Anarchist Cookbook's effect drops a troll bomb with the player's bomb effects every fifth frame it has left. static void anarchist_cookbook_update(Entity_Player& player) { constexpr int TROLL_BOMB_PERIOD = 5; TemporaryEffect* cookbook = player.temporaryEffects.GetCollectibleEffect(COLLECTIBLE_ANARCHIST_COOKBOOK); if (!cookbook || cookbook->cooldown % TROLL_BOMB_PERIOD != 0) return; Vector spot = room_pickup_position_random(false, false); Entity* spawned = g_game->Spawn({.position = spot, .spawner = &player, .type = ENTITY_BOMB, .variant = BOMB_TROLL, .seed = Random()}); if (spawned->type != ENTITY_BOMB) return; auto& bomb = *static_cast(spawned); bomb.isLoadCostumes = true; bomb.tearFlags = player.GetBombFlags(false); } // Faded Polaroid every 300 frames, one time in five, fades the player for 3 to 7 seconds (times its multiplier). static void faded_polaroid_update(Entity_Player& player) { constexpr int POLAROID_PERIOD = 300; constexpr int POLAROID_ODDS = 5; constexpr int POLAROID_SECONDS_MIN = 3; constexpr int POLAROID_SECONDS_RANGE = 5; constexpr int POLAROID_FRAMES_PER_SECOND = 30; TemporaryEffects& effects = player.temporaryEffects; if (effects.HasTrinketEffect(TRINKET_FADED_POLAROID) || !player.HasTrinket(TRINKET_FADED_POLAROID)) return; if (!player.IsFrame(POLAROID_PERIOD, 0) || random_below(POLAROID_ODDS) != 0) return; TemporaryEffect fade(g_manager->itemConfig.GetTrinket(TRINKET_FADED_POLAROID)); int multiplier = player.GetTrinketMultiplier(TRINKET_FADED_POLAROID); fade.cooldown = multiplier * (random_below(POLAROID_SECONDS_RANGE) + POLAROID_SECONDS_MIN) * POLAROID_FRAMES_PER_SECOND; effects.AddEffect(fade, true, 1); } // A link the player keeps to an aura riding on it: spawned once while it is wanted, else removed. static void aura_keep(Entity_Player& player, EntityPtr& aura, bool isWanted, int subType) { if (!isWanted) { if (aura) aura->Remove(); aura = nullptr; return; } if (aura) return; Entity* halo = g_game->Spawn({.position = player.pos, .spawner = &player, .subType = subType, .type = ENTITY_EFFECT, .variant = EFFECT_HALO, .seed = Random()}); halo->parent = &player; aura = halo; } // Dad's Ring freezes the vulnerable enemies touching the player under its halo. static void dads_ring_update(Entity_Player& player) { bool isWorn = player.HasCollectible(COLLECTIBLE_DADS_RING); if (isWorn) for (Entity* enemy : entity_query_radius(player.pos, DADS_RING_RADIUS, QUERY_ENEMIES)) if (enemy->IsVulnerableEnemy(nullptr)) enemy->AddFreeze(EntityRef(&player), enemy->IsBoss() ? DADS_RING_BOSS_FREEZE : DADS_RING_FREEZE, false); aura_keep(player, player.dadsRingAura, isWorn, HALO_DADS_RING); } // Berserk!'s ending ticks: the tick starts with 45 frames left and stops before it, or when the effect is gone. static void berserk_tick_update(Entity_Player& player) { constexpr int BERSERK_TICK_FRAMES = 45; constexpr int BERSERK_TICK_DELAY = 60; SFXManager& sfx = g_manager->sfxManager; bool isStopped = sfx.IsPlaying(SOUND_BERSERK_TICK); if (TemporaryEffect* berserk = player.temporaryEffects.GetCollectibleEffect(COLLECTIBLE_BERSERK)) { if (berserk->cooldown == BERSERK_TICK_FRAMES) sfx.Play(SOUND_BERSERK_TICK, {.frameDelay = BERSERK_TICK_DELAY}); isStopped = berserk->cooldown > BERSERK_TICK_FRAMES; } if (isStopped) sfx.Stop(SOUND_BERSERK_TICK); } // Venus charms the vulnerable enemies around the player and 2Spooky frightens them. With both, the original weighs // the squared distance against the enemy's size plus 80, so the fright only reaches the nearest. static void spooky_venus_update(Entity_Player& player) { bool isSpooky = player.HasCollectible(COLLECTIBLE_2SPOOKY); bool isVenus = player.HasCollectible(COLLECTIBLE_VENUS); if (!isSpooky && !isVenus) return; for (Entity* enemy : entity_query_radius(player.pos, isVenus ? VENUS_RADIUS : SPOOKY_RADIUS, QUERY_ENEMIES)) { if (!enemy->IsVulnerableEnemy(nullptr) || enemy == &player) continue; bool isBoss = enemy->IsBoss(); int charm = isBoss ? VENUS_CHARM_FRAMES : VENUS_CHARM_FRAMES - enemy->charmedCountdown; if (isVenus && charm >= 1) enemy->AddCharmed(EntityRef(&player), charm, false, false); if (!isSpooky) continue; float distanceSquared = vector_length_squared(vector_sub(enemy->pos, player.pos)); if (isVenus && enemy->size + SPOOKY_FEAR_REACH < distanceSquared) continue; enemy->AddFear(EntityRef(&player), isBoss ? SPOOKY_BOSS_FEAR_FRAMES : SPOOKY_FEAR_FRAMES, false); } } // Monstrance burns the vulnerable enemies around the player every fourth tick, harder the deeper the floor and the // nearer the enemy's edge, under its halo. A pacifist room has neither. static void monstrance_update(Entity_Player& player) { bool isWorn = player.HasCollectible(COLLECTIBLE_MONSTRANCE) && !g_game->room->isPacifist; if (isWorn && player.GetIntervalTicks(MONSTRANCE_PERIOD, 0) != 0) { LerpRange falloff = MONSTRANCE_FALLOFF; falloff.outMin = (float)g_game->stage * MONSTRANCE_STAGE_DAMAGE + MONSTRANCE_BASE_DAMAGE; for (Entity* enemy : entity_query_radius(player.pos, MONSTRANCE_RADIUS, QUERY_ENEMIES)) { if (!enemy->IsVulnerableEnemy(nullptr) || enemy == &player) continue; float edge = vector_distance(player.pos, enemy->pos) - enemy->size; enemy->TakeDamage(lerp_range(edge, falloff), 0, EntityRef(&player), MONSTRANCE_HIT_COUNTDOWN); } } aura_keep(player, player.monstranceAura, isWorn, HALO_MONSTRANCE); } // Mars' dash recharges outside its dash, twice as fast with a pony. When the dash ends the player may dash again, // briefly unhurt. A full charge beeps, flashes red and shows Mars' ready costume. static void mars_recharge_update(Entity_Player& player) { if (!player.HasCollectible(COLLECTIBLE_MARS) || player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) || player.marsCooldown < 0) return; if (!player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MARS)) { if (!player.isMarsDashReady) { player.isMarsDashReady = true; player.ClearEntityFlags(FLAG_NO_PHYSICS_KNOCKBACK); player.SetMinDamageCooldown(MARS_READY_DAMAGE_COOLDOWN); } player.marsDashDirection = -1; } bool isPony = player.HasCollectible(COLLECTIBLE_PONY) || player.HasCollectible(COLLECTIBLE_WHITE_PONY); player.marsCooldown = std::max(player.marsCooldown - (isPony ? MARS_READY_PONY_STEP : 1), -1); if (player.marsCooldown != -1) return; npc_sound_play(SOUND_BEEP, 1, 2, MARS_READY_PITCH); player.SetColor(MARS_READY_COLOR, MARS_READY_FLASH_FRAMES, FLASH_PRIORITY, true, true); player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_MARS), false); } // Divine Intervention's shield recharges outside interpolation, beeping and flashing gold when ready. static void divine_intervention_recharge(Entity_Player& player) { constexpr ColorMod DIVINE_READY_COLOR = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {1, 0.9f, 0.6f}}; if (!player.HasCollectible(COLLECTIBLE_DIVINE_INTERVENTION) || player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) || player.divineInterventionCooldown < 0) return; player.divineInterventionCooldown = std::max(player.divineInterventionCooldown - 1, -1); if (player.divineInterventionCooldown != -1) return; npc_sound_play(SOUND_BEEP, 1, 2, MARS_READY_PITCH); player.SetColor(DIVINE_READY_COLOR, MARS_READY_FLASH_FRAMES, FLASH_PRIORITY, true, true); } // Tooth and Nail counts the frames: three fading warnings, then the player turns to a statue for half a second. Losing // the item ends it. static void tooth_and_nail_update(Entity_Player& player) { if (player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) return; TemporaryEffects& effects = player.temporaryEffects; int& frames = player.toothAndNailFrames; if (!player.HasCollectible(COLLECTIBLE_TOOTH_AND_NAIL)) { if (frames <= 0) return; frames = 0; if (!effects.HasNullEffect(NULLITEM_TOOTH_AND_NAIL_STATUE)) return; effects.RemoveNullEffect(NULLITEM_TOOTH_AND_NAIL_STATUE, 1); player.SetColor(GREY_FLASH, FLASH_FRAMES, FLASH_PRIORITY, false, true); return; } frames++; if (std::ranges::find(TOOTH_AND_NAIL_WARNINGS, frames) != std::end(TOOTH_AND_NAIL_WARNINGS)) { int left = TOOTH_AND_NAIL_WARNING_LAST - frames / TOOTH_AND_NAIL_WARNING_STEP; constexpr float WARNING_PITCH_EVEN = 1.7f; constexpr float WARNING_PITCH_ODD = 1.4f; float volume = WARNING_VOLUME - (float)left * WARNING_VOLUME_STEP; npc_sound_play(SOUND_BUTTON_PRESS, volume, 1, left % 2 == 0 ? WARNING_PITCH_EVEN : WARNING_PITCH_ODD); float offset = WARNING_OFFSET - (float)left * WARNING_OFFSET_STEP; ColorMod warning = {{1, 1, 1, 1}, {1, 1, 1, 1 - (float)left * WARNING_FADE_STEP}, {offset, offset, offset}}; player.SetColor(warning, FLASH_FRAMES, FLASH_PRIORITY, false, true); } else if (frames == TOOTH_AND_NAIL_STATUE_FRAME) { if (effects.HasNullEffect(NULLITEM_TOOTH_AND_NAIL_STATUE)) return; effects.AddNullEffect(NULLITEM_TOOTH_AND_NAIL_STATUE, true, 1); player.SetColor(GREY_FLASH, FLASH_FRAMES, FLASH_PRIORITY, false, true); npc_sound_play(SOUND_GOOATTACH0, 1, 2, 1); } else if (frames >= TOOTH_AND_NAIL_END_FRAME) { effects.RemoveNullEffect(NULLITEM_TOOTH_AND_NAIL_STATUE, 1); player.SetColor(GREY_FLASH, FLASH_FRAMES, FLASH_PRIORITY, false, true); frames = 0; } } // Reverse Empress' last 90 frames blink its costume, faster at first (every 4 frames, then every 8 under 32 left). static void reverse_empress_blink_update(Entity_Player& player) { constexpr int EMPRESS_BLINK_FRAMES = 90; constexpr int EMPRESS_FAST_BLINK_FRAMES = 32; TemporaryEffect* empress = player.temporaryEffects.GetNullEffect(NULLITEM_REVERSE_EMPRESS); if (!empress || empress->cooldown >= EMPRESS_BLINK_FRAMES) return; int phase = empress->cooldown < EMPRESS_FAST_BLINK_FRAMES ? empress->cooldown % 8 : empress->cooldown % 16 / 2; bool isShown = player.IsNullItemCostumeVisible(NULLITEM_REVERSE_EMPRESS, -1); ItemConfig_Item* costume = g_manager->itemConfig.GetNullItem(NULLITEM_REVERSE_EMPRESS); if (phase < 4 && isShown) player.RemoveCostume(costume); else if (phase >= 4 && !isShown) player.AddCostume(costume, false); } // IBS charges with the damage enemies took this frame, up to full. A spent charge (negative) drains back to zero // over a second. static void ibs_charge_update(Entity_Player& player) { if (player.HasCollectible(COLLECTIBLE_IBS)) { float dealt = g_game->room->entityList.enemyDamageInflicted; if (dealt > 0 && player.ibsCharge >= 0) player.ibsCharge = std::min(player.ibsCharge + damage_charge_scale() * dealt * IBS_CHARGE_PER_DAMAGE, 1.0f); } if (player.ibsCharge < 0) player.ibsCharge = std::min(player.ibsCharge + 1.0f / IBS_DRAIN_FRAMES, 0.0f); } // The Birthright's frame: Eve's Dead Bird always flies (its costume hidden), and Tainted Keeper pulls the coins near // it that are about to vanish. The Lost's Dead Bird always flies too. static void birthright_dead_bird_update(Entity_Player& player) { TemporaryEffects& effects = player.temporaryEffects; bool isDeadBirdIdle = player.HasCollectible(COLLECTIBLE_DEAD_BIRD) && !player.isCoopGhost && !effects.HasCollectibleEffect(COLLECTIBLE_DEAD_BIRD); if (player.HasCollectible(COLLECTIBLE_BIRTHRIGHT) && player.playerType == PLAYER_EVE && isDeadBirdIdle) { effects.AddCollectibleEffect(COLLECTIBLE_DEAD_BIRD, true, 1); player.RemoveCostume(g_manager->itemConfig.GetCollectible(COLLECTIBLE_DEAD_BIRD)); } else if (player.HasCollectible(COLLECTIBLE_BIRTHRIGHT) && player.playerType == PLAYER_KEEPER_B) for (Entity* entity : entity_query_radius(player.pos, KEEPER_COIN_PULL_RADIUS, QUERY_PICKUPS)) { if (entity->type != ENTITY_PICKUP || entity->variant != PICKUP_COIN || entity->isDead) continue; if (static_cast(entity)->timeout <= 0) continue; Vector pull = vector_sub(player.pos, entity->pos); if (vector_length_squared(pull) <= KEEPER_COIN_PULL_MIN_SQUARED) continue; entity->velocity = vector_resized(pull, KEEPER_COIN_PULL_SPEED); entity->entityGridCollisionClass = GRIDCOLL_WALLS; } bool isLost = player.playerType == PLAYER_THELOST || player.playerType == PLAYER_THELOST_B; isDeadBirdIdle = player.HasCollectible(COLLECTIBLE_DEAD_BIRD) && !player.isCoopGhost && !effects.HasCollectibleEffect(COLLECTIBLE_DEAD_BIRD); if (isLost && isDeadBirdIdle) effects.AddCollectibleEffect(COLLECTIBLE_DEAD_BIRD, true, 1); } // Purgatory keeps one of its rifts in a room still fighting (or under an ambush), checked every 30 frames. static void purgatory_update(Entity_Player& player) { if (!player.HasCollectible(COLLECTIBLE_PURGATORY) || !player.IsFrame(PURGATORY_PERIOD, 0)) return; if (g_game->room->IsClear() && !g_game->ambush.isActive) return; for (Entity* rift : entity_query(ENTITY_EFFECT, EFFECT_PURGATORY)) if (rift->subtype == 0 && rift->spawnerEntity.get() == &player) return; Vector spot = room_pickup_position_random(true, false); uint32_t seed = player.GetCollectibleRNG(COLLECTIBLE_PURGATORY).Next(); g_game->Spawn({.position = spot, .spawner = &player, .type = ENTITY_EFFECT, .variant = EFFECT_PURGATORY, .seed = seed}) ->Update(); } // Plan C's countdown kills the player when it runs out, forgetting what hurt it. Judas with his Birthright gets Plan // C's effect first. static void plan_c_update(Entity_Player& player) { if (player.planCKillCountdown <= 0 || --player.planCKillCountdown != 0) return; TemporaryEffects& effects = player.temporaryEffects; if (player.playerType == PLAYER_JUDAS && player.HasCollectible(COLLECTIBLE_BIRTHRIGHT) && !effects.HasCollectibleEffect(COLLECTIBLE_PLAN_C)) effects.AddCollectibleEffect(COLLECTIBLE_PLAN_C, false, 1); player.Kill(EntityRef()); player.lastDamageFlags = 0; player.lastDamageSource.type = 0; player.lastDamageSource.variant = 0; } // Isaac's Heart keeps the player apart: other enemies and co-op players touching it are pushed back, and enemy shots // that reach it pop. static void isaacs_heart_update(Entity_Player& player) { if (!player.HasCollectible(COLLECTIBLE_ISAACS_HEART)) return; EntityList_EL entities = g_game->room->entityList.updateEL; for (Entity* entity : entities) { if (entity->type == ENTITY_PROJECTILE) { float reach = entity->size + player.size + HEART_BLOCK_MARGIN; Vector offset = vector_sub(entity->pos, player.pos); bool isNear = std::fabs(offset.x) < reach && std::fabs(offset.y) < reach && vector_length(offset) < reach; if (static_cast(entity)->height > HEART_BLOCK_HEIGHT && isNear) entity->isDead = true; continue; } Entity* pushed = entity->to_npc_or_coop_player(); if (!pushed || pushed->entityCollisionClass == ENTCOLL_NONE) continue; float reach = pushed->size + player.size + HEART_PUSH_MARGIN; Vector away = vector_sub(pushed->pos, player.pos); if (std::fabs(away.x) >= reach || std::fabs(away.y) >= reach) continue; float distance = vector_length(away); if (distance >= reach || distance <= 0) continue; away = vector_scale(away, 1 / reach); float closing = vector_dot(pushed->velocity, away); if (closing < 0) pushed->AddVelocity_divided(vector_scale(away, -closing), false); } } // Linger Bean leaves a lingering cloud each time the fire button has been held another 240 frames (twice, the frame // it is reached and the next), larger with Gigante Bean. static void linger_bean_update(Entity_Player& player) { if (!player.HasCollectible(COLLECTIBLE_LINGER_BEAN) || g_game->stageTransition.state != 0) return; int held = player.shootHeldFrames; if (!player.AreControlsEnabled() || player.fireBlockCooldown >= 1 || held % LINGER_BEAN_PERIOD >= 2 || held <= 1) return; Entity* cloud = g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_EFFECT, .variant = EFFECT_BROWN_CLOUD, .seed = Random()}); if (player.HasTrinket(TRINKET_GIGANTE_BEAN)) cloud->sprite.scale = vector_scale(cloud->sprite.scale, GIGANTE_CLOUD_SCALE); cloud->Update(); npc_sound_play(SOUND_LINGER_BEAN, 1, 2, 1); } // A blood splat under the player (Entity_NPC::MakeSplat's), optionally tinted. static Entity* splat_make(Entity_Player& player, const ColorMod* color) { Entity* splat = spawn_at(ENTITY_EFFECT, EFFECT_BLOOD_SPLAT, 0, player.pos, &player); float size = random_unit() * PLAYER_SPLAT_SIZE_RANGE + PLAYER_SPLAT_SIZE_MIN; splat->sprite.scale = vector_make(size, size); splat->Update(); if (color) splat->SetColor(*color, -1, FLASH_PRIORITY, false, true); return splat; } // Every third frame the player may leave a splat: half the time when bleeding (the SMB Super Fan, headless, Anemic, // Akeldama, the dead Tainted Lazarus, and a quarter of Tainted Eve's and Tainted Lazarus' frames), else from Dirty // Mind, Rotten Tomato, a Pound of Flesh or Neptunus, the first one held. static void splats_update(Entity_Player& player) { if (!player.IsFrame(SPLAT_PERIOD, 0) || player.IsHologram()) return; int type = player.playerType; bool isOftenBleeding = player.HasCollectible(COLLECTIBLE_SMB_SUPER_FAN) || player.IsHeadless() || player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_ANEMIC) || player.HasCollectible(COLLECTIBLE_AKELDAMA) || type == PLAYER_LAZARUS2_B; bool isBleeding = isOftenBleeding || ((type == PLAYER_LAZARUS_B || type == PLAYER_EVE_B) && random_below(4) == 0); constexpr int BLEEDING_ODDS = 2; constexpr int DIRTY_MIND_ODDS = 4; constexpr int ROTTEN_TOMATO_ODDS = 8; constexpr int POUND_OF_FLESH_ODDS = 6; constexpr int NEPTUNUS_ODDS = 2; if (isBleeding) { if (random_below(BLEEDING_ODDS) == 0) splat_make(player, nullptr); } else if (player.HasCollectible(COLLECTIBLE_DIRTY_MIND)) { if (random_below(DIRTY_MIND_ODDS) == 0) splat_make(player, &DIRTY_MIND_SPLAT); } else if (player.HasCollectible(COLLECTIBLE_ROTTEN_TOMATO)) { if (random_below(ROTTEN_TOMATO_ODDS) == 0) splat_make(player, &ROTTEN_TOMATO_SPLAT); } else if (player.HasCollectible(COLLECTIBLE_POUND_OF_FLESH)) { if (random_below(POUND_OF_FLESH_ODDS) == 0) splat_make(player, nullptr); } else if (player.HasCollectible(COLLECTIBLE_NEPTUNUS) && random_below(NEPTUNUS_ODDS) == 0) splat_make(player, &NEPTUNUS_SPLAT); } // The fading looks: under the camo seeds, Camo Undies' cloak or Faded Polaroid's flicker, the player's color slides // toward a near black tinted like its footprints, settling at once on a room's first frames. static void camo_fade_update(Entity_Player& player) { Game& game = *g_game; float fade = 1; bool isCamo = game.seedEffects.HasSeedEffect(SEED_CAMO_ISAAC) || game.seedEffects.HasSeedEffect(SEED_CAMO_EVERYTHING) || player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_CAMO_UNDIES); if (!isCamo) { TemporaryEffect* polaroid = player.temporaryEffects.GetTrinketEffect(TRINKET_FADED_POLAROID); if (!polaroid) return; if (polaroid->cooldown < FADED_POLAROID_FADE_FRAMES) { fade = std::sin((float)polaroid->cooldown * FADED_POLAROID_PULSE); if (fade <= 0) return; } } float settle = game.room->GetFrameCount() > 1 ? CAMO_SETTLE : 1; ColorMod footprints = color_lerp(player.footprintColor2, player.footprintColor1, 0.5f); ColorMod camo = color_lerp(player.colorOverride, footprints, settle); camo._tint[0] = camo._tint[1] = camo._tint[2] = CAMO_TINT; camo._tint[3] = 1; player.colorOverride = camo; player.sprite.color = color_lerp(player.color, camo, fade); } // The player's size and shadow follow its sprite's layer scale (with the original's extra 1 in the sum), held between // 0.3 and 1: smaller with Mini Mush, halved by Pluto or Inner Child's shrink (with fewer collision points), doubled // up to 2 by Mega Mush with a triple shadow. A co-op ghost's shadow is halved and the invisible seed hides it. static void size_update(Entity_Player& player) { ANM2& sprite = player.sprite; float scale = 1; for (LayerState& layer : sprite.layerStates) scale += layer.size.x; scale = std::clamp(scale / (float)sprite.layerStates.size() * player.playerSpriteScale.x, SIZE_SCALE_MIN, 1.0f); int points = player.config->gridCollisionPoints; float shadow = 1; if (player.HasCollectible(COLLECTIBLE_MINI_MUSH)) scale *= MINI_MUSH_SIZE; if (player.HasCollectible(COLLECTIBLE_PLUTO) || player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_INNER_CHILD)) { scale *= SMALL_SIZE; points = std::min(points, SMALL_COLLISION_POINTS); } if (player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH)) { scale = std::min(scale + scale, MEGA_MUSH_SIZE_MAX); shadow = MEGA_MUSH_SHADOW; } if (player.isCoopGhost) shadow *= GHOST_SHADOW; if (g_game->seedEffects.HasSeedEffect(SEED_INVISIBLE_ISAAC)) shadow = 0; EntityConfig_Entity* entry = g_manager->entityConfig.GetEntity(player.type, player.variant, 0); player.SetSize(scale * entry->collisionRadius, player.sizeMulti, points); player.shadowSize = shadow * player.config->shadowSize; } // The written pieces of the items' frame (update_effects 00794e50) the plain path runs after its others, in their // order there. void items_frame_update(Entity_Player& player) { TemporaryEffects& effects = player.temporaryEffects; anarchist_cookbook_update(player); faded_polaroid_update(player); dads_ring_update(player); if (effects.HasCollectibleEffect(COLLECTIBLE_NOTCHED_AXE) && !player.HasCollectible(COLLECTIBLE_NOTCHED_AXE)) effects.RemoveCollectibleEffect(COLLECTIBLE_NOTCHED_AXE, -1); if (effects.GetNullEffect(NULLITEM_CAMO_BOOST)) effects.RemoveNullEffect(NULLITEM_CAMO_BOOST, 1); berserk_tick_update(player); if (effects.HasCollectibleEffect(COLLECTIBLE_URN_OF_SOULS) && !player.HasCollectible(COLLECTIBLE_URN_OF_SOULS)) effects.RemoveCollectibleEffect(COLLECTIBLE_URN_OF_SOULS, -1); spooky_venus_update(player); monstrance_update(player); mars_recharge_update(player); divine_intervention_recharge(player); tooth_and_nail_update(player); reverse_empress_blink_update(player); if (effects.HasNullEffect(NULLITEM_REVERSE_STARS) && player.IsExtraAnimationFinished()) effects.RemoveNullEffect(NULLITEM_REVERSE_STARS, 1); ibs_charge_update(player); birthright_dead_bird_update(player); purgatory_update(player); isaacs_heart_update(player); plan_c_update(player); linger_bean_update(player); if (player.hallowedGroundCountdown > 0 && --player.hallowedGroundCountdown < 1) { player.AddCacheFlags(FRAME_STAT_CACHE); player.EvaluateItems(); } splats_update(player); if (effects.HasNullEffect(NULLITEM_SPIN_TO_WIN)) { if (player.activeItems[ACTIVE_SLOT_PRIMARY].item == COLLECTIBLE_SPIN_TO_WIN) player.AddActiveCharge(SPIN_TO_WIN_DRAIN, ACTIVE_SLOT_PRIMARY, false, false, false); else effects.RemoveNullEffect(NULLITEM_SPIN_TO_WIN, 1); } if (player.grantedCollectibleCountdown > 0 && --player.grantedCollectibleCountdown < 1) { player.grantedCollectibleFlags = 0; player.AddCacheFlags(FRAME_STAT_CACHE); player.EvaluateItems(); } camo_fade_update(player); size_update(player); }