Skip to main content

ShootCommand.ixx File

Command for triggering shooting actions on GameObjects. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacemechanics

High-level gameplay systems and components for game logic. More...

namespacecombat

Combat-related gameplay systems, components, and commands. More...

namespacecommands

Combat-related commands for translating input into combat actions. More...

Classes Index

classShootCommand

Command that triggers a shooting action on a GameObject. More...

Description

Command for triggering shooting actions on GameObjects.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ShootCommand.ixx
3 * @brief Command for triggering shooting actions on GameObjects.
4 */
5module;
6
7export module helios.engine.mechanics.combat.commands.ShootCommand;
8
9import helios.engine.ecs;
10import helios.math.types;
11import helios.engine.mechanics.combat.components.ShootComponent;
12import helios.engine.modules.physics.motion.components.Move2DComponent;
13
14
15import helios.engine.runtime.world.UpdateContext;
16import helios.engine.runtime.world.GameWorld;
17
18
20
21 /**
22 * @brief Command that triggers a shooting action on a GameObject.
23 *
24 * @details ShootCommand is a TargetedCommand that initiates projectile firing
25 * on the target entity. The command carries an intensity value (typically from
26 * trigger pressure or button state) that controls fire rate or projectile behavior.
27 *
28 * When executed, the command:
29 * 1 Retrieves the target's ShootComponent
30 * 2 Optionally retrieves Move2DComponent for velocity inheritance
31 * 3 Calls `ShootComponent::shoot()` with intensity and source velocity
32 *
33 * The source velocity allows projectiles to inherit the shooter's momentum,
34 * preventing projectiles from spawning "behind" a fast-moving entity.
35 *
36 * Example usage:
37 * ```cpp
38 * // In an input system
39 * float triggerValue = inputSnapshot.gamepadState().triggerRight();
40 * if (triggerValue > 0.0f) {
41 * commandBuffer.add<ShootCommand>(player.guid(), triggerValue);
42 * }
43 * ```
44 *
45 * @note The target GameObject must have a ShootComponent attached for this
46 * command to have any effect. Move2DComponent is optional.
47 *
48 * @see ShootComponent
49 * @see TargetedCommand
50 * @see TwinStickInputSystem
51 */
53
54 /**
55 * @brief The fire intensity factor (0.0 to 1.0).
56 *
57 * @details Derived from trigger pressure or button state.
58 * Higher values may affect fire rate or projectile properties.
59 */
60 const float intensity_;
61
62
63 const helios::engine::ecs::EntityHandle entityHandle_;
64
65 public:
66
67 /**
68 * @brief Constructs a ShootCommand with the specified intensity.
69 *
70 * @param intensity Fire intensity factor (0.0 to 1.0).
71 * Typically from gamepad trigger pressure.
72 */
73 explicit ShootCommand(
74 const helios::engine::ecs::EntityHandle entityHandle,
75 float intensity
76 ) :
77 entityHandle_(entityHandle),
78 intensity_(intensity)
79 {}
80
81 /**
82 * @brief Returns the fire intensity.
83 *
84 * @return The intensity value (0.0 to 1.0).
85 */
86 [[nodiscard]] float intensity() const noexcept {
87 return intensity_;
88 }
89
90 /**
91 * @brief Executes the shoot command on the target GameObject.
92 *
93 * @details Retrieves the ShootComponent and optionally the Move2DComponent
94 * from the target. Calls `ShootComponent::shoot()` with the intensity and
95 * the entity's current velocity for momentum inheritance.
96 *
97 * @param gameObject The target entity with a ShootComponent.
98 */
99 void execute(helios::engine::runtime::world::UpdateContext& updateContext) const noexcept {
100
101 auto gameObject = updateContext.find(entityHandle_);
102
103 if (!gameObject) {
104 return;
105 }
106
107 auto* shootComponent = gameObject->get<helios::engine::mechanics::combat::components::ShootComponent>();
108
109 if (shootComponent) {
111
112 shootComponent->shoot(
113 intensity_,
114 m2d != nullptr ? m2d->velocity() : helios::math::vec3f{0.0f, 0.0f, 0.0f}
115 );
116 }
117
118 }
119
120
121 };
122
123
124}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.