diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-04-08 11:42:25 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-04-08 11:42:25 +0200 |
commit | 348c550ca170ff94c3c9f76e2d85b0513011e063 (patch) | |
tree | 2885c48b1035ab77cdbbcecd385823557c9fb609 | |
parent | 05c01e7aa13d8a6fe7302462fc32a5c559fade56 (diff) |
fix: fix selecting factions
-rw-r--r-- | src/server.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/server.rs b/src/server.rs index 84f9235..003b5e5 100644 --- a/src/server.rs +++ b/src/server.rs @@ -61,7 +61,7 @@ impl Plugin for ServerPlugin { }) .add_systems(Startup, setup) .add_systems(Update, (connects, disconnects)) - .add_systems(Update, receive_message) + .add_systems(Update, (receive_message_select_champion, receive_message_select_faction)) .add_systems(FixedUpdate, timers_tick) .add_systems(FixedUpdate, effective_stats.after(buffs_despawn)) .add_systems(FixedUpdate, health_regen.after(timers_tick)) @@ -174,7 +174,7 @@ fn connects( } } -fn receive_message( +fn receive_message_select_champion( entity_map: Res<EntityMap>, mut commands: Commands, mut reader: EventReader<MessageEvent<SelectChampion>>, @@ -189,6 +189,21 @@ fn receive_message( } } +fn receive_message_select_faction( + entity_map: Res<EntityMap>, + mut commands: Commands, + mut reader: EventReader<MessageEvent<SelectFaction>>, +) { + for event in reader.read() { + let client_id = event.context(); + let SelectFaction(faction) = event.message(); + let Some(entity) = entity_map.0.get(client_id) else { + continue; + }; + commands.entity(*entity).insert(*faction); + } +} + fn disconnects( mut commands: Commands, mut disconnects: EventReader<server::DisconnectEvent>, |