Walk into the Projector Room screen to enter a black room with 20 ringing red-phone tables. Sweep all phones, then step into the yellow-roofed glass case to restore the lights and claim the FLUORESCENT Light Switch skill. - Blender: phone_table, case_frame and case_glass GLBs + reproducible build_blackout_props.py, concept lineup and source .blend - Sim: BlackoutSequence state machine, Game ownership, spawn freeze during the pocket, FLUORESCENT active skill with unlock flag and buff effect - Render: uAlpha glass blending, three ActorModels, blackout camera/pass, event VFX, HUD progress card and third skill stamp - Dev flags: --blackout-test, --blackout-auto, --blackout-reveal - Tests: headless blackout chain/claim test (8/8 CTest pass) - Docs: BLACKOUT_RITUAL.md plus design/roadmap/art/README updates
267 lines
9.6 KiB
C++
267 lines
9.6 KiB
C++
#include "game/skills.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <cstddef>
|
|
|
|
#include "core/events.hpp"
|
|
#include "core/spatial_hash.hpp"
|
|
#include "game/buffs.hpp"
|
|
#include "game/enemies.hpp"
|
|
#include "game/player.hpp"
|
|
|
|
namespace {
|
|
|
|
constexpr float kConcreteCooldown = 6.0f;
|
|
constexpr float kWarpCooldown = 9.0f;
|
|
constexpr float kWarpDuration = 0.75f;
|
|
constexpr float kWarpRadius = 4.5f;
|
|
constexpr float kWarpDamage = 75.0f;
|
|
constexpr float kWarpPull = 7.0f;
|
|
constexpr float kGatherTime = 0.38f;
|
|
constexpr float kFlightSpeed = 17.0f;
|
|
constexpr float kBlastRadius = 3.4f;
|
|
constexpr float kBlastDamage = 95.0f;
|
|
constexpr float kCastRange = 18.0f;
|
|
constexpr float kManualHold = 5.0f;
|
|
constexpr float kCrowdRadius = 2.6f;
|
|
constexpr float kFluorescentCooldown = 14.0f;
|
|
constexpr float kLightRadius = 6.0f;
|
|
constexpr float kLightDuration = 10.0f;
|
|
constexpr float kLightDamageMult = 1.25f;
|
|
|
|
// Picks the densest nearby crowd and returns its centroid; a lone enemy is a
|
|
// valid target. Returns false when there is nothing in casting range.
|
|
bool pick_crowd(const EnemySystem& enemies, Vec2 from, Vec2& center) {
|
|
SpatialHash hash(kCrowdRadius);
|
|
for (std::size_t i = 0; i < enemies.enemies.size(); ++i)
|
|
hash.insert(static_cast<int>(i), enemies.enemies[i].pos);
|
|
hash.build();
|
|
|
|
const std::size_t stride = enemies.enemies.size() > 200
|
|
? enemies.enemies.size() / 100 : 1;
|
|
int best_count = -1;
|
|
float best_dist = 0.0f;
|
|
Vec2 best_center{};
|
|
for (std::size_t i = 0; i < enemies.enemies.size(); i += stride) {
|
|
const Vec2 here = enemies.enemies[i].pos;
|
|
const float dist = distance(here, from);
|
|
if (dist > kCastRange) continue;
|
|
|
|
int count = 0;
|
|
Vec2 sum{};
|
|
hash.query(here, kCrowdRadius, [&](int id) {
|
|
const Vec2 other = enemies.enemies[static_cast<std::size_t>(id)].pos;
|
|
if (distance(here, other) <= kCrowdRadius) {
|
|
++count;
|
|
sum += other;
|
|
}
|
|
});
|
|
// Density wins; ties go to the closest crowd so the pile doesn't fly
|
|
// across the whole floor for an equally sized group.
|
|
if (count > best_count || (count == best_count && dist < best_dist)) {
|
|
best_count = count;
|
|
best_dist = dist;
|
|
best_center = sum * (1.0f / static_cast<float>(count));
|
|
}
|
|
}
|
|
if (best_count < 0) return false;
|
|
center = best_center;
|
|
return true;
|
|
}
|
|
|
|
void try_cast(SkillSystem& skills, Player& player, EnemySystem& enemies,
|
|
EventQueue& events) {
|
|
const int index = static_cast<int>(SkillType::ConcreteCall);
|
|
if (skills.cooldowns[index] > 0.0f || !player.alive()) return;
|
|
|
|
Vec2 center{};
|
|
if (!pick_crowd(enemies, player.pos, center)) return; // keep the cast ready
|
|
|
|
ConcretePile pile;
|
|
pile.pos = player.pos;
|
|
pile.target = center;
|
|
pile.phase = PilePhase::Gather;
|
|
pile.phase_duration = kGatherTime;
|
|
pile.damage = kBlastDamage * player.stats.damage_mult;
|
|
pile.blast_radius = kBlastRadius;
|
|
skills.piles.add(pile);
|
|
skills.cooldowns[index] = kConcreteCooldown;
|
|
// The event carries the landing zone and blast radius for a brief ground
|
|
// telegraph; the presenter knows the player position for the gather dust.
|
|
events.push(EventType::SkillCast, center, pile.blast_radius);
|
|
}
|
|
|
|
void try_cast_warp(SkillSystem& skills, Player& player, EnemySystem& enemies,
|
|
EventQueue& events) {
|
|
const int index = static_cast<int>(SkillType::Warp);
|
|
if (skills.cooldowns[index] > 0.0f || !player.alive()) return;
|
|
|
|
Vec2 center{};
|
|
if (!pick_crowd(enemies, player.pos, center)) return;
|
|
|
|
WarpField field;
|
|
field.pos = center;
|
|
field.duration = kWarpDuration;
|
|
field.radius = kWarpRadius;
|
|
field.damage = kWarpDamage * player.stats.damage_mult;
|
|
skills.warps.add(field);
|
|
skills.cooldowns[index] = kWarpCooldown;
|
|
events.push(EventType::SkillCast, center, field.radius,
|
|
static_cast<unsigned>(index));
|
|
}
|
|
|
|
// The projector-screen ritual reward: flood the room with fluorescent light.
|
|
void try_cast_fluorescent(SkillSystem& skills, Player& player, EnemySystem& enemies,
|
|
BuffSystem& buffs, EventQueue& events) {
|
|
const int index = static_cast<int>(SkillType::Fluorescent);
|
|
if (!skills.fluorescent_unlocked || skills.cooldowns[index] > 0.0f ||
|
|
!player.alive()) {
|
|
return;
|
|
}
|
|
BuffEffect effect;
|
|
effect.damage_taken_mult = kLightDamageMult;
|
|
for (std::size_t i = 0; i < enemies.enemies.size(); ++i) {
|
|
if (distance(player.pos, enemies.enemies[i].pos) > kLightRadius) continue;
|
|
buffs.apply(static_cast<int>(i), effect, kLightDuration, "FLUORESCENT LIGHT");
|
|
enemies.enemies[i].hit_flash = 0.15f;
|
|
}
|
|
skills.cooldowns[index] = kFluorescentCooldown;
|
|
events.push(EventType::SkillCast, player.pos, kLightRadius,
|
|
static_cast<unsigned>(index));
|
|
}
|
|
|
|
void detonate(const ConcretePile& pile, EnemySystem& enemies, EventQueue& events) {
|
|
for (Enemy& e : enemies.enemies) {
|
|
if (distance(pile.pos, e.pos) >= pile.blast_radius + e.radius) continue;
|
|
e.hp -= pile.damage * e.mods.damage_taken_mult;
|
|
e.hit_flash = 0.15f;
|
|
events.push(EventType::EnemyHit, e.pos, pile.damage);
|
|
}
|
|
events.push(EventType::AreaDetonation, pile.pos, pile.blast_radius,
|
|
kDetonateConcrete);
|
|
}
|
|
|
|
void warp_burst(const WarpField& field, EnemySystem& enemies, EventQueue& events) {
|
|
for (Enemy& e : enemies.enemies) {
|
|
if (distance(field.pos, e.pos) >= field.radius + e.radius) continue;
|
|
e.hp -= field.damage * e.mods.damage_taken_mult;
|
|
e.hit_flash = 0.15f;
|
|
events.push(EventType::EnemyHit, e.pos, field.damage);
|
|
}
|
|
events.push(EventType::WarpBurst, field.pos, field.radius);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
const char* skill_name(SkillType type) {
|
|
switch (type) {
|
|
case SkillType::ConcreteCall: return "CONCRETE CALL";
|
|
case SkillType::Warp: return "WARP";
|
|
case SkillType::Fluorescent: return "FLUORESCENT";
|
|
default: return "UNKNOWN";
|
|
}
|
|
}
|
|
|
|
float skill_cooldown(SkillType type) {
|
|
switch (type) {
|
|
case SkillType::ConcreteCall: return kConcreteCooldown;
|
|
case SkillType::Warp: return kWarpCooldown;
|
|
case SkillType::Fluorescent: return kFluorescentCooldown;
|
|
default: return 1.0f;
|
|
}
|
|
}
|
|
|
|
void SkillSystem::reset() {
|
|
for (float& cd : cooldowns) cd = 0.0f;
|
|
manual_hold = 0.0f;
|
|
autoplay_enabled = true;
|
|
piles.clear();
|
|
warps.clear();
|
|
}
|
|
|
|
void SkillSystem::reset_all() {
|
|
reset();
|
|
fluorescent_unlocked = false;
|
|
}
|
|
|
|
void SkillSystem::update(float dt, const InputState& in, Player& player,
|
|
EnemySystem& enemies, BuffSystem& buffs,
|
|
EventQueue& events) {
|
|
if (in.toggle_autoplay) autoplay_enabled = !autoplay_enabled;
|
|
manual_hold = std::max(0.0f, manual_hold - dt);
|
|
for (float& cd : cooldowns) cd = std::max(0.0f, cd - dt);
|
|
|
|
if (in.skill_concrete || in.skill_warp || in.skill_fluorescent) {
|
|
// A manual press takes control; autoplay stays off for a short window
|
|
// even if the skill is still cooling down.
|
|
manual_hold = kManualHold;
|
|
}
|
|
if (in.skill_concrete) try_cast(*this, player, enemies, events);
|
|
if (in.skill_warp) try_cast_warp(*this, player, enemies, events);
|
|
if (in.skill_fluorescent) try_cast_fluorescent(*this, player, enemies, buffs, events);
|
|
if (autoplay_active()) {
|
|
// Generic autoplay: every skill is cast from this same path when the
|
|
// player isn't driving them by hand.
|
|
try_cast(*this, player, enemies, events);
|
|
try_cast_warp(*this, player, enemies, events);
|
|
try_cast_fluorescent(*this, player, enemies, buffs, events);
|
|
}
|
|
|
|
for (std::size_t i = 0; i < piles.size();) {
|
|
ConcretePile& pile = piles[i];
|
|
pile.phase_time += dt;
|
|
if (pile.phase == PilePhase::Gather) {
|
|
pile.pos = player.pos; // the heap forms around the agent
|
|
pile.size = std::min(1.0f, pile.phase_time / pile.phase_duration);
|
|
if (pile.phase_time >= pile.phase_duration) {
|
|
pile.phase = PilePhase::Flight;
|
|
pile.phase_time = 0.0f;
|
|
pile.phase_duration = std::max(
|
|
0.05f, distance(pile.pos, pile.target) / kFlightSpeed);
|
|
}
|
|
++i;
|
|
continue;
|
|
}
|
|
|
|
const Vec2 delta = pile.target - pile.pos;
|
|
const float dist = length(delta);
|
|
const float step = kFlightSpeed * dt;
|
|
if (dist <= step + 0.25f) {
|
|
pile.pos = pile.target;
|
|
detonate(pile, enemies, events);
|
|
piles.remove_at(i);
|
|
continue;
|
|
}
|
|
pile.pos += normalized(delta) * step;
|
|
++i;
|
|
}
|
|
|
|
// WARP: drag the whole crowd inward, then burst it.
|
|
for (std::size_t i = 0; i < warps.size();) {
|
|
WarpField& field = warps[i];
|
|
field.timer += dt;
|
|
for (Enemy& e : enemies.enemies) {
|
|
const Vec2 delta = field.pos - e.pos;
|
|
const float dist = length(delta);
|
|
if (dist > field.radius || dist < 0.25f) continue;
|
|
const float pull = std::min(kWarpPull, dist * 3.0f) * dt;
|
|
e.pos += normalized(delta) * pull;
|
|
}
|
|
if (field.timer >= field.duration) {
|
|
warp_burst(field, enemies, events);
|
|
warps.remove_at(i);
|
|
continue;
|
|
}
|
|
++i;
|
|
}
|
|
}
|
|
|
|
float SkillSystem::readiness(SkillType type) const {
|
|
return std::clamp(1.0f - cooldown_left(type) / skill_cooldown(type),
|
|
0.0f, 1.0f);
|
|
}
|
|
|
|
float SkillSystem::cooldown_left(SkillType type) const {
|
|
return cooldowns[static_cast<int>(type)];
|
|
}
|