aboutsummaryrefslogtreecommitdiffstats
path: root/src/server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.rs')
-rw-r--r--src/server.rs70
1 files changed, 38 insertions, 32 deletions
diff --git a/src/server.rs b/src/server.rs
index a509f28..b6c23c6 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -68,6 +68,10 @@ impl Plugin for ServerPlugin {
receive_message_select_faction,
),
)
+ .add_systems(
+ Update,
+ (receive_message_imperative, receive_message_activation),
+ )
.add_systems(FixedUpdate, timers_tick)
.add_systems(FixedUpdate, effective_stats.after(buffs_despawn))
.add_systems(FixedUpdate, health_regen.after(timers_tick))
@@ -80,7 +84,8 @@ impl Plugin for ServerPlugin {
activation.after(cooldown_decrement),
imperative_walk_to,
)
- .after(player_input),
+ .after(receive_message_activation)
+ .after(receive_message_imperative),
)
.add_systems(
FixedUpdate,
@@ -101,7 +106,6 @@ impl Plugin for ServerPlugin {
)
.add_systems(FixedUpdate, cooldown_decrement)
.add_systems(FixedUpdate, (buffs_despawn, buffs_tick).chain())
- .add_systems(FixedUpdate, player_input)
.add_systems(
FixedUpdate,
(tower_ai, (minion_ai_attack, minion_ai_walk).chain())
@@ -210,6 +214,36 @@ fn receive_message_select_faction(
}
}
+fn receive_message_imperative(
+ entity_map: Res<EntityMap>,
+ mut commands: Commands,
+ mut reader: EventReader<MessageEvent<Imperative>>,
+) {
+ for event in reader.read() {
+ let client_id = event.context();
+ let imperative = event.message();
+ let Some(entity) = entity_map.0.get(client_id) else {
+ continue;
+ };
+ commands.entity(*entity).insert(*imperative);
+ }
+}
+
+fn receive_message_activation(
+ entity_map: Res<EntityMap>,
+ mut commands: Commands,
+ mut reader: EventReader<MessageEvent<Activation>>,
+) {
+ for event in reader.read() {
+ let client_id = event.context();
+ let activation = event.message();
+ let Some(entity) = entity_map.0.get(client_id) else {
+ continue;
+ };
+ commands.entity(*entity).insert(*activation);
+ }
+}
+
fn disconnects(
mut commands: Commands,
mut disconnects: EventReader<server::DisconnectEvent>,
@@ -223,34 +257,6 @@ fn disconnects(
}
}
-fn player_input(
- entity_map: Res<EntityMap>,
- mut input_reader: EventReader<server::InputEvent<Inputs>>,
- mut imperatives: Query<&mut Imperative>,
- mut activations: Query<&mut Activation>,
-) {
- for input in input_reader.read() {
- let client_id = input.context();
- if let Some(input) = input.input() {
- if let Some(entity_id) = entity_map.0.get(client_id) {
- match input {
- Inputs::Imperative(new_imperative) => {
- if let Ok(mut imperative) = imperatives.get_mut(*entity_id) {
- *imperative = *new_imperative;
- }
- }
- Inputs::Activation(new_activation) => {
- if let Ok(mut activation) = activations.get_mut(*entity_id) {
- *activation = *new_activation;
- }
- }
- Inputs::None => {}
- }
- }
- }
- }
-}
-
fn imperative_walk_to(
mut players: Query<(Entity, &mut Imperative, &EffectiveStats)>,
mut positions: Query<&mut PlayerPosition>,
@@ -615,7 +621,7 @@ fn projectile_despawn(
};
let applied_damage = damage.apply(hit_effective_stats.0);
hit_health.apply_damage(applied_damage);
- let _ = connection_manager.send_message_to_target::<Channel1, HealthChanged>(
+ let _ = connection_manager.send_message_to_target::<Input, HealthChanged>(
HealthChanged(HealthEvent {
target_player: *hit_player_id,
health_gained: -applied_damage,
@@ -647,7 +653,7 @@ fn health_regen(
if health_regen_timer.0.just_finished() {
for (target_player, mut health, effective_stats) in healths.iter_mut() {
health.heal(HEALTH_REGEN, effective_stats.0.max_health);
- let _ = connection_manager.send_message_to_target::<Channel1, HealthChanged>(
+ let _ = connection_manager.send_message_to_target::<Input, HealthChanged>(
HealthChanged(HealthEvent {
target_player: *target_player,
health_gained: HEALTH_REGEN,