From 8f33512ea2732075eba30786e8d32fd505c89b1e Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 3 Dec 2019 21:46:01 -0800 Subject: [PATCH] move new char logic into its own function --- src/login/character.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/login/character.rs b/src/login/character.rs index e53b7d4..fab6d04 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -179,6 +179,24 @@ pub struct CharacterServerState { level_table: CharacterLevelTable, } + + + +fn new_character(entity_gateway: &mut EG, user: &UserAccount, preview: &CharacterPreview) { + let mut char = entity_gateway.new_character_by_user(&user); + char.slot = preview.slot; + char.character = preview.character.as_character(); + /*let char = Character { + id: 9, + slot: preview.slot, + user_id: user.id, + character: preview.character.as_character() +};*/ + entity_gateway.set_character(&char); +} + + + impl CharacterServerState { pub fn new(entity_gateway: EG) -> CharacterServerState { let (param_header, param_data) = generate_param_data("data/param/"); @@ -347,16 +365,7 @@ impl CharacterServerState { let client = self.clients.get_mut(&id).ok_or(CharacterError::ClientNotFound(id))?; let mut user = client.user.as_mut().unwrap(); if user.flags == USERFLAG_NEWCHAR { - let mut char = self.entity_gateway.new_character_by_user(&user); - char.slot = preview.slot; - char.character = preview.character.as_character(); - let char = Character { - id: 9, - slot: preview.slot, - user_id: user.id, - character: preview.character.as_character() - }; - self.entity_gateway.set_character(&char); + new_character(&mut self.entity_gateway, &user, preview) } if user.flags == USERFLAG_DRESSINGROOM { // TODO: dressing room stuff