Files
isaac-port/src/entity_player_damage.cpp
T

1590 lines
77 KiB
C++

#include "boss_repentance.h"
#include "boss_ai.h"
#include "entity_bomb.h"
#include "entity_combat.h"
#include "entity_effect_combat.h"
#include "entity_familiar.h"
#include "entity_laser.h"
#include "entity_pickup.h"
#include "entity_npc.h"
#include "entity_player.h"
#include "entity_player_characters.h"
#include "entity_player_passives.h"
#include "entity_player_trinkets.h"
#include "entity_tear.h"
#include "game.h"
#include "grid_entity_trap_door.h"
#include "level.h"
#include "log.h"
#include "lua_engine.h"
#include "manager.h"
#include "npc_ai.h"
#include "npc_basement.h"
#include "persistent_game_data.h"
#include "room.h"
#include "room_grid.h"
#include <algorithm>
#include <cmath>
constexpr int COLLECTIBLE_BINKY = 438;
constexpr int COLLECTIBLE_CONE_HEAD = 457;
constexpr int COLLECTIBLE_JELLY_BELLY = 690;
constexpr int COLLECTIBLE_MARBLES = 538;
constexpr int COLLECTIBLE_METAL_PLATE = 449;
constexpr int COLLECTIBLE_SPIRIT_SHACKLES = 674;
constexpr int TRINKET_BLIND_RAGE = 81;
constexpr int TRINKET_CROW_HEART = 107;
constexpr int TRINKET_FINGER_BONE = 128;
constexpr int TRINKET_SWALLOWED_M80 = 178;
constexpr int TRINKET_WALNUT = 108;
constexpr int NULLITEM_DOUBLE_DAMAGE = 29;
constexpr int NULLITEM_SHACKLES_GHOST = 101;
constexpr int SAMSON_B_HIT_CHARGE = 10000;
constexpr int BLEED_OUT_HEALTH = 600;
constexpr int SIREN_CHARM_SPARE_FRAMES = 29;
constexpr int WHITE_FIRE_VARIANT = 4;
constexpr int EFFECT_SELF_DAMAGE = 19;
constexpr int EFFECT_POISON_CLOUD = 123;
constexpr int ITEM_STATE_HOLD_STILL = 47;
constexpr int BABY_GHOST = 59;
constexpr int BABY_HALO = 24;
constexpr int BABY_SHIELD = 11;
constexpr int BABY_BOMB = 20;
constexpr int BABY_FART = 17;
constexpr int BABY_BOOK = 44;
// The thieves that knock a coin loose: Greed and its likes by their hits or shots, the Ultra Greeds also by what they
// spawn.
constexpr int COIN_THIEF_TYPES[] = {50, 86, 90, 294, 299, 406};
constexpr int COIN_SHOOTER_TYPES[] = {50, 86, 90};
constexpr int ULTRA_GREED = 406;
constexpr int ULTRA_GREED_DOOR = 294;
constexpr int SOUND_NAIL_HURT_1 = 104;
constexpr int SOUND_NAIL_HURT_2 = 106;
constexpr int SOUND_BOSS_DELAY_RANDOM = 130;
constexpr int SOUND_BOSS_DELAY_MIN = 50;
constexpr int SOUND_FRAME_DELAY = 2;
// Tainted Jacob turned ghost by Dark Esau cannot be hurt for 90 frames.
constexpr int JACOB_GHOST_COOLDOWN = 90;
constexpr uint64_t DAMAGE_NO_HURT_EFFECTS = 0x100d0400;
constexpr uint64_t DAMAGE_ISAACS_HEART_PIERCE = 0x2820;
constexpr uint64_t DAMAGE_UNPENALIZED = DAMAGE_NO_PENALTIES | DAMAGE_RED_HEARTS;
constexpr int LAST_DAMAGE_STAGE_MAX = 13;
constexpr int HURT_FRAMES_PER_HEART = 60;
constexpr int HURT_HEARTS_MAX = 2;
constexpr int HIT_COOLDOWN = 4;
constexpr uint32_t STAGE_FULL_HEART_DAMAGE = 7;
constexpr int MASSIVE_DAMAGE = 24;
constexpr int EVIL_CHARM_GRACE_FRAMES = 30;
constexpr int COOLDOWN_SCALE_MIN = 16;
constexpr int COOLDOWN_SCALE_SHIFT = 3;
constexpr int CROW_HEART_KEEP_2 = 25;
constexpr int CROW_HEART_KEEP_3 = 50;
// A bone heart's break: its shards and snap, and Brittle Bones' ring of tears.
constexpr ColorMod BONE_SHARD_COLOR = {{0.7f, 0.7f, 0.65f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
constexpr int BONE_SHARD_COUNT = 8;
constexpr float BONE_SHARD_SPEED_MIN = 2;
constexpr float BONE_SHARD_SPEED_RANDOM = 3;
constexpr float BONE_SNAP_VOLUME = 0.7f;
constexpr float BONE_SNAP_PITCH_RANDOM = 0.2f;
constexpr float BRITTLE_BONES_TURN = 360;
constexpr int BRITTLE_BONES_TEARS = 10;
constexpr float BRITTLE_BONES_SPEED = 10;
constexpr float BRITTLE_BONES_SCALE = 1.355f;
constexpr float BRITTLE_BONES_DAMAGE_SCALE = 2;
constexpr float BRITTLE_BONES_DAMAGE_BONUS = 22;
constexpr float DAMAGE_ROUNDING = 0.5f;
constexpr float HALVED_DAMAGE = 0.5f;
constexpr float HALVED_DAMAGE_DEATHMATCH = 0.75f;
constexpr float DOUBLED_DAMAGE_DEATHMATCH = 1.25f;
constexpr float VOICE_PITCH_PLAYER = 1;
constexpr float VOICE_PITCH_BABY = 1.5f;
constexpr float VOICE_PITCH_PER_PILL = 0.1f;
constexpr float VOICE_PITCH_PLUTO = 0.5f;
constexpr float VOICE_PITCH_STEP = 0.2f;
constexpr float VOICE_PITCH_MIN = 0.5f;
constexpr float VOICE_PITCH_MAX = 2;
constexpr float REMOTE_VOLUME_SCALE = 0.1f;
constexpr int PILL_EFFECT_PUBERTY = 33;
constexpr int PILL_EFFECT_HELIUM = 32;
// The extra lives the HUD counts: 1up!, Ankh, Guppy's Collar, Judas' Shadow, Lazarus' Rags and Inner Child.
constexpr int EXTRA_LIFE_ITEMS[] = {11, 161, 212, 311, 332, 688};
constexpr int TAINTED_LOST_BIRTHRIGHT = 619;
// The hazards Evil Charm protects from: fires, creep, and the effects that hurt on contact.
constexpr int EVIL_CHARM_EFFECTS[] = {22, 23, 24, 25, 26, 32, 37, 44, 45, 46, 53, 54, 56, 78, 90, 94, 141, 147, 155, 169, 204};
constexpr int EVIL_CHARM_GRID_VARIANT = 10000;
// The temporary effects that make the player invincible to any hit: Gamekid, My Little Unicorn, Unicorn Stump and
// Teleport.
constexpr int INVINCIBLE_EFFECTS[] = {93, 77, 298, 44};
constexpr int NULLITEM_INVINCIBLE_SHIELD = 59;
constexpr int BLOOD_DONATION_VARIANT = 2;
constexpr int BLOOD_BANK_VARIANT = 5;
constexpr float GNAWED_LEAF_MASS = 1000;
constexpr int BREATH_OF_LIFE_WINDOW = 5;
// Whether a hit passes the player by: its own self damage, friendly sources, another's Dark Esau, a dead player,
// Isaac's Heart, Evil Charm's hazards, a co-op baby still appearing, and a Visage chain whose end holds the player.
static bool is_damage_ignored(Entity_Player& player, const EntityRef& source, uint64_t damageFlags)
{
Game& game = *g_game;
Entity* entity = source.entity;
if (source.type == ENTITY_EFFECT && source.variant == EFFECT_SELF_DAMAGE && source.spawnerType == ENTITY_PLAYER)
return true;
if (source.IsFriendly() && !game.deathmatchManager.is_active()) return true;
if (source.IsFriendly()) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (friendly fire in versus)");
if (damageFlags & DAMAGE_IGNORED) return true;
Entity* darkEsau = player.darkEsau.get();
bool isOtherEsau = entity && entity->type == ENTITY_DARK_ESAU && entity != darkEsau &&
(entity->parent.get() != darkEsau || !darkEsau) && (entity->child.get() != darkEsau || !darkEsau) &&
entity->spawnerEntity.get() != &player && entity->spawnerEntity.get() != darkEsau;
if (isOtherEsau || player.isDead) return true;
Entity_Player* heartOwner = player.playerType == PLAYER_THESOUL_B && player.twin_get() ? player.twin_get() : &player;
bool isHeartProtected = heartOwner->HasCollectible(COLLECTIBLE_ISAACS_HEART) || player.playerType == PLAYER_THEFORGOTTEN_B;
if (isHeartProtected && !(damageFlags & DAMAGE_ISAACS_HEART_PIERCE)) return true;
if (player.is_evil_charm_immune(source)) return true;
bool isAppearing = player.sprite.IsPlaying("Appear") || player.sprite.IsPlaying("Glitch");
if ((player.variant == PLAYER_VARIANT_COOP_BABY || player.isCoopGhost) && isAppearing) return true;
if (source.type != ENTITY_VISAGE || source.variant != VISAGE_CHAIN || !entity) return false;
Entity* link = entity;
while (link->child && link->child->type == ENTITY_VISAGE && link->child->variant == VISAGE_CHAIN) link = link->child.get();
return link->target.get() == &player;
}
// A charmed Bishop takes the hit for the player: it is hurt instead and its shield flashes on the player. Whether a
// Bishop took it.
static bool bishop_shield_block(Entity_Player& player)
{
constexpr float BISHOP_HIT_DAMAGE = 3.5f;
constexpr int BISHOP_HIT_COUNTDOWN = 15;
constexpr int BISHOP_SOUND_DELAY = 10;
constexpr float BISHOP_SHIELD_RISE = -24;
Entity* bishop = bishop_nearest_find(player.pos, true);
if (!bishop) return false;
bishop->TakeDamage(BISHOP_HIT_DAMAGE, DAMAGE_COUNTDOWN, EntityRef(), BISHOP_HIT_COUNTDOWN);
int sound = SOUND_BISHOP_HIT;
seed_fart_sound_override(&sound);
g_manager->sfxManager.Play(sound, {.frameDelay = BISHOP_SOUND_DELAY});
if (player.hitEffect) player.hitEffect->Remove();
auto* shield = static_cast<Entity_Effect*>(g_game->Spawn({.position = player.pos, .spawner = bishop,
.type = ENTITY_EFFECT, .variant = EFFECT_BISHOP_SHIELD,
.seed = Random()}));
shield->parent = bishop;
shield->target = &player;
shield->parentOffset = vector_make(0, BISHOP_SHIELD_RISE);
shield->posOffset = vector_make(player.posOffset.x, player.posOffset.y + BISHOP_SHIELD_RISE);
shield->Update();
player.hitEffect = shield;
return true;
}
// (007c7b10) Dull Razor's wisps shield the player: for each live one, one hit in five (not a fake or red heart one)
// is taken by the wisp, which dies, and the player stays unhurtable for a moment. Whether a wisp took it.
static bool wisp_shield_block(Entity_Player& player, uint64_t damageFlags)
{
constexpr int SHIELD_ODDS = 5;
constexpr int SHIELD_COOLDOWN = 15;
for (Entity* entity : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP))
{
auto& wisp = *static_cast<Entity_Familiar*>(entity);
bool isShield = !wisp.isDead && wisp.player == &player && wisp.subtype == COLLECTIBLE_DULL_RAZOR &&
!(damageFlags & (DAMAGE_FAKE | DAMAGE_RED_HEARTS));
if (!isShield || Random() % SHIELD_ODDS != 0) continue;
player.damageCooldown = std::max(player.damageCooldown, SHIELD_COOLDOWN);
wisp.Kill(EntityRef());
return true;
}
return false;
}
// Plays one of the player's sounds at a volume and pitch, unless the seeds swap it for a fart.
static void voice_play(int sound, float volume, int frameDelay, float pitch)
{
seed_fart_sound_override(&sound);
g_manager->sfxManager.Play(sound, {.volume = volume, .frameDelay = frameDelay, .pitch = pitch});
}
// The answers' strengths and odds: Pyromaniac's heart icon, Host Hat's guard and return volley, Metal Plate's and
// Cone Head's chances, and Jelly Belly's bounce.
constexpr float HEART_ICON_RISE = -24;
constexpr int HOST_HAT_VOLLEY_ODDS = 5;
constexpr float RETURN_SHOT_SPEED = 10;
constexpr float HOST_HAT_SPREAD = 15;
constexpr uint32_t RETURN_SHOT_FLAGS = 7;
constexpr int METAL_PLATE_ODDS = 4;
constexpr int CONE_HEAD_ODDS = 5;
constexpr int CONE_HEAD_FLASH_FRAMES = 10;
constexpr int JELLY_BELLY_ODDS = 2;
constexpr float JELLY_BELLY_REACH = 10;
constexpr float JELLY_BELLY_SHOT_SPEED = 10;
constexpr float JELLY_BELLY_PUSH = 20;
constexpr int JELLY_BELLY_PUSH_FRAMES = 15;
constexpr float JELLY_BELLY_SPEED_UNIT = 25;
constexpr float JELLY_BELLY_PLAYER_PUSH = 40;
constexpr float JELLY_BELLY_BOUNCE = 20;
constexpr float JELLY_BELLY_SHOT_BOUNCE = 14;
constexpr int JELLY_BELLY_COOLDOWN = 8;
constexpr float JELLY_SHOT_VOLUME = 0.8f;
constexpr float JELLY_SHOT_PITCH = 1.25f;
constexpr ColorMod METAL_PLATE_TEAR_COLOR = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
constexpr ColorMod CONE_HEAD_FLASH = {{0.7f, 0.7f, 1, 1}, {0, 0, 0, 0}, {0, 0, 0}};
// The four looks of a Host Hat animation, picked by the way a vector leans.
static std::string host_hat_anim(std::string_view base, Vector direction)
{
constexpr std::string_view SIDES[] = {"Left", "Up", "Right", "Down"};
return std::string(base) + std::string(SIDES[vector_to_direction(direction)]);
}
// The shot a hat or plate sends back: the way the hitting shot came, at 10.
static Vector return_shot_velocity(const EntityRef& source)
{
return vector_scale(vector_resized(source.velocity, RETURN_SHOT_SPEED), -1);
}
// Jelly Belly's bounce, half the time against a living source (an enemy, a shot or a player) that reaches it: an
// enemy is knocked away, a shot turned back, another player pushed by their speeds. Whether it bounced the hit.
static bool jelly_belly_bounce(Entity_Player& player, const EntityRef& source, uint64_t damageFlags)
{
if (!player.HasCollectible(COLLECTIBLE_JELLY_BELLY) || (damageFlags & (DAMAGE_NO_MODIFIERS | DAMAGE_FAKE))) return false;
Entity* hitter = source.entity;
bool isLiving = hitter && ((source.type >= ENTITY_FIRST_ENEMY && source.type <= ENTITY_LAST_ENEMY) ||
source.type == ENTITY_PROJECTILE || source.type == ENTITY_PLAYER);
if (random_below(JELLY_BELLY_ODDS) != 0 || !isLiving) return false;
float reach = hitter->size * std::max(hitter->sizeMulti.x, hitter->sizeMulti.y) + player.size + JELLY_BELLY_REACH;
bool isTouching = vector_distance(hitter->pos, player.pos) <= reach;
if (hitter->is_player())
{
if (hitter->HasEntityFlags(FLAG_KNOCKED_BACK) || !isTouching) return false;
float combined = vector_length_squared(hitter->velocity) + vector_length_squared(player.velocity);
float push = std::clamp(combined / JELLY_BELLY_SPEED_UNIT, 0.0f, 1.0f) * JELLY_BELLY_PLAYER_PUSH;
float strength = vector_length_squared(player.velocity) / combined * push;
Vector away = vector_scale(vector_normalized(vector_sub(hitter->pos, player.pos)), strength);
hitter->AddKnockback(EntityRef(&player), away, 1, true);
player.jellyBellyBounceTimer = JELLY_BELLY_BOUNCE;
voice_play(SOUND_JELLY_BOUNCE, 1, SOUND_FRAME_DELAY, 1);
}
else if (hitter->IsEnemy())
{
if (!isTouching) return false;
Vector away = vector_resized(vector_sub(hitter->pos, player.pos), JELLY_BELLY_PUSH);
hitter->AddKnockback(EntityRef(&player), away, JELLY_BELLY_PUSH_FRAMES, true);
player.jellyBellyBounceTimer = JELLY_BELLY_BOUNCE;
voice_play(SOUND_JELLY_BOUNCE, 1, SOUND_FRAME_DELAY, 1);
}
else if (hitter->type == ENTITY_PROJECTILE || hitter->type == ENTITY_TEAR)
{
Vector away = vector_resized(vector_sub(hitter->pos, player.pos), JELLY_BELLY_SHOT_SPEED);
if (hitter->type == ENTITY_PROJECTILE) static_cast<Entity_Projectile*>(hitter)->Reflect(away);
else static_cast<Entity_Tear*>(hitter)->Deflect(&player, away);
player.jellyBellyBounceTimer = JELLY_BELLY_SHOT_BOUNCE;
voice_play(SOUND_BLOBBY_WIGGLE, JELLY_SHOT_VOLUME, SOUND_FRAME_DELAY, JELLY_SHOT_PITCH);
}
else return false;
player.SetMinDamageCooldown(JELLY_BELLY_COOLDOWN);
player.AddEntityFlags(FLAG_NO_DAMAGE_BLINK);
return true;
}
// Walnut cracks open on an explosion a third of the time: a trinket, a heart, a key and a coin (times its multiplier)
// near the player, and it is gone.
static void walnut_crack(Entity_Player& player)
{
constexpr int WALNUT_CHANCE = 33;
constexpr int WALNUT_PICKUPS[] = {PICKUP_TRINKET, PICKUP_HEART, PICKUP_KEY, PICKUP_COIN};
RNG& rng = player.GetTrinketRNG(TRINKET_WALNUT);
if (rng.Next() % 100 >= WALNUT_CHANCE) return;
int count = player.GetTrinketMultiplier(TRINKET_WALNUT);
for (int variant : WALNUT_PICKUPS)
for (int i = 0; i < count; i++)
{
uint32_t seed = rng.Next();
Vector spot = room_free_pickup_position_find({.position = player.pos, .step = PICKUP_SPOT_STEP});
g_game->Spawn({.position = spot, .spawner = &player, .type = ENTITY_PICKUP, .variant = variant, .seed = seed});
}
player.TryRemoveTrinket(TRINKET_WALNUT);
}
// The items that answer a hit before it lands, in the original's order: Pyromaniac heals from explosions and shrugs
// off fire, Host Hat guards explosions and sometimes fires back at shots, Dr. Fetus and the bone with Ipecac ignore
// their own blasts, Hot Bombs fire, the bomb baby explosions, Jelly Belly bounces, Metal Plate returns shots and Cone
// Head shrugs off a fifth of the hits, after a charmed Bishop's shield and Walnut's crack. Whether the hit is stopped.
static bool damage_reactions_check(Entity_Player& player, const EntityRef& source, uint64_t damageFlags)
{
bool isExplosion = damageFlags & DAMAGE_EXPLOSION;
bool isFire = damageFlags & DAMAGE_FIRE;
if (bishop_shield_block(player)) return true;
if (player.HasTrinket(TRINKET_WALNUT) && isExplosion) walnut_crack(player);
if (player.HasCollectible(COLLECTIBLE_PYROMANIAC) && isFire) return true;
if (player.HasCollectible(COLLECTIBLE_PYROMANIAC) && isExplosion)
{
if (player.redHearts >= player.GetEffectiveMaxHearts()) return true;
Entity* icon = g_game->Spawn({.position = player.pos, .type = ENTITY_EFFECT, .variant = EFFECT_HEART, .seed = Random()});
icon->sprite.offset = vector_make(0, HEART_ICON_RISE);
icon->renderDepthOffset = 1;
player.AddHearts(1, false, false);
return true;
}
if (player.HasCollectible(COLLECTIBLE_HOST_HAT) && isExplosion)
{
player.PlayCollectibleAnim(COLLECTIBLE_HOST_HAT, false, host_hat_anim("Guard", vector_from_direction(player.headDirection)), -1);
return true;
}
bool isFetusBomb = source.spawnerType == ENTITY_PLAYER || source.spawnerType == ENTITY_FAMILIAR;
isFetusBomb = isFetusBomb && source.entity && source.entity->type == ENTITY_BOMB &&
static_cast<Entity_Bomb*>(source.entity)->isFetus;
bool isFetus = player.HasWeaponType(WEAPON_BOMBS) ||
(player.HasWeaponType(WEAPON_BONE) && player.HasCollectible(COLLECTIBLE_DR_FETUS));
if (isFetus && player.HasCollectible(COLLECTIBLE_IPECAC) && isExplosion && isFetusBomb) return true;
bool isBoneIpecac = player.HasWeaponType(WEAPON_BONE) && player.HasCollectible(COLLECTIBLE_IPECAC);
if (isBoneIpecac && isExplosion && source.type == ENTITY_KNIFE) return true;
if (player.HasCollectible(COLLECTIBLE_HOT_BOMBS) && isFire) return true;
if (player.variant == PLAYER_VARIANT_COOP_BABY && player.babySkin == BABY_BOMB && isExplosion) return true;
if (jelly_belly_bounce(player, source, damageFlags)) return true;
if (player.HasCollectible(COLLECTIBLE_HOST_HAT) && random_below(HOST_HAT_VOLLEY_ODDS) == 0 &&
source.type == ENTITY_PROJECTILE)
{
Vector back = return_shot_velocity(source);
for (float turn : {-HOST_HAT_SPREAD, 0.0f, HOST_HAT_SPREAD})
player.FireTear({player.pos, vector_rotated(back, turn)}, RETURN_SHOT_FLAGS, nullptr, 1);
player.PlayCollectibleAnim(COLLECTIBLE_HOST_HAT, false, host_hat_anim("Shooting", back), -1);
return true;
}
bool isShot = source.type == ENTITY_PROJECTILE || source.type == ENTITY_TEAR;
if (player.HasCollectible(COLLECTIBLE_METAL_PLATE) &&
player.GetCollectibleRNG(COLLECTIBLE_METAL_PLATE).RandomInt(METAL_PLATE_ODDS) == 0 && isShot)
{
Entity_Tear* tear = player.FireTear({player.pos, return_shot_velocity(source)}, RETURN_SHOT_FLAGS, nullptr, 1);
TearFlags flags = tear->tearFlags;
flags.set(TEAR_HOMING);
flags.set(TEAR_CONFUSION);
tear->SetTearFlags(flags);
tear->SetColor(METAL_PLATE_TEAR_COLOR, -1, 255, false, true);
tear->Update();
return true;
}
if (player.HasCollectible(COLLECTIBLE_CONE_HEAD) && !(damageFlags & (DAMAGE_NO_MODIFIERS | DAMAGE_FAKE)) &&
player.GetCollectibleRNG(COLLECTIBLE_CONE_HEAD).RandomInt(CONE_HEAD_ODDS) == 0)
{
player.SetColor(CONE_HEAD_FLASH, CONE_HEAD_FLASH_FRAMES, 1, true, true);
return true;
}
return false;
}
// Whether a list of ids has one.
template <size_t N> static bool is_listed(const int (&ids)[N], int id)
{
return std::ranges::find(ids, id) != std::end(ids);
}
// 007db330 A damage cooldown in frames, scaled down in versus.
static int damage_cooldown_scale(int frames)
{
if (!g_game->deathmatchManager.is_active()) return frames;
return frames > COOLDOWN_SCALE_MIN - 1 ? frames >> COOLDOWN_SCALE_SHIFT : 1;
}
// Blind Rage's and Finger Bone's part of 007729d0: Blind Rage stretches the invincibility frames, and Finger Bone
// gives a bone heart one hit in 25 (12, 8 with stronger copies).
static void blind_rage_finger_bone_hit(Entity_Player& player)
{
constexpr int FINGER_BONE_ODDS[] = {25, 12, 8};
if (player.HasTrinket(TRINKET_BLIND_RAGE))
player.damageCooldown = damage_cooldown_scale(player.GetTrinketMultiplier(TRINKET_BLIND_RAGE) * 2) * player.damageCooldown;
if (!player.HasTrinket(TRINKET_FINGER_BONE)) return;
int multiplier = player.GetTrinketMultiplier(TRINKET_FINGER_BONE);
int odds = FINGER_BONE_ODDS[multiplier == 2 ? 1 : multiplier == 3 ? 2 : 0];
if (player.GetTrinketRNG(TRINKET_FINGER_BONE).RandomInt((uint32_t)odds) == 0) player.AddBoneHearts(1);
}
// The bestiary count an enemy adds to, unless the save is frozen or the enemy has no page.
static void bestiary_count_add(std::map<int, int>& counts, int type, int variant)
{
PersistentGameData& data = g_manager->persistentGameData;
EntityConfig_Entity* entity = data.isReadOnly ? nullptr : g_manager->entityConfig.GetBestiaryConfig(type, variant);
if (entity && entity->isBestiary) counts[entity->id << 20 | entity->variant << 8]++;
}
// The damage a hit deals in half hearts: rounded, two from the Womb on or on a victory lap, halved by the Wafer and
// its likes, doubled by the double damage effect, and set by the seeds that hurt more.
static int damage_amount_get(Entity_Player& player, float damage, uint64_t damageFlags, const EntityRef& source)
{
Game& game = *g_game;
bool isDeathmatch = game.deathmatchManager.is_active();
int amount = (int)(damage + DAMAGE_ROUNDING);
if (isDeathmatch && amount == 0 && damage > 0) amount = 1;
if (damageFlags & DAMAGE_NO_MODIFIERS) return amount;
if (!game.IsGreedMode() && (game.stage >= STAGE_FULL_HEART_DAMAGE || game.victoryLap >= 1 || game.IsAscent()))
amount = std::max(amount, 2);
bool isHardMode = game.difficulty == DIFFICULTY_HARD || game.difficulty == DIFFICULTY_GREEDIER;
bool isHalved = player.HasCollectible(COLLECTIBLE_WAFER) ||
player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_WAFER) ||
player.GetTrinketMultiplier(TRINKET_CALLUS) > 2 || (source.flags & ENTITY_REF_WEAKNESS) ||
(player.HasCollectible(COLLECTIBLE_DOGMA) && !isHardMode);
if (isHalved && amount > 1)
amount = std::max((int)((float)amount * (isDeathmatch ? HALVED_DAMAGE_DEATHMATCH : HALVED_DAMAGE) + DAMAGE_ROUNDING), 1);
if (player.temporaryEffects.HasNullEffect(NULLITEM_DOUBLE_DAMAGE))
amount = (int)((float)std::max(amount, 2) * (isDeathmatch ? DOUBLED_DAMAGE_DEATHMATCH : 1));
if (player.GetHealthType() == HEALTH_COIN) amount = 2;
if (game.seedEffects.HasSeedEffect(SEED_ISAAC_TAKES_HIGH_DAMAGE)) amount = std::max(amount, 2);
if (game.seedEffects.HasSeedEffect(SEED_ISAAC_TAKES_MASSIVE_DAMAGE)) amount = std::max(amount, MASSIVE_DAMAGE);
return amount;
}
// The soul half hearts above the last bone heart, which a hit takes before the bone heart.
static int souls_above_bones_count(Entity_Player& player)
{
int count = 0;
for (int slot = player.boneHearts + (player.soulHearts + 1) / 2 - 1; slot >= 0 && !player.IsBoneHeart(slot); slot--)
count = count == 0 && (player.soulHearts & 1) ? 1 : count + 2;
return std::min(count, player.soulHearts);
}
// A bone heart breaking: bone shards and a snap, The Forgotten's floor marked as hurt, and Brittle Bones' ring of bone
// tears with its tears up.
static void bone_heart_break(Entity_Player& player, bool isPenalized)
{
player.boneHearts--;
player.UpdateHeartDependentEffects();
if (player.playerType == PLAYER_THEFORGOTTEN && isPenalized && !player.parent)
{
g_game->SetRedHeartDamage();
g_game->room->isRedHeartDamaged = true;
}
game_particles_spawn({.color = BONE_SHARD_COLOR, .position = player.pos, .height = player.posOffset.y,
.speed = random_unit() * BONE_SHARD_SPEED_RANDOM + BONE_SHARD_SPEED_MIN,
.count = BONE_SHARD_COUNT, .variant = EFFECT_TOOTH_PARTICLE});
voice_play(SOUND_BONE_SNAP, BONE_SNAP_VOLUME, SOUND_FRAME_DELAY, random_unit() * BONE_SNAP_PITCH_RANDOM + 1);
if (!player.HasCollectible(COLLECTIBLE_BRITTLE_BONES)) return;
float turn = random_unit() * BRITTLE_BONES_TURN;
for (int i = 0; i < BRITTLE_BONES_TEARS; i++)
{
uint32_t seed = Random();
Vector direction = vector_from_angle(((float)i / BRITTLE_BONES_TEARS + turn) * BRITTLE_BONES_TURN);
auto* tear = static_cast<Entity_Tear*>(g_game->Spawn({.position = player.pos,
.velocity = vector_scale(direction, BRITTLE_BONES_SPEED),
.spawner = &player, .type = ENTITY_TEAR,
.variant = TEAR_BONE, .seed = seed}));
TearParams params = player.GetTearHitParams(WEAPON_TEARS, 1, random_below(2) * 2 - 1, nullptr);
params.tearFlags.set(TEAR_BONE_FLAG);
tear->SetTearFlags(params.tearFlags);
tear->SetScale(params.tearScale * BRITTLE_BONES_SCALE);
tear->SetCollisionDamage(params.tearDamage * BRITTLE_BONES_DAMAGE_SCALE + BRITTLE_BONES_DAMAGE_BONUS);
tear->SetHeight(params.tearHeight);
tear->parent = &player;
tear->Update();
}
player.brittleBonesUpgrades++;
player.cacheFlags |= CACHE_FIREDELAY;
player.EvaluateItems();
}
// Takes a hit's half hearts from the red hearts: rotten hearts double what they lose, a bone heart filled with red only
// loses its own heart, an eternal heart soaks up the hit (when red hearts are not hit first or not enough), and a red
// heart lost marks the floor as hurt unless Crow Heart keeps it. Returns what was taken.
static int red_hearts_remove(Entity_Player& player, int amount, bool isRedFirst, bool isBoneFilled, uint64_t damageFlags,
bool isPenalized)
{
if (player.rottenHearts > 0 && player.eternalHearts < 1)
{
int rotten = isRedFirst ? std::max(0, player.rottenHearts * 2 - player.redHearts + amount) : amount;
amount += std::min(player.rottenHearts, rotten);
}
if (player.boneHearts > 0 && isBoneFilled) amount = std::min(amount, (player.redHearts & 1) ? 1 : 2);
if (player.eternalHearts > 0)
{
int unshielded = player.redHearts - (player.soulHearts + player.boneHearts < 1 ? 1 : 0) - player.rottenHearts;
if (!(damageFlags & DAMAGE_RED_HEARTS) || amount > unshielded)
{
amount = std::max(amount - player.eternalHearts, 0);
player.eternalHearts = 0;
}
}
bool isRedLost = amount > player.rottenHearts * 2;
int rottenLost = isRedFirst ? std::max(0, player.rottenHearts * 2 - player.redHearts + amount) : amount;
player.rottenHearts = std::max(player.rottenHearts - (rottenLost + 1) / 2, 0);
player.AddHearts(-amount, false, false);
bool isKeeper = player.playerType == PLAYER_KEEPER || player.playerType == PLAYER_KEEPER_B;
bool isTemporaryRed = player.playerType == PLAYER_MAGDALENE_B && player.redHearts >= maggy_heart_limit(player);
if (isRedLost && !isKeeper && !player.parent && isPenalized && amount > 0 && player.redHearts < player.maxHearts &&
!isTemporaryRed)
{
int multiplier = player.GetTrinketMultiplier(TRINKET_CROW_HEART);
uint32_t keptChance = multiplier == 2 ? CROW_HEART_KEEP_2 : multiplier >= 3 ? CROW_HEART_KEEP_3 : 0;
if (player.GetTrinketRNG(TRINKET_CROW_HEART).RandomInt(100) >= keptChance)
{
g_game->SetRedHeartDamage();
g_game->room->isRedHeartDamaged = true;
}
}
return amount;
}
// Takes a hit's half hearts: the soul hearts above the last bone heart first (a black heart among them sets off the
// Necronomicon), then a bone heart, then the red hearts. Red Heart damage and Crow Heart hit the red hearts first when
// there are enough. An eternal heart soaks up a hit that would empty the last heart. Golden hearts break with the
// hearts emptied. Returns what was taken.
static int hearts_remove(Entity_Player& player, int amount, uint64_t damageFlags, bool isPenalized)
{
int soulBoneCount = (player.soulHearts + 1) / 2 + player.boneHearts;
int filledCount = (std::min(player.redHearts, player.maxHearts) + 1) / 2;
bool isRedAsked = (damageFlags & DAMAGE_RED_HEARTS) || player.HasTrinket(TRINKET_CROW_HEART);
bool isRedFirst = isRedAsked && player.redHearts >= amount;
int soulsAbove = player.boneHearts > 0 ? souls_above_bones_count(player) : player.soulHearts;
bool isBoneFilled = player.boneHearts > 0 && player.redHearts >= player.maxHearts + player.boneHearts * 2 - 1;
if (soulsAbove > 0 && !isRedFirst)
{
amount = std::min(amount, soulsAbove);
for (int heart = player.soulHearts; heart > player.soulHearts - amount; heart--)
{
if (!player.IsBlackHeart(heart)) continue;
player.RemoveBlackHeart(heart);
player.UseActiveItem({.item = COLLECTIBLE_NECRONOMICON, .flags = USE_NOANIM | USE_ALLOWNONMAIN});
voice_play(SOUND_BLACK_POOF, 1, SOUND_FRAME_DELAY, 1);
}
if (player.eternalHearts > 0 && player.redHearts < 1 && player.boneHearts < 1 && player.soulHearts - amount < 1)
{
amount = std::max(amount - player.eternalHearts, 0);
player.eternalHearts = 0;
}
if (amount > 0) player.soulHearts -= std::min(player.soulHearts, amount);
}
else if (player.boneHearts > 0 && !isBoneFilled && !isRedFirst)
{
if (player.eternalHearts > 0 && player.redHearts < 1 && player.soulHearts < 1 && player.boneHearts < 2)
{
amount = std::max(amount - player.eternalHearts, 0);
player.eternalHearts = 0;
}
if (amount > 0) bone_heart_break(player, isPenalized);
}
else amount = red_hearts_remove(player, amount, isRedFirst, isBoneFilled, damageFlags, isPenalized);
player.update_greeds_gullet();
int golden = player.goldenHearts;
int newSoulBoneCount = (player.soulHearts + 1) / 2 + player.boneHearts;
int newFilledCount = (std::min(player.redHearts, player.maxHearts) + 1) / 2;
for (; soulBoneCount > newSoulBoneCount && player.goldenHearts > 0; soulBoneCount--) player.goldenHearts--;
for (; filledCount > newFilledCount && player.goldenHearts > 0; filledCount--) player.goldenHearts--;
if (player.goldenHearts < golden) player.BreakGoldenHearts(golden - player.goldenHearts);
return amount;
}
// 007db2d0 Spends one of the Holy Mantles Wooden Cross lends (one per copy, two at most, beyond those spent), moving
// one from the lent half of the stacks to the spent half. Whether there was one.
static bool wooden_cross_mantle_spend(Entity_Player& player)
{
constexpr int CROSS_MANTLES_MAX = 2;
constexpr int STACK_LOW_MASK = 0xf;
constexpr int STACK_HIGH_SHIFT = 4;
int crosses = std::min(player.GetTrinketMultiplier(TRINKET_WOODEN_CROSS), CROSS_MANTLES_MAX);
uint8_t stacks = player.holyMantleStacks;
if (crosses - (stacks & STACK_LOW_MASK) <= 0) return false;
player.holyMantleStacks = (uint8_t)((((stacks >> STACK_HIGH_SHIFT) - 1) << STACK_HIGH_SHIFT) | ((stacks + 1) & STACK_LOW_MASK));
return true;
}
// Holy Mantle's shield takes the hit: it shatters with a burst that follows the player, a Wooden Cross mantle, the
// Blanket's, the room's own mantle or a Holy Card's is spent, and the player is invincible for a second (longer with
// Blind Rage). The hit does not hurt.
static bool holy_mantle_block(Entity_Player& player)
{
constexpr int MANTLE_BREAK_SUBTYPE = 11;
constexpr float MANTLE_BREAK_DEPTH = 16;
constexpr int MANTLE_COOLDOWN = 60;
TemporaryEffects& effects = player.temporaryEffects;
voice_play(SOUND_HOLY_MANTLE, 1, SOUND_FRAME_DELAY, 1);
uint32_t seed = Random();
auto* burst = static_cast<Entity_Effect*>(g_game->Spawn({.position = player.pos, .spawner = &player,
.subType = MANTLE_BREAK_SUBTYPE, .type = ENTITY_EFFECT,
.variant = EFFECT_POOF02, .seed = seed}));
burst->FollowParent(&player);
burst->posOffset = player.posOffset;
burst->sprite.scale = player.sprite.scale;
burst->renderDepthOffset = MANTLE_BREAK_DEPTH;
burst->Update();
effects.RemoveCollectibleEffect(COLLECTIBLE_HOLY_MANTLE, 1);
if (!wooden_cross_mantle_spend(player))
{
if (effects.HasCollectibleEffect(COLLECTIBLE_BLANKET)) effects.RemoveCollectibleEffect(COLLECTIBLE_BLANKET, 1);
else if (player.HasCollectible(COLLECTIBLE_HOLY_MANTLE) && player.holyMantleState == 0) player.holyMantleState = 1;
else if (effects.HasNullEffect(NULLITEM_HOLY_CARD)) effects.RemoveNullEffect(NULLITEM_HOLY_CARD, 1);
}
if (effects.GetCollectibleEffectNum(COLLECTIBLE_HOLY_MANTLE) < 1)
player.RemoveCostume(g_manager->itemConfig.GetCollectible(COLLECTIBLE_HOLY_MANTLE));
player.damageCooldown = damage_cooldown_scale(MANTLE_COOLDOWN);
if (player.HasTrinket(TRINKET_BLIND_RAGE))
player.damageCooldown *= damage_cooldown_scale(player.GetTrinketMultiplier(TRINKET_BLIND_RAGE) * 2);
player.ClearEntityFlags(FLAG_NO_DAMAGE_BLINK);
return false;
}
// The items a landed hit sets off: collectibles 1 to 366, then the trinkets and later collectibles
// (entity_player_hits.cpp), Eve's Dead Bird and Samson's Bloody Lust, then Tainted Samson's rage. Bleeding out
// restarts its timer. The amount is the hit's hearts, not yet taken. Whether the hurt animation still plays.
static bool hit_items_check(Entity_Player& player, int amount, const ItemsHit& hit)
{
passives_hit_trigger(player, amount);
bool isHurtShown = late_items_hit_trigger(player, hit);
character_items_hit(player);
if (player.playerType == PLAYER_SAMSON_B && (player.redHearts > 0 || player.soulHearts > 0 || player.boneHearts > 0))
player.add_samson_berserk_charge(SAMSON_B_HIT_CHARGE);
if (player.HasEntityFlags(FLAG_BLEED_OUT) && player.bleedSource.entity == &player && player.bleedOutHealth > 0)
player.bleedOutHealth = BLEED_OUT_HEALTH;
if (!player.proceduralItems.empty())
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (glitched items, trigger_set_dispatch)");
return isHurtShown;
}
// Glass Cannon held in a slot shatters on a penalized hit: it becomes the Broken Glass Cannon with a crash, an impact
// and shards, the player bleeds (Anemic, and Judas' Birthright's timed boost with Book of Belial), and takes two more
// full heart hits of its own.
static void glass_cannon_break(Entity_Player& player)
{
constexpr int GLASS_SHARD_COUNT = 8;
constexpr float GLASS_SHARD_SPEED_RANGE = 3;
constexpr float GLASS_SHARD_SPEED_MIN = 2;
constexpr int BELIAL_BOOST_FRAMES = 4;
constexpr float SHATTER_DAMAGE = 2;
constexpr uint64_t SHATTER_FLAGS = DAMAGE_NOKILL | DAMAGE_ISAAC_HURT | DAMAGE_INVINCIBLE | DAMAGE_NO_MODIFIERS;
constexpr int SHATTER_COUNTDOWN = 30;
int slot = player.GetActiveItemSlot(COLLECTIBLE_GLASS_CANNON);
if (slot < 0) return;
player.RemoveCollectible(player.activeItems[slot].item, false, slot, true);
player.AddCollectible(COLLECTIBLE_BROKEN_GLASS_CANNON, 0, false, slot, 0);
voice_play(SOUND_GLASS_BREAK, 1, SOUND_FRAME_DELAY, 1);
g_game->Spawn({.position = player.pos, .type = ENTITY_EFFECT, .variant = EFFECT_IMPACT, .seed = Random()})->Update();
game_particles_spawn({.position = player.pos,
.height = player.posOffset.y,
.speed = random_unit() * GLASS_SHARD_SPEED_RANGE + GLASS_SHARD_SPEED_MIN,
.count = GLASS_SHARD_COUNT,
.variant = EFFECT_TOOTH_PARTICLE});
TemporaryEffects& effects = player.temporaryEffects;
if (!effects.HasCollectibleEffect(COLLECTIBLE_ANEMIC))
effects.AddEffect(TemporaryEffect(g_manager->itemConfig.GetCollectible(COLLECTIBLE_ANEMIC)), true, 1);
if (player.HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE))
effects.AddNullEffect(NULLITEM_JUDAS_BIRTHRIGHT, true, BELIAL_BOOST_FRAMES);
for (int hit = 0; hit < 2; hit++)
{
player.ResetDamageCooldown();
player.TakeDamage(SHATTER_DAMAGE, SHATTER_FLAGS, EntityRef(&player), SHATTER_COUNTDOWN);
}
}
// Whether the hit comes from a familiar the Siren charmed under 30 frames ago, or from a relay of its hits.
static bool is_siren_charm_fresh(const EntityRef& source)
{
Entity* hitter = source.type == ENTITY_SIREN_HELPER && source.entity ? source.entity->parent.get() : nullptr;
if (source.type == ENTITY_FAMILIAR) hitter = source.entity;
if (!hitter || hitter->type != ENTITY_FAMILIAR) return false;
int frames = static_cast<Entity_Familiar*>(hitter)->sirenCharmFrames;
return frames >= 1 && frames <= SIREN_CHARM_SPARE_FRAMES;
}
// A hit that spawns a fly gives one blue fly to the player behind the hit (its source or the source's spawner), else
// to the player nearest the one hit. The fly goes after the player hit.
static void hit_fly_spawn(Entity_Player& player, const EntityRef& source)
{
Entity* owner = source.entity;
if (owner && !owner->is_player()) owner = owner->spawnerEntity.get();
if (!owner || !owner->is_player()) owner = game_nearest_player(player.pos);
static_cast<Entity_Player*>(owner)->AddBlueFlies(1, owner->pos, &player);
}
// Greed and the coin thieves (all hits in Pay to Play) knock a coin out of the player, then one to three more fly
// out as pennies.
static void coins_drop(Entity_Player& player)
{
constexpr int COIN_DROP_RANGE = 3;
constexpr float COIN_DROP_SPEED_RANGE = 5;
constexpr float COIN_DROP_SPEED_MIN = 2;
player.AddCoins(-1);
int dropped = std::min(random_below(COIN_DROP_RANGE) + 1, player.numCoins);
for (int i = 0; i < dropped; i++)
{
uint32_t seed = Random();
Vector direction = random_direction();
Vector velocity = vector_scale(direction, random_unit() * COIN_DROP_SPEED_RANGE + COIN_DROP_SPEED_MIN);
g_game->Spawn({.position = player.pos, .velocity = velocity, .spawner = &player, .subType = COIN_PENNY,
.type = ENTITY_PICKUP, .variant = PICKUP_COIN, .seed = seed});
}
player.AddCoins(-dropped);
}
// The co-op babies that answer a hit: the fart baby farts (or only blows), the bomb baby explodes and the book baby
// rolls the room with the D6.
static void coop_baby_hit(Entity_Player& player)
{
constexpr float BABY_FART_RADIUS = 85;
constexpr float BABY_BEAN_RADIUS = 120;
constexpr float BABY_BOMB_DAMAGE = 40;
constexpr float BABY_BOMB_RADIUS = 60;
switch (player.babySkin)
{
case BABY_FART:
{
bool isBlowOnly = random_below(2) != 0;
if (!isBlowOnly) game_fart({.position = player.pos, .source = &player, .radius = BABY_FART_RADIUS});
game_butter_bean_fart({.position = player.pos, .source = &player, .radius = BABY_BEAN_RADIUS,
.isShowEffect = isBlowOnly, .isSuperKnockback = false});
break;
}
case BABY_BOMB:
explosion_damage({.position = player.pos, .source = &player, .damage = BABY_BOMB_DAMAGE,
.radius = BABY_BOMB_RADIUS});
g_game->Spawn({.position = player.pos, .type = ENTITY_EFFECT, .variant = EFFECT_BOMB_EXPLOSION,
.seed = Random()})->Update();
break;
case BABY_BOOK:
player.UseActiveItem({.item = COLLECTIBLE_D6, .flags = USE_NOANIM});
break;
}
}
// Marbles: a hit holding a trinket swallows it one time in ten (always in Pica Run), as by the Smelter.
static void marbles_swallow(Entity_Player& player)
{
constexpr int MARBLES_ODDS = 10;
bool isRolled = player.GetCollectibleRNG(COLLECTIBLE_MARBLES).RandomInt(MARBLES_ODDS) == 0;
if (!isRolled && g_game->challenge != CHALLENGE_PICA_RUN) return;
player.FlushQueueItem();
player.UseActiveItem({.item = COLLECTIBLE_SMELTER, .flags = USE_NOANIM});
sound_play(SOUND_VAMP_GULP);
}
// Heartbreak: a killing hit breaks a heart container (one for coin health, else two) and sets off the Necronomicon.
// True when a heart is left to save the player with.
static bool heartbreak_break(Entity_Player& player)
{
player.AddBrokenHearts(player.GetHealthType() == HEALTH_COIN ? 1 : 2);
player.UseActiveItem({.item = COLLECTIBLE_NECRONOMICON, .flags = USE_NOANIM | USE_ALLOWNONMAIN});
sound_play(SOUND_BLACK_POOF);
return player.GetHeartLimit(false) >= 1;
}
// Monkey Paw: a black heart per copy near the player on its last heart, three times before the paw is spent.
static void monkey_paw_grant(Entity_Player& player)
{
for (int i = player.GetTrinketMultiplier(TRINKET_MONKEY_PAW); i > 0; i--)
{
uint32_t seed = Random();
Vector spot = room_free_pickup_position_find({.position = player.pos, .step = PICKUP_SPOT_STEP});
g_game->Spawn({.position = spot, .spawner = &player, .subType = HEART_BLACK, .type = ENTITY_PICKUP,
.variant = PICKUP_HEART, .seed = seed});
}
if (--player.monkeyPawCounter >= 1) return;
player.TryRemoveTrinket(TRINKET_MONKEY_PAW);
player.monkeyPawCounter = MONKEY_PAW_USES;
}
// Astral Projection's start: the room pauses, the body stays behind as a ghost corpse and the spirit goes on for 150
// frames, with a bloom, a white flash fading back to the room's colours, a shockwave and a heartbeat.
static void astral_projection_start(Entity_Player& player)
{
constexpr int ASTRAL_PAUSE = 60;
constexpr int ASTRAL_ROOM_FRAMES = 150;
constexpr int ASTRAL_BLOOM = 10;
constexpr float ASTRAL_FLASH_RATE = 0.015f;
constexpr float ASTRAL_FADE_RATE = 0.008f;
constexpr float ASTRAL_SHOCK_AMPLITUDE = 0.05f;
constexpr float ASTRAL_SHOCK_SPEED = 0.07f;
constexpr int ASTRAL_SHOCK_DURATION = 12;
constexpr ColorModState ASTRAL_FLASH = {1, 1, 1, 1, 0, 1};
Game& game = *g_game;
Room& room = *game.room;
room.SetPauseTimer(ASTRAL_PAUSE);
player.spawn_ghost_corpse();
player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_ASTRAL_PROJECTION, true, 1);
TemporaryEffect roomEffect(g_manager->itemConfig.GetCollectible(COLLECTIBLE_ASTRAL_PROJECTION));
roomEffect.cooldown = ASTRAL_ROOM_FRAMES;
room.temporaryEffects.AddEffect(roomEffect, true, 1);
game.bloomDuration = ASTRAL_BLOOM;
game.bloomTimer = ASTRAL_BLOOM;
game.bloomStrength = 1;
game.SetColorModifier(ASTRAL_FLASH, false, ASTRAL_FLASH_RATE);
game.SetColorModifier(room.get_color_modifier(), true, ASTRAL_FADE_RATE);
shockwave_make(player.pos, ASTRAL_SHOCK_AMPLITUDE, ASTRAL_SHOCK_SPEED, ASTRAL_SHOCK_DURATION);
sound_play(SOUND_HEARTBEAT);
player.damageCooldown += damage_cooldown_scale(ASTRAL_PAUSE);
}
// 007729d0 The player takes a hit: the hit is ignored or turned by many items, then costs its hearts, plays the hurt
// grunt and the Hit animation, starts the invincibility frames, and kills the player out of hearts. True when it hurt.
bool Entity_Player::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& source, int damageCountdown)
{
Game& game = *g_game;
Entity_Player* twin = twin_get();
if (playerType == PLAYER_THESOUL_B && twin && !twin->HasCollectible(COLLECTIBLE_ISAACS_HEART))
{
if (twin->itemState == COLLECTIBLE_GLASS_CANNON) twin->bodySprite.Reset();
return twin->TakeDamage(damage, damageFlags, source, damageCountdown);
}
if (is_siren_charm_fresh(source)) return false;
if (wisp_shield_block(*this, damageFlags)) return false;
if (source.type == ENTITY_FIREPLACE && source.variant == WHITE_FIRE_VARIANT)
{
bool isGhost = playerType == PLAYER_THELOST || playerType == PLAYER_THELOST_B || playerType == PLAYER_THESOUL_B;
if (isGhost || HasInstantDeathCurse() || isDead) return false;
spawn_ghost_corpse();
if (!temporaryEffects.HasNullEffect(NULLITEM_LOST_CURSE)) game.playerManager.add_lost_curse(NULLITEM_LOST_CURSE);
sound_play(SOUND_FIREDEATH_HISS);
// The controllers' rumble is not wired here.
return true;
}
if (IsHologram() || is_damage_ignored(*this, source, damageFlags)) return false;
if (damage_reactions_check(*this, source, damageFlags)) return false;
if (!(damageFlags & DAMAGE_NO_HURT_EFFECTS)) play_hurt_effects();
bool isSeedProtected = game.seedEffects.HasSeedEffect(SEED_INVINCIBLE) ||
(variant == PLAYER_VARIANT_COOP_BABY && game.seedEffects.HasSeedEffect(SEED_KIDS_MODE)) ||
(game.deathmatchManager.is_active() && isInvincible);
if (isSeedProtected)
{
damageCooldown = std::min((int)(damage + DAMAGE_ROUNDING), HURT_HEARTS_MAX) * HURT_FRAMES_PER_HEART;
return false;
}
bool isPoisonImmune = HasPoisonImmunity() && !(source.type == ENTITY_EFFECT && source.variant == EFFECT_POISON_CLOUD);
if (damage <= 0 && (damageFlags & DAMAGE_POISON_BURN) && !isPoisonImmune)
{
damageEvents.push_back({.source = source, .damage = damage, .damageFlags = damageFlags});
pendingDamageFlags |= damageFlags;
pendingDamage += damage;
}
int hurtFrames = (int)(damage + DAMAGE_ROUNDING);
int amount = damage_amount_get(*this, damage, damageFlags, source);
bool isFake = damageFlags & DAMAGE_FAKE;
if (isFake) amount = 0;
if (damageFlags & DAMAGE_SPAWN_FLY) hit_fly_spawn(*this, source);
bool isInvincibleNow = HasInvincibility(damageFlags, source);
bool isPenalized = !(damageFlags & DAMAGE_UNPENALIZED);
if (variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_SHIELD && hasBabyRoomShield)
{
isInvincibleNow = true;
hasBabyRoomShield = false;
}
bool isBlocked = (damageCooldown > 0 && !(damageFlags & DAMAGE_THROUGH_COOLDOWN)) || damage <= 0 || isInvincibleNow;
if (isBlocked && !isFake) return false;
if (temporaryEffects.HasCollectibleEffect(COLLECTIBLE_HOLY_MANTLE) && !(damageFlags & DAMAGE_RED_HEARTS))
return holy_mantle_block(*this);
if (hallowedGroundCountdown > 0 && !(damageFlags & DAMAGE_NO_MODIFIERS) &&
GetCollectibleRNG(COLLECTIBLE_HALLOWED_GROUND).RandomInt(2) == 0)
{
constexpr ColorMod HALLOWED_FLASH = {{1, 1, 1, 1}, {0, 0, 0, 0}, {64 / 255.0f, 64 / 255.0f, 128 / 255.0f}};
constexpr int HALLOWED_FLASH_FRAMES = 15;
constexpr int HALLOWED_COOLDOWN = 8;
SetColor(HALLOWED_FLASH, HALLOWED_FLASH_FRAMES, 255, true, true);
damageCooldown = damage_cooldown_scale(HALLOWED_COOLDOWN);
AddEntityFlags(FLAG_NO_DAMAGE_BLINK);
return false;
}
if (!lua_engine_get().EntityTakeDamage(this, (float)amount, damageFlags, source, damageCountdown)) return false;
if (try_end_astral_projection()) return false;
if (playerType == PLAYER_JACOB_B && source.type == ENTITY_DARK_ESAU)
{
spawn_ghost_corpse();
ChangePlayerType(PLAYER_JACOB2_B, false);
SetMinDamageCooldown(JACOB_GHOST_COOLDOWN);
return false;
}
Entity* attacker = source.entity ? source.entity->GetPlayerAncestor() : nullptr;
if (attacker) Player_stats_add(game.onlinePlayerStats, ONLINE_STAT_PLAYER_DAMAGE_DEALT, (Entity_Player*)attacker, amount);
Player_stats_add(game.onlinePlayerStats, ONLINE_STAT_DAMAGE_TAKEN, this, amount);
lastDamageSource = source;
lastDamageFlags = damageFlags;
isHurtThisRoom = true;
maggyHealthDrainCooldown = 0;
damageCooldown = HIT_COOLDOWN;
float volume = local_volume_get();
if (isPenalized)
{
roomDamageTaken += amount;
if (playerType != PLAYER_MAGDALENE_B || !is_maggy_draining(*this)) totalDamageTaken += amount;
}
if (source.type >= ENTITY_FIRST_ENEMY && source.type <= ENTITY_LAST_ENEMY)
bestiary_count_add(g_manager->persistentGameData.bestiary.hits, source.type, source.variant);
if (game.debugFlags & DEBUG_DAMAGE_VALUES)
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (spawn_debug_damage_text)");
if ((damageFlags & (DAMAGE_FIRE | DAMAGE_POOP)) && !(damageFlags & DAMAGE_EXPLOSION))
voice_play(SOUND_FIREDEATH_HISS, 1, SOUND_FRAME_DELAY, 1);
bool isThief = is_listed(COIN_THIEF_TYPES, source.type) || source.spawnerType == ULTRA_GREED ||
source.spawnerType == ULTRA_GREED_DOOR ||
(source.type == ENTITY_PROJECTILE && is_listed(COIN_SHOOTER_TYPES, source.spawnerType));
if ((isThief || game.challenge == CHALLENGE_PAY_TO_PLAY) && numCoins > 0) coins_drop(*this);
if (variant == PLAYER_VARIANT_COOP_BABY) coop_baby_hit(*this);
bool isTrinketQueued = queuedItem.item && queuedItem.item->type == ITEM_TRINKET;
if (HasCollectible(COLLECTIBLE_MARBLES) && (trinkets[0] != 0 || isTrinketQueued)) marbles_swallow(*this);
float pitch = get_voice_pitch();
int grunt = SOUND_ISAAC_HURT_GRUNT;
if (temporaryEffects.HasCollectibleEffect(COLLECTIBLE_THE_NAIL)) grunt = random_below(2) ? SOUND_NAIL_HURT_1 : SOUND_NAIL_HURT_2;
voice_play(grunt, volume, SOUND_FRAME_DELAY, pitch);
if (source.type == ENTITY_MOM || source.type == ENTITY_MOMS_HEART)
voice_play(source.type == ENTITY_MOM ? SOUND_MOM_VOX_EVILLAUGH : SOUND_MOM_VOX_FILTERED_EVILLAUGH, 1,
random_below(SOUND_BOSS_DELAY_RANDOM) + SOUND_BOSS_DELAY_MIN, 1);
bool isHurt = hit_items_check(*this, amount, {source, damageFlags, damage, isPenalized});
for (size_t i = 0; i < game.room->entityList.updateEL.size(); i++)
{
Entity* entity = game.room->entityList.updateEL[i];
if (entity->IsFamiliar() && static_cast<Entity_Familiar*>(entity)->player == this)
static_cast<Entity_Familiar*>(entity)->trigger_player_damage({source, damage, damageFlags});
else if (!entity->IsFamiliar() && entity->IsEnemy())
static_cast<Entity_NPC*>(entity)->on_player_damaged();
}
if (isPenalized && !parent)
{
game.SetStateFlag(LEVEL_STATE_DAMAGED, true);
game.lastLevelWithDamage = std::clamp((int)game.stage, 0, LAST_DAMAGE_STAGE_MAX);
}
if (game.debugFlags & DEBUG_INFINITE_HP) amount = 0;
else if (amount > 0 && game.deathmatchManager.is_active())
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (versus hearts)");
else if (amount > 0) amount = hearts_remove(*this, amount, damageFlags, isPenalized);
bool isAstral = HasCollectible(COLLECTIBLE_ASTRAL_PROJECTION) && !game.room->IsClear() &&
!temporaryEffects.HasCollectibleEffect(COLLECTIBLE_ASTRAL_PROJECTION) && !astralProjectionBody;
bool isInstantDeath = HasInstantDeathCurse() && amount > 0;
bool isDeathSkipped = isAstral || temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BERSERK);
if ((redHearts < 1 && soulHearts < 1 && boneHearts < 1) || isInstantDeath)
{
bool isHeartbreakSaved = HasCollectible(COLLECTIBLE_HEARTBREAK) && heartbreak_break(*this);
if (isHeartbreakSaved || (damageFlags & DAMAGE_NOKILL)) TryPreventDeath();
else
{
if (isInstantDeath)
{
redHearts = 0;
soulHearts = 0;
blackHearts = 0;
boneHearts = 0;
eternalHearts = 0;
rottenHearts = 0;
}
if (!isDeathSkipped)
{
if (isInstantDeath) Kill(EntityRef());
bool isKilled = try_trigger_astral_projection();
lastDamageSource = source;
if (isKilled && game.deathmatchManager.is_active())
for (Entity* killer = source.entity; killer; killer = killer->spawnerEntity.get())
if (killer->is_player())
{
static_cast<Entity_Player*>(killer)->trigger_npc_death(this);
break;
}
if (isDead) death_count(source, damageFlags);
}
}
}
bool isTeleported = !isDead && cursed_eye_teleport(*this);
bool isHitAnimated = pitfallState == 0 && isHurt && !isTeleported;
if (HasTrinket(TRINKET_CURSED_SKULL) && !isDead) cursed_skull_teleport(*this);
if (redHearts <= scale_for_hard_difficulty(1))
{
last_heart_items_trigger(*this, damageFlags);
bool isLastHeart = soulHearts < 1 || (redHearts < 1 && soulHearts == scale_for_hard_difficulty(1));
if (isLastHeart && HasTrinket(TRINKET_MONKEY_PAW) && variant == PLAYER_VARIANT_PLAYER) monkey_paw_grant(*this);
}
damageCooldown = damage_cooldown_scale(std::min(hurtFrames, HURT_HEARTS_MAX) * HURT_FRAMES_PER_HEART);
flags &= ~FLAG_NO_DAMAGE_BLINK;
if (isAstral) astral_projection_start(*this);
blind_rage_finger_bone_hit(*this);
if (isPenalized && HasCollectible(COLLECTIBLE_GLASS_CANNON)) glass_cannon_break(*this);
if (isHitAnimated)
{
if (twin && twin->playerType == PLAYER_THESOUL_B) twin->PlayExtraAnimation("Hit");
else if (game.challenge != CHALLENGE_GUARDIAN) PlayExtraAnimation("Hit");
if (itemState != ITEM_STATE_HOLD_STILL) ResetItemState();
}
isHurtPending = true;
// Rumble is not wired to the controllers here.
ClampGoldenHearts(false);
update_bone_hearts();
if (damageCooldown > 0 && !isDead && twin && twin->damageCooldown < damageCooldown && !twin->isDead)
twin->damageCooldown = damageCooldown;
if (HasTrinket(TRINKET_SWALLOWED_M80) && !(damageFlags & DAMAGE_NO_PENALTIES))
{
int odds = std::max(1, 3 - GetTrinketMultiplier(TRINKET_SWALLOWED_M80));
if (GetTrinketRNG(TRINKET_SWALLOWED_M80).RandomInt(odds) == 0)
UseActiveItem({.item = COLLECTIBLE_KAMIKAZE, .flags = USE_NOANIM | USE_NOCOSTUME | USE_ALLOWNONMAIN});
}
bool isGlitching = isPlayingExtraAnimation && sprite.IsPlaying("Glitch");
if (!isDead && playerType == PLAYER_EDEN_B && isPenalized && !isGlitching)
tainted_eden_glitch(*this);
return true;
}
// Counts the player's death in the bestiary of the enemy behind the hit. Dying to an explosive poison tear (Ipecac)
// unlocks Lil Spewer.
void Entity_Player::death_count(const EntityRef& source, uint64_t damageFlags)
{
PersistentGameData_Bestiary& bestiary = g_manager->persistentGameData.bestiary;
if (source.type >= ENTITY_FIRST_ENEMY && source.type <= ENTITY_LAST_ENEMY)
bestiary_count_add(bestiary.deaths, source.type, source.variant);
else if (source.spawnerType >= ENTITY_FIRST_ENEMY && source.spawnerType <= ENTITY_LAST_ENEMY)
bestiary_count_add(bestiary.deaths, source.spawnerType, (int)source.spawnerVariant);
if (!(damageFlags & DAMAGE_EXPLOSION) || source.type != ENTITY_TEAR || !source.entity) return;
TearFlags& tearFlags = static_cast<Entity_Tear*>(source.entity)->tearFlags;
if (tearFlags[TEAR_EXPLOSIVE] && tearFlags[TEAR_POISON]) g_manager->persistentGameData.TryUnlock(ACHIEVEMENT_LIL_SPEWER);
}
// 0060d090 Ends the invincibility frames.
void Entity_Player::ResetDamageCooldown()
{
damageCooldown = 0;
}
// 007db6b0 Whether a hit kills at once: the Lost's curse, or Tainted Jacob's ghost.
bool Entity_Player::HasInstantDeathCurse()
{
return (!temporaryEffects.isDisabled &&
std::ranges::any_of(temporaryEffects.effects, [](const TemporaryEffect& effect)
{ return effect.item->type == ITEM_NULL && effect.item->id == NULLITEM_LOST_CURSE; })) ||
playerType == PLAYER_JACOB2_B;
}
// 007bf670 The lives the HUD counts: Dead Cat's and the items that revive, Lazarus's own and Tainted Lost's Birthright.
int Entity_Player::GetExtraLives()
{
int lives = deadCatLives;
for (int item : EXTRA_LIFE_ITEMS) lives += collectibleCounts[item];
if (playerType == PLAYER_THELOST_B) lives += collectibleCounts[TAINTED_LOST_BIRTHRIGHT];
return lives + (playerType == PLAYER_LAZARUS);
}
// 0075d900 Whether an item's costume shows on a layer of the player's sprite, or on any layer for a negative one.
bool Entity_Player::IsItemCostumeVisible(ItemConfig_Item* item, int playerSpriteLayerID)
{
int first = std::max(playerSpriteLayerID, 0);
int end = playerSpriteLayerID < 0 ? COSTUME_LAYER_COUNT : playerSpriteLayerID + 1;
for (int layer = first; layer < end; layer++)
if (playerCostumeMap[layer].index >= 0 && costumeSpriteDescs[playerCostumeMap[layer].index].item == item)
return true;
return false;
}
// 0075d980 Whether a null item's costume shows on a layer, as IsItemCostumeVisible for an id out of range asks of none.
bool Entity_Player::IsNullItemCostumeVisible(int nullItemID, int playerSpriteLayerID)
{
std::vector<std::unique_ptr<ItemConfig_Item>>& nullItems = g_manager->itemConfig.nullItems;
bool isKnown = nullItemID >= 0 && nullItemID < (int)nullItems.size();
return IsItemCostumeVisible(isKnown ? nullItems[nullItemID].get() : nullptr, playerSpriteLayerID);
}
// 007c3100 Whether a hit passes the player by: the invincibility items' effects, Gnawed Leaf's statue, Breath of Life,
// Taurus's charge, the shields red heart hits still pass, the halo baby and a co-op ghost. Book of Shadows lets a blood
// donation hurt.
bool Entity_Player::HasInvincibility(uint64_t damageFlags, const EntityRef& source)
{
if (damageFlags & DAMAGE_INVINCIBLE) return false;
TemporaryEffects& effects = temporaryEffects;
bool isRedHit = damageFlags & DAMAGE_RED_HEARTS;
bool isInvincible = effects.HasCollectibleEffect(COLLECTIBLE_BOOK_OF_SHADOWS);
if (isInvincible)
{
bool isBloodSlot = source.type == ENTITY_SLOT && (source.variant == BLOOD_DONATION_VARIANT || source.variant == BLOOD_BANK_VARIANT);
if (isBloodSlot && effects.GetCollectibleEffect(COLLECTIBLE_BOOK_OF_SHADOWS)->unknown != 0) isInvincible = false;
}
if (!isInvincible)
{
TemporaryEffect* taurus = effects.HasCollectibleEffect(COLLECTIBLE_TAURUS) ? effects.GetCollectibleEffect(COLLECTIBLE_TAURUS) : nullptr;
isInvincible = std::ranges::any_of(INVINCIBLE_EFFECTS, [&](int item) { return effects.HasCollectibleEffect(item); }) ||
(HasCollectible(COLLECTIBLE_GNAWED_LEAF) && mass == GNAWED_LEAF_MASS && !isRedHit) ||
effects.HasCollectibleEffect(COLLECTIBLE_BREATH_OF_LIFE) || (taurus && taurus->cooldown != 0) ||
(effects.HasNullEffect(NULLITEM_INVINCIBLE_SHIELD) && !isRedHit) ||
(effects.HasNullEffect(NULLITEM_REVERSE_CHARIOT) && !isRedHit) ||
((effects.HasCollectibleEffect(COLLECTIBLE_DARK_ARTS) || isDarkArtsBlastPending) && !isRedHit) ||
(suplexState != 0 && !isRedHit) || effects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH);
}
return isInvincible || (variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_HALO) || isCoopGhost;
}
// 007c3320 Whether poison passes the player by: Jupiter, Bob's Curse and the Bob transformation.
bool Entity_Player::HasPoisonImmunity()
{
return HasCollectible(COLLECTIBLE_JUPITER) || HasCollectible(COLLECTIBLE_BOBS_CURSE) || HasPlayerForm(PLAYER_FORM_BOB);
}
// 007dba30 Whether Evil Charm keeps a hazard off the player: fireplaces always, creep and the like only for their
// first frames on it.
bool Entity_Player::is_evil_charm_immune(EntityRef source)
{
if (!HasCollectible(COLLECTIBLE_EVIL_CHARM) && !temporaryEffects.HasCollectibleEffect(COLLECTIBLE_EVIL_CHARM)) return false;
if (source.type == ENTITY_FIREPLACE) return true;
bool isHazard = (source.type == 0 && source.variant == EVIL_CHARM_GRID_VARIANT) ||
(source.type == ENTITY_PROJECTILE && source.variant == 2) ||
(source.type == ENTITY_EFFECT && is_listed(EVIL_CHARM_EFFECTS, source.variant));
if (!isInEvilCharmHazard && !isHazard)
{
isInEvilCharmHazard = false;
return false;
}
isInEvilCharmHazard = true;
return isHazard && evilCharmHazardFrames < EVIL_CHARM_GRACE_FRAMES;
}
// 007c9ad0 The pitch of the player's voice: higher for babies, Pluto, Inner Child, Binky and Helium pills, lower
// for Puberty pills and the Adult transformation.
float Entity_Player::get_voice_pitch()
{
float pitch = variant == PLAYER_VARIANT_PLAYER ? VOICE_PITCH_PLAYER : VOICE_PITCH_BABY;
pitch += (float)(pillEffectUses[PILL_EFFECT_PUBERTY] - pillEffectUses[PILL_EFFECT_HELIUM]) * VOICE_PITCH_PER_PILL;
if (HasCollectible(COLLECTIBLE_PLUTO) || temporaryEffects.HasCollectibleEffect(COLLECTIBLE_INNER_CHILD))
pitch += VOICE_PITCH_PLUTO;
if (HasCollectible(COLLECTIBLE_BINKY)) pitch += VOICE_PITCH_STEP;
if (HasPlayerForm(PLAYER_FORM_ADULT)) pitch -= VOICE_PITCH_STEP;
return std::clamp(pitch, VOICE_PITCH_MIN, VOICE_PITCH_MAX);
}
// 007cf8c0 Whether the player plays on this machine: every one does offline.
bool Entity_Player::IsLocalPlayer()
{
return !g_manager->netplayManager.is_online() || g_manager->netplayManager.IsIdxLocalPlayer(controllerIndex);
}
// 007cf8f0 The volume of the player's sounds: full for a local player, the remote players' option for others.
float Entity_Player::local_volume_get()
{
if (IsLocalPlayer()) return 1;
return (float)g_manager->optionsConfig.onlinePlayerVolume * REMOTE_VOLUME_SCALE;
}
// 007d1c10 Breath of Life's answer to a hit in its first frames of invincibility: four holy beams strike around the
// player and it stays unhurtable for 30 frames more (as Book of Shadows), or with Book of Belial the Necronomicon
// goes off and the dark spell lasts. With the Book of Virtues its wisps are topped up to four. True when it answered.
uint32_t Entity_Player::play_hurt_effects()
{
constexpr int BREATH_BEAMS = 4;
constexpr float BREATH_BEAM_TURN = 90;
constexpr int BREATH_BEAM_TIMEOUT = 30;
constexpr float BREATH_BEAM_RISE = -12;
constexpr float BREATH_BEAM_DAMAGE = 12;
constexpr float BREATH_BEAM_DEPTH = 3000;
constexpr float LAST_BREATH_BEAM_DEPTH = -10;
constexpr int SHADOWS_FRAMES = 30;
constexpr int SHADOWS_LONG = 149;
constexpr int BELIAL_FRAMES = 150;
constexpr int BELIAL_COUNT = 20;
constexpr int BREATH_WISPS = 4;
constexpr ColorMod BREATH_BEAM_COLOR = {{1, 1, 1, 1}, {1, 1, 1, 1}, {0, 0, 0}};
TemporaryEffect* effect = temporaryEffects.GetCollectibleEffect(COLLECTIBLE_BREATH_OF_LIFE);
bool isBlocked = damageCooldown > 0 && !HasEntityFlags(FLAG_NO_DAMAGE_BLINK);
if (isBlocked || !effect || effect->count != 2) return 0;
if (effect->cooldown < g_manager->itemConfig.GetCollectible(COLLECTIBLE_BREATH_OF_LIFE)->maxCooldown - BREATH_OF_LIFE_WINDOW)
return 0;
temporaryEffects.RemoveCollectibleEffect(COLLECTIBLE_BREATH_OF_LIFE, 1);
if (!HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE))
{
for (int i = 0; i < BREATH_BEAMS; i++)
{
Entity_Laser* beam = Entity_Laser::ShootAngle({.position = pos, .posOffset = vector_make(0, BREATH_BEAM_RISE),
.source = this, .angleDegrees = (float)i * BREATH_BEAM_TURN,
.timeout = BREATH_BEAM_TIMEOUT, .variant = LASER_LIGHT_BEAM});
beam->SetCollisionDamage(BREATH_BEAM_DAMAGE);
beam->SetColor(BREATH_BEAM_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true);
beam->isDisableFollowParent = true;
beam->renderDepthOffset = i == BREATH_BEAMS - 1 ? LAST_BREATH_BEAM_DEPTH : BREATH_BEAM_DEPTH;
}
TemporaryEffect* shadows = temporaryEffects.GetCollectibleEffect(COLLECTIBLE_BOOK_OF_SHADOWS);
if (!shadows || shadows->cooldown <= SHADOWS_LONG)
{
TemporaryEffect shield(g_manager->itemConfig.GetCollectible(COLLECTIBLE_BOOK_OF_SHADOWS));
shield.cooldown = SHADOWS_FRAMES;
temporaryEffects.AddEffect(shield, true, 1);
}
}
else
{
UseActiveItem({.item = COLLECTIBLE_NECRONOMICON, .flags = USE_NOANIM | USE_ALLOWNONMAIN});
sound_play(SOUND_BLACK_POOF);
sound_play(SOUND_DEVIL_CARD);
TemporaryEffect spell(g_manager->itemConfig.GetNullItem(NULLITEM_DARK_ARTS));
spell.cooldown = BELIAL_FRAMES;
temporaryEffects.AddEffect(spell, true, BELIAL_COUNT);
}
if (!HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES)) return 1;
int wisps = 0;
for (Entity* entity : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP))
if (entity->subtype == COLLECTIBLE_BREATH_OF_LIFE && static_cast<Entity_Familiar*>(entity)->player == this) wisps++;
for (int i = wisps; i < BREATH_WISPS; i++) AddWisp(COLLECTIBLE_BREATH_OF_LIFE, pos, true, false);
return 1;
}
// 007caaa0 Whether a heart container is a bone heart.
bool Entity_Player::IsBoneHeart(int heart)
{
return boneHearts > 0 && (boneHeartsMask & 1 << heart);
}
// 007591e0 Turns the black heart holding a soul heart, counted in halves from 0, back into a soul heart.
void Entity_Player::RemoveBlackHeart(int soulHeartIndex)
{
if (soulHeartIndex > soulHearts || soulHeartIndex < 0) return;
blackHearts &= ~(1u << (soulHeartIndex >> 1 & 31));
ClampGoldenHearts(false);
update_bone_hearts();
}
// 00759220 Whether a soul heart, counted in halves from 1, is the first half of a black heart.
bool Entity_Player::IsBlackHeart(int heart)
{
return heart <= soulHearts && heart >= 1 && (heart & 1) && (blackHearts & 1 << ((heart - 1) / 2));
}
// 007caad0 Leaves a player a last half heart of its kind when a hit was not to kill. True when it did.
bool Entity_Player::TryPreventDeath()
{
if (boneHearts + redHearts + soulHearts != 0) return false;
switch (GetHealthType())
{
case HEALTH_DEFAULT:
if (playerType == PLAYER_BETHANY)
{
if (maxHearts < 2) AddMaxHearts(2, false);
AddHearts(1, true, false);
return true;
}
if (maxHearts <= 0) break;
AddHearts(scale_for_hard_difficulty(1), true, false);
return true;
case HEALTH_COIN:
if (maxHearts < 2) AddMaxHearts(2, false);
AddHearts(2, true, false);
return true;
case HEALTH_BONE:
AddBoneHearts(1);
return true;
default:
break;
}
soulHearts = 1;
return true;
}
// Spirit Shackles' second chance: the player comes back as a shackled ghost with a last heart of its kind, its body
// left behind (once) in the middle of its death, chained to it.
static void spirit_shackles_bind(Entity_Player& player)
{
constexpr int SHACKLED_COOLDOWN = 30;
constexpr int BODY_STATE = 10;
constexpr float SHACKLES_CHAIN_SCALE = 80;
constexpr float SHACKLES_CHAIN_REACH = 10;
player.temporaryEffects.AddNullEffect(NULLITEM_SHACKLES_GHOST, true, 1);
player.temporaryEffects.AddNullEffect(NULLITEM_SPIRIT_SHACKLES_DISABLED, true, 1);
player.soulHearts = 0;
player.blackHearts = 0;
player.eternalHearts = 0;
player.boneHeartsMask = 0;
player.boneHearts = 0;
player.rottenHearts = 0;
HealthType health = player.GetHealthType();
if (player.maxHearts >= 1) player.redHearts = health == HEALTH_COIN ? 2 : 1;
else if (health == HEALTH_BONE)
{
player.redHearts = 0;
player.AddBoneHearts(1);
}
else if (health == HEALTH_COIN)
{
player.redHearts = 2;
player.maxHearts = 2;
}
else if (player.playerType == PLAYER_BETHANY)
{
player.maxHearts = 2;
player.redHearts = 1;
}
else
{
player.redHearts = 0;
player.soulHearts = 1;
}
player.damageCooldown = SHACKLED_COOLDOWN;
if (!player.astralProjectionBody)
{
auto* body = static_cast<Entity_Effect*>(g_game->Spawn({.position = player.pos, .spawner = &player,
.type = ENTITY_EFFECT, .variant = EFFECT_DEVIL,
.seed = Random()}));
body->sprite = player.sprite;
if (LayerState* ghost = body->sprite.GetLayer("ghost")) ghost->isVisible = false;
body->sprite.overlayAnimState.SetAnimationData(nullptr);
body->sprite.Play("Death");
body->AddEntityFlags(FLAG_DONT_OVERWRITE);
body->state = BODY_STATE;
body->Update();
player.astralProjectionBody = body;
}
auto* chain = static_cast<Entity_Effect*>(g_game->Spawn({.position = player.pos, .type = ENTITY_EFFECT,
.variant = EFFECT_FORGOTTEN_CHAIN, .seed = Random()}));
chain->child = player.astralProjectionBody;
chain->target = &player;
chain->scale = SHACKLES_CHAIN_SCALE;
chain->targetPosition = vector_make(SHACKLES_CHAIN_REACH, 0);
chain->Update();
}
// 007afc20 Kills the player out of hearts and starts the death sequence, unless it is dead, a ghost, berserk or
// projected. Spirit Shackles gives a second chance instead. True when it killed.
bool Entity_Player::try_trigger_astral_projection()
{
bool isOutOfHearts = redHearts < 1 && soulHearts < 1 && boneHearts < 1;
if (g_game->deathmatchManager.is_active() && isOutOfHearts && blackHearts > 0) isOutOfHearts = false;
if (isDead || !isOutOfHearts || isCoopGhost) return false;
TemporaryEffect* astral = temporaryEffects.isDisabled ? nullptr : temporaryEffects.GetCollectibleEffect(COLLECTIBLE_ASTRAL_PROJECTION);
int astralState = astral ? astral->count : 0;
if (astralState == 1 || temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BERSERK)) return false;
if (astralState != 2)
{
bool isShackled = HasCollectible(COLLECTIBLE_SPIRIT_SHACKLES) &&
temporaryEffects.GetNullEffectNum(NULLITEM_SPIRIT_SHACKLES_DISABLED) == 0 &&
temporaryEffects.GetNullEffectNum(NULLITEM_SHACKLES_GHOST) == 0;
if (isShackled)
{
spirit_shackles_bind(*this);
return false;
}
if (lastDamageSource.type == ENTITY_SLOT || (lastDamageFlags & DAMAGE_DEVIL))
Player_stats_add(g_game->onlinePlayerStats, ONLINE_STAT_DEAL_DEATHS, this, 1);
lastDamageSource = EntityRef();
}
Kill(EntityRef());
return true;
}
// The spirit's way back to its body: a trail of ghostly wisps along the way (between 4 and 12, one per 20 units)
// drifting after it, and a white poof where the spirit was.
static void astral_trail_spawn(Entity_Player& player, Entity& body)
{
constexpr float ASTRAL_TRAIL_STEP_SCALE = 0.1f;
constexpr float ASTRAL_TRAIL_STEP_MAX = 4;
constexpr float ASTRAL_TRAIL_SPACING = 20;
constexpr int ASTRAL_TRAIL_MIN = 4;
constexpr int ASTRAL_TRAIL_MAX = 12;
constexpr float ASTRAL_TRAIL_SCATTER = 15;
constexpr float ASTRAL_TRAIL_SCALE_RANGE = 0.3f;
constexpr float ASTRAL_TRAIL_HEIGHT = 16;
constexpr int ASTRAL_POOF_SUBTYPE = 10;
constexpr ColorMod ASTRAL_TRAIL_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 1, 1}};
constexpr ColorMod ASTRAL_POOF_COLOR = {{1, 1, 1, 1}, {1, 1, 1, 1}, {0, 0, 0}};
Vector toBody = vector_sub(body.pos, player.pos);
Vector step = vector_scale(toBody, ASTRAL_TRAIL_STEP_SCALE);
if (vector_length(step) > ASTRAL_TRAIL_STEP_MAX) step = vector_resized(step, ASTRAL_TRAIL_STEP_MAX);
int count = std::clamp((int)std::floor(vector_length(toBody) / ASTRAL_TRAIL_SPACING), ASTRAL_TRAIL_MIN, ASTRAL_TRAIL_MAX);
for (int i = 1; i <= count; i++)
{
float along = (float)i / (float)(count + 1);
Vector direction = random_direction();
Vector scatter = vector_scale(direction, random_unit() * ASTRAL_TRAIL_SCATTER);
Vector spot = vector_add(scatter, vector_add(player.pos, vector_scale(toBody, along)));
uint32_t seed = Random();
Vector velocity = vector_scale(step, random_unit() * HALF + HALF);
Entity* wisp = g_game->Spawn({.position = spot, .velocity = velocity, .type = ENTITY_EFFECT,
.variant = EFFECT_HAEMO_TRAIL, .seed = seed});
wisp->SetColor(ASTRAL_TRAIL_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true);
float size = along * (random_unit() * ASTRAL_TRAIL_SCALE_RANGE + ASTRAL_TRAIL_SCALE_RANGE);
wisp->sprite.scale = vector_make(size, size);
wisp->posOffset = vector_make(player.posOffset.x, player.posOffset.y - player.sprite.scale.y * ASTRAL_TRAIL_HEIGHT);
}
Entity* poof = g_game->Spawn({.position = player.pos, .velocity = step, .subType = ASTRAL_POOF_SUBTYPE,
.type = ENTITY_EFFECT, .variant = EFFECT_POOF02, .seed = Random()});
poof->SetColor(ASTRAL_POOF_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true);
poof->posOffset = player.posOffset;
poof->sprite.scale = player.sprite.scale;
}
// 007d35b0 Ends Astral Projection's spirit form when the spirit is hit: the spirit flies back to its body along a
// ghostly trail, flashes white with a bloom and the room's colours at once, and then dies if it has no hearts left
// (the death skipping ahead) or stays unhurtable for 4 seconds. True when it ended.
bool Entity_Player::try_end_astral_projection()
{
constexpr int ASTRAL_END_BLOOM = 10;
constexpr float ASTRAL_END_BLOOM_STRENGTH = 0.6f;
constexpr int ASTRAL_END_FLASH = 8;
constexpr int ASTRAL_END_COOLDOWN = 120;
constexpr float DEATH_SKIP_FRAME = 24;
constexpr ColorMod WHITE_FLASH = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 1, 1}};
TemporaryEffect* astral = temporaryEffects.isDisabled ? nullptr : temporaryEffects.GetCollectibleEffect(COLLECTIBLE_ASTRAL_PROJECTION);
if (!astral || astral->count != 1) return false;
ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(COLLECTIBLE_ASTRAL_PROJECTION);
if (item) temporaryEffects.AddEffect(TemporaryEffect(item), true, 1);
RemoveCostume(item);
if (Entity* body = astralProjectionBody.get())
{
astral_trail_spawn(*this, *body);
velocity = {};
Teleport(body->pos, false, false);
body->Remove();
}
ResetColor();
ColorMod flash = sprite.color;
color_multiply(flash, WHITE_FLASH);
SetColor(flash, ASTRAL_END_FLASH, COLOR_PRIORITY_DEFAULT, true, true);
Game& game = *g_game;
game.bloomDuration = ASTRAL_END_BLOOM;
game.bloomTimer = ASTRAL_END_BLOOM;
game.bloomStrength = ASTRAL_END_BLOOM_STRENGTH;
game.targetColorModifier = game.room->get_color_modifier();
game.currentColorModifier = game.targetColorModifier;
game.isColorModifierLerped = false;
try_trigger_astral_projection();
if (!isDead)
{
damageCooldown = std::max(damageCooldown, ASTRAL_END_COOLDOWN);
return true;
}
if (std::string_view(GetDeathAnimName()) != "Death") return true;
PlayExtraAnimation("Death");
if (sprite.animState.animData) sprite.animState.SetFrameFloat(DEATH_SKIP_FRAME);
int sound = SOUND_ISAACDIES;
seed_fart_sound_override(&sound);
g_manager->sfxManager.Play(sound, {.pitch = get_voice_pitch()});
return true;
}
// 007828f0 The animation the player dies with: the Lost's for ghosts and the cursed, Forgotten's, or falling in a hole.
const char* Entity_Player::GetDeathAnimName()
{
bool isGhost = playerType == PLAYER_THELOST || playerType == PLAYER_THELOST_B || playerType == PLAYER_JACOB2_B ||
playerType == PLAYER_THESOUL_B || playerType == PLAYER_THESOUL ||
temporaryEffects.GetCollectibleEffectNum(COLLECTIBLE_ASTRAL_PROJECTION) == 1 ||
temporaryEffects.GetNullEffectNum(NULLITEM_SHACKLES_GHOST) == 1 ||
temporaryEffects.HasNullEffect(NULLITEM_LOST_CURSE) ||
(variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_GHOST) || isCoopGhost;
if (isGhost) return "LostDeath";
if (playerType == PLAYER_THEFORGOTTEN_B) return "ForgottenDeath";
return pitfallState == 0 ? "Death" : "HoleDeath";
}
// 007abe20 Plays an animation on the whole sprite, over the body and head, until it ends.
void Entity_Player::PlayExtraAnimation(std::string_view animName)
{
isPlayingItemAnimation = false;
bodySprite.Reset();
sprite.playbackSpeed = 1;
sprite.overlayAnimState.SetAnimationData(nullptr);
if (sprite.SetAnimation(animName))
{
sprite.animState.Rewind();
sprite.animState.isPlaying = true;
}
isPlayingItemAnimation = false;
isPlayingExtraAnimation = true;
}
// 007abcc0 Plays the teleport out (up, with the portal's sound) or in.
void Entity_Player::AnimateTeleport(bool isUp)
{
PlayExtraAnimation(isUp ? "TeleportUp" : "TeleportDown");
if (isUp) sound_play(SOUND_HELL_PORTAL2);
}
// 007abe90 Plays an animation of the player's sprite on its body sprite, as picking items up does.
void Entity_Player::PlayExtraAnimation(std::string_view animation, bool)
{
bodySprite = sprite;
bodySprite.playbackSpeed = 1;
if (bodySprite.SetAnimation(animation))
{
bodySprite.animState.Rewind();
bodySprite.animState.isPlaying = true;
}
isPlayingExtraAnimation = false;
isPlayingItemAnimation = true;
}
// 007c36b0 Puts away what the player holds up for an item: its costumes for the hold, and the item over its head.
void Entity_Player::ResetItemState()
{
if (itemState == COLLECTIBLE_SHOOP_DA_WHOOP) TryRemoveCollectibleCostume(COLLECTIBLE_SHOOP_DA_WHOOP, false);
else if (itemState == COLLECTIBLE_BOOMERANG)
RemoveCostume(g_manager->itemConfig.GetNullItem(NULLITEM_BOOMERANG));
if (variant == PLAYER_VARIANT_PLAYER && !isCoopGhost)
{
std::erase_if(costumeSpriteDescs, [](const CostumeSpriteDesc& desc) { return desc.isItemStateOnly; });
UpdateCostumes();
}
bool isHiding = bodySprite.animState.animData && bodySprite.animState.isPlaying && bodySprite.GetAnimation() == "HideItem";
if ((isPlayingExtraAnimation || isPlayingItemAnimation) && !isHiding && itemState == COLLECTIBLE_MOMS_BRACELET)
PlayExtraAnimation("HideItem");
itemState = 0;
}
// 006dad80 Notes the last damage the player took, as a deal or a trinket's price does without a hit.
void Entity_Player::set_last_damage(uint64_t damageFlags, const EntityRef& source)
{
lastDamageFlags = damageFlags;
lastDamageSource = source;
}
// 0085e260 Lengthens the frames the controls stay off.
void Entity_Player::AddControlsCooldown(int frames)
{
controlsCooldown += frames;
}
// 0085e280 The last hit's damage flags.
uint64_t Entity_Player::GetLastDamageFlags()
{
return lastDamageFlags;
}