Browse Source

options saved to character!

pbs
andy 4 years ago
parent
commit
62e5a966f6
  1. 3
      src/entity/character.rs
  2. 1
      src/entity/gateway/inmemory.rs
  3. 11
      src/ship/character.rs
  4. 1
      src/ship/packet/handler/lobby.rs
  5. 12
      src/ship/packet/handler/settings.rs
  6. 5
      src/ship/ship.rs

3
src/entity/character.rs

@ -260,6 +260,7 @@ pub struct NewCharacterEntity {
pub tech_menu: CharacterTechMenu,
pub meseta: u32,
pub bank_meseta: u32,
pub option_flags: u32,
}
impl NewCharacterEntity {
@ -280,6 +281,7 @@ impl NewCharacterEntity {
tech_menu: CharacterTechMenu::new(),
meseta: 0,
bank_meseta: 0,
option_flags: 0,
}
}
}
@ -307,4 +309,5 @@ pub struct CharacterEntity {
pub meseta: u32,
// TODO: this should not be tied to the character
pub bank_meseta: u32,
pub option_flags: u32,
}

1
src/entity/gateway/inmemory.rs

@ -127,6 +127,7 @@ impl EntityGateway for InMemoryGateway {
tech_menu: character.tech_menu,
meseta: character.meseta,
bank_meseta: character.bank_meseta,
option_flags: character.option_flags,
};
characters.insert(new_character.id, new_character.clone());
Some(new_character)

11
src/ship/character.rs

@ -86,6 +86,7 @@ pub struct FullCharacterBytesBuilder<'a> {
joystick_config: Option<&'a [u8; 0x38]>,
symbol_chat: Option<&'a [u8; 1248]>,
tech_menu: Option<&'a [u8; 40]>,
option_flags: Option<u32>,
}
@ -101,6 +102,7 @@ impl<'a> FullCharacterBytesBuilder<'a> {
joystick_config: None,
symbol_chat: None,
tech_menu: None,
option_flags: None,
}
}
@ -167,6 +169,13 @@ impl<'a> FullCharacterBytesBuilder<'a> {
}
}
pub fn option_flags(self, option_flags: u32) -> FullCharacterBytesBuilder<'a> {
FullCharacterBytesBuilder {
option_flags: Some(option_flags),
..self
}
}
pub fn build(self) -> character::FullCharacter {
let character = self.character.unwrap();
let stats = self.stats.unwrap();
@ -177,6 +186,7 @@ impl<'a> FullCharacterBytesBuilder<'a> {
let joystick_config = self.joystick_config.unwrap();
let symbol_chat = self.symbol_chat.unwrap();
let tech_menu = self.tech_menu.unwrap();
let option_flags = self.option_flags.unwrap();
let mut inventory_items = inventory.as_client_inventory_items();
inventory_items[7].material_count = character.materials.power as u8;
@ -207,6 +217,7 @@ impl<'a> FullCharacterBytesBuilder<'a> {
symbol_chats: *symbol_chat,
tech_menu: *tech_menu,
bank: bank.as_client_bank_items(),
option_flags: option_flags,
..character::FullCharacter::default()
}
}

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

@ -34,6 +34,7 @@ pub fn block_selected(id: ClientId,
.joystick_config(&client.settings.settings.joystick_config)
.symbol_chat(&client.settings.settings.symbol_chats)
.tech_menu(&client.character.tech_menu.as_bytes())
.option_flags(client.character.option_flags)
.build();
Ok(vec![

12
src/ship/packet/handler/settings.rs

@ -13,3 +13,15 @@ pub async fn update_config<EG: EntityGateway>(id: ClientId,
entity_gateway.save_character(&client.character).await;
Box::new(None.into_iter())
}
pub async fn save_options<EG: EntityGateway>(id: ClientId,
save_options: &SaveOptions,
clients: &mut Clients,
entity_gateway: &mut EG)
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
// // TODO: don't unwrap?
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
client.character.option_flags = save_options.options;
entity_gateway.save_character(&client.character).await;
Box::new(None.into_iter())
}

5
src/ship/ship.rs

@ -91,6 +91,7 @@ pub enum RecvShipPacket {
QuestFileRequest(QuestFileRequest),
QuestChunkAck(QuestChunkAck),
DoneLoadingQuest(DoneLoadingQuest),
SaveOptions(SaveOptions),
}
impl RecvServerPacket for RecvShipPacket {
@ -126,6 +127,7 @@ impl RecvServerPacket for RecvShipPacket {
0x84 => Ok(RecvShipPacket::LobbySelect(LobbySelect::from_bytes(data)?)),
0xA2 => Ok(RecvShipPacket::RequestQuestList(RequestQuestList::from_bytes(data)?)),
0xAC => Ok(RecvShipPacket::DoneLoadingQuest(DoneLoadingQuest::from_bytes(data)?)),
0x1ED => Ok(RecvShipPacket::SaveOptions(SaveOptions::from_bytes(data)?)),
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
}
}
@ -556,6 +558,9 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
RecvShipPacket::DoneLoadingQuest(_) => {
handler::quest::done_loading_quest(id, &mut self.clients, &self.client_location)?
},
RecvShipPacket::SaveOptions(save_options) => {
handler::settings::save_options(id, save_options, &mut self.clients, &mut self.entity_gateway).await
},
})
}

Loading…
Cancel
Save