112 lines
4.7 KiB
C++
112 lines
4.7 KiB
C++
#include "boss_ai.h"
|
|
#include "npc_depths.h"
|
|
|
|
// The Keeper's four faces, its spit's reach, pause and spread, and how it hangs.
|
|
constexpr uint32_t HANGER_FACES = 4;
|
|
constexpr ColorMod HANGER_SPLAT_COLOR = {{0.4f, 0.2f, 0.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
constexpr float HANGER_WALL_MARGIN = 30;
|
|
constexpr float HANGER_TOP_MARGIN = 10;
|
|
constexpr uint32_t HANGER_DRIP_ODDS = 10;
|
|
constexpr float HANGER_DRIP_SIZE = 0.5f;
|
|
constexpr float HANGER_DRIP_MIN = 0.4f;
|
|
constexpr float HANGER_TARGET_REACH = 10;
|
|
constexpr float HANGER_CONTROL_REACH = 100;
|
|
constexpr float HANGER_RANGE = 260;
|
|
constexpr int HANGER_RANGE_FRAMES = 7;
|
|
constexpr int HANGER_COOLDOWN_UNIT = 7;
|
|
constexpr int HANGER_COOLDOWN_MIN = 6;
|
|
constexpr float HANGER_CONTROL_DEADZONE = 0.1f;
|
|
constexpr float HANGER_MIN_FRICTION = 0.01f;
|
|
constexpr float HANGER_MIN_DISTANCE = 0.1f;
|
|
constexpr float HANGER_ACCEL = 0.13f;
|
|
constexpr float HANGER_SHOT_HEIGHT = -20;
|
|
constexpr float HANGER_SHOT_FALL = 2;
|
|
constexpr float HANGER_SHOT_SPEED = 7;
|
|
constexpr float HANGER_FRICTION = 0.93f;
|
|
|
|
// Its face's idle and spitting animations.
|
|
static std::string face_animation_get(Entity_NPC& npc, std::string_view kind)
|
|
{
|
|
return std::string(kind) + "0" + std::to_string(npc.i1 + 1);
|
|
}
|
|
|
|
// The aim toward its target, or its controller's steer.
|
|
static Vector hanger_aim_get(Entity_NPC& npc, Vector target)
|
|
{
|
|
if (npc.controllerID == -1) return vector_sub(target, npc.pos);
|
|
return vector_scale(npc.controllerMovement, HANGER_CONTROL_REACH);
|
|
}
|
|
|
|
// Hanging, it drifts toward its target and starts spitting once it is in range and its cooldown is over.
|
|
static void hanger_drift(Entity_NPC& npc)
|
|
{
|
|
Vector aim = vector_sub(npc.CalcTargetPosition(HANGER_TARGET_REACH), npc.pos);
|
|
if (npc.controllerID != -1) aim = vector_scale(npc.GetControllerInput(0), HANGER_CONTROL_REACH);
|
|
|
|
bool isReady = npc.projectileCooldown < 1 || (npc.projectileCooldown -= npc_ticks_get(npc)) < 1;
|
|
if (isReady && npc.IsTargetInAttackRange(HANGER_RANGE, HANGER_RANGE_FRAMES, false))
|
|
{
|
|
npc.controllerMovement =
|
|
npc.controllerID == -1 ? Vector{} : npc.GetControllerMovementInput(HANGER_CONTROL_DEADZONE);
|
|
npc_anim_restart(npc.sprite, face_animation_get(npc, "AttackHead"));
|
|
npc.sprite.isFlipX = (npc.controllerID == -1 ? aim.x : npc.controllerMovement.x) > 0;
|
|
npc.state = NPC_STATE_ATTACK;
|
|
npc.projectileCooldown = (int)((Random() & 1) + HANGER_COOLDOWN_MIN) * HANGER_COOLDOWN_UNIT;
|
|
}
|
|
|
|
if (std::abs(npc.friction) <= HANGER_MIN_FRICTION) return;
|
|
float distance = vector_length(aim);
|
|
float push = std::abs(distance) <= HANGER_MIN_DISTANCE ? 0 : HANGER_ACCEL / distance;
|
|
npc_push(npc, vector_scale(aim, push));
|
|
}
|
|
|
|
// Spitting, it fires three shots at its target on the Shoot event, then hangs again once the animation ends.
|
|
static void hanger_spit(Entity_NPC& npc)
|
|
{
|
|
if (npc.controllerID == -1) npc.controllerMovement = {};
|
|
else
|
|
{
|
|
Vector input = npc.GetControllerMovementInput(HANGER_CONTROL_DEADZONE);
|
|
if (!vector_is_zero(input)) npc.controllerMovement = input;
|
|
}
|
|
|
|
if (npc.sprite.animState.animData)
|
|
{
|
|
if (npc.sprite.animState.IsEventTriggered("Shoot"))
|
|
{
|
|
npc_sound_play(SOUND_BLOODSHOOT, 1, 2, champion_pitch_get(npc));
|
|
ProjectileParams params;
|
|
params.heightModifier += HANGER_SHOT_HEIGHT;
|
|
params.fallingSpeedModifier += HANGER_SHOT_FALL;
|
|
Vector aim = hanger_aim_get(npc, npc.GetPlayerTarget()->pos);
|
|
Vector velocity = vector_scale(vector_normalized(aim), HANGER_SHOT_SPEED);
|
|
npc.FireProjectiles(npc.pos, velocity, PROJECTILES_THREE, params);
|
|
}
|
|
if (!npc_anim_is_done(npc)) return;
|
|
}
|
|
npc_anim_restart(npc.sprite, face_animation_get(npc, "Head"));
|
|
npc.state = NPC_STATE_MOVE;
|
|
}
|
|
|
|
// 0051cb30 NpcAI::ENTITY_HANGER: the Keeper, a hanging head with an eternal fly that drifts after its target, kept
|
|
// near the top wall, and spits three shots at it when in range.
|
|
void npc_hanger_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.state == NPC_STATE_INIT)
|
|
{
|
|
npc.state = NPC_STATE_MOVE;
|
|
Entity* fly = g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_ETERNALFLY, .seed = Random()});
|
|
fly->parent = &npc;
|
|
npc.splatColor = HANGER_SPLAT_COLOR;
|
|
RNG faces = {npc.initSeed, 5, 9, 7};
|
|
npc.i1 = (int)faces.RandomInt(HANGER_FACES);
|
|
npc_anim_loop(npc.sprite, face_animation_get(npc, "Head"));
|
|
}
|
|
|
|
npc.pos = g_game->room->GetClampedPositionImpl(npc.pos, HANGER_WALL_MARGIN, 0, HANGER_TOP_MARGIN, 0);
|
|
if (Random() % HANGER_DRIP_ODDS == 0) npc.MakeSplat(random_unit() * HANGER_DRIP_SIZE + HANGER_DRIP_MIN);
|
|
if (npc.state != NPC_STATE_ATTACK) hanger_drift(npc);
|
|
else hanger_spit(npc);
|
|
npc.friction *= HANGER_FRICTION;
|
|
}
|