224 lines
9.3 KiB
C++
224 lines
9.3 KiB
C++
#include "boss_ai.h"
|
|
#include "entity_player.h"
|
|
#include "npc_depths.h"
|
|
#include "room_grid.h"
|
|
#include "room_transition.h"
|
|
|
|
// Its fall: the frames it hovers (a random wait first) and the size its shadow grows to.
|
|
constexpr uint32_t HAND_WAIT_SPREAD = 150;
|
|
constexpr int HAND_FOLLOW_FRAMES = 78;
|
|
constexpr int HAND_DROP_FRAMES = 90;
|
|
constexpr float HAND_SHADOW_SIZE = 0.43333334f;
|
|
constexpr float HAND_FOLLOW_DROP = 1;
|
|
constexpr float HAND_CONTROL_SPEED = 1.6f;
|
|
constexpr float HAND_CONTROL_SLOW_SPEED = 0.1f;
|
|
constexpr int HAND_SHAKE = 10;
|
|
constexpr int HAND_LAUGH_DELAY = 10;
|
|
constexpr float HAND_FRICTION = 0.6f;
|
|
|
|
// On the floor: how long it lies stunned, how its shadow fades as it rises, and how long effects on it hold.
|
|
constexpr int HAND_STUN_FRAMES = 51;
|
|
constexpr float HAND_SHADOW_FADE = 0.7f;
|
|
constexpr int HAND_STATUS_HOLD = 3;
|
|
|
|
// Mom's Dead Hand: the cracks its landing sends out, and the spiders it leaves.
|
|
constexpr uint32_t HAND_CRACK_SPREAD = 1;
|
|
constexpr float HAND_CRACK_MIN = 3;
|
|
constexpr float HAND_CRACK_TURN = 360;
|
|
constexpr uint32_t HAND_SPIDER_SPREAD = 1;
|
|
constexpr int HAND_SPIDER_MIN = 2;
|
|
constexpr float HAND_SPIDER_REACH = 80;
|
|
constexpr float HAND_SPIDER_HEIGHT = -30;
|
|
|
|
// While it falls, lies or rises, the charm, confusion, fear and shrink on it never run out.
|
|
static void moms_hand_status_hold(Entity_NPC& npc)
|
|
{
|
|
EntityRef self(&npc);
|
|
if (npc.HasEntityFlags(FLAG_CHARM) && npc.charmedCountdown < HAND_STATUS_HOLD) npc.AddCharmed(self, 1, false, false);
|
|
if (npc.HasEntityFlags(FLAG_CONFUSION) && npc.confusionCountdown < HAND_STATUS_HOLD) npc.AddConfusion(self, 1, false);
|
|
if (npc.HasEntityFlags(FLAG_FEAR) && npc.fearCountdown < HAND_STATUS_HOLD) npc.AddFear(self, 1, false);
|
|
if (npc.HasEntityFlags(FLAG_SHRINK) && npc.shrinkCountdown < HAND_STATUS_HOLD) npc.AddShrink(self, 1, false);
|
|
}
|
|
|
|
// Hovering, its shadow grows over its target (or drifts where its controller steers, faster while it shoots) until
|
|
// it drops.
|
|
static void moms_hand_hover(Entity_NPC& npc)
|
|
{
|
|
npc.shadowSize = std::min((float)npc.stateFrame / HAND_DROP_FRAMES * HAND_SHADOW_SIZE, HAND_SHADOW_SIZE);
|
|
if (npc.controllerID != -1)
|
|
{
|
|
float speed = npc.stateFrame < HAND_DROP_FRAMES ? HAND_CONTROL_SPEED : HAND_CONTROL_SLOW_SPEED;
|
|
npc.pathfinder.FindGridPath({}, speed, 0, DIRECT_PATH_FAR);
|
|
if (npc.IsControllerActionPressed(CONTROLLER_ACTION_SHOOT)) npc.stateFrame += npc_ticks_get(npc) * 2;
|
|
}
|
|
else if (npc.stateFrame < HAND_FOLLOW_FRAMES && !npc.HasEntityFlags(FLAG_DISTRACTED))
|
|
npc.pos = vector_add(npc.GetPlayerTarget()->pos, vector_make(0, HAND_FOLLOW_DROP));
|
|
else if (npc.stateFrame < HAND_FOLLOW_FRAMES)
|
|
{
|
|
Vector away = vector_sub(npc.CalcTargetPosition(0), npc.pos);
|
|
if (vector_length_squared(away) > 0) npc.pos = vector_add(vector_normalized(away), npc.pos);
|
|
}
|
|
|
|
if (npc.stateFrame <= HAND_DROP_FRAMES - 1) return;
|
|
npc_sound_play(SOUND_BIRD_FLAP, 1, 2, champion_pitch_get(npc));
|
|
npc.state = NPC_STATE_STOMP;
|
|
npc.stateFrame = 0;
|
|
npc_anim_restart(npc.sprite, "JumpDown");
|
|
}
|
|
|
|
// Landing: it can be hit once down (the Dead Hand sends out three or four cracks), then lies stunned.
|
|
static void moms_hand_land(Entity_NPC& npc)
|
|
{
|
|
AnimationState& anim = npc.sprite.animState;
|
|
if (anim.animData)
|
|
{
|
|
if (anim.IsEventTriggered("Land"))
|
|
{
|
|
npc.PlaySound(SOUND_FORESTBOSS_STOMPS, 1, 2, false, 1);
|
|
if (npc.type == ENTITY_MOMS_DEAD_HAND)
|
|
{
|
|
float step = HAND_CRACK_TURN / ((float)(Random() & HAND_CRACK_SPREAD) + HAND_CRACK_MIN);
|
|
for (float angle = 0; angle < HAND_CRACK_TURN; angle += step)
|
|
{
|
|
auto* crack = static_cast<Entity_Effect*>(g_game->Spawn({.position = npc.pos, .spawner = &npc,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_CRACKWAVE,
|
|
.seed = Random()}));
|
|
crack->parent = &npc;
|
|
crack->rotation = angle;
|
|
}
|
|
}
|
|
}
|
|
if (anim.animData && anim.WasEventTriggered("Land")) npc.entityCollisionClass = ENTCOLL_ALL;
|
|
if (!npc_anim_is_done(npc)) return;
|
|
}
|
|
npc.state = NPC_STATE_IDLE;
|
|
npc.stateFrame = 0;
|
|
npc_anim_loop(npc.sprite, "Stunned");
|
|
}
|
|
|
|
// Rising back to hover: it slips out of reach on the Jump event.
|
|
static void moms_hand_rise(Entity_NPC& npc)
|
|
{
|
|
AnimationState& anim = npc.sprite.animState;
|
|
if (anim.animData && anim.WasEventTriggered("Jump"))
|
|
{
|
|
npc.entityCollisionClass = ENTCOLL_NONE;
|
|
npc.shadowSize *= HAND_SHADOW_FADE;
|
|
}
|
|
if (!npc_anim_is_done(npc)) return;
|
|
npc.state = NPC_STATE_MOVE;
|
|
npc.stateFrame = 0;
|
|
npc.sprite.SetFrame("JumpDown", 0);
|
|
}
|
|
|
|
// Carrying off what it grabbed: untouchable while it lifts, then, a player in hand, back to the floor's first room.
|
|
static void moms_hand_carry(Entity_NPC& npc)
|
|
{
|
|
npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS);
|
|
npc.isInvincible = true;
|
|
npc.health = npc.maxHitPoints;
|
|
npc_anim_loop(npc.sprite, "Grab");
|
|
if (!npc_anim_is_done(npc)) return;
|
|
|
|
npc.ClearEntityFlags(FLAG_NO_STATUS_EFFECTS);
|
|
npc.isInvincible = false;
|
|
if (npc.i1 == ENTITY_PLAYER && npc.i2 == 0)
|
|
{
|
|
for (Entity_Player* player : g_game->playerManager.playerList)
|
|
if (player->momsHandTimer > 0)
|
|
{
|
|
player->isControlsEnabled = true;
|
|
player->entityCollisionClass = ENTCOLL_ALL;
|
|
player->momsHandTimer = 0;
|
|
}
|
|
g_game->leaveDoor = -1;
|
|
g_game->StartRoomTransition({.animation = TRANSITION_FADE, .roomIndex = g_game->startingRoomIdx});
|
|
}
|
|
npc.entityCollisionClass = ENTCOLL_NONE;
|
|
npc.shadowSize *= HAND_SHADOW_FADE;
|
|
npc.state = NPC_STATE_MOVE;
|
|
npc.stateFrame = 0;
|
|
npc.sprite.SetFrame("JumpDown", 0);
|
|
}
|
|
|
|
// 00533b80 NpcAI::ENTITY_MOMS_HAND: Mom's Hand and Mom's Dead Hand hover over their target, slam down, lie stunned
|
|
// and rise again. A hand that grabs carries it off. The Dead Hand cracks the floor and leaves spiders.
|
|
void npc_moms_hand_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.state == NPC_STATE_INIT)
|
|
{
|
|
npc.state = NPC_STATE_MOVE;
|
|
npc.entityGridCollisionClass = GRIDCOLL_NONE;
|
|
npc.entityCollisionClass = ENTCOLL_NONE;
|
|
npc.stateFrame = -(int)(Random() % HAND_WAIT_SPREAD);
|
|
if (npc.sprite.SetAnimation("JumpDown", SWITCH_KEEP_FRAME) && npc.sprite.animState.animData)
|
|
{
|
|
npc.sprite.animState.SetFrameFloat(0);
|
|
npc.sprite.animState.isPlaying = false;
|
|
}
|
|
npc.ClearEntityFlags(FLAG_APPEAR);
|
|
npc.shadowSize = 0;
|
|
npc_sound_play(SOUND_MOM_VOX_EVILLAUGH, 1, HAND_LAUGH_DELAY, champion_pitch_get(npc));
|
|
game_shake_screen(HAND_SHAKE);
|
|
return;
|
|
}
|
|
|
|
if (npc.pendingDamage > 0)
|
|
for (DamageEvent& event : npc.damageEvents)
|
|
if ((event.damageFlags & DAMAGE_EXPLOSION) && event.source.type == ENTITY_MOMS_DEAD_HAND) event.damage = 0;
|
|
npc.stateFrame += npc_ticks_get(npc);
|
|
npc.friction *= HAND_FRICTION;
|
|
if (npc.state == NPC_STATE_JUMP || npc.state == NPC_STATE_MOVE || npc.state == NPC_STATE_STOMP)
|
|
moms_hand_status_hold(npc);
|
|
|
|
if (npc.state == NPC_STATE_MOVE) moms_hand_hover(npc);
|
|
else if (npc.state == NPC_STATE_STOMP) moms_hand_land(npc);
|
|
else if (npc.state == NPC_STATE_IDLE && npc.stateFrame >= HAND_STUN_FRAMES)
|
|
{
|
|
npc.state = NPC_STATE_JUMP;
|
|
npc.stateFrame = 0;
|
|
npc_anim_loop(npc.sprite, "JumpUp");
|
|
}
|
|
else if (npc.state == NPC_STATE_JUMP) moms_hand_rise(npc);
|
|
else if (npc.state == NPC_STATE_SPECIAL) moms_hand_carry(npc);
|
|
|
|
if (!npc.isDead || npc.type != ENTITY_MOMS_DEAD_HAND) return;
|
|
int spiders = (int)(Random() & HAND_SPIDER_SPREAD) + HAND_SPIDER_MIN;
|
|
for (int i = 0; i < spiders; i++)
|
|
{
|
|
Vector spot = room_free_pickup_position_find({.position = npc.pos, .step = random_unit() * HAND_SPIDER_REACH});
|
|
Entity_NPC::ThrowSpider(npc.pos, &npc, spot, false, HAND_SPIDER_HEIGHT);
|
|
}
|
|
}
|
|
|
|
// A player Mom's hand carries off stays away 240 frames.
|
|
constexpr int GRABBED_FRAMES = 240;
|
|
|
|
// 007b9a60 Taken by Mom's hand: a player vanishes untouchable and without control for a while, a co-op baby is gone.
|
|
void moms_hand_player_grab(Entity_Player& player)
|
|
{
|
|
if (player.variant == PLAYER_VARIANT_PLAYER)
|
|
{
|
|
player.isControlsEnabled = false;
|
|
player.isVisible = false;
|
|
player.entityCollisionClass = ENTCOLL_NONE;
|
|
player.momsHandTimer = GRABBED_FRAMES;
|
|
}
|
|
else if (player.variant == PLAYER_VARIANT_COOP_BABY) g_game->playerManager.RemoveCoPlayer(&player);
|
|
}
|
|
|
|
// 007b9aa0 Outside room transitions a carried player's time runs out, and it drops back in where it was taken.
|
|
void moms_hand_player_release_update(Entity_Player& player)
|
|
{
|
|
if (g_game->roomTransition.mode != TRANSITION_NONE || player.momsHandTimer <= 0 || --player.momsHandTimer != 0)
|
|
return;
|
|
|
|
player.isControlsEnabled = true;
|
|
player.entityCollisionClass = ENTCOLL_ALL;
|
|
player.momsHandTimer = 0;
|
|
npc_sound_play(SOUND_HELL_PORTAL1, 1, 2, 1);
|
|
player.PlayExtraAnimation("TeleportDown");
|
|
player.isVisible = true;
|
|
}
|