648 lines
29 KiB
C++
648 lines
29 KiB
C++
#include "entity_player_forgotten.h"
|
|
#include "entity_familiar.h"
|
|
#include "entity_npc.h"
|
|
#include "entity_pickup.h"
|
|
#include "entity_projectile.h"
|
|
#include "game.h"
|
|
#include "hud.h"
|
|
#include "manager.h"
|
|
#include "menu_manager.h"
|
|
#include "npc_ai.h"
|
|
#include "room.h"
|
|
#include "room_descriptor.h"
|
|
#include "room_grid.h"
|
|
#include "room_transition.h"
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
constexpr int FORGOTTEN_SWAP_COOLDOWN = 15;
|
|
constexpr int FORGOTTEN_SWAP_HOLD_COOLDOWN = 10;
|
|
constexpr int D_INFINITY_FACES = 10;
|
|
constexpr int D_INFINITY_FACE_SHIFT = 16;
|
|
constexpr int D_INFINITY_FACE_MASK = 0xffff;
|
|
constexpr int TAINTED_ISAAC_SLOTS = 8;
|
|
constexpr int TAINTED_ISAAC_BIRTHRIGHT_SLOTS = 12;
|
|
constexpr uint32_t DROP_HOLD_FRAMES = 120;
|
|
constexpr uint32_t SPECIAL_DAILY_NO_DROP = 4;
|
|
constexpr int ACTION_TRIGGER_DROP = 0x20;
|
|
constexpr int DROP_TRINKET_TRIES = 2;
|
|
constexpr int DROP_POCKET_TRIES = 4;
|
|
constexpr int POCKET_SLOT_FIRST_FILLED = -1;
|
|
constexpr int DROPPED_POCKET_COOLDOWN = 4;
|
|
constexpr uint32_t CHALLENGE_PRIDE_DAY = 28;
|
|
constexpr float GFUEL_HORN_VOLUME = 1.2f;
|
|
constexpr int GFUEL_HORN_SHAKE = 8;
|
|
constexpr int DARK_PRINCES_CROWN_RED_HEARTS = 2;
|
|
constexpr float DARK_PRINCES_CROWN_DEATHMATCH_MIN = 0.1f;
|
|
constexpr float DARK_PRINCES_CROWN_DEATHMATCH_MAX = 0.3f;
|
|
constexpr float DARK_PRINCES_CROWN_OFFSET_Y = -7;
|
|
|
|
// The swap's poofs: the white trail of puffs from The Soul to the body, its speed and size, and the projectiles the
|
|
// body clears as The Forgotten gets up.
|
|
constexpr ColorMod FORGOTTEN_SWAP_FLASH = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 1, 1}};
|
|
constexpr int FORGOTTEN_SWAP_FLASH_FRAMES = 8;
|
|
constexpr int SWAP_FLASH_PRIORITY = 255;
|
|
constexpr float SWAP_POOF_SPEED_SCALE = 0.1f;
|
|
constexpr float SWAP_POOF_SPEED_MAX = 4;
|
|
constexpr int SWAP_POOF_SUBTYPE = 10;
|
|
constexpr float SWAP_TRAIL_SPACING = 20;
|
|
constexpr int SWAP_TRAIL_MIN = 4;
|
|
constexpr int SWAP_TRAIL_MAX = 12;
|
|
constexpr float SWAP_TRAIL_TURN = 3.14f;
|
|
constexpr float SWAP_TRAIL_SPREAD = 15;
|
|
constexpr float SWAP_TRAIL_SPEED_MIN = 0.5f;
|
|
constexpr float SWAP_TRAIL_SIZE_MIN = 0.3f;
|
|
constexpr float SWAP_TRAIL_HEIGHT = -16;
|
|
constexpr int SWAP_BODY_SETTLE_FRAMES = 10;
|
|
constexpr float SWAP_BODY_CLEAR_RADIUS = 25;
|
|
constexpr float SWAP_PROJECTILE_HEIGHT_MIN = -50;
|
|
|
|
// The body lying in a room: the grid path mark it leaves, the crawlspace's drag, and the shots it draws to itself.
|
|
constexpr int FORGOTTEN_BODY_GRID_PATH = 950;
|
|
constexpr int FORGOTTEN_BODY_LEFT_GRID_PATH = 900;
|
|
constexpr float FORGOTTEN_BODY_DUNGEON_FRICTION = 0.95f;
|
|
constexpr float FORGOTTEN_BODY_LURE_RADIUS = 30;
|
|
constexpr float FORGOTTEN_BODY_LURE_TURN_MAX = 0.99f;
|
|
constexpr float HALF_TURN_RADIANS = 3.1415927f;
|
|
|
|
// The chain from The Soul to the body: its eight links spread along it, how far The Soul strays before it pulls, and
|
|
// its colour on a co-op ghost.
|
|
constexpr int CHAIN_LINK_FIRST = 2;
|
|
constexpr int CHAIN_LINK_END = 10;
|
|
constexpr float CHAIN_LINK_SPACING = 10;
|
|
constexpr float CHAIN_ANCHOR_SPAN = 0.1f;
|
|
constexpr float CHAIN_PULL = 0.01f;
|
|
constexpr float CHAIN_BODY_PULL = 0.5f;
|
|
constexpr float CHAIN_HEIGHT = 16;
|
|
constexpr int CHAIN_SUBTYPE_LINK = 1;
|
|
constexpr int BABY_GHOST_SOUL = 58;
|
|
constexpr ColorMod CHAIN_GHOST_COLOR = {{1, 0.05f, 0.12f, 0.2f}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
|
|
// The Purity glow's sheets by its state (00b6bb40).
|
|
constexpr std::string_view PURITY_GLOW_SHEETS[] = {
|
|
"gfx/characters/costumes/PurityGlow_red.png", "gfx/characters/costumes/PurityGlow_blue.png",
|
|
"gfx/characters/costumes/PurityGlow_yellow.png", "gfx/characters/costumes/PurityGlow_orange.png"};
|
|
|
|
// Puts a crown's float animation on, unless it already plays it (a looping one that stopped starts over).
|
|
static void crown_animation_set(ANM2& crown, std::string_view animation)
|
|
{
|
|
const AnimationState& state = crown.animState;
|
|
bool isKept = state.animData && crown.GetAnimation() == animation && !(state.IsLoopingAnimation() && !state.isPlaying);
|
|
if (isKept || !crown.SetAnimation(animation)) return;
|
|
crown.animState.Rewind();
|
|
crown.animState.isPlaying = true;
|
|
}
|
|
|
|
// The flash a player gives when The Forgotten and The Soul swap: its own colour lit up for eight frames.
|
|
static void swap_flash(Entity_Player& player)
|
|
{
|
|
ColorMod flash = player.sprite.color;
|
|
color_multiply(flash, FORGOTTEN_SWAP_FLASH);
|
|
player.SetColor(flash, FORGOTTEN_SWAP_FLASH_FRAMES, SWAP_FLASH_PRIORITY, true, false);
|
|
}
|
|
|
|
// The trail of white puffs The Soul leaves on its way back into the body, thicker the further it flies.
|
|
static void swap_trail_spawn(Entity_Player& player, Vector toBody, Vector poofVelocity)
|
|
{
|
|
Vector bodyPos = player.forgottenBody->pos;
|
|
int count = std::clamp((int)std::floor(vector_length(toBody) / SWAP_TRAIL_SPACING), SWAP_TRAIL_MIN, SWAP_TRAIL_MAX);
|
|
|
|
for (int i = 1; i <= count; i++)
|
|
{
|
|
float t = (float)i / (float)(count + 1);
|
|
Vector along = vector_make(player.pos.x + (bodyPos.x - player.pos.x) * t,
|
|
player.pos.y + (bodyPos.y - player.pos.y) * t);
|
|
float angle = random_unit() * SWAP_TRAIL_TURN;
|
|
angle += angle;
|
|
float spread = random_unit();
|
|
Vector spot = vector_make(std::cos(angle) * spread * SWAP_TRAIL_SPREAD + along.x,
|
|
along.y + spread * std::sin(angle) * SWAP_TRAIL_SPREAD);
|
|
uint32_t seed = Random();
|
|
float speed = random_unit() * SWAP_TRAIL_SPEED_MIN + SWAP_TRAIL_SPEED_MIN;
|
|
Entity* puff = g_game->Spawn({.position = spot, .velocity = vector_scale(poofVelocity, speed),
|
|
.type = ENTITY_EFFECT, .variant = EFFECT_HAEMO_TRAIL, .seed = seed});
|
|
puff->SetColor(FORGOTTEN_SWAP_FLASH, -1, SWAP_FLASH_PRIORITY, false, false);
|
|
float size = random_unit() * SWAP_TRAIL_SIZE_MIN + SWAP_TRAIL_SIZE_MIN;
|
|
puff->sprite.scale = vector_make(size * t, size * t);
|
|
puff->posOffset = vector_make(player.posOffset.x, player.sprite.scale.y * SWAP_TRAIL_HEIGHT + player.posOffset.y);
|
|
}
|
|
}
|
|
|
|
// The Soul going back into the body: the puffs (unless quiet), the projectiles about a settled body cleared, then The
|
|
// Forgotten stands where the body lay and the body goes.
|
|
static void soul_return(Entity_Player& player, bool isNoEffects)
|
|
{
|
|
Entity_Familiar* body = player.forgottenBody;
|
|
Vector toBody = body ? vector_sub(body->pos, player.pos) : Vector{};
|
|
Vector poofVelocity = vector_scale(toBody, SWAP_POOF_SPEED_SCALE);
|
|
|
|
if (!isNoEffects)
|
|
{
|
|
if (body)
|
|
{
|
|
if (vector_length(poofVelocity) > SWAP_POOF_SPEED_MAX) poofVelocity = vector_resized(poofVelocity, SWAP_POOF_SPEED_MAX);
|
|
swap_trail_spawn(player, toBody, poofVelocity);
|
|
}
|
|
Entity* poof = g_game->Spawn({.position = player.pos, .velocity = poofVelocity, .subType = SWAP_POOF_SUBTYPE,
|
|
.type = ENTITY_EFFECT, .variant = EFFECT_POOF02, .seed = Random()});
|
|
poof->posOffset = player.posOffset;
|
|
poof->sprite.scale = player.sprite.scale;
|
|
if (body && g_game->frameCount - body->spawnFrame > SWAP_BODY_SETTLE_FRAMES)
|
|
for (Entity* entity : entity_query_radius(body->pos, body->size + SWAP_BODY_CLEAR_RADIUS, QUERY_PROJECTILES))
|
|
{
|
|
auto* projectile = static_cast<Entity_Projectile*>(entity);
|
|
if (projectile->isDead || projectile->height <= SWAP_PROJECTILE_HEIGHT_MIN) continue;
|
|
projectile->projectileFlags = 0;
|
|
projectile->isDead = true;
|
|
}
|
|
}
|
|
if (!body) return;
|
|
|
|
player.Teleport(body->pos, false, false);
|
|
player.velocity = {};
|
|
body->Remove();
|
|
}
|
|
|
|
// The swap's Whore of Babylon: its effects are taken off and put back, less one when the old form woke it, and the new
|
|
// form wakes it again at one red heart.
|
|
static void babylon_reapply(Entity_Player& player, bool wasAwake)
|
|
{
|
|
TemporaryEffects& effects = player.temporaryEffects;
|
|
int count = effects.GetCollectibleEffectNum(COLLECTIBLE_WHORE_OF_BABYLON);
|
|
|
|
for (int i = 0; i < count; i++) effects.RemoveCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON, 1);
|
|
int kept = wasAwake ? count - 1 : count;
|
|
if (player.HasCollectible(COLLECTIBLE_WHORE_OF_BABYLON) && !effects.HasCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON))
|
|
{
|
|
ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(COLLECTIBLE_WHORE_OF_BABYLON);
|
|
if (!item->isAddCostumeOnPickup) player.RemoveCostume(item);
|
|
if (player.redHearts < 2) effects.AddCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON, true, 1);
|
|
}
|
|
for (int i = 0; i < kept; i++) effects.AddCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON, true, 1);
|
|
}
|
|
|
|
// The swap's heart effects for the new form: Empty Vessel's flight with no red hearts, Crown of Light's glow at full red
|
|
// health unhurt this room, and Dark Prince's Crown's at two red hearts (a share in versus), with the crowns' floats.
|
|
static void swap_crowns_update(Entity_Player& player)
|
|
{
|
|
TemporaryEffects& effects = player.temporaryEffects;
|
|
ItemConfig& config = g_manager->itemConfig;
|
|
|
|
effects.RemoveCollectibleEffect(COLLECTIBLE_EMPTY_VESSEL, 1);
|
|
if (player.HasCollectible(COLLECTIBLE_EMPTY_VESSEL) && !effects.HasCollectibleEffect(COLLECTIBLE_EMPTY_VESSEL))
|
|
{
|
|
player.RemoveCostume(config.GetNullItem(NULLITEM_EMPTY_VESSEL));
|
|
if (player.redHearts < 1)
|
|
{
|
|
effects.AddCollectibleEffect(COLLECTIBLE_EMPTY_VESSEL, true, 1);
|
|
player.AddCostume(config.GetNullItem(NULLITEM_EMPTY_VESSEL), false);
|
|
}
|
|
}
|
|
|
|
if (player.HasCollectible(COLLECTIBLE_CROWN_OF_LIGHT))
|
|
{
|
|
bool isLit = !player.isHurtThisRoom && player.redHearts >= player.GetEffectiveMaxHearts();
|
|
if (isLit && !effects.HasCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT))
|
|
{
|
|
effects.AddCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT, true, 1);
|
|
crown_animation_set(player.crownOfLightSprite, "FloatGlow");
|
|
}
|
|
else if (!isLit && effects.HasCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT))
|
|
{
|
|
effects.RemoveCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT, 1);
|
|
crown_animation_set(player.crownOfLightSprite, "FloatNoGlow");
|
|
}
|
|
}
|
|
if (!player.HasCollectible(COLLECTIBLE_DARK_PRINCES_CROWN)) return;
|
|
|
|
float share = (float)player.redHearts / (float)player.maxHearts;
|
|
bool isLit = g_game->deathmatchManager.is_active()
|
|
? share >= DARK_PRINCES_CROWN_DEATHMATCH_MIN && share <= DARK_PRINCES_CROWN_DEATHMATCH_MAX
|
|
: player.redHearts == DARK_PRINCES_CROWN_RED_HEARTS;
|
|
if (isLit && !effects.HasCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN))
|
|
{
|
|
effects.AddCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN, true, 1);
|
|
crown_animation_set(player.darkPrincesCrownSprite, "FloatGlow");
|
|
}
|
|
else if (!isLit && effects.HasCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN))
|
|
{
|
|
effects.RemoveCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN, 1);
|
|
crown_animation_set(player.darkPrincesCrownSprite, "FloatNoGlow");
|
|
}
|
|
player.darkPrincesCrownSprite.offset =
|
|
player.HasCollectible(COLLECTIBLE_CROWN_OF_LIGHT) ? vector_make(0, DARK_PRINCES_CROWN_OFFSET_Y) : Vector{};
|
|
}
|
|
|
|
// 007cc200 Swaps The Forgotten and The Soul (or, when forced, Tainted Jacob and his ghost) with the sub player: their
|
|
// hearts, character, tear side and weapons trade places. The Soul leaves the body where The Forgotten stood and The
|
|
// Forgotten gets up from it (with Birthright the body may be in another room, which the swap travels to). The heart
|
|
// effects are settled again for the new form. False when the swap is refused: on cooldown, an empty Soul, or a
|
|
// transition.
|
|
bool Entity_Player::SwapForgottenForm(bool isForce, bool isNoEffects)
|
|
{
|
|
Game& game = *g_game;
|
|
if (!subPlayer) return false;
|
|
|
|
bool isForgotten = playerType == PLAYER_THEFORGOTTEN || playerType == PLAYER_THESOUL;
|
|
bool isJacob = playerType == PLAYER_JACOB_B || playerType == PLAYER_JACOB2_B;
|
|
if (isForgotten && !isForce)
|
|
{
|
|
if (forgottenSwapFormCooldown > 0) return false;
|
|
if (subPlayer->redHearts < 1 && subPlayer->soulHearts < 1 && subPlayer->boneHearts < 1) return false;
|
|
if (game.roomTransition.mode != TRANSITION_NONE || game.stageTransition.state != STAGE_TRANSITION_NONE ||
|
|
game.deathCertificateExitTimer > 0)
|
|
return false;
|
|
}
|
|
else if (!isForgotten && (!isJacob || !isForce)) return false;
|
|
|
|
if (isForgotten && !isNoEffects) forgottenSwapFormCooldown = FORGOTTEN_SWAP_COOLDOWN;
|
|
RemoveSkinCostume();
|
|
bool wasBabylonAwake = HasCollectible(COLLECTIBLE_WHORE_OF_BABYLON) && redHearts <= 1;
|
|
for (int slot = 1; slot < WEAPON_SLOT_COUNT; slot++)
|
|
if (weapons[slot]) weapons[slot]->ClearReferences();
|
|
|
|
Entity_Player& other = *subPlayer;
|
|
std::swap(redHearts, other.redHearts);
|
|
std::swap(maxHearts, other.maxHearts);
|
|
std::swap(soulHearts, other.soulHearts);
|
|
std::swap(blackHearts, other.blackHearts);
|
|
std::swap(eternalHearts, other.eternalHearts);
|
|
std::swap(boneHearts, other.boneHearts);
|
|
std::swap(boneHeartsMask, other.boneHeartsMask);
|
|
std::swap(brokenHearts, other.brokenHearts);
|
|
std::swap(rottenHearts, other.rottenHearts);
|
|
std::swap(reverseEmpressMaxHearts, other.reverseEmpressMaxHearts);
|
|
std::swap(goldenHearts, other.goldenHearts);
|
|
std::swap(playerType, other.playerType);
|
|
std::swap(tearDisplacement, other.tearDisplacement);
|
|
std::swap(strengthMaxHearts, other.strengthMaxHearts);
|
|
std::swap(itemHeartsOverflow, other.itemHeartsOverflow);
|
|
std::swap(weaponTypes, other.weaponTypes);
|
|
std::swap_ranges(weapons.begin() + 1, weapons.end(), other.weapons.begin() + 1);
|
|
for (int slot = 1; slot < WEAPON_SLOT_COUNT; slot++)
|
|
if (weapons[slot]) weapons[slot]->owner = this;
|
|
|
|
if (playerType == PLAYER_THESOUL)
|
|
{
|
|
if (!isNoEffects || !forgottenBody) spawn_forgotten_body();
|
|
ResetColor();
|
|
if (!isNoEffects) swap_flash(*this);
|
|
}
|
|
else if (playerType == PLAYER_THEFORGOTTEN)
|
|
{
|
|
int roomIdx = forgottenBodyRoomIdx >= 0 ? forgottenBodyRoomIdx % DIMENSION_ROOM_COUNT : forgottenBodyRoomIdx;
|
|
int dimension = forgottenBodyRoomIdx >= 0 ? forgottenBodyRoomIdx / DIMENSION_ROOM_COUNT : 0;
|
|
bool isBodyAway = !forgottenBody && forgottenBodyRoomIdx != FORGOTTEN_BODY_ROOM_NONE &&
|
|
game.GetRoomByIdx(roomIdx, dimension) != game.room->descriptor;
|
|
if (isBodyAway && HasCollectible(COLLECTIBLE_BIRTHRIGHT))
|
|
{
|
|
game.leaveDoor = -1;
|
|
game.StartRoomTransition({.player = this, .animation = TRANSITION_FORGOTTEN_TELEPORT,
|
|
.direction = DIRECTION_NONE, .dimension = dimension, .roomIndex = roomIdx});
|
|
forgottenBodyRoomIdx = FORGOTTEN_BODY_ROOM_NONE;
|
|
}
|
|
else soul_return(*this, isNoEffects);
|
|
ResetColor();
|
|
if (!isNoEffects) swap_flash(*this);
|
|
forgottenBodyRoomIdx = FORGOTTEN_BODY_ROOM_NONE;
|
|
}
|
|
|
|
babylon_reapply(*this, wasBabylonAwake);
|
|
swap_crowns_update(*this);
|
|
cacheFlags |= CACHE_ALL;
|
|
itemHoldCooldown = FORGOTTEN_SWAP_HOLD_COOLDOWN;
|
|
EvaluateItems();
|
|
stop_costume_item_anims();
|
|
update_player_skin();
|
|
update_purity_glow();
|
|
return true;
|
|
}
|
|
|
|
// 007c7a20 Gives every layer of the costume an item wears a new spritesheet. Co-op babies and ghosts wear none.
|
|
void Entity_Player::ReplaceCostumeSprite(ItemConfig_Item* item, std::string_view path)
|
|
{
|
|
if (variant == PLAYER_VARIANT_COOP_BABY || isCoopGhost || !item) return;
|
|
|
|
for (CostumeSpriteDesc& costume : costumeSpriteDescs)
|
|
{
|
|
if (costume.item != item) continue;
|
|
for (int layer = 0; layer < (int)costume.sprite.layerStates.size(); layer++)
|
|
costume.sprite.ReplaceSpritesheet(layer, path);
|
|
costume.sprite.LoadGraphics();
|
|
}
|
|
}
|
|
|
|
// 007c7c60 Colours Purity's glow by its state. A state past the four logs an error and, where the original read past
|
|
// its table, keeps the last colour.
|
|
void Entity_Player::update_purity_glow()
|
|
{
|
|
int state = purityState;
|
|
if (state > (int)std::size(PURITY_GLOW_SHEETS) - 1)
|
|
{
|
|
KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"[err] Purity has a wrong state!");
|
|
state = (int)std::size(PURITY_GLOW_SHEETS) - 1;
|
|
}
|
|
ReplaceCostumeSprite(g_manager->itemConfig.GetNullItem(NULLITEM_PURITY_GLOW), PURITY_GLOW_SHEETS[state]);
|
|
}
|
|
|
|
// The pocket a slot names, -1 the first holding a card or pill, or the slot count when none does.
|
|
static int pocket_slot_resolve(Entity_Player& player, int slot)
|
|
{
|
|
if (slot != POCKET_SLOT_FIRST_FILLED) return slot;
|
|
for (slot = 0; slot < POCKET_SLOT_COUNT; slot++)
|
|
if (player.pocketItems[slot].id != 0 && player.pocketItems[slot].type != POCKET_ACTIVE) return slot;
|
|
return POCKET_SLOT_COUNT;
|
|
}
|
|
|
|
// Takes a card or pill out of its pocket, the pockets behind moving up and the last one emptied. The Red Key's door
|
|
// hints are redrawn.
|
|
static void pocket_slot_clear(Entity_Player& player, int slot)
|
|
{
|
|
std::move(player.pocketItems.begin() + slot + 1, player.pocketItems.end(), player.pocketItems.begin() + slot);
|
|
player.pocketItems[POCKET_SLOT_COUNT - 1] = {.id = 0, .type = POCKET_CARD};
|
|
g_game->room->UpdateRedKey();
|
|
}
|
|
|
|
// 00753900 The pocket in a slot, clamped to the four.
|
|
PocketItem& Entity_Player::GetPocketItem(int slot)
|
|
{
|
|
return pocketItems[std::clamp(slot, 0, POCKET_SLOT_COUNT - 1)];
|
|
}
|
|
|
|
// 007a4850 Removes the card or pill in a slot (-1 for the first), never a pocket active.
|
|
void Entity_Player::RemovePocketItem(int slot)
|
|
{
|
|
slot = pocket_slot_resolve(*this, slot);
|
|
if (slot >= POCKET_SLOT_COUNT || pocketItems[slot].id == 0 || pocketItems[slot].type == POCKET_ACTIVE) return;
|
|
pocket_slot_clear(*this, slot);
|
|
}
|
|
|
|
// 007a48f0 Drops the card or pill in a slot (-1 for the first) at a position as its pickup, which the player cannot
|
|
// take back for four frames.
|
|
void Entity_Player::DropPocketItem(int slot, Vector position)
|
|
{
|
|
slot = pocket_slot_resolve(*this, slot);
|
|
if (slot >= POCKET_SLOT_COUNT || pocketItems[slot].id == 0 || pocketItems[slot].type == POCKET_ACTIVE) return;
|
|
|
|
PocketItem& held = pocketItems[slot];
|
|
int variant = held.type == POCKET_CARD ? PICKUP_TAROTCARD : PICKUP_PILL;
|
|
Entity* pickup = g_game->Spawn({.position = position, .spawner = this, .subType = held.id, .type = ENTITY_PICKUP,
|
|
.variant = variant, .seed = Random()});
|
|
if (pickup) static_cast<Entity_Pickup*>(pickup)->collisionCooldown = DROPPED_POCKET_COOLDOWN;
|
|
pocket_slot_clear(*this, slot);
|
|
}
|
|
|
|
// The drop button's turn of the pockets: each filled pocket moves one slot forward and the first goes last.
|
|
static void pocket_items_rotate(Entity_Player& player)
|
|
{
|
|
for (int slot = 1; slot < POCKET_SLOT_COUNT && player.pocketItems[slot].id != 0; slot++)
|
|
{
|
|
std::swap(player.pocketItems[slot], player.pocketItems[slot - 1]);
|
|
g_game->hud.refresh_request(HUD_REFRESH_PLAYER);
|
|
}
|
|
}
|
|
|
|
// The drop button's turn of the active slots: D Infinity shows its next face first and swaps only past its last.
|
|
static void active_items_rotate(Entity_Player& player)
|
|
{
|
|
ActiveItemDesc& active = player.activeItems[ACTIVE_SLOT_PRIMARY];
|
|
if (active.item == COLLECTIBLE_D_INFINITY)
|
|
{
|
|
uint32_t face = (uint32_t)((active.varData >> D_INFINITY_FACE_SHIFT) + 1) % D_INFINITY_FACES;
|
|
active.varData = (int)(face << D_INFINITY_FACE_SHIFT) | (active.varData & D_INFINITY_FACE_MASK);
|
|
g_game->hud.InvalidateActiveItem(&player, ACTIVE_SLOT_PRIMARY);
|
|
if (face != 0) return;
|
|
}
|
|
player.SwapActiveItems();
|
|
}
|
|
|
|
// The drop button's turn of the tainted inventories: Tainted Isaac's items and Tainted Cain's bag and item cards.
|
|
static void tainted_inventory_rotate(Entity_Player& player)
|
|
{
|
|
HUD& hud = g_game->hud;
|
|
|
|
if (player.playerType == PLAYER_ISAAC_B)
|
|
{
|
|
int limit = player.HasCollectible(COLLECTIBLE_BIRTHRIGHT) ? TAINTED_ISAAC_BIRTHRIGHT_SLOTS : TAINTED_ISAAC_SLOTS;
|
|
auto end = std::find_if(player.inventory.begin(), player.inventory.begin() + limit, [](int entry) { return entry < 0; });
|
|
if (end - player.inventory.begin() > 1)
|
|
{
|
|
std::rotate(player.inventory.begin(), player.inventory.begin() + 1, end);
|
|
hud.mark_all_slots_dirty(HISTORY_KEEP_ICONS, HISTORY_KEEP_ITEMS);
|
|
}
|
|
}
|
|
if (player.playerType != PLAYER_CAIN_B) return;
|
|
|
|
std::array<char, BAG_OF_CRAFTING_SIZE>& bag = player.bagOfCraftingContent;
|
|
char first = bag[0];
|
|
if (first != 0 && bag[1] != 0)
|
|
{
|
|
int slot = 0;
|
|
for (; slot < BAG_OF_CRAFTING_SIZE - 1 && bag[slot + 1] != 0; slot++) bag[slot] = bag[slot + 1];
|
|
bag[slot] = first;
|
|
}
|
|
if (player.itemCards.size() > 1)
|
|
{
|
|
std::rotate(player.itemCards.begin(), player.itemCards.begin() + 1, player.itemCards.end());
|
|
hud.mark_all_slots_dirty(HISTORY_KEEP_ICONS, HISTORY_KEEP_ITEMS);
|
|
}
|
|
}
|
|
|
|
// The drop button held two seconds: the trinkets (but Tick, and Rainbow Worm in Pride Day) and the cards and pills go
|
|
// to the floor.
|
|
static void drop_hold_update(Entity_Player& player)
|
|
{
|
|
Game& game = *g_game;
|
|
bool isAnythingToDrop = false;
|
|
|
|
player.actionHoldDrop = 0;
|
|
for (uint32_t trinket : player.trinkets)
|
|
{
|
|
if (trinket == 0) continue;
|
|
if (game.deathmatchManager.is_active())
|
|
reconstruction_missing("Entity_Player::pockets_rotate 007a42b0 (a versus mode's trinket drop)");
|
|
if (trinket != TRINKET_TICK && !(trinket == TRINKET_RAINBOW_WORM && game.challenge == CHALLENGE_PRIDE_DAY))
|
|
isAnythingToDrop = true;
|
|
}
|
|
for (uint32_t slot = 0; slot < player.GetMaxPocketItems(); slot++)
|
|
if (player.pocketItems[slot].id != 0 && player.pocketItems[slot].type != POCKET_ACTIVE) isAnythingToDrop = true;
|
|
if (!isAnythingToDrop) return;
|
|
|
|
game.hud.refresh_request(HUD_REFRESH_PLAYER);
|
|
player.lastActionTriggers |= ACTION_TRIGGER_DROP;
|
|
for (int i = 0; i < DROP_TRINKET_TRIES; i++)
|
|
{
|
|
player.DropTrinket(room_free_pickup_position_find({.position = player.pos}), false);
|
|
if (player.variant == PLAYER_VARIANT_PLAYER && !player.isCoopGhost) player.InvalidateCoPlayerItems();
|
|
}
|
|
for (int i = 0; i < DROP_POCKET_TRIES; i++)
|
|
player.DropPocketItem(POCKET_SLOT_FIRST_FILLED, room_free_pickup_position_find({.position = player.pos}));
|
|
}
|
|
|
|
// 007a42b0 The drop button. A press swaps The Forgotten and The Soul, or else turns the pockets and, with no item state
|
|
// up, the active slots. Tainted Isaac's inventory and Tainted Cain's bag turn too, and the G FUEL! seed honks. Held two
|
|
// seconds (not in the daily that forbids it) it drops the trinkets and pocket items. The write the hold makes to a
|
|
// field nothing reads (+0x1880) is left out.
|
|
void Entity_Player::pockets_rotate()
|
|
{
|
|
Game& game = *g_game;
|
|
if (variant != PLAYER_VARIANT_PLAYER || isCoopGhost || IsHologram()) return;
|
|
|
|
if (forgottenSwapFormCooldown > 0) forgottenSwapFormCooldown--;
|
|
if (input_is_action_triggered(ACTION_DROP, controllerIndex, this))
|
|
{
|
|
if (!SwapForgottenForm(false, false))
|
|
{
|
|
pocket_items_rotate(*this);
|
|
if (itemState == 0) active_items_rotate(*this);
|
|
}
|
|
tainted_inventory_rotate(*this);
|
|
if (g_fuel_count() > 0)
|
|
{
|
|
npc_sound_play(SOUND_GFUEL_AIR_HORN, GFUEL_HORN_VOLUME, 1, 1);
|
|
game_shake_screen(GFUEL_HORN_SHAKE);
|
|
}
|
|
}
|
|
|
|
if (!input_is_action_pressed(ACTION_DROP, controllerIndex, this))
|
|
{
|
|
actionHoldDrop = 0;
|
|
return;
|
|
}
|
|
if ((uint32_t)++actionHoldDrop > DROP_HOLD_FRAMES && game.dailyChallenge._specialDailyId != SPECIAL_DAILY_NO_DROP)
|
|
drop_hold_update(*this);
|
|
}
|
|
|
|
// 0060de70 (the body's case) Lies on the floor, or floats in the Beast's dungeon, unmoved by knockback. It appears
|
|
// with its animation unless the room has just started.
|
|
void forgotten_body_init(Entity_Familiar& body)
|
|
{
|
|
Room& room = *g_game->room;
|
|
bool isFresh = room.GetFrameCount() < 2;
|
|
bool isFloating = room.IsBeastDungeon();
|
|
|
|
body.AddEntityFlags(FLAG_NO_PHYSICS_KNOCKBACK | FLAG_DONT_OVERWRITE);
|
|
body.entityGridCollisionClass = isFloating ? GRIDCOLL_WALLS : GRIDCOLL_GROUND;
|
|
if (isFloating) body.sprite.Play(isFresh ? "FlyingIdle" : "FlyingAppear");
|
|
else body.sprite.Play(isFresh ? "Idle" : "Appear");
|
|
}
|
|
|
|
// 0061da10 (the body's case) Plays its idle on the floor or in the air and holds its place, marking its grid square
|
|
// (in a crawlspace it slides to a stop instead). Enemy shots that pass closer to the body than to the player are bent
|
|
// towards it, the more the more they head away.
|
|
void forgotten_body_update(Entity_Familiar& body)
|
|
{
|
|
Room& room = *g_game->room;
|
|
|
|
if (body.sprite.IsFinished()) body.sprite.Play(body.entityGridCollisionClass != GRIDCOLL_WALLS ? "Idle" : "FlyingIdle");
|
|
if (room.roomType != ROOM_DUNGEON)
|
|
{
|
|
if (vector_is_zero(body.targetPosition))
|
|
{
|
|
body.pathfinder.UpdateGridIndex();
|
|
body.targetPosition = body.pos;
|
|
}
|
|
body.velocity = vector_sub(body.targetPosition, body.pos);
|
|
room.SetGridPath(body.pathfinder.gridIndex, FORGOTTEN_BODY_GRID_PATH);
|
|
}
|
|
else body.friction *= FORGOTTEN_BODY_DUNGEON_FRICTION;
|
|
|
|
for (Entity* shot : entity_query_radius(body.pos, FORGOTTEN_BODY_LURE_RADIUS, QUERY_PROJECTILES))
|
|
{
|
|
if (shot->HasEntityFlags(FLAG_FRIENDLY)) continue;
|
|
Vector toBody = vector_sub(body.pos, shot->pos);
|
|
if (vector_length_squared(toBody) >= vector_length_squared(vector_sub(shot->pos, body.player->pos))) continue;
|
|
|
|
Vector heading = vector_normalized(shot->velocity);
|
|
Vector lure = vector_normalized(toBody);
|
|
Vector lured = vector_scale(lure, vector_length(shot->velocity));
|
|
float kept = std::min(FORGOTTEN_BODY_LURE_TURN_MAX, std::acos(vector_dot(heading, lure)) / HALF_TURN_RADIANS);
|
|
shot->velocity = vector_add(vector_scale(shot->velocity, kept), vector_scale(lured, 1 - kept));
|
|
}
|
|
}
|
|
|
|
// 006121d0 (the body's case) The square the body lay on keeps a weaker mark than the one it held, unless something
|
|
// stronger marked it since.
|
|
void forgotten_body_clear(Entity_Familiar& body)
|
|
{
|
|
int gridIndex = body.pathfinder.gridIndex;
|
|
std::array<int, ROOM_GRID_CELLS>& paths = g_game->room->gridPaths;
|
|
if (gridIndex >= 0 && gridIndex < ROOM_GRID_CELLS && paths[gridIndex] <= FORGOTTEN_BODY_GRID_PATH)
|
|
paths[gridIndex] = FORGOTTEN_BODY_LEFT_GRID_PATH;
|
|
}
|
|
|
|
// Entity_Effect::Update 005d4380 (case 006040d8) The Forgotten's chain from the body (child) to The Soul (target): the
|
|
// first frame lays eight links along it. The chain end pulls a Soul that strays past its length back (and in a
|
|
// crawlspace drags the body along), every link sits its share of the way from the body to The Soul at their heights,
|
|
// and the chain shows The Soul's colour. Without both ends, or for The Soul's Birthright, it fades away.
|
|
static EffectUpdateEnd forgotten_chain_update(Entity_Effect& chain)
|
|
{
|
|
Room& room = *g_game->room;
|
|
|
|
if (chain.subtype == 0 && chain.state == 0)
|
|
{
|
|
chain.rotation = CHAIN_ANCHOR_SPAN;
|
|
for (int i = CHAIN_LINK_FIRST; i < CHAIN_LINK_END; i++)
|
|
{
|
|
auto* link = static_cast<Entity_Effect*>(
|
|
g_game->Spawn({.position = chain.pos, .spawner = &chain, .subType = CHAIN_SUBTYPE_LINK,
|
|
.type = ENTITY_EFFECT, .variant = EFFECT_FORGOTTEN_CHAIN, .seed = Random()}));
|
|
link->parent = &chain;
|
|
link->child = chain.child;
|
|
link->target = chain.target;
|
|
link->targetPosition = chain.targetPosition;
|
|
link->rotation = (float)i / CHAIN_LINK_SPACING;
|
|
link->Update();
|
|
}
|
|
chain.state = 1;
|
|
}
|
|
|
|
Entity* body = chain.child;
|
|
Entity* soul = chain.target;
|
|
auto* soulPlayer = soul ? soul->ToPlayer() : nullptr;
|
|
bool isBirthright = soulPlayer && soulPlayer->playerType == PLAYER_THESOUL &&
|
|
soulPlayer->HasCollectible(COLLECTIBLE_BIRTHRIGHT);
|
|
if (!body || !soul || isBirthright)
|
|
{
|
|
chain.velocity = {};
|
|
chain.sprite.Play("Disappear");
|
|
if (chain.sprite.IsFinished()) chain.Remove();
|
|
return EFFECT_UPDATE_FINISH;
|
|
}
|
|
|
|
Vector anchor = vector_add(body->pos, chain.targetPosition);
|
|
if (chain.subtype == 0)
|
|
{
|
|
Vector stray = vector_sub(soul->pos, anchor);
|
|
float length = vector_length(stray);
|
|
if (chain.scale < length)
|
|
{
|
|
stray = vector_scale(stray, (chain.scale / length - 1) * CHAIN_PULL);
|
|
soul->velocity = vector_add(soul->velocity, stray);
|
|
if (room.roomType == ROOM_DUNGEON) body->velocity = vector_sub(body->velocity, vector_scale(stray, CHAIN_BODY_PULL));
|
|
}
|
|
}
|
|
|
|
float t = chain.rotation;
|
|
Vector spot = vector_make(anchor.x + (soul->pos.x - anchor.x) * t, anchor.y + (soul->pos.y - anchor.y) * t);
|
|
float soulHeight = soul->posOffset.y - soul->sprite.scale.y * CHAIN_HEIGHT;
|
|
float bodyHeight = body->posOffset.y - body->sprite.scale.y * CHAIN_HEIGHT;
|
|
chain.posOffset.y = bodyHeight + (soulHeight - bodyHeight) * t;
|
|
if (room.GetFrameCount() < 1) chain.pos = spot;
|
|
else chain.velocity = vector_sub(spot, chain.pos);
|
|
chain.isVisible = !soul->isDead;
|
|
chain.sprite.color = soul->IsType(ENTITY_PLAYER, PLAYER_VARIANT_COOP_BABY, BABY_GHOST_SOUL) ? CHAIN_GHOST_COLOR
|
|
: soul->sprite.color;
|
|
chain.sprite.scale = body->sprite.scale;
|
|
return EFFECT_UPDATE_FINISH;
|
|
}
|
|
|
|
constexpr auto PLAYER_EFFECT_BEHAVIOURS = std::to_array<EffectBehaviour>({
|
|
{EFFECT_FORGOTTEN_CHAIN, nullptr, forgotten_chain_update, nullptr},
|
|
});
|
|
|
|
std::span<const EffectBehaviour> player_effect_behaviours()
|
|
{
|
|
return PLAYER_EFFECT_BEHAVIOURS;
|
|
}
|