jake
5 years ago
6 changed files with 165 additions and 148 deletions
-
33src/ship/packet/builder/lobby.rs
-
40src/ship/packet/builder/mod.rs
-
77src/ship/packet/builder/room.rs
-
138src/ship/packet/handler/room.rs
-
21src/ship/room.rs
-
4src/ship/ship.rs
@ -1 +1,41 @@ |
|||
pub mod lobby;
|
|||
pub mod room;
|
|||
|
|||
use libpso::character::character::Inventory;
|
|||
use libpso::packet::ship::{PlayerHeader, PlayerInfo};
|
|||
use libpso::utf8_to_utf16_array;
|
|||
use crate::common::leveltable::CharacterLevelTable;
|
|||
use crate::ship::character::CharacterBytesBuilder;
|
|||
use crate::ship::ship::ClientState;
|
|||
use crate::ship::location::AreaClient;
|
|||
|
|||
pub fn player_header(tag: u32, client: &ClientState, area_client: &AreaClient) -> PlayerHeader {
|
|||
PlayerHeader {
|
|||
tag: tag,
|
|||
guildcard: client.user.id.0,
|
|||
_unknown1: [0; 5],
|
|||
client_id: area_client.local_client.id() as u32,
|
|||
name: libpso::utf8_to_utf16_array!(client.character.name, 16),
|
|||
_unknown2: 2,
|
|||
}
|
|||
}
|
|||
|
|||
pub fn player_info(tag: u32, client: &ClientState, area_client: &AreaClient, level_table: &CharacterLevelTable) -> PlayerInfo {
|
|||
let (level, stats) = level_table.get_stats_from_exp(client.character.char_class, client.character.exp);
|
|||
let character = CharacterBytesBuilder::new()
|
|||
.character(&client.character)
|
|||
.stats(&stats)
|
|||
.level(level - 1)
|
|||
.build();
|
|||
PlayerInfo {
|
|||
header: player_header(tag, client, area_client),
|
|||
inventory: Inventory {
|
|||
item_count: client.inventory.count() as u8,
|
|||
hp_mats_used: 0, // TODO: materials
|
|||
tp_mats_used: 0, // TODO: materials
|
|||
language: 0, // TODO: account language
|
|||
items: client.inventory.as_client_inventory_items(),
|
|||
},
|
|||
character: character,
|
|||
}
|
|||
}
|
@ -0,0 +1,77 @@ |
|||
use std::collections::HashMap;
|
|||
use libpso::packet::ship::*;
|
|||
use crate::common::serverstate::ClientId;
|
|||
use crate::common::leveltable::CharacterLevelTable;
|
|||
use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Clients};
|
|||
use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder};
|
|||
use crate::ship::location::{ClientLocation, RoomId, AreaClient};
|
|||
use crate::entity::character::CharacterEntity;
|
|||
use crate::ship::items::ActiveInventory;
|
|||
use crate::ship::room::RoomState;
|
|||
use crate::ship::packet::builder::{player_header, player_info};
|
|||
use libpso::character::character::{Inventory, InventoryItem};
|
|||
use libpso::utf8_to_utf16_array;
|
|||
|
|||
pub fn join_room(id: ClientId,
|
|||
clients: &Clients,
|
|||
client_location: &ClientLocation,
|
|||
room_id: RoomId,
|
|||
room: &RoomState)
|
|||
-> Result<JoinRoom, ShipError> {
|
|||
let all_clients = client_location.get_clients_in_room(room_id).map_err(|err| ShipError::ClientError(format!("{:?}", err)))?;
|
|||
let players = all_clients.iter()
|
|||
.enumerate()
|
|||
.fold(Ok([PlayerHeader::default(); 4]), |acc, (i, c)| {
|
|||
let header_client = clients.get(&c.client).ok_or(ShipError::ClientNotFound(id))?;
|
|||
let header_area_client = client_location.get_local_client(id).map_err(|err| ShipError::ClientError(format!("{:?}", err)))?;
|
|||
acc.map(|mut a| {
|
|||
a[i] = player_header(0x10000, &header_client, &header_area_client);
|
|||
a
|
|||
})
|
|||
})?;
|
|||
|
|||
let area_client = client_location.get_local_client(id).map_err(|err| ShipError::ClientError(format!("{:?}", err)))?;
|
|||
let leader = client_location.get_room_leader(room_id).map_err(|err| ShipError::ClientError(format!("{:?}", err)))?;
|
|||
Ok(JoinRoom {
|
|||
flag: all_clients.len() as u32,
|
|||
maps: room.maps.map_headers(),
|
|||
players: players,
|
|||
client: area_client.local_client.id(),
|
|||
leader: leader.local_client.id(),
|
|||
one: 1,
|
|||
difficulty: room.mode.difficulty().into(),
|
|||
battle: room.mode.battle(),
|
|||
event: 0,
|
|||
section: room.section_id.into(),
|
|||
challenge: room.mode.challenge(),
|
|||
random_seed: room.random_seed,
|
|||
episode: room.mode.episode().into(),
|
|||
one2: 1,
|
|||
single_player: room.mode.single_player(),
|
|||
unknown: 0,
|
|||
})
|
|||
}
|
|||
|
|||
|
|||
pub fn add_to_room(id: ClientId,
|
|||
client: &ClientState,
|
|||
area_client: &AreaClient,
|
|||
leader: &AreaClient,
|
|||
level_table: &CharacterLevelTable,
|
|||
room_id: RoomId,
|
|||
)
|
|||
-> Result<AddToRoom, ShipError> {
|
|||
|
|||
Ok(AddToRoom {
|
|||
flag: 1,
|
|||
client: area_client.local_client.id(),
|
|||
leader: leader.local_client.id(),
|
|||
one: 0, // TODO: ????????
|
|||
lobby: 0xFF,
|
|||
block: 0,
|
|||
event: 0,
|
|||
padding: 0,
|
|||
playerinfo: player_info(0x10000, client, &area_client, level_table),
|
|||
})
|
|||
}
|
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue