Browse Source

move block_selected

pbs
jake 5 years ago
parent
commit
07403fe815
  1. 29
      src/ship/packet/handler/lobby.rs
  2. 33
      src/ship/ship.rs

29
src/ship/packet/handler/lobby.rs

@ -7,6 +7,35 @@ use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder};
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
use libpso::character::character;
// this function needs a better home
pub fn block_selected(id: ClientId,
pkt: &MenuSelect,
clients: &mut HashMap<ClientId, ClientState>,
level_table: &CharacterLevelTable)
-> Result<Vec<SendShipPacket>, ShipError> {
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
client.block = pkt.item as u32;
let (level, stats) = level_table.get_stats_from_exp(client.character.char_class, client.character.exp);
let fc = FullCharacterBytesBuilder::new()
.character(&client.character)
.stats(&stats)
.level(level)
.inventory(&client.inventory)
.key_config(&client.settings.settings.key_config)
.joystick_config(&client.settings.settings.joystick_config)
.symbol_chat(&client.settings.settings.symbol_chats)
.tech_menu(&client.character.tech_menu.as_bytes())
.build();
Ok(vec![
SendShipPacket::FullCharacter(FullCharacter {
character: fc,
}),
SendShipPacket::CharDataRequest(CharDataRequest {}),
])
}
pub fn send_player_to_lobby(id: ClientId,
_pkt: &CharData,

33
src/ship/ship.rs

@ -136,13 +136,13 @@ impl SendServerPacket for SendShipPacket {
pub struct ClientState {
pub user: UserAccountEntity,
settings: UserSettingsEntity,
pub settings: UserSettingsEntity,
pub character: CharacterEntity,
session: Session,
//guildcard: GuildCard,
inventory: items::ActiveInventory,
pub inventory: items::ActiveInventory,
//bank: Bank,
block: u32,
pub block: u32,
}
impl ClientState {
@ -183,31 +183,6 @@ impl<EG: EntityGateway> ShipServerState<EG> {
}
}
fn block_selected(&mut self, id: ClientId, pkt: &MenuSelect) -> Result<Vec<SendShipPacket>, ShipError> {
let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
client.block = pkt.item as u32;
let (level, stats) = self.level_table.get_stats_from_exp(client.character.char_class, client.character.exp);
let fc = FullCharacterBytesBuilder::new()
.character(&client.character)
.stats(&stats)
.level(level)
.inventory(&client.inventory)
.key_config(&client.settings.settings.key_config)
.joystick_config(&client.settings.settings.joystick_config)
.symbol_chat(&client.settings.settings.symbol_chats)
.tech_menu(&client.character.tech_menu.as_bytes())
.build();
Ok(vec![
SendShipPacket::FullCharacter(FullCharacter {
character: fc,
}),
SendShipPacket::CharDataRequest(CharDataRequest {}),
])
}
fn message(&mut self, id: ClientId, msg: &Message) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
match &msg.msg {
GameMessage::RequestExp(request_exp) => {
@ -268,7 +243,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
},
RecvShipPacket::MenuSelect(menuselect) => {
match menuselect.menu {
BLOCK_MENU_ID => Box::new(self.block_selected(id, menuselect)?.into_iter().map(move |pkt| (id, pkt))),
BLOCK_MENU_ID => Box::new(handler::lobby::block_selected(id, menuselect, &mut self.clients, &self.level_table)?.into_iter().map(move |pkt| (id, pkt))),
ROOM_MENU_ID => Box::new(handler::room::join_room(id, menuselect, &mut self.client_location, &mut self.clients, &self.level_table, &mut self.rooms)?.into_iter()),
_ => unreachable!(),
}

Loading…
Cancel
Save