Browse Source

update_config so players can save palette changes

pbs
Andy Newjack 5 years ago
parent
commit
ee640b7a00
  1. 9
      src/entity/character.rs
  2. 1
      src/ship/character.rs
  3. 14
      src/ship/ship.rs

9
src/entity/character.rs

@ -2,6 +2,7 @@ use std::convert::{From, Into, TryFrom, TryInto};
use std::collections::HashMap;
use libpso::character::character;
use libpso::packet::ship::{UpdateConfig};
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
pub enum CharacterClass {
@ -213,6 +214,14 @@ impl CharacterConfig {
raw_data: [0; 0xE8],
}
}
pub fn update(&mut self, new_config: &UpdateConfig) {
self.raw_data = new_config.config;
}
pub fn as_bytes(&self) -> [u8; 0xE8] {
self.raw_data
}
}

1
src/ship/character.rs

@ -67,6 +67,7 @@ impl<'a> CharacterBytesBuilder<'a> {
hair_b: character.appearance.hair_b,
prop_x: character.appearance.prop_x,
prop_y: character.appearance.prop_y,
config: character.config.as_bytes(),
techniques: character.techs.as_bytes(),
..character::Character::default()
}

14
src/ship/ship.rs

@ -43,6 +43,7 @@ pub enum RecvShipPacket {
PlayerChat(PlayerChat),
CreateRoom(CreateRoom),
RoomNameRequest(RoomNameRequest),
UpdateConfig(UpdateConfig),
}
impl RecvServerPacket for RecvShipPacket {
@ -56,6 +57,7 @@ impl RecvServerPacket for RecvShipPacket {
0x06 => Ok(RecvShipPacket::PlayerChat(PlayerChat::from_bytes(data)?)),
0xC1 => Ok(RecvShipPacket::CreateRoom(CreateRoom::from_bytes(data)?)),
0x8A => Ok(RecvShipPacket::RoomNameRequest(RoomNameRequest::from_bytes(data)?)),
0x7ED => Ok(RecvShipPacket::UpdateConfig(UpdateConfig::from_bytes(data)?)),
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
}
}
@ -398,6 +400,13 @@ impl<EG: EntityGateway> ShipServerState<EG> {
let room_state = self.rooms[area.id()].as_ref().unwrap();
Box::new(vec![(id, SendShipPacket::RoomNameResponse(RoomNameResponse {name: room_state.name.clone()}))].into_iter())
}
fn update_config(&mut self, id: ClientId, update_config: &UpdateConfig) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
client.character.config.update(update_config);
self.entity_gateway.set_character(&client.character);
Box::new(None.into_iter())
}
}
@ -450,7 +459,10 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
},
RecvShipPacket::RoomNameRequest(_req) => {
self.room_name_request(id)
}
},
RecvShipPacket::UpdateConfig(pkt) => {
self.update_config(id, pkt)
},
})
}

Loading…
Cancel
Save