#include "game/buffs.hpp" #include "game/enemies.hpp" #include "game/player.hpp" namespace { // World objects use their own catch field; shard pickup radius (and its // Directive upgrades) must not make buff/debuff objects easier to collect. constexpr float kObjectCatchRadius = 2.8f; // > the 2.5 m lightswitch bait ring constexpr float kEnemyBuffRange = 2.2f; // nearest enemy takes an enemy-channel effect struct WorldObjSpec { BuffEffect effect; float duration; const char* name; }; // §4.6 catalog (Phase 2: enemy channel added): const WorldObjSpec kWorldCatalog[] = { // Player channel — apply to the player (caught in the open): {{0.65f}, 30.0f, "SLOW"}, // Slow: player −35% speed {{1.0f, 0.0f, 0.0f, 1.3f}, 25.0f, "VULNERABLE"}, // Vulnerable: enemies deal +30% to player {{1.0f, 1.6f, 0.0f, 1.0f}, 20.0f, "DOT"}, // Dot: nearby enemies deal 1.5–2.5 DPS {{1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 2.0f}, 12.0f, "TAKEN"}, // Taken: pulls, immune while near {{1.0f, 0.0f, 0.0f, 1.0f, 2.0f, 0.0f}, 10.0f, "CONFUSE"}, // Confuse: enemies drag the player // Enemy channel — apply to nearby enemies: {{0.6f}, 20.0f, "ENEMY_SLOW"}, // Slow: enemies −40% speed {{0.0f, 0.0f, 0.4f}, 25.0f, "ENEMY_BURN"}, // Dot: enemy burns 0.4 DPS {{0.0f, 0.0f, 0.0f, 1.3f}, 25.0f, "ENEMY_VULNERABLE"}, // Vulnerable: enemies +30% taken damage {{0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.3f}, 10.0f, "ENEMY_IMMUNE"}, // Immune: resonance immune }; } // namespace void BuffSystem::update(float dt) { for (std::size_t i = 0; i < buffs_.size();) { Buff& b = buffs_[i]; if (b.duration > 0.0f) { b.duration -= dt; if (b.duration <= 0.0f) { buffs_.remove_at(i); continue; } } ++i; } } void BuffSystem::update_world_objects(const Player& player, const EnemySystem& enemies) { for (int i = 0; i < world_object_count();) { WorldObject& obj = world_object(i); if (distance(obj.pos, player.pos) >= kObjectCatchRadius) { ++i; continue; } // An enemy-channel effect goes to the closest nearby enemy; otherwise // the object resolves on the player. Bait has no effect (ritual counter). if (!obj.effect.empty()) { const Enemy* near = nullptr; int near_idx = -1; float near_d = 0.0f; for (std::size_t j = 0; j < enemies.enemies.size(); ++j) { const float d = distance(obj.pos, enemies.enemies[j].pos); if (near == nullptr || d < near_d) { near = &enemies.enemies[j]; near_idx = static_cast(j); near_d = d; } } apply(near != nullptr && near_d < kEnemyBuffRange ? near_idx : -1, obj.effect, obj.duration, obj.name); } remove_world_object(i); } } void BuffSystem::apply(int subject, const BuffEffect& effect, float duration, const char* name) { if (static_cast(buffs_.size()) >= kBuffCap) return; Buff b; b.subject = subject; b.effect = effect; b.duration = duration; b.name = name != nullptr ? name : ""; buffs_.add(b); } void BuffSystem::expire_subject(int subject) { buffs_.remove_if([subject](const Buff& b) { return b.subject == subject; }); } void BuffSystem::spawn_world_object(Vec2 pos, Rng& rng, int kind) { if (static_cast(world_objects_.size()) >= kWorldCap) return; // Explicit object spawns are guaranteed: a ritual/side-room reward must // always pay out, and no object is attached to a crystal drop. const int n = static_cast(sizeof(kWorldCatalog) / sizeof(kWorldCatalog[0])); const int idx = (kind >= 0 && kind < n) ? kind : rng.range_int(0, n - 1); const WorldObjSpec& spec = kWorldCatalog[idx]; WorldObject obj; obj.pos = pos; obj.effect = spec.effect; obj.duration = spec.duration; obj.name = spec.name; world_objects_.add(obj); } bool BuffSystem::spawn_bait(Vec2 pos, const char* name) { if (static_cast(world_objects_.size()) >= kWorldCap) return false; WorldObject obj; obj.pos = pos; obj.effect = BuffEffect{}; // the bait itself is the quest item — zero effect obj.duration = 0.0f; obj.subject = -1; obj.name = name; world_objects_.add(obj); return true; } PlayerMods BuffSystem::player_mods() const { PlayerMods m; for (const Buff& b : buffs_) { if (b.subject != -1) continue; m.speed_mult *= b.effect.speed_mult; m.damage_taken_mult *= b.effect.damage_taken_mult; m.confused += b.effect.confused; m.taken += b.effect.taken; m.dot_dps += b.effect.dot_dps; } return m; } EnemyMods BuffSystem::enemy_mods(int enemy_id) const { EnemyMods m; for (const Buff& b : buffs_) { if (b.subject != enemy_id) continue; m.speed_mult *= b.effect.speed_mult; m.burn_dps += b.effect.burn_dps; m.immune += b.effect.immune; m.damage_taken_mult *= b.effect.damage_taken_mult; } return m; }