|
R-Type
Distributed multiplayer game engine in C++
|
System managing weapon firing and cooldowns. More...
#include <WeaponSystem.hpp>


Public Types | |
| using | ProjectileCreatedCallback = std::function< void(uint32_t, uint32_t, float, float, float, float, float, int, bool)> |
| Callback for projectile creation events Parameters: projectileId, ownerId, posX, posY, dirX, dirY, speed, damage, friendly. | |
Public Member Functions | |
| WeaponSystem ()=default | |
| Default constructor. | |
| WeaponSystem (ProjectileCreatedCallback callback) | |
| Constructor with callback for projectile creation events. | |
| ~WeaponSystem () override=default | |
| Default destructor. | |
| void | setProjectileCreatedCallback (ProjectileCreatedCallback callback) |
| Set the callback for projectile creation events. | |
| void | update (Registry ®istry, float deltaTime) override |
| Manages weapon cooldowns for all entities. | |
| std::uint32_t | fireWeapon (Registry ®istry, std::uint32_t ownerId, bool isFriendly) |
| Fire a weapon from an entity, spawning a projectile. | |
| std::uint32_t | fireChargedShot (Registry ®istry, std::uint32_t ownerId, float chargeLevel, bool isFriendly) |
| Fire a charged shot if charge is sufficient, otherwise fire normal shot. | |
| ComponentMask | getComponentMask () const override |
| Gets the component mask for this system. | |
Public Member Functions inherited from ecs::ISystem | |
| virtual | ~ISystem ()=default |
| Virtual destructor. | |
Private Member Functions | |
| Velocity | calculateProjectileVelocity (float baseSpeed, bool isFriendly) |
| Calculate projectile initial velocity based on owner's velocity. | |
| Transform | calculateProjectileTransform (Registry ®istry, std::uint32_t ownerId, bool isFriendly) |
| Calculate projectile spawn position based on owner position. | |
| std::uint32_t | createProjectile (Registry ®istry, std::uint32_t ownerId, const Transform &transform, const Velocity &velocity, float damage, bool isFriendly, bool isCharged) |
| Create a single projectile with specified properties. | |
| void | fireMultipleShots (Registry ®istry, std::uint32_t ownerId, float damage, float speed, bool isFriendly, bool isCharged, int shotCount) |
| Fire multiple projectiles based on multishot buff. | |
Private Attributes | |
| ProjectileCreatedCallback | _projectileCreatedCallback |
System managing weapon firing and cooldowns.
Handles weapon cooldown timers, projectile spawning, and weapon mechanics. Requires Weapon and Transform components. Optionally uses Velocity for weapon direction.
Definition at line 29 of file WeaponSystem.hpp.
| using ecs::WeaponSystem::ProjectileCreatedCallback = std::function<void(uint32_t, uint32_t, float, float, float, float, float, int, bool)> |
Callback for projectile creation events Parameters: projectileId, ownerId, posX, posY, dirX, dirY, speed, damage, friendly.
Definition at line 35 of file WeaponSystem.hpp.
|
default |
Default constructor.
|
inlineexplicit |
Constructor with callback for projectile creation events.
| callback | Function to call when a projectile is created |
Definition at line 48 of file WeaponSystem.hpp.
|
overridedefault |
Default destructor.
|
private |
Calculate projectile spawn position based on owner position.
| registry | Reference to the ECS registry |
| ownerId | Entity ID of the weapon owner |
| isFriendly | Whether this is a friendly projectile (affects spawn offset) |
Definition at line 133 of file WeaponSystem.cpp.
References ecs::Registry::getComponent(), ecs::Transform::getPosition(), and ecs::Registry::hasComponent().
Referenced by fireChargedShot(), fireMultipleShots(), and fireWeapon().

|
private |
Calculate projectile initial velocity based on owner's velocity.
| baseSpeed | Base projectile speed from weapon |
| isFriendly | Whether this is a friendly projectile (affects direction) |
Definition at line 127 of file WeaponSystem.cpp.
Referenced by fireChargedShot(), and fireWeapon().
|
private |
Create a single projectile with specified properties.
| registry | Reference to the ECS registry |
| ownerId | Entity ID of the weapon owner |
| transform | Projectile spawn position |
| velocity | Projectile velocity |
| damage | Projectile damage |
| isFriendly | Whether this is a friendly projectile |
| isCharged | Whether this is a charged shot (affects visuals) |
Definition at line 210 of file WeaponSystem.cpp.
References _projectileCreatedCallback, AnimDB::createPlayerBulletAnimations(), ecs::Registry::getComponent(), ecs::Velocity::getDirection(), ecs::Weapon::getFireRate(), ecs::Transform::getPosition(), ecs::Velocity::getSpeed(), ecs::Registry::hasComponent(), ecs::Registry::newEntity(), and ecs::Registry::setComponent().
Referenced by fireChargedShot(), fireMultipleShots(), and fireWeapon().

