R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
WeaponSystem.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** RTYPE
4** File description:
5** WeaponSystem
6*/
7
8#pragma once
9
10#include <cstdint>
11#include <functional>
12#include <memory>
13#include "../../Components/Buff.hpp"
14#include "../../Components/Projectile.hpp"
15#include "../../Components/Transform.hpp"
16#include "../../Components/Velocity.hpp"
17#include "../../Components/Weapon.hpp"
18#include "../ISystem.hpp"
19
20namespace ecs {
29 class WeaponSystem : public ISystem {
30 public:
36 std::function<void(uint32_t, uint32_t, float, float, float, float, float, int, bool)>;
37
41 WeaponSystem() = default;
42
49
53 ~WeaponSystem() override = default;
54
63
74 void update(Registry &registry, float deltaTime) override;
75
87 std::uint32_t fireWeapon(Registry &registry, std::uint32_t ownerId, bool isFriendly);
88
102 std::uint32_t fireChargedShot(Registry &registry, std::uint32_t ownerId, float chargeLevel,
103 bool isFriendly);
104
110 ComponentMask getComponentMask() const override;
111
112 private:
120 Velocity calculateProjectileVelocity(float baseSpeed, bool isFriendly);
121
130 Transform calculateProjectileTransform(Registry &registry, std::uint32_t ownerId, bool isFriendly);
131
144 std::uint32_t createProjectile(Registry &registry, std::uint32_t ownerId, const Transform &transform,
145 const Velocity &velocity, float damage, bool isFriendly,
146 bool isCharged);
147
159 void fireMultipleShots(Registry &registry, std::uint32_t ownerId, float damage, float speed,
160 bool isFriendly, bool isCharged, int shotCount);
161
163 };
164} // namespace ecs
Base interface for all ECS systems.
Definition ISystem.hpp:37
Manages entities, their signatures and component type registrations.
Definition Registry.hpp:68
Component representing position, rotation and scale in 2D space.
Definition Transform.hpp:20
Component representing movement direction and speed.
Definition Velocity.hpp:20
System managing weapon firing and cooldowns.
std::uint32_t fireChargedShot(Registry &registry, std::uint32_t ownerId, float chargeLevel, bool isFriendly)
Fire a charged shot if charge is sufficient, otherwise fire normal shot.
void update(Registry &registry, float deltaTime) override
Manages weapon cooldowns for all entities.
std::uint32_t fireWeapon(Registry &registry, std::uint32_t ownerId, bool isFriendly)
Fire a weapon from an entity, spawning a projectile.
std::function< void(uint32_t, uint32_t, float, float, float, float, float, int, bool)> ProjectileCreatedCallback
Callback for projectile creation events Parameters: projectileId, ownerId, posX, posY,...
ProjectileCreatedCallback _projectileCreatedCallback
WeaponSystem()=default
Default constructor.
~WeaponSystem() override=default
Default destructor.
std::uint32_t createProjectile(Registry &registry, std::uint32_t ownerId, const Transform &transform, const Velocity &velocity, float damage, bool isFriendly, bool isCharged)
Create a single projectile with specified properties.
ComponentMask getComponentMask() const override
Gets the component mask for this system.
WeaponSystem(ProjectileCreatedCallback callback)
Constructor with callback for projectile creation events.
void fireMultipleShots(Registry &registry, std::uint32_t ownerId, float damage, float speed, bool isFriendly, bool isCharged, int shotCount)
Fire multiple projectiles based on multishot buff.
Velocity calculateProjectileVelocity(float baseSpeed, bool isFriendly)
Calculate projectile initial velocity based on owner's velocity.
void setProjectileCreatedCallback(ProjectileCreatedCallback callback)
Set the callback for projectile creation events.
Transform calculateProjectileTransform(Registry &registry, std::uint32_t ownerId, bool isFriendly)
Calculate projectile spawn position based on owner position.
Maximum number of distinct component types supported by the Registry.
Definition GameLogic.hpp:26
std::uint64_t ComponentMask
Type alias for component bitmask.
Definition ISystem.hpp:24