41 lines
1.4 KiB
C++
41 lines
1.4 KiB
C++
#include "game/entities/concrete/floor_trap.hpp"
|
|
|
|
#include <string>
|
|
|
|
#include "game/entities/entity_factory.hpp"
|
|
#include "game/entities/event_bus.hpp"
|
|
#include "game/entities/player.hpp"
|
|
|
|
FloorTrap::FloorTrap(const fkyaml::node& yaml) {
|
|
name_ = yaml.contains("name") ? yaml["name"].get_value<std::string>() : std::string("floor_trap");
|
|
collides_ = false;
|
|
interactable_ = false;
|
|
// Trigger d'àrea: la trampa no bloqueja el pas però vol rebre
|
|
// `onPlayerContact` quan el jugador la solapa. Tanca el gap latent
|
|
// que la deixava muda (`checkPlayerCollisions` filtrava pel `collides`).
|
|
triggers_on_overlap_ = true;
|
|
|
|
if (yaml.contains("cycle")) {
|
|
const auto& c = yaml["cycle"];
|
|
const float ACTIVE = c.contains("active_duration") ? c["active_duration"].get_value<float>() : 0.3F;
|
|
const float INACTIVE = c.contains("inactive_duration") ? c["inactive_duration"].get_value<float>() : 2.0F;
|
|
setCycle(ACTIVE, INACTIVE);
|
|
}
|
|
if (yaml.contains("stats") && yaml["stats"].contains("damage")) {
|
|
setDamage(yaml["stats"]["damage"].get_value<int>());
|
|
}
|
|
}
|
|
|
|
void FloorTrap::onPlayerContact(Player* player) {
|
|
if (!isActive()) { return; }
|
|
if (bus_ != nullptr) {
|
|
bus_->publish(Event{
|
|
.name = "player_hit",
|
|
.payload = getDamage(),
|
|
.player_id = (player != nullptr) ? player->getId() : -1,
|
|
});
|
|
}
|
|
}
|
|
|
|
REGISTER_ENTITY("floor_trap", FloorTrap)
|