| std::uint32_t ecs::WeaponSystem::fireChargedShot | ( | Registry & | registry, |
| std::uint32_t | ownerId, | ||
| float | chargeLevel, | ||
| bool | isFriendly | ||
| ) |
Fire a charged shot if charge is sufficient, otherwise fire normal shot.
If the provided charge level meets the minimum threshold (0.5f or 50%), fires a charged projectile with increased damage and speed. Otherwise, fires a normal projectile.
| registry | Reference to the ECS registry |
| ownerId | Entity ID of the weapon owner |
| chargeLevel | Current charge level (0.0f to 1.0f) |
| isFriendly | Whether this is a friendly projectile |
Definition at line 150 of file WeaponSystem.cpp.
References calculateProjectileTransform(), calculateProjectileVelocity(), createProjectile(), ecs::DoubleShot, fireMultipleShots(), fireWeapon(), ecs::Registry::getComponent(), ecs::Weapon::getDamage(), ecs::Buff::hasBuff(), ecs::Registry::hasComponent(), ecs::MultiShot, and ecs::TripleShot.
Referenced by update().

|
private |
Fire multiple projectiles based on multishot buff.
| registry | Reference to the ECS registry |
| ownerId | Entity ID of the weapon owner |
| damage | Projectile damage |
| speed | Projectile speed |
| isFriendly | Whether projectiles are friendly |
| isCharged | Whether this is a charged shot |
| shotCount | Number of projectiles to fire |
Definition at line 258 of file WeaponSystem.cpp.
References calculateProjectileTransform(), createProjectile(), ecs::Transform::getPosition(), ecs::Registry::hasComponent(), and ecs::Transform::setPosition().
Referenced by fireChargedShot(), and fireWeapon().

| std::uint32_t ecs::WeaponSystem::fireWeapon | ( | Registry & | registry, |
| std::uint32_t | ownerId, | ||
| bool | isFriendly | ||
| ) |
Fire a weapon from an entity, spawning a projectile.
Creates a new projectile entity with appropriate components. Resets the weapon cooldown timer based on fire rate.
| registry | Reference to the ECS registry |
| ownerId | Entity ID of the weapon owner |
| isFriendly | Whether this is a friendly projectile |
Definition at line 85 of file WeaponSystem.cpp.
References calculateProjectileTransform(), calculateProjectileVelocity(), createProjectile(), ecs::DoubleShot, fireMultipleShots(), ecs::Registry::getComponent(), ecs::Weapon::getDamage(), ecs::Buff::hasBuff(), ecs::Registry::hasComponent(), ecs::MultiShot, and ecs::TripleShot.
Referenced by fireChargedShot(), and update().

|
overridevirtual |
Gets the component mask for this system.
Implements ecs::ISystem.
Definition at line 206 of file WeaponSystem.cpp.
Referenced by update().
|
inline |
Set the callback for projectile creation events.
| callback | Function to call when a projectile is created |
Definition at line 60 of file WeaponSystem.hpp.
References _projectileCreatedCallback.
|
overridevirtual |
Manages weapon cooldowns for all entities.
Updates weapon cooldowns for all entities with weapons.
Decrements weapon cooldown timers each frame. When cooldown reaches 0, the weapon is ready to fire. Actual projectile creation is handled by input or AI systems.
| registry | Reference to the ECS registry |
| deltaTime | Time elapsed since last frame (in seconds) |
Implements ecs::ISystem.
Definition at line 24 of file WeaponSystem.cpp.
References fireChargedShot(), fireWeapon(), ecs::Registry::getComponent(), getComponentMask(), ecs::Registry::getEntitiesWithMask(), ecs::Registry::hasComponent(), and ecs::Weapon::setCooldown().

|
private |
Definition at line 162 of file WeaponSystem.hpp.
Referenced by createProjectile(), and setProjectileCreatedCallback().