Skip to main content

DamageOnCollisionSystem Class

Emits HealthChangedEvents when solid collisions involve damage dealers. More...

Declaration

class helios::engine::mechanics::damage::systems::DamageOnCollisionSystem { ... }

Public Member Typedefs Index

usingEngineRoleTag = helios::engine::common::tags::SystemRole

Public Member Functions Index

voidupdate (helios::engine::runtime::world::UpdateContext &updateContext) noexcept

Processes collision events and applies damage to targets. More...

Private Static Attributes Index

static const helios::util::log::Logger &logger_ = ...

Description

Emits HealthChangedEvents when solid collisions involve damage dealers.

Listens for SolidCollisionEvents and checks if the source entity has a DamageDealerComponent. If the target has a HealthComponent, emits an ApplyDamageCommand. Resolves the true attacker (instigator) via EmittedByComponent when applicable (e.g. projectiles).

Definition at line 62 of file DamageOnCollisionSystem.ixx.

Public Member Typedefs

EngineRoleTag

using helios::engine::mechanics::damage::systems::DamageOnCollisionSystem::EngineRoleTag = helios::engine::common::tags::SystemRole

Public Member Functions

update()

void helios::engine::mechanics::damage::systems::DamageOnCollisionSystem::update (helios::engine::runtime::world::UpdateContext & updateContext)
inline noexcept

Processes collision events and applies damage to targets.

Parameters
updateContext

The current frame's update context.

Definition at line 78 of file DamageOnCollisionSystem.ixx.

79
80 auto eventPass = updateContext.readPass<
82
83 for (const auto& event : eventPass) {
84
85 auto go = updateContext.find(event.collisionContext().source);
86
87 if (!go) {
88 continue;
89 }
90
91 auto* ddc = go->get<DamageDealerComponent>();
92 if (!ddc) {
93 continue;
94 }
95
96 auto other = event.collisionContext().other;
97 if (!other.has_value()) {
98 continue;
99 }
100
101 auto target = updateContext.find(other.value());
102 if (!target) {
103 continue;
104 }
105 auto* hc = target->get<HealthComponent>();
106 if (!hc) {
107 continue;
108 }
109
110
111 const auto damageApplied = ddc->damage(event.collisionContext().otherCollisionLayerId);
112
113 logger_.info(std::format(
114 "Hitting entity {0} with {1} damage!", other.value().entityId, damageApplied
115 ));
116
117 // the go itself is the source
118 auto instigator= go->entityHandle();
119 auto causer = go->entityHandle();
120
121 auto* ebc = go->get<EmittedByComponent>();
122 if (ebc) {
123 // else the source is assigned to the go emitted
124 // by the go
125 instigator = ebc->source();
126 }
127
128 const auto interactionContext = InteractionContext{
129 .target = other.value(),
130 .instigator = instigator,
131 .causer = causer,
132 .contact = event.collisionContext().contact,
133 };
134
135 auto dc = DamageContext{
136 .interactionContext = interactionContext,
137 .damage = damageApplied
138 };
139
140 updateContext.queueCommand<ApplyDamageCommand>(dc);
141
142 }
143
144 }

Private Static Attributes

logger_

const helios::util::log::Logger& helios::engine::mechanics::damage::systems::DamageOnCollisionSystem::logger_
static

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.