|
@ -76,7 +76,7 @@ impl Into<u8> for Difficulty { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
pub enum RoomMode {
|
|
|
pub enum RoomMode {
|
|
|
Single {
|
|
|
Single {
|
|
|
episode: Episode,
|
|
|
episode: Episode,
|
|
@ -114,14 +114,6 @@ impl RoomMode { |
|
|
RoomMode::Challenge {episode, ..} => *episode,
|
|
|
RoomMode::Challenge {episode, ..} => *episode,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub fn get_flags(&self) -> u8 {
|
|
|
|
|
|
match self {
|
|
|
|
|
|
RoomMode::Battle {..} => 0x10,
|
|
|
|
|
|
RoomMode::Challenge {..} => 0x20,
|
|
|
|
|
|
_ => 0x0,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -135,7 +127,10 @@ pub struct RoomState { |
|
|
// drop_table
|
|
|
// drop_table
|
|
|
// items on ground
|
|
|
// items on ground
|
|
|
// enemy info
|
|
|
// enemy info
|
|
|
|
|
|
pub difficulty: u8,
|
|
|
pub players: u8,
|
|
|
pub players: u8,
|
|
|
|
|
|
pub episode: u8,
|
|
|
|
|
|
pub flags: u8,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl RoomState {
|
|
|
impl RoomState {
|
|
@ -145,6 +140,34 @@ impl RoomState { |
|
|
}
|
|
|
}
|
|
|
}*/
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_flags(mode: &RoomMode, password: [u16; 16]) -> u8 {
|
|
|
|
|
|
let mut flags = 0u8;
|
|
|
|
|
|
|
|
|
|
|
|
match mode {
|
|
|
|
|
|
RoomMode::Single {..} => {flags += 0x04}
|
|
|
|
|
|
RoomMode::Battle {..} => {flags += 0x10},
|
|
|
|
|
|
RoomMode::Challenge {..} => {flags += 0x20},
|
|
|
|
|
|
_ => {flags += 0x40},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if password[0] > 0 {
|
|
|
|
|
|
flags += 0x02;
|
|
|
|
|
|
}
|
|
|
|
|
|
flags
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_episode(mode: &RoomMode) -> u8 {
|
|
|
|
|
|
let mut episode = 0u8;
|
|
|
|
|
|
|
|
|
|
|
|
episode = mode.episode().into();
|
|
|
|
|
|
|
|
|
|
|
|
match mode {
|
|
|
|
|
|
RoomMode::Single {..} => {episode += 0x10},
|
|
|
|
|
|
_ => {episode += 0x40},
|
|
|
|
|
|
}
|
|
|
|
|
|
episode
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
pub fn from_create_room(create_room: &libpso::packet::ship::CreateRoom) -> Result<RoomState, RoomCreationError> {
|
|
|
pub fn from_create_room(create_room: &libpso::packet::ship::CreateRoom) -> Result<RoomState, RoomCreationError> {
|
|
|
if [create_room.battle, create_room.challenge, create_room.single_player].iter().sum::<u8>() > 1 {
|
|
|
if [create_room.battle, create_room.challenge, create_room.single_player].iter().sum::<u8>() > 1 {
|
|
|
return Err(RoomCreationError::InvalidMode)
|
|
|
return Err(RoomCreationError::InvalidMode)
|
|
@ -174,14 +197,16 @@ impl RoomState { |
|
|
}
|
|
|
}
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
let ep = room_mode.episode();
|
|
|
|
|
|
Ok(RoomState {
|
|
|
Ok(RoomState {
|
|
|
mode: room_mode,
|
|
|
mode: room_mode,
|
|
|
name: String::from_utf16_lossy(&create_room.name).trim_matches(char::from(0)).into(),
|
|
|
name: String::from_utf16_lossy(&create_room.name).trim_matches(char::from(0)).into(),
|
|
|
password: create_room.password,
|
|
|
password: create_room.password,
|
|
|
//maps: [0; 0x20],
|
|
|
//maps: [0; 0x20],
|
|
|
maps: Maps::new(ep),
|
|
|
|
|
|
players: 1,
|
|
|
|
|
|
|
|
|
maps: Maps::new(room_mode.episode()),
|
|
|
|
|
|
difficulty: create_room.difficulty + 0x22,
|
|
|
|
|
|
players: 0,
|
|
|
|
|
|
episode: RoomState::get_episode(&room_mode),
|
|
|
|
|
|
flags: RoomState::get_flags(&room_mode, create_room.password),
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|