#include "boss_ai.h" #include "npc_caves.h" #include "sfx_manager.h" // Gurdy Jr.'s subtypes: the twins, and the blue one that neither sprays nor summons. constexpr int GURDY_JR_TWINS = 1; constexpr int GURDY_JR_BLUE = 2; constexpr float GURDY_JR_TWIN_OFFSET = 24; // Gurdy Jr.'s attacks, by state: a rest, the slide, the spray and the summon. constexpr int GURDY_JR_REST = NPC_STATE_JUMP; constexpr int GURDY_JR_SLIDE = NPC_STATE_ATTACK; constexpr int GURDY_JR_SPRAY = NPC_STATE_ATTACK2; constexpr int GURDY_JR_SUMMON = NPC_STATE_ATTACK3; // The slide's phases (i2): pushed while it winds up, sliding, and stopping. enum GurdyJrSlide { GURDY_JR_SLIDE_PUSH, GURDY_JR_SLIDE_GLIDE, GURDY_JR_SLIDE_END }; // What a controlling player asks of it from the idle pose. enum GurdyJrOrder { GURDY_JR_ORDER_NONE = -1, GURDY_JR_ORDER_SLIDE, GURDY_JR_ORDER_SPRAY, GURDY_JR_ORDER_SUMMON }; constexpr uint64_t GURDY_JR_DISTRACTED = FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK; constexpr float GURDY_JR_FRICTION = 0.8f; constexpr float GURDY_JR_SLIDE_FRICTION = 0.97f; constexpr float GURDY_JR_SLIDE_START_FRICTION = 0.7f; constexpr float GURDY_JR_SLIDE_TICKS = 5; constexpr float GURDY_JR_STEER = 0.2f; constexpr float GURDY_JR_SUMMON_STEER = 0.1f; constexpr float GURDY_JR_AIM_REACH_SQUARED = 10; constexpr int GURDY_JR_CALM_TURNS = 3; constexpr float GURDY_JR_SLIDE_HEALTH = 100; constexpr float GURDY_JR_DELIRIUM_SLIDE_HEALTH = 8; constexpr int GURDY_JR_SUMMON_ENEMY_LIMIT = 6; constexpr int GURDY_JR_REST_FRAMES = 35; constexpr float GURDY_JR_SLIDE_SPEED = 4; constexpr float GURDY_JR_TWIN_SLIDE = 0.7f; constexpr float GURDY_JR_SLIDE_STOP_SQUARED = 4; constexpr int GURDY_JR_SLIDE_FRAMES = 9; constexpr float GURDY_JR_SPLAT_SIZE = 2; constexpr float GURDY_JR_SPLAT_MIN = 0.4f; constexpr float GURDY_JR_SPRAY_SPEED = 10; constexpr float GURDY_JR_HARD_SPRAY_SPEED = 12; constexpr int GURDY_JR_POOF_FRONT = 3; constexpr int GURDY_JR_POOF_SIDE = 4; constexpr float GURDY_JR_POOF_SIDE_OFFSET = 50; constexpr float GURDY_JR_POOF_SIDE_SCALE = 0.5f; constexpr int GURDY_JR_POOTER_LIMIT = 3; constexpr float GURDY_JR_MOUTH_X = 30; constexpr float GURDY_JR_MOUTH_Y = 35; constexpr float GURDY_JR_POOTER_LIFT = -5; constexpr float GURDY_JR_SUMMON_POOF_Y = 60; constexpr float GURDY_JR_SUMMON_POOF_DEPTH = 4; constexpr int GURDY_JR_DEATH_FRAMES = 2; constexpr float GURDY_JR_DEATH_VOLUME = 1.2f; // A poof of dust around it as it sprays, offset and shrunk for the side ones. static Entity* gurdy_jr_poof_spawn(Entity_NPC& npc, int subType) { return g_game->Spawn({.position = npc.pos, .spawner = &npc, .subType = subType, .type = ENTITY_EFFECT, .variant = EFFECT_POOF02, .seed = Random()}); } // The idle pose picks the next attack: while calm (three idle turns, health above 100, 8 for a Delirium form) a rest, // a spray or a summon at random, else the slide. A controlled one does what its player asks. static void gurdy_jr_idle(Entity_NPC& npc) { npc.sprite.Play("Idle"); int order = GURDY_JR_ORDER_NONE; if (npc.controllerID != -1) { if (!npc.HasEntityFlags(GURDY_JR_DISTRACTED)) npc.SpawnControlTarget(0, -1); if (npc.is_controller_input_idle() && vector_length_squared(vector_sub(npc.pos, npc.GetAimTargetPosition())) > GURDY_JR_AIM_REACH_SQUARED) order = GURDY_JR_ORDER_SLIDE; else if (npc.IsControllerActionPressed(CONTROLLER_ACTION_SHOOT) && npc.subtype != GURDY_JR_TWINS && npc.subtype != GURDY_JR_BLUE) order = GURDY_JR_ORDER_SPRAY; else if (npc.IsControllerActionPressed(CONTROLLER_ACTION_GROAN) && npc.subtype != GURDY_JR_TWINS) order = GURDY_JR_ORDER_SUMMON; } if ((npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) || (npc.controllerID != -1 && order == GURDY_JR_ORDER_NONE)) return; int turns = ++npc.projectileCooldown; float slideHealth = npc.HasEntityFlags(FLAG_DELIRIUM_FORM) ? GURDY_JR_DELIRIUM_SLIDE_HEALTH : GURDY_JR_SLIDE_HEALTH; if (npc.controllerID == -1 && turns < GURDY_JR_CALM_TURNS && npc.health >= slideHealth) { npc.stateFrame = 0; if (npc.subtype == GURDY_JR_TWINS) { npc.state = NPC_STATE_IDLE; return; } std::vector attacks = {GURDY_JR_REST}; if (npc.subtype != GURDY_JR_BLUE) attacks.push_back(GURDY_JR_SPRAY); if (npc.GetAliveEnemyCount() < GURDY_JR_SUMMON_ENEMY_LIMIT) attacks.push_back(GURDY_JR_SUMMON); npc.state = attacks[random_below((int)attacks.size())]; npc.stateFrame = 0; return; } if (npc.controllerID != -1 && order != GURDY_JR_ORDER_SLIDE) { if (order == GURDY_JR_ORDER_SPRAY) npc.state = GURDY_JR_SPRAY; else if (order == GURDY_JR_ORDER_SUMMON) npc.state = GURDY_JR_SUMMON; npc.stateFrame = 0; return npc.ClearChild(); } if (npc.HasEntityFlags(GURDY_JR_DISTRACTED)) return; npc.state = GURDY_JR_SLIDE; npc.i2 = GURDY_JR_SLIDE_PUSH; npc.projectileCooldown = 0; Vector away = vector_sub(npc.pos, npc.GetPlayerTarget()->pos); if (npc.controllerID != -1) away = vector_sub(npc.pos, npc.GetAimTargetPosition()); float speed = GURDY_JR_SLIDE_SPEED / vector_length(away); npc.friction *= GURDY_JR_SLIDE_START_FRICTION; npc.sprite.Play("Attack03Start"); if (npc.subtype == GURDY_JR_TWINS) speed *= GURDY_JR_TWIN_SLIDE; npc.PlaySound(SOUND_MONSTER_ROAR_1, 1, 2, false, 1); npc.targetPosition = vector_scale(away, -speed); npc.i1 = 0; npc.ClearChild(); } // The slide at its target: pushed while it winds up, then sliding until it slows or ten turns pass, splatting blood // every five frames. static void gurdy_jr_slide(Entity_NPC& npc) { if (npc_anim_is_done(npc) || npc.HasEntityFlags(GURDY_JR_DISTRACTED)) { if (npc.i2 == GURDY_JR_SLIDE_PUSH) npc.i2 = GURDY_JR_SLIDE_GLIDE; else if (npc.i2 == GURDY_JR_SLIDE_END) npc.state = NPC_STATE_IDLE; else if (vector_length_squared(npc.velocity) <= GURDY_JR_SLIDE_STOP_SQUARED || npc.i1++ > GURDY_JR_SLIDE_FRAMES) { npc.i2 = GURDY_JR_SLIDE_END; npc.sprite.Play("Attack03End"); } else npc_anim_restart(npc.sprite, "Slide"); } else if (npc.i2 == GURDY_JR_SLIDE_PUSH) { npc.friction *= GURDY_JR_FRICTION; npc_push(npc, npc.targetPosition); } if (!npc.GetIntervalTicks(GURDY_JR_SLIDE_TICKS, 0)) return; float size = random_unit(); Random(); Random(); npc.MakeSplat(size * GURDY_JR_SPLAT_SIZE + GURDY_JR_SPLAT_MIN); } // The spray: a roar, then eight shots around it with a poof of dust in front and to each side. Steerable only between // the roar and the shots. static float gurdy_jr_spray(Entity_NPC& npc) { float steer = npc.sprite.WasEventTriggered("Sound") && !npc.sprite.WasEventTriggered("Shoot") ? 1 : 0; npc.sprite.Play("Attack02"); if (npc.sprite.IsEventTriggered("Sound")) npc.PlaySound(SOUND_BOSS_LITE_ROAR, 1, 2, false, 1); else if (npc.sprite.IsEventTriggered("Shoot")) { npc.PlaySound(SOUND_FORESTBOSS_STOMPS, 1, 2, false, 1); npc.PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); float speed = game_is_hard_mode() ? GURDY_JR_HARD_SPRAY_SPEED : GURDY_JR_SPRAY_SPEED; npc.FireProjectiles(npc.pos, vector_make(speed, 0), PROJECTILES_EIGHT, ProjectileParams()); Entity* front = gurdy_jr_poof_spawn(npc, GURDY_JR_POOF_FRONT); front->sprite.isFlipX = (Random() & 1) == 0; front->Update(); for (float side : {GURDY_JR_POOF_SIDE_OFFSET, -GURDY_JR_POOF_SIDE_OFFSET}) { Entity* poof = gurdy_jr_poof_spawn(npc, GURDY_JR_POOF_SIDE); poof->posOffset = vector_make(side, 0); if (side > 0) poof->sprite.isFlipX = true; poof->sprite.scale = vector_make(GURDY_JR_POOF_SIDE_SCALE, GURDY_JR_POOF_SIDE_SCALE); poof->Update(); } } if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; return steer; } // The summon: a Pooter (a Super Pooter for the blue one) coughed up from its mouth, at most three for a Delirium form. static void gurdy_jr_summon(Entity_NPC& npc) { npc.sprite.Play("Attack01"); if (npc.sprite.IsEventTriggered("Shoot")) { int variant = npc.subtype == GURDY_JR_BLUE ? 1 : 0; if (!npc.HasEntityFlags(FLAG_DELIRIUM_FORM) || npc.CountRelatedEntities(ENTITY_POOTER, variant, nullptr) < GURDY_JR_POOTER_LIMIT) { npc.PlaySound(SOUND_SUMMONSOUND, 1.1f, 2, false, 1); Vector scale = npc.sprite.scale; Vector mouth = vector_make(npc.pos.x - scale.x * GURDY_JR_MOUTH_X, npc.pos.y - scale.y * GURDY_JR_MOUTH_Y); Entity* pooter = g_game->Spawn({.position = mouth, .velocity = vector_make(0, GURDY_JR_POOTER_LIFT), .spawner = &npc, .type = ENTITY_POOTER, .variant = variant, .seed = Random()}); pooter->ClearEntityFlags(FLAG_APPEAR); scale = npc.sprite.scale; Entity* poof = g_game->Spawn({.position = npc.pos, .subType = 1, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); poof->SetColor(COLOR_DEFAULT, -1, COLOR_PRIORITY_DEFAULT, false, true); poof->renderDepthOffset = GURDY_JR_SUMMON_POOF_DEPTH; poof->posOffset = vector_make(scale.x * -GURDY_JR_MOUTH_X, scale.y * -GURDY_JR_SUMMON_POOF_Y); poof->Update(); } } if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; } // 0051d300 NpcAI::ENTITY_GURDY_JR: Gurdy Jr. rests, slides at its target splatting blood, sprays eight shots or // coughs up Pooters. Twins (subtype 1) bring a brother and only slide. void boss_gurdy_jr_update(Entity_NPC& npc) { if (npc.state == NPC_STATE_INIT) { npc.state = NPC_STATE_IDLE; npc.stateFrame = 0; if (npc.subtype != GURDY_JR_TWINS || npc.spawnerType == npc.type) return; g_game->Spawn({.position = vector_make(npc.pos.x + GURDY_JR_TWIN_OFFSET, npc.pos.y), .velocity = npc.velocity, .spawner = &npc, .subType = npc.subtype, .type = npc.type, .variant = npc.variant, .seed = Random()}); npc.pos.x -= GURDY_JR_TWIN_OFFSET; return; } if (npc.isDead) npc_sound_play(SOUND_MONSTER_ROAR_2, GURDY_JR_DEATH_VOLUME, GURDY_JR_DEATH_FRAMES, champion_pitch_get(npc)); if (npc.state != GURDY_JR_SLIDE) npc.friction *= GURDY_JR_FRICTION; else if (npc.GetIntervalTicks(GURDY_JR_SLIDE_TICKS, 0)) npc.friction *= GURDY_JR_SLIDE_FRICTION; float steer = GURDY_JR_STEER; switch (npc.state) { case NPC_STATE_IDLE: gurdy_jr_idle(npc); break; case GURDY_JR_REST: npc.sprite.Play("Idle"); npc.stateFrame += npc_ticks_get(npc); if (npc.stateFrame > GURDY_JR_REST_FRAMES) npc.state = NPC_STATE_IDLE; break; case GURDY_JR_SLIDE: gurdy_jr_slide(npc); steer = 0; break; case GURDY_JR_SPRAY: steer = gurdy_jr_spray(npc); break; case GURDY_JR_SUMMON: gurdy_jr_summon(npc); steer = GURDY_JR_SUMMON_STEER; break; } if (npc.controllerID == -1 || steer <= 0) return; npc.velocity = vector_add(npc.velocity, vector_scale(npc.GetControllerInput(0), steer * npc.speedMultiplier)); }