diff --git a/client/src/lib.rs b/client/src/lib.rs index 0f0eb33f22..f078192d21 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -762,22 +762,19 @@ impl Client { }, ServerMsg::PlayerListUpdate(PlayerListUpdate::LevelChange(uid, next_level)) => { if let Some(player_info) = self.player_list.get_mut(&uid) { - if let Some(character) = &player_info.character { - // TODO: assign next value - // &character.level = next_level; - } else { - warn!( - "Received msg to update character level info to {} for uid \ - {}, but this player's character is None.", - next_level, uid - ); - } - } else { - warn!( - "Received msg to update character level info to {} for uid {}, \ - but they were not in the list.", - next_level, uid - ); + player_info.character = match &player_info.character { + Some(character) => Some(common::msg::CharacterInfo { + name: character.name.to_string(), + level: next_level, + }), + None => { + warn!( + "Received msg to update character level info to {} for \ + uid {}, but this player's character is None.", + next_level, uid + ); + }, + }; } }, ServerMsg::PlayerListUpdate(PlayerListUpdate::Remove(uid)) => { diff --git a/common/src/event.rs b/common/src/event.rs index 762703337d..b8f5cc6a80 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -90,6 +90,7 @@ pub enum ServerEvent { Mount(EcsEntity, EcsEntity), Unmount(EcsEntity), Possess(Uid, Uid), + LevelUp(EcsEntity, u32), SelectCharacter { entity: EcsEntity, character_id: i32, diff --git a/common/src/sys/stats.rs b/common/src/sys/stats.rs index 448b97fec8..5321b54c7a 100644 --- a/common/src/sys/stats.rs +++ b/common/src/sys/stats.rs @@ -66,6 +66,7 @@ impl<'a> System<'a> for Sys { stat.exp.change_by(-(stat.exp.maximum() as i64)); stat.level.change_by(1); stat.exp.update_maximum(stat.level.level()); + server_event_emitter.emit(ServerEvent::LevelUp(entity, stat.level.level())); } stat.update_max_hp(); diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 266145cbe3..45be81d287 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -2,7 +2,7 @@ use crate::{client::Client, Server, SpawnPoint, StateExt}; use common::{ assets, comp::{self, object, Body, HealthChange, HealthSource, Item, Player, Stats}, - msg::ServerMsg, + msg::{PlayerListUpdate, ServerMsg}, state::BlockChange, sync::{Uid, WorldSyncExt}, sys::combat::{BLOCK_ANGLE, BLOCK_EFFICIENCY}, @@ -295,3 +295,17 @@ pub fn handle_explosion(server: &Server, pos: Vec3, power: f32, owner: Opti .cast(); } } + +pub fn handle_level_up(server: &mut Server, entity: EcsEntity, new_level: u32) { + let uids = server.state.ecs().read_storage::(); + let uid = uids + .get(entity) + .expect("Failed to fetch uid component for entity.") + .0; + + server + .state + .notify_registered_clients(ServerMsg::PlayerListUpdate(PlayerListUpdate::LevelChange( + uid, new_level, + ))); +} diff --git a/server/src/events/mod.rs b/server/src/events/mod.rs index d36f86e9d4..04d540badc 100644 --- a/server/src/events/mod.rs +++ b/server/src/events/mod.rs @@ -4,7 +4,8 @@ use entity_creation::{ handle_create_character, handle_create_npc, handle_create_waypoint, handle_shoot, }; use entity_manipulation::{ - handle_damage, handle_destroy, handle_explosion, handle_land_on_ground, handle_respawn, + handle_damage, handle_destroy, handle_explosion, handle_land_on_ground, handle_level_up, + handle_respawn, }; use interaction::{handle_lantern, handle_mount, handle_possess, handle_unmount}; use inventory_manip::handle_inventory; @@ -75,6 +76,7 @@ impl Server { body, main, } => handle_create_character(self, entity, character_id, body, main), + ServerEvent::LevelUp(entity, new_level) => handle_level_up(self, entity, new_level), ServerEvent::ExitIngame { entity } => handle_exit_ingame(self, entity), ServerEvent::CreateNpc { pos,