1014 lines
50 KiB
C++
1014 lines
50 KiB
C++
#include "entity_effect_combat.h"
|
|
#include "entity_familiar.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 "level.h"
|
|
#include "log.h"
|
|
#include "lua_engine.h"
|
|
#include "manager.h"
|
|
#include "npc_ai.h"
|
|
#include "room.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;
|
|
|
|
// Zodiac's sign a landed hit may set off, until the zodiac's hits are written.
|
|
constexpr int ZODIAC = 392;
|
|
|
|
constexpr int ENTITY_SEGMENTED_WORM = 903;
|
|
constexpr int ENTITY_DAMAGE_RELAY = 966;
|
|
constexpr int SIREN_CHARM_SPARE_FRAMES = 29;
|
|
constexpr int SEGMENTED_WORM_VARIANT = 10;
|
|
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 ENEMY_TYPE_LAST = 999;
|
|
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 uint32_t CHALLENGE_PAY_TO_PLAY = 24;
|
|
|
|
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;
|
|
|
|
constexpr uint64_t DAMAGE_INVINCIBLE_IGNORED = 1ull << 13;
|
|
constexpr uint64_t DAMAGE_IGNORED = 1ull << 34;
|
|
// 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 DEBUG_INFINITE_HP = 1 << 2;
|
|
constexpr uint32_t DEBUG_DAMAGE_VALUES = 1 << 6;
|
|
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, and a co-op baby still appearing.
|
|
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_SEGMENTED_WORM && source.variant == SEGMENTED_WORM_VARIANT && entity)
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (a worm segment of the player's own)");
|
|
return false;
|
|
}
|
|
|
|
// Whether a Bishop the player charmed stands in the room to take the hit (find_nearest_enemy 004e7d10).
|
|
static bool is_bishop_present()
|
|
{
|
|
return std::ranges::any_of(g_game->room->entityList.updateEL, [](Entity* entity)
|
|
{ return entity->type == ENTITY_BISHOP && entity->HasEntityFlags(FLAG_CHARM); });
|
|
}
|
|
|
|
// Whether a wisp of the player's could take the hit (FUN_007c7b10).
|
|
static bool is_wisp_shield_present(Entity_Player& player)
|
|
{
|
|
return std::ranges::any_of(g_game->room->entityList.updateEL, [&](Entity* entity)
|
|
{
|
|
return !entity->isDead && entity->IsFamiliar() && entity->variant == Entity_Familiar::WISP &&
|
|
entity->subtype == COLLECTIBLE_DULL_RAZOR &&
|
|
static_cast<Entity_Familiar*>(entity)->player == &player;
|
|
});
|
|
}
|
|
|
|
// The items that answer a hit before it lands, each stopping or turning it, none written yet.
|
|
static void damage_reactions_check(Entity_Player& player, uint64_t damageFlags)
|
|
{
|
|
bool isExplosion = damageFlags & DAMAGE_EXPLOSION;
|
|
bool isFire = damageFlags & DAMAGE_FIRE;
|
|
|
|
if (is_bishop_present()) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (a charmed Bishop's shield)");
|
|
if (player.HasTrinket(TRINKET_WALNUT) && isExplosion)
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Walnut)");
|
|
if (player.HasCollectible(COLLECTIBLE_PYROMANIAC) && (isFire || isExplosion))
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Pyromaniac)");
|
|
if (player.HasCollectible(COLLECTIBLE_HOST_HAT))
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Host Hat)");
|
|
bool isFetus = player.HasWeaponType(WEAPON_BOMBS) || player.HasWeaponType(WEAPON_BONE);
|
|
if (isFetus && player.HasCollectible(COLLECTIBLE_IPECAC) && isExplosion)
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Ipecac with Dr. Fetus)");
|
|
if (player.HasCollectible(COLLECTIBLE_HOT_BOMBS) && isFire)
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Hot Bombs)");
|
|
if (player.variant == PLAYER_VARIANT_COOP_BABY && player.babySkin == BABY_BOMB && isExplosion)
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (the bomb baby)");
|
|
if (player.HasCollectible(COLLECTIBLE_JELLY_BELLY) && !(damageFlags & (DAMAGE_NO_MODIFIERS | DAMAGE_FAKE)))
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Jelly Belly)");
|
|
if (player.HasCollectible(COLLECTIBLE_METAL_PLATE) || player.HasCollectible(COLLECTIBLE_CONE_HEAD))
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Metal Plate and Cone Head)");
|
|
}
|
|
|
|
// 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]++;
|
|
}
|
|
|
|
// 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 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);
|
|
if (player.HasCollectible(ZODIAC)) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Zodiac's sign)");
|
|
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;
|
|
}
|
|
|
|
// 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_DAMAGE_RELAY && 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;
|
|
}
|
|
|
|
// 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 (is_wisp_shield_present(*this)) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (wisp shields)");
|
|
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;
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (white fire's lost curse)");
|
|
}
|
|
if (IsHologram() || is_damage_ignored(*this, source, damageFlags)) return false;
|
|
damage_reactions_check(*this, damageFlags);
|
|
|
|
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) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (a fly for the hit)");
|
|
|
|
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))
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Hallowed Ground)");
|
|
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 <= ENEMY_TYPE_LAST)
|
|
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)
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (dropping coins to Greed)");
|
|
if (variant == PLAYER_VARIANT_COOP_BABY && (babySkin == BABY_FART || babySkin == BABY_BOMB || babySkin == BABY_BOOK))
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (the co-op babies that answer hits)");
|
|
if (HasCollectible(COLLECTIBLE_MARBLES) && (trinkets[0] != 0 || queuedItem.item))
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Marbles)");
|
|
|
|
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)
|
|
{
|
|
if (HasCollectible(COLLECTIBLE_HEARTBREAK)) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Heartbreak)");
|
|
if (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)
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Monkey Paw)");
|
|
}
|
|
|
|
damageCooldown = damage_cooldown_scale(std::min(hurtFrames, HURT_HEARTS_MAX) * HURT_FRAMES_PER_HEART);
|
|
flags &= ~FLAG_NO_DAMAGE_BLINK;
|
|
if (isAstral) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Astral Projection)");
|
|
blind_rage_finger_bone_hit(*this);
|
|
if (isPenalized && HasCollectible(COLLECTIBLE_GLASS_CANNON)) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Glass Cannon)");
|
|
|
|
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))
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Swallowed M80)");
|
|
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 one's own Ipecac unlocks an
|
|
// achievement that is not written yet.
|
|
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 <= ENEMY_TYPE_LAST)
|
|
bestiary_count_add(bestiary.deaths, source.type, source.variant);
|
|
else if (source.spawnerType >= ENTITY_FIRST_ENEMY && source.spawnerType <= ENEMY_TYPE_LAST)
|
|
bestiary_count_add(bestiary.deaths, source.spawnerType, (int)source.spawnerVariant);
|
|
if ((damageFlags & DAMAGE_EXPLOSION) && source.type == ENTITY_TEAR && source.entity)
|
|
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (the achievement for dying to Ipecac)");
|
|
}
|
|
|
|
// 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_IGNORED) 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 holy light when the player is hit as it runs out, not written yet. True when it shines.
|
|
uint32_t Entity_Player::play_hurt_effects()
|
|
{
|
|
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;
|
|
reconstruction_missing("Entity_Player::play_hurt_effects 007d1c10 (Breath of Life)");
|
|
}
|
|
|
|
// 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;
|
|
}
|
|
|
|
// 007afc20 Kills the player out of hearts and starts the death sequence, unless it is dead, a ghost, berserk or
|
|
// projected. Spirit Shackles' second chance is not written yet. 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) reconstruction_missing("Entity_Player::try_trigger_astral_projection 007afc20 (Spirit Shackles)");
|
|
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;
|
|
}
|
|
|
|
// 007d35b0 Ends Astral Projection's spirit form when the spirit is hit, not written yet. True when it ended.
|
|
bool Entity_Player::try_end_astral_projection()
|
|
{
|
|
TemporaryEffect* astral = temporaryEffects.isDisabled ? nullptr : temporaryEffects.GetCollectibleEffect(COLLECTIBLE_ASTRAL_PROJECTION);
|
|
if (!astral || astral->count != 1) return false;
|
|
reconstruction_missing("Entity_Player::try_end_astral_projection 007d35b0");
|
|
}
|
|
|
|
// 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;
|
|
}
|