diff options
Diffstat (limited to 'src/server.rs')
-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>, |