1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! Events for faction system
use crateEvent;
use ;
use HashMap;
use ;
// ========================================
// Command Events (Request)
// ========================================
/// Request to launch an operation (Command Event)
///
/// This is a "command" event that requests an operation to be launched.
/// `FactionSystem` processes this and publishes `OperationLaunchedEvent`.
///
/// # Example
///
/// ```ignore
/// use issun::event::EventBus;
/// use issun::plugin::faction::{OperationLaunchRequested, FactionId};
/// use serde_json::json;
///
/// let mut bus = resources.get_mut::<EventBus>().await.unwrap();
/// bus.publish(OperationLaunchRequested {
/// faction_id: FactionId::new("crimson-syndicate"),
/// operation_name: "Capture Nova Harbor".into(),
/// metadata: json!({
/// "target": "nova-harbor",
/// "troops": 50,
/// "strategy": "stealth"
/// }),
/// });
/// ```
/// Request to resolve an operation (Command Event)
///
/// This is a "command" event that requests an operation to be resolved.
/// `FactionSystem` processes this and publishes either `OperationCompletedEvent` or `OperationFailedEvent`.
///
/// # Example
///
/// ```ignore
/// use issun::event::EventBus;
/// use issun::plugin::faction::{OperationResolveRequested, OperationId, Outcome};
/// use std::collections::HashMap;
/// use serde_json::json;
///
/// let mut bus = resources.get_mut::<EventBus>().await.unwrap();
/// bus.publish(OperationResolveRequested {
/// operation_id: OperationId::new("op-001"),
/// outcome: Outcome {
/// operation_id: OperationId::new("op-001"),
/// success: true,
/// metrics: HashMap::from([
/// ("casualties".into(), 5.0),
/// ("control_gained".into(), 0.15),
/// ]),
/// metadata: json!({ "notes": "Minimal resistance" }),
/// },
/// });
/// ```
// ========================================
// State Events (Notification)
// ========================================
/// Published when an operation is launched (State Change Event)
///
/// This event is published after an operation has been launched.
/// It represents a **confirmed state change** and can be replicated over network.
///
/// # Example
///
/// ```ignore
/// use issun::event::EventBus;
/// use issun::plugin::faction::OperationLaunchedEvent;
///
/// // In a system
/// let mut bus = resources.get_mut::<EventBus>().await.unwrap();
/// let reader = bus.reader::<OperationLaunchedEvent>();
///
/// for event in reader.iter() {
/// println!(
/// "Faction {} launched operation {}",
/// event.faction_id.as_str(),
/// event.operation_name
/// );
/// }
/// ```
/// Published when an operation is completed (State Change Event)
///
/// This event is published after an operation has completed successfully.
/// It represents a **confirmed state change** and can be replicated over network.
///
/// # Example
///
/// ```ignore
/// use issun::event::EventBus;
/// use issun::plugin::faction::OperationCompletedEvent;
///
/// // In a system
/// let mut bus = resources.get_mut::<EventBus>().await.unwrap();
/// let reader = bus.reader::<OperationCompletedEvent>();
///
/// for event in reader.iter() {
/// println!(
/// "Faction {} completed operation {}: {}",
/// event.faction_id.as_str(),
/// event.operation_id.as_str(),
/// if event.success { "SUCCESS" } else { "FAILED" }
/// );
/// }
/// ```
/// Published when an operation fails (State Change Event)
///
/// This event is published after an operation has failed.
/// It represents a **confirmed state change** and can be replicated over network.
///
/// # Example
///
/// ```ignore
/// use issun::event::EventBus;
/// use issun::plugin::faction::OperationFailedEvent;
///
/// // In a system
/// let mut bus = resources.get_mut::<EventBus>().await.unwrap();
/// let reader = bus.reader::<OperationFailedEvent>();
///
/// for event in reader.iter() {
/// println!(
/// "Faction {} operation {} failed: {}",
/// event.faction_id.as_str(),
/// event.operation_id.as_str(),
/// event.reason
/// );
/// }
/// ```