cntrl/src/game/buffs.cpp
dandovlatov 89d2bb8806 FBC: NIGHT SHIFT - pacing pass and cyan crystal / buff decoupling
Pacing:
- Spin cooldown 0.55 -> 0.95 s (-3%/level instead of -8%); damage ramp +28%/level
- Weaken fire-rate offers (Rapid Cycling +8%, Board Favor +4%, Maintenance +5%)
- Stretch XP curve to 10+6*level and offer cadence to 3 s (5 s idle)
- Calm early director income and spawn interval; docs updated

Crystal/buff decoupling:
- Kills drop XP shards only; remove per-kill random buff world object
- PickupSystem owns shards alone; BuffSystem catches world objects with its
  own 2.8 m radius, independent of shard pickup magnet/upgrades
- Explicit guaranteed world-object spawns for rituals and side rooms;
  effect-less bait consumed without a buff
- ShardCollected only emitted for actual shard/XP rewards
- Update design docs, RPG_LITE and README
2026-11-24 21:55:59 +04:00

144 lines
5.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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<int>(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<int>(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<int>(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<int>(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<int>(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;
}