Skip to main content

CombatScoringSystem.ixx File

System that awards scores based on combat events. 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...

namespacescoring

Score management and tracking system for game mechanics. More...

namespacesystems

Systems for score processing and observation. More...

Classes Index

classCombatScoringSystem

System that processes death events and awards scores. More...

Macro Definitions Index

#defineHELIOS_LOG_SCOPE   "helios::engine::mechanics::scoring::systems::CombatScoringSystem"

Description

System that awards scores based on combat events.

Macro Definitions

HELIOS_LOG_SCOPE

#define HELIOS_LOG_SCOPE   "helios::engine::mechanics::scoring::systems::CombatScoringSystem"

Definition at line 46 of file CombatScoringSystem.ixx.

46#define HELIOS_LOG_SCOPE "helios::engine::mechanics::scoring::systems::CombatScoringSystem"

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file CombatScoringSystem.ixx
3 * @brief System that awards scores based on combat events.
4 */
5module;
6
7#include <algorithm>
8#include <cassert>
9#include <cmath>
10#include <format>
11#include <helios/helios_config.h>
12#include <unordered_set>
13#include <vector>
14
15
16export module helios.engine.mechanics.scoring.systems.CombatScoringSystem;
17
18import helios.engine.mechanics.scoring.commands;
19import helios.engine.mechanics.scoring.components;
20import helios.engine.mechanics.scoring.types;
21
22import helios.engine.runtime.world.GameWorld;
23import helios.engine.runtime.world.UpdateContext;
24
25import helios.engine.state.Bindings;
26import helios.engine.runtime.messaging.command.EngineCommandBuffer;
27
28
29import helios.engine.ecs.types.EntityId;
30
31import helios.engine.mechanics.health.events.HealthDepletedEvent;
32
33
34import helios.engine.modules.physics.collision.events;
35
36
37import helios.util.log;
38
39
44using namespace helios::engine::ecs::types;
45
46#define HELIOS_LOG_SCOPE "helios::engine::mechanics::scoring::systems::CombatScoringSystem"
47import helios.engine.common.tags.SystemRole;
48
50
51 /**
52 * @brief System that processes death events and awards scores.
53 *
54 * Listens for HealthDepletedEvent and checks if the killed entity has a
55 * ScoreValueComponent. If so, issues an UpdateScoreCommand to
56 * credit the attacker's score pool.
57 */
59
62
63 public:
64
66
67
68 /**
69 * @brief Processes death events and issues score commands.
70 *
71 * @param updateContext The current frame's update context.
72 */
74
75 for (auto& event : updateContext.readPass<HealthDepletedEvent>()) {
76
77 if (!event.damageContext()) {
78 continue;
79 }
80
81 const auto& attackContext = event.damageContext();
82
83 const auto interactionContext = attackContext->interactionContext;
84
85 const auto enemy = updateContext.find(event.source());
86 const auto instigator = updateContext.find(interactionContext.instigator);
87
88 if (!enemy || !instigator) {
89 continue;
90 }
91
92 auto* svc = enemy->get<ScoreValueComponent<KillReward>>();
93 if (!svc) {
94 continue;
95 }
96
97 auto* scc = instigator->get<ScorePoolComponent>();
98 if (!scc) {
99 continue;
100 }
101
102 auto scoreContext = ScoreValueContext{
103 .scoreTypeId = ScoreTypeId::id<KillReward>(),
104 .scorePoolId = scc->scorePoolId(),
105 .value = svc->score().value()
106 };
107
108 logger_.info(
109 std::format("Entity {0} killed. Reward: {1}",
110 instigator->entityHandle().entityId,
111 svc->score().value())
112 );
113
114 updateContext.queueCommand<UpdateScoreCommand>(
115 std::move(scoreContext)
116 );
117 }
118
119 }
120
121 };
122
123}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.