23 : _registry(registry), _roomSystem(roomSystem), _networkSync(networkSync)
33 uint32_t>> pendingSpawns;
41 for (
auto &&[tf, type, roomId, weapon] : view) {
50 if (weapon.fireRate <= 0.0f) {
55 const float fireInterval = (1.0f / weapon.fireRate);
57 if (weapon.lastShotTime >= fireInterval) {
58 weapon.lastShotTime = 0.0f;
62 uint32_t shooterIdx =
static_cast<uint32_t
>(tf.position.x * 1000 + tf.position.y);
63 pendingSpawns.emplace_back(tf, roomId, isBoomerang, shooterIdx);
67 for (
const auto& [tf, roomId, isBoomerang, shooterIdx] : pendingSpawns) {
80 uint32_t shooterIndex)
84 log::error(
"Failed to spawn enemy bullet entity: {}", entityRes.error().message());
99 float bulletSpeed = isBoomerang ? -200.0f :
_bulletSpeed;
106 float bboxW = isBoomerang ? 24.0f : 8.0f;
107 float bboxH = isBoomerang ? 24.0f : 4.0f;
114 int damage = isBoomerang ? 25 : 10;
152 const auto players = room->getPlayers();
153 std::vector<uint32_t> sessions;
154 sessions.reserve(players.size());
155 for (
const auto& player : players) {
156 sessions.push_back(player->getId());
161 static_cast<uint32_t
>(bullet.
index()),
162 static_cast<uint8_t
>(bulletType),
Logger declaration with support for multiple log levels.
Represents an entity in the ECS (Entity-Component-System) architecture.
constexpr std::uint32_t index(void) const
auto spawn(void) -> std::expected< Entity, rtp::Error >
auto add(Entity entity, Args &&...args) -> std::expected< std::reference_wrapper< T >, rtp::Error >
auto zipView(this Self &self)
Network packet with header and serializable body.
EnemyShootSystem(ecs::Registry ®istry, RoomSystem &roomSystem, NetworkSyncSystem &networkSync)
Constructor for EnemyShootSystem.
float _bulletSpeed
Speed of the spawned bullets.
ecs::Registry & _registry
Reference to the entity registry.
NetworkSyncSystem & _networkSync
Reference to the NetworkSyncSystem.
RoomSystem & _roomSystem
Reference to the RoomSystem.
void spawnBullet(const ecs::components::Transform &tf, const ecs::components::RoomId &roomId, bool isBoomerang=false, uint32_t shooterIndex=0)
Spawn a bullet entity at the given transform and room.
float _spawnOffsetX
X offset for bullet spawn position.
void update(float dt) override
Update enemy shooting system logic for one frame.
System to handle network-related operations on the server side.
void sendPacketToSessions(const std::vector< uint32_t > &sessions, const net::Packet &packet, net::NetworkMode mode)
Send a packet to multiple sessions.
System to handle room-related operations on the server side.
std::shared_ptr< Room > getRoom(uint32_t roomId)
Get a room by its ID.
@ InGame
Game in progress.
constexpr Entity NullEntity
void error(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an error message.
EntityType
Types of entities in the game.
@ EntitySpawn
Entity spawn notification.
File : GameManager.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue....
Marks a projectile as a boomerang and stores state for return logic.
bool returning
Whether the boomerang is on its way back.
uint32_t ownerIndex
ECS entity index of the owner who fired this boomerang.
rtp::Vec2f startPos
Spawn position to compute travel distance.
float maxDistance
Distance before returning.
Component representing damage value.
Component representing a network identifier for an entity.
Component representing a network identifier for an entity.
uint32_t id
Unique network identifier for the entity.
Component representing a weapon configuration.
float lastShotTime
Time since last shot.
Component representing a 2D velocity.
Entity spawn notification data.