cntrl/src/game/buffs.cpp

107 lines
3.7 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"
namespace {
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::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, float corruption_c, int kind) {
if (static_cast<int>(world_objects_.size()) >= kWorldCap) return;
// Rate scales with corruption: the House fills with junk mid-run.
if (!(rng.next_float() < 0.8f + 1.5f * corruption_c)) return;
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;
}