23 , _networkSync(networkSync)
39 const Vec2f &spawnPos)
43 log::error(
"Failed to spawn player entity: {}",
44 entityRes.error().message());
45 throw std::runtime_error(
46 std::string(
"Failed to spawn player entity: ") +
47 std::string(entityRes.error().message()));
54 {spawnPos.
x, spawnPos.
y},
66 auto weaponKind = player->getWeaponKind();
67 weapon.
kind = weaponKind;
71 weapon.kind = weaponKind;
73 log::warning(
"Weapon configurations not found, using default weapon settings for kind {}",
static_cast<int>(weaponKind));
79 if (weapon.maxAmmo >= 0) {
80 ammoComp.
max =
static_cast<uint16_t
>(weapon.maxAmmo);
81 ammoComp.current =
static_cast<uint16_t
>(weapon.ammo > 0 ? weapon.ammo : weapon.maxAmmo);
88 ammoComp.reloadCooldown = weapon.beamCooldown;
90 ammoComp.reloadCooldown = 2.0f;
92 ammoComp.reloadTimer = 0.0f;
93 ammoComp.isReloading =
false;
94 ammoComp.dirty =
true;
128 wcfg.
kind = weaponKind;
132 wcfg.
kind = weaponKind;
134 log::warning(
"Weapon configurations not found, using default weapon settings for kind {}",
static_cast<int>(weaponKind));
139 auto &weapons = weaponRes->get();
140 if (weapons.has(entity)) {
141 weapons[entity] = wcfg;
151 auto &ammos = ammoRes->get();
152 if (ammos.has(entity) && wcfg.
maxAmmo >= 0) {
153 ammos[entity].
max =
static_cast<uint16_t
>(wcfg.
maxAmmo);
154 ammos[entity].current =
static_cast<uint16_t
>(wcfg.
ammo > 0 ? wcfg.
ammo : ammos[entity].current);
157 if (ammos.has(entity)) {
164 log::info(
"Applied weapon {} to entity {}",
static_cast<int>(weaponKind), entity.
index());
168 uint32_t roomId,
const Vec2f &pos,
174 log::error(
"Failed to spawn enemy entity: {}",
175 entityRes.error().message());
176 throw std::runtime_error(
177 std::string(
"Failed to spawn enemy entity: ") +
178 std::string(entityRes.error().message()));
192 static_cast<uint32_t
>(entity.
index())});
221 pattern, speed, amplitude, frequency});
223 float fireRate = 0.6f;
241 float bboxWidth = 30.0f;
242 float bboxHeight = 18.0f;
270 float speed,
float amplitude,
278 uint32_t roomId,
const Vec2f &pos,
283 log::error(
"Failed to spawn powerup entity: {}",
284 entityRes.error().message());
285 throw std::runtime_error(
286 std::string(
"Failed to spawn powerup entity: ") +
287 std::string(entityRes.error().message()));
315 static_cast<uint32_t
>(entity.
index())});
324 uint32_t roomId,
const Vec2f &pos,
const Vec2f &size,
329 log::error(
"Failed to spawn obstacle entity: {}",
330 entityRes.error().message());
331 throw std::runtime_error(
332 std::string(
"Failed to spawn obstacle entity: ") +
333 std::string(entityRes.error().message()));
356 static_cast<uint32_t
>(entity.
index())});
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 get(this const Self &self) -> std::expected< std::reference_wrapper< ConstLike< Self, SparseArray< T > > >, rtp::Error >
void update(float dt) override
Update movement system logic for one frame.
ecs::Entity creaetEnemyEntity(uint32_t roomId, const Vec2f &pos, ecs::components::Patterns pattern, float speed, float amplitude, float frequency)
Create a new enemy entity in the ECS with default type Scout.
ecs::Entity createObstacleEntity(uint32_t roomId, const Vec2f &pos, const Vec2f &size, int health, net::EntityType type=net::EntityType::Obstacle)
Create a new obstacle entity in the ECS.
ecs::Entity createPlayerEntity(PlayerPtr player)
Create a new player entity in the ECS.
EntitySystem(ecs::Registry ®istry, ServerNetwork &network, NetworkSyncSystem &networkSync)
Constructor for EntitySystem.
void applyWeaponToEntity(ecs::Entity entity, ecs::components::WeaponKind weaponKind)
Apply a weapon configuration to an existing entity (player)
ecs::Entity createEnemyEntity(uint32_t roomId, const Vec2f &pos, ecs::components::Patterns pattern, float speed, float amplitude, float frequency, net::EntityType type=net::EntityType::Scout)
Create a new enemy entity in the ECS.
ecs::Entity createPowerupEntity(uint32_t roomId, const Vec2f &pos, ecs::components::PowerupType type, float value, float duration)
Create a new powerup entity in the ECS.
ecs::Registry & _registry
Reference to the entity registry.
System to handle network-related operations on the server side.
Implementation ASIO du serveur réseau (TCP + UDP)
const rtp::ecs::components::SimpleWeapon & getWeaponDef(rtp::ecs::components::WeaponKind kind)
WeaponKind
Types of player weapons.
@ Classic
Default spam/charge laser.
@ Beam
Continuous beam 5s active, 5s cooldown.
Patterns
Enum representing different enemy movement patterns.
PowerupType
Supported powerup types.
void error(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an error message.
void warning(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log a warning message.
void info(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an informational message.
EntityType
Types of entities in the game.
File : GameManager.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue....
std::shared_ptr< Player > PlayerPtr
Shared pointer type for Player.
Ammo tracking for weapons.
Component representing an entity's health.
Component representing a movement pattern.
Component representing movement speed with temporary boosts.
Component representing a network identifier for an entity.
Component representing a powerup pickup.
Component representing a network identifier for an entity.
Component representing a weapon configuration.
float beamCooldown
Beam cooldown time (Beam)
int maxAmmo
Max ammo (-1 = infinite)
bool isBoomerang
Projectile returns (Boomerang)
int ammo
Current ammo (-1 = infinite)
float fireRate
Shots per second (or cooldown)
int damage
Damage per shot.
float lastShotTime
Time since last shot.
WeaponKind kind
Weapon type.
Component representing a 2D velocity